Arrays Matlab多项式拟合

Arrays Matlab多项式拟合,arrays,matlab,Arrays,Matlab,我想要一个步长为0.5的-2到2的向量,它将被保存为x。下一步,我想要y=3*x^3+3*x+6 当我做x=linspace(-2,3,9)时,我得到 但编译器仍然抱怨: 错误使用^ Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform elementwise matrix powers, use '.^

我想要一个步长为0.5的-2到2的向量,它将被保存为x。下一步,我想要y=3*x^3+3*x+6

当我做x=linspace(-2,3,9)时,我得到

但编译器仍然抱怨: 错误使用^

Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform elementwise matrix powers, use '.^'.
在幂号之前用一个点(.)就行了。这是因为你要对整个矩阵使用幂号,你需要做元素操作

x=linspace(-2,3,9)
y=3*x.^3+3*x+6

您需要执行elementwise.^操作(请参阅错误消息)。 matlab中有两种类型的操作。通常的矢量运算(*,/,^)及其元素对应运算(.*,./,.^)

当使用标量时,这并不重要,但只要在向量或矩阵上运行,操作就会改变


寻找更深入的解释。

不是dot产品。
x=linspace(-2,3,9)
y=3*x.^3+3*x+6