English 中文(简体)
Difference between MATLAB s matrix notations
原标题:

How do you read the following MATLAB codes?

#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

where

A =

     2     1
     1     1
最佳回答

In your second case p,d=eig(A) MATLAB is merely printing the previously calculated value of p from case 1 and then running the command d=eig(A).

Before running case 2 try

>> clear p d

If you then run p,d=eig(A) it will return an error saying that p is undefined function or variable.

From 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.

Note there is no V,D = EIG(X) option. MATLAB functions that return more than one value will group them using the format:

[ ] = function()
问题回答
p,d=eig(A) 

is the same as

p
d=eig(A)




相关问题
Matrix to Represent a Triangle in Screen Space

So i have a set of four points in 3D Space. P1 [0, 0, 0] P2 [128, 0, 0] P3 [0, 128, 0] P4 [128, 128, 0] Which I m then projecting orthographically to the screen effectively giving me two ...

Multiply a 3D matrix with a 2D matrix

Suppose I have an AxBxC matrix X and a BxD matrix Y. Is there a non-loop method by which I can multiply each of the C AxB matrices with Y?

matrix and vector template classes in c++

#include <array> template <typename T> class Vector4<T> { std::array<T, 4> _a; // or T _a[4]; ? }; template <typename T> class Matrix4<T> { std::array<...

Linear Independence Matrix

Suppose we have a m by n matrix A with rank m and a set K⊆{1..n} such that the columns of A indexed by K are linearly independent. Now we want to extend K and find a set L so that k⊆L and columns ...

Difference between MATLAB s matrix notations

How do you read the following MATLAB codes? #1 K>> [p,d]=eig(A) // Not sure about the syntax. p = 0.5257 -0.8507 -0.8507 -0.5257 d = ...

Strange error when using sparse matrices and glmnet

I m getting a weird error when training a glmnet regression. invalid class "dgCMatrix" object: length(Dimnames[[2]]) must match Dim[2] It only happens occasionally, and perhaps only under larger ...

Java large datastructure for storing a matrix

I need to store a 2d matrix containing zip codes and the distance in km between each one of them. My client has an application that calculates the distances which are then stored in an Excel file. ...

Checking row and column for a word in python

I am trying to create a checking program to see if the word is in a matrix horizontally or vertically. I have the code for checking the row, but would checking the column be similar to the row code? ...

热门标签