matlab计算功能介,第四章 MATLAB的数值计算功能(三)

三. 逆矩阵及行列式(Revers and determinant

of matrix)

1. 方阵的逆和行列式(Revers and determinant of square

matrix)

若a是方阵,且为非奇异阵,则方程ax=I和

xa=I有相同的解X。X称为a的逆矩阵,记做a-1,在MATLAB中

用inv 函数来计算矩阵的逆。计算方阵的行列式则用det函数。

DET Determinant.

DET(X) is the determinant of the square matrix X.

Use COND

instead of DET to test for matrix singularity.

INV  Matrix

inverse.

INV(X) is the inverse of the square matrix X. A warning message

is printed if X is badly scaled or nearly singular.

例:计算方阵的行列式和逆矩阵。

a=[3 -3 1;-3 5 -2;1 -2 1];

b=[14 13 5;

5 1 12;6 14 5];

d1=det(a)

x1=inv(a)

d2=det(b)

x2=inv(b)

d1 =

1

x1 =

1.0000 1.0000 1.0000

1.0000 2.0000 3.0000

1.0000 3.0000 6.0000

d2 =

-1351

x2 =

0.1207 -0.0037 -0.1118

-0.0348 -0.0296 0.1058

-0.0474 0.0873 0.0377

2. 广义逆矩阵(伪逆)(Generalized inverse matrix)

一般非方阵无逆矩阵和行列式,方程ax=I

和xa=I至少有一个无解,这种矩阵可以求得特殊的逆矩阵,成为广义逆矩阵(generalized

inverse matrix)(或伪逆

pseudoinverse)。矩阵amn存在广义逆矩阵xnm,使得

ax=Imn, MATLAB用pinv函数来计算广义逆矩阵。

例:计算广义逆矩阵。

a=[8 14; 1 3;

9 6]

x=pinv(a)

b=x*a

c=a*x

d=c*a

%d=a*x*a=a

e=x*c %e=x*a*x=x

a =

8 14

1 3

9 6

x =

-0.0661 -0.0402 0.1743

0.1045 0.0406 -0.0974

b =

1.0000 -0.0000

-0.0000 1.0000

c =

0.9334 0.2472 0.0317

0.2472 0.0817 -0.1177

0.0317 -0.1177 0.9849

d =

8.0000 14.0000

1.0000 3.0000

9.0000 6.0000

e =

-0.0661 -0.0402 0.1743

0.1045 0.0406 -0.0974

PINV  Pseudoinverse.

X = PINV(A) produces a matrix X of the same

dimensions as A' so that A*X*A = A, X*A*X = X and A*X and X*A are

Hermitian. The computation is based on SVD(A) and any singular

values less than a tolerance are treated as zero.

The

default tolerance is MAX(SIZE(A)) * NORM(A) * EPS.

PINV(A,TOL) uses the tolerance TOL instead of the default.

四. 矩阵分解(Matrix decomposition)

MATLAB求解线性方程的过程基于三种分解法则:

(1)Cholesky分解,针对对称正定矩阵;

(2)高斯消元法, 针对一般矩阵;

(3)正交化, 针对一般矩阵(行数≠列数)

这三种分解运算分别由chol, lu和 qr三个函数来分解.

1. Cholesky分解(Cholesky Decomposition)

仅适用于对称和上三角矩阵

例:cholesky分解。

a=pascal(6)

b=chol(a)

a =

1 1 1 1 1 1

1 2 3 4 5 6

1 3 6 10 15 21

1 4 10 20 35 56

1 5 15 35 70 126

1 6 21 56 126 252

b =

1 1 1 1 1 1

0 1 2 3 4 5

0 0 1 3 6 10

0 0 0 1 4 10

0 0 0 0 1 5

0 0 0 0 0 1

CHOL Cholesky

factorization.

CHOL(X) uses only the diagonal and upper triangle

of X. The lower triangular is assumed to be the (complex conjugate)

transpose of the upper. If X is positive

definite, then R = CHOL(X) produces an upper triangular R so that

R'*R = X. If X is not positive definite, an error message is

printed.

[R,p] = CHOL(X), with two output arguments, never produces

an

error message. If X is positive definite, then

p is 0 and R is the same as

above. But if X is not positive

definite, then p is a positive integer.

When X is

full, R is an upper triangular matrix of order q = p-1

so that

R'*R = X(1:q,1:q). When X is sparse, R is an upper triangular

matrix of size q-by-n so that the L-shaped region of the first q

rows and first q columns of R'*R agree with those of X.

2. LU分解(LU factorization).

用lu函数完成LU分解,将矩阵分解为上、下两个三角阵,其调用格式为:

[l,u]=lu(a)  l代表下三角阵,u代表上三角阵。

