Graphics Programs Reference
In-Depth Information
Solving Linear Systems
Suppose
A
is a nonsingular
n
×
n
matrix and
b
is a column vector of length
n
.
Then typing
x=A\b
numerically computes the unique solution to
A*x=b
.
Type
help mldivide
for more information.
If either
A
or
b
is symbolic rather than numeric, then
x=A\b
computes
the solution to
A*x=b
symbolically. To calculate a symbolic solution when
bothinputs are numeric, type
x = sym(A)\b
.
Calculating Eigenvalues and Eigenvectors
The eigenvalues of a square matrix
A
are calculated with
eig(A)
. The com-
mand
[U, R] = eig(A)
calculates boththe eigenvalues and eigenvectors.
The eigenvalues are the diagonal elements of the diagonal matrix
R
, and the
columns of
U
are the eigenvectors. Here is an example illustrating the use of
eig
:
>>A=[3-20;2-20;011];
>> eig (A)
ans =
1
-1
2
>> [U, R] = eig(A)
U=
0
-0.4082
-0.8165
0
-0.8165
-0.4082
1.0000
0.4082
-0.4082
R=
1
0
0
0
-1
0
0
0
2
The eigenvector in the first column of
U
corresponds to the eigenvalue
in the first column of
R
, and so on. These are numerical values for the
eigenpairs. To get symbolically calculated eigenpairs, type
[U, R] =
eig(sym(A))
.
Search WWH ::
Custom Search