MATLAB矩阵表示法之间的区别

时间:2009-11-13 11:14:59

标签: matlab matrix

您如何阅读以下MATLAB代码?

#1

K>> [p,d]=eig(A)                     // Not sure about the syntax.

p =

    0.5257   -0.8507
   -0.8507   -0.5257


d =                               // Why do you get a matrix?

    0.3820         0                  
         0    2.6180

#2

K>> p,d=eig(A)                  // Not sure about the syntax.

p =

    0.5257   -0.8507
   -0.8507   -0.5257


d =                                       // Why do you get a vector?

    0.3820
    2.6180

,其中

A =

     2     1
     1     1

2 个答案:

答案 0 :(得分:18)

在第二种情况下,p,d=eig(A) MATLAB仅打印案例1中先前计算的p值,然后运行命令d=eig(A)

在运行案例2之前尝试

>> clear p d

如果然后运行p,d=eig(A),它将返回错误,指出p是未定义的函数或变量。

来自help eig

E = EIG(X) is a vector containing the eigenvalues of a square
matrix X.

[V,D] = EIG(X) produces a diagonal matrix D of eigenvalues and a
full matrix V whose columns are the corresponding eigenvectors so
that X*V = V*D.

注意没有V,D = EIG(X)选项。返回多个值的MATLAB函数将使用以下格式对它们进行分组:

[ ] = function()

答案 1 :(得分:3)

p,d=eig(A) 

相同
p
d=eig(A)