例:

LU分解。

a=[47 24 22;

11 44 0;30 38 41]

[l,u]=lu(a)

a =

47 24 22

11 44 0

30 38 41

l =

1.0000 0 0

0.2340 1.0000 0

0.6383 0.5909 1.0000

u =

47.0000 24.0000 22.0000

0 38.3830 -5.1489

0 0 30.0000

LU

LU

factorization.

[L,U] = LU(X) stores an upper triangular matrix in

U and a "psychologically lower triangular matrix" (i.e. a product

of lower triangular and permutation matrices) in L, so that X =

L*U. X can be rectangular.

[L,U,P] = LU(X) returns unit lower triangular

matrix L, upper triangular matrix U, and permutation matrix P so

that P*X = L*U.

3. QR分解(Orthogonal-triangular decomposition).

函数调用格式:[q,r]=qr(a),

q代表正规正交矩阵,r代表三角形矩阵。原始阵a不必一定是方阵。如果矩阵a是m×n阶的,则矩阵q是m×m阶的,矩阵r是m×n阶的。

例:QR分解.

A=[22 46 20 20; 30 36 46 44;39 8 45 2];

[q,r]=qr(A)

q =

-0.4082 -0.7209 -0.5601

-0.5566 -0.2898 0.7786

-0.7236 0.6296 -0.2829

r =

-53.8981 -44.6027 -66.3289 -34.1014

0 -38.5564 0.5823 -25.9097

0 0 11.8800 22.4896

QR

Orthogonal-triangular

decomposition.

[Q,R] = QR(A) produces an upper triangular matrix R of the

same

dimension

as A and a unitary matrix Q so that A = Q*R.

[Q,R,E] = QR(A) produces a permutation matrix E, an upper

triangular R and a unitary Q so that A*E = Q*R. The column

permutation E is chosen so that abs(diag(R)) is decreasing.

[Q,R] = QR(A,0) produces the "economy size"

decomposition. If A is m-by-n with m > n, then only the first n

columns of Q are computed.

4. 特征值与特征矢量(Eigenvalues and eigenvectors).

MATLAB中使用函数eig计算特征值和 特征矢量,有两种调用方法:

*e=eig(a), 其中e是包含特征值的矢量;

*[v,d]=eig(a),

其中v是一个与a相同的n×n阶矩阵,它的每一列是矩阵a的一个特征值所对应的特征矢量,d为对角阵,其对角元素即为矩阵a的特征值。

例:计算特征值和特征矢量。

a=[34 25 15;

18 35 9; 41 21 9]

e=eig(a)

[v,d]=eig(a)

a =

34 25 15

18 35 9

41 21 9

e =

68.5066

15.5122

-6.0187

v =

-0.6227 -0.4409 -0.3105

-0.4969 0.6786 -0.0717

-0.6044 -0.5875 0.9479

d =

68.5066 0 0

0 15.5122 0

0 0 -6.0187

EIG Eigenvalues and

eigenvectors.

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,'nobalance') performs the computation

with balancing

disabled,

which sometimes gives more accurate results for certain

problems

with unusual scaling. If X is symmetric, EIG(X,'nobalance')

is

ignored since X is already balanced.

5. 奇异值分解.( Singular value decomposition).

如存在两个矢量u,v及一常数c,使得矩阵A满足:Av=cu, A’u=cv

称c为奇异值,称u,v为奇异矢量。

将奇异值写成对角方阵∑,而相对应的奇异矢量作为列矢量则可写成两个正交矩阵U,V,

使得: AV=U∑, A‘U=V∑ 因为U,V正交,所以可得奇异值表达式:

A=U∑V’。

一个m行n列的矩阵A经奇异值分解,可求得m行m列的U,

m行n列的矩阵∑和n行n列的矩阵V.。

奇异值分解用svd函数实现,调用格式为;

[u,s,v]=svd(a)

SVD Singular value decomposition.

[U,S,V] = SVD(X) produces a diagonal matrix S, of

the same dimension as X and with nonnegative diagonal elements in

decreasing order, and unitary matrices U and V so that X =

U*S*V'.

S = SVD(X) returns a vector containing the singular values.

[U,S,V] = SVD(X,0) produces the "economy size"

decomposition. If X is m-by-n with m > n, then only the first n

columns of U are computed and S is n-by-n.

例: 奇异值分解。

a=[8 5; 7 3;4 6];

[u,s,v]=svd(a)

%

s为奇异值对角方阵

u =

-0.6841 -0.1826 -0.7061

-0.5407 -0.5228 0.6591

-0.4895 0.8327 0.2589

s =

13.7649 0

0 3.0865

0 0

v =

-0.8148 -0.5797

-0.5797 0.8148

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值