matlab中x.^2与x^2有什么区别?

.^2是矩阵中的每个元素都求平方,^2是求矩阵的平方或两个相同的矩阵相乘,因此要求矩阵为方阵,且看下面的例子
x=1:4
x =

1 2 3 4

x.^2

ans =

1 4 9 16

x^2

Error using ^
Inputs must be a scalar and a square matrix.
To compute elementwise POWER, use POWER (.^) instead.
x=[1 2;3 4]

x =

1 2

3 4
x^2

ans =

7 10

15 22
x.^2
ans =

1 4

9 16

猜你喜欢

转载自blog.csdn.net/yimixgg/article/details/82622184