MATLAB矩阵表示法之间的区别

Léo*_* 준영 1 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
Run Code Online (Sandbox Code Playgroud)

#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
Run Code Online (Sandbox Code Playgroud)

哪里

A =

     2     1
     1     1
Run Code Online (Sandbox Code Playgroud)

Adr*_*ian 18

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

在运行案例2之前尝试

>> clear p d
Run Code Online (Sandbox Code Playgroud)

如果你然后运行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.
Run Code Online (Sandbox Code Playgroud)

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

[ ] = function()
Run Code Online (Sandbox Code Playgroud)