文档视界 最新最全的文档下载
当前位置:文档视界 › matalb矩阵计算(MATLAB矩阵计算)

matalb矩阵计算(MATLAB矩阵计算)

matalb矩阵计算(MATLAB矩阵计算)
matalb矩阵计算(MATLAB矩阵计算)

matalb矩阵计算(MATLAB矩阵计算)matalb矩阵计算(MATLAB矩阵计算)

4.1 array operations and matrix operations

From the appearance of the shape and structure of the data matrix, two-dimensional array and no difference in mathematics. However, as the embodiment of a matrix transformation or mapping operator matrix with mathematical rules, clear and strict. And array operation is defined by the software of MATLAB rules, its purpose is for data management, simple operation. The instruction form nature and perform calculations effectively. Therefore, when using MATLAB, in particular to a clear distinction between clear array operations and matrix operations. Table 4.1.1 lists the similarities and differences between the essence and connotation of two kinds of operation instruction.

4.1.1 array operations and matrix operations, instruction forms and substantive meaning

Array operation

Matrix operation

instructions

Meaning

instructions

Meaning

A.'

Non conjugate transpose

A'

Conjugate transpose

A=s

Assign scalar s to each element of the array A

S+B

Add scalar s to each element of the array B, respectively

S-B, B-s

The difference between the scalar s and the elements of the array B S.*A

Scalar s is the product of the elements of the array A, respectively S*A

The product of the scalar s and the elements of the matrix A, respectively

S./B, B.\s

Scalar s is separated by the elements of array B, respectively

S*inv (B)

Inverse multiplicative scalar B of matrix s

A.^n

The N sub order of each element of the array A

A^n

When A is a square matrix, the n power of the matrix A

A+B

The addition of an array corresponding element

A+B

matrix addition

A-B

Subtracting elements of an array

A-B

Matrix subtraction

A.*B

Multiplication of an array corresponding element

A*B

The product of the same matrix Neville

A./B

The elements of A are excluded by the corresponding elements of B A/B

A right, except B

B.\A

It must be the same

B\A

A left except

B (usually different from right division)

Exp (A)

For the end to e respectively with A elements as index, exponentiation

Expm (A)

Matrix exponential function of A

Log (A)

The logarithm of the elements of A

Logm (A)

The matrix logarithmic function of A

Sqrt (A)

The square root of the elements of the product of A

Sqrtm (A)

A's square function of matrices

From the above we can see that the array operations such as multiplication, addition, multiplication, transpose, add "points". Therefore, we should pay special attention to "multiply, divide, involution, trigonometric and exponential function", two operations are fundamentally different. In addition, in the implementation of the array and array operation when the array must be involved in computing Tongwei, the result is always with the original array array dimensions.

4.2 basic operations of an array

In MATLAB, an array operation is a.MATLAB that uses the same calculation for multiple numbers to process arrays in a very intuitive way

4.2.1 point transpose and conjugate transpose

` - dot transpose. Non conjugate transpose, equivalent to conj (A') A=1:5;

'b=a.'

= b

One

Two

Three

Four

Five

'c=b.'

= C

12345

This shows that the two transpose of the row vector yields the original row vector

Conjugate transpose. Transpose the vectors and conjugate each element:

D=a+i*a

= D

Columns 1 through 3

1 + 1.0000i

2 + 2.0000i

3 + 3.0000i

Columns 4 through 5

4 + 4.0000i

5 + 5.0000i

E=d'

= e

1 - 1.0000i

2 - 2.0000i

3 - 3.0000i

4 - 4.0000i

5 - 5.0000i

4.2.2 scalar (scalar) and four operations of an array

Simple mathematical operations can be performed between scalar and array, such as addition, subtraction, multiplication, division, and mixing operations

"G=[1 234"

5678

91011 12]

G=g-2

= g

-1 012

3456

78910

2*g-1

= ans

-3 -1 13

57911

13151719

Four operations between 4.2.3 arrays

In MATLAB, the array between the four operations, an array of participating in operation must have the same dimension, subtraction, multiplication, addition, operation is carried out according to the elements and elements forms. Among them, the array between the addition, subtraction and matrix addition, subtraction to the same operator, as: "+" "-". However, the array multiplication, division and matrix multiplication, division operation symbol is completely different, there

are differences, between the array multiplication and division operators: "*", "/" or ".".

1. array by element add, minus

"G=[1 234"

5678

91011 12]

"H=[1 111; 2222; 333; 3]"

> g+h% added by element

= ans

2345

78910

12131415

> ans-h%, subtract by element

= ans

1234

5678

9 10 11 12

> > > > > > > 2 g / h) 混合运算

years.

1 3 5 7

8 10 12 14

15 17 19 21

2. 按元素乘

> > > > > > > g * h

years.

1 2 3 4

10 12 14 16

27 30 33 36

3. 按元素除

数组间的除法运算符有两个, 即左除 "/" 和右除 "." 它们之间的关系是.

a /

b = b.

> > > > > > > g / h

years.

1.0000

2.0000

3.0000

4.0000

2.5000

3.0000

4.1000 4.0000

3.0000 3.3333 3.6667

4.0000

"h \ g

years.

1.0000

2.0000

3.0000

4.0000

2.5000

3.0000

4.1000 4.0000

3.0000 3.3333 3.6667

4.0000

幂运算.

在matlab中, 数组的幂运算的运算为 "." 表示每一个元素进行幂运算. > > > > > > > (2% 数组g每个元素的平方.

years.

1 4 9 4

25, 36, 49, 64

81% (144

> > > > > > > g ^ (- 1)) 数组g的每个元素的倒数

years.

1.0000 0.5000 0.3333 0.2500

0.2000 0.1667 0.1429 0.1250

0.1111 0.1000 0.0909 0.0833

> > > > > > > 2 g%, 以g的每个元素为指数对2进行乘方运算.

years.

2 4 8 16

32, 64, 128, 256

512 1024, 2048, 4096

> > > > > > > "h% 以h的每个元素为指数对g中相应元素进行乘方运算.

years.

1 2 3 4

25, 36, 49, 64

729 1000, 1728

> > > > > > > (h - 1).

years.

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

5 6 7 8

81% (144

- 数组的指数, 对数和开方运算

在matlab中, 所谓数组的运算实质是是数组内部每个元素的运算, 因此, 数组的指数, 对数和开方运算与标量的运算规则完全是一样的, 运算符函数分别为: exp () log (), () must 等.

> > a = [1, 3, 4, 5, 2, 6, 3, 2, 4].

> > > > > > > c = exp (a)

c =

2.7183 20.0855 54.5982

7.3891 403.4288 148.4132

20.0855 7.3891 54.5982

> > > > > > > > > > > >

数组的对数, 开方运算与数组的指数运算, 其方式完全一样, 这里不详述.

向量运算.

对于一行或一列的矩阵, 为向量, matlab有专门的函数来进行向量点积, 叉积

和混合积的运算.

the 向量的点积运算

在高等数学中, 我们知道, 两向量的点积指两个向量在其中一个向量方向上的

投影的乘积, 通常用来定义向量的长度.在matlab中, 向量的点积用函数 "dot"

来实现, 其调用格式如下.

c = dot (a, b) - 返回向量a与b的点积, 结果存放于c中.

c = dot (a, b, d) - 返回向量a与b在维数为dim的点积, 结果存放于c中.

> > a = [4 2 5 3 1).

> > b = (3 8 10 12 13].

> > > > > > > c = (a, b).

c =

137

> > > > > > > c = dot (a, b, (4)

c =

32 50 36 13 6

a 向量的叉积运算

在高等数学中, 我们知道, 两向量的叉积返回的是与两个向量组成的平面垂直的向量.在matlab中, 向量的点积用函数 cross 来实现, 其调用格式如下.

c = cross (a, b) - 返回向量a与b的叉积, 即, 结果存放于c中.

c = cross (a, b, d) - 返回向量a与b在维数为dim的叉积, 结果存放于c 中.

> > a = [2, 5].

> > b = [3, 10].

> > > > > > > c = cross (a, b)

c =

0 - 5 4

these 向量的混合运算

> > > > > > > d = dot (a, cross (b, c))

d =

41

上例表明, 首先进行的是向量b与c的叉积运算, 然后再把叉积运算的结果与向量a进行点积运算.

4.4 矩阵的基本运算

如果说matlab的最大特点是强大的矩阵运算功能, 此话毫不为过.事实上, matlab中所有的计算都是以矩阵为基本单元进行的.matlab对矩阵的运算功能最全面, 也是最为强大的.矩阵在形式上与构造方面是等同于前面所述的数组的, 当其数学意义却是完全不同的.

矩阵的基本运算包括矩阵的四则运算, 矩阵与标时的运算, 矩阵的幂运算, 指数运算, 对数运算, 开方运算及以矩阵的逆运算, 行列式运算等.

it 矩阵的四则运算

矩阵的四则运算与前面介绍的数组的四则运算基本相同.但也有一些

差别.

1. 矩阵的加减

The addition and subtraction of a matrix is exactly the same as the addition and subtraction of an array, which requires the exact size of the two matrix to be exactly the same

"A=[1 2; 35; 2; 6]";

"B=[2 4; 18; 9; 0]";

C=a+b

= C

36

413

116

Multiplication of 2. matrices

For the multiplication of matrices, from linear algebra, we know that the two matrices required to be multiplied have the same common dimension as:

"A=[1 2; 35; 2; 6]";

"B=[2 41; 89, 0]";

C=a*b

= C

18221

46573

52622

A A matrix is a matrix order, will require

B matrix multiplication and must be an order, get the matrix order. That is, only when the first matrix (left column matrix) is equal to the number of second matrices (right matrix) the number of rows, the product of two matrices is meaning.

Division of 3. matrices

For the division of a matrix, there are two arithmetic symbols, namely "left" except "symbol" and "right" except "sign" / "." the right division of the matrix is slower, and the "left" operation can avoid the influence of singular matrix

For the equation, if this equation is overdetermined equation, then use division can automatically find the solution of minimizing square. If the equation is Diophantine equation, is used to solve the division operator at least at most rank (A)

(rank of matrix A) non zero elements, and the solution of this type of in the solution of a minimum norm.

"A=[21 3420; 57820; 211417; 3431; 38]";

"B=[10 2030, 40]'";

X=b\a

= x

0.7667, 1.1867, 0.8767

The above equation is overdetermined. Note that the resulting matrix X is column vector,

"A=[21 34205; 78202114; 173431; 38]";

"B=[10 20, 30]'";

X=b\a

= x

1.6286, 1.2571, 1.1071, 1.0500

The equation above is an indeterminate equation

Four operations between 4. matrices and scalars

The four operations and the four operations of scalar matrix

and array and scalar between identical, i.e. each element in the matrix and scalar add, subtract, multiply, with the exception of the four operations. That is, when a division operation is performed, the scalar can only do the dividend.

Power operation of 5. matrices

The power operation of a matrix is different from the power operation of a scalar. Using the symbol ^, it is not a power operation for each element of the matrix, but is related to some decomposition of the matrix

"B=[21 3420; 782021; 1734; 31]";

C=b^2

= C

343320741754

355537662631

353623122015

6. matrix index, logarithmic and square root operation

The index matrix calculation, logarithmic and square root operations and an array of the corresponding operations are different. It is not a single element in the matrix operations, but for the whole matrix. These operations function as follows:

Expm, expm1, expm2, expm3 - exponential arithmetic functions;

Logm - logarithmic function;

Sqrtm - root operation function.

"A=[1 34; 265; 32; 4]";

> c=expm (a)

= C

1.0e+004 *

0.4668, 0.7694, 0.9200

0.7919, 1.3065, 1.5613

0.4807, 0.7919, 0.9475

> c=logm (a)

= C

0.5002 + 2.4406i 0.5960 - 0.6800i 0.7881 - 1.2493i

0.4148 + 0.4498i 1.4660 - 0.1253i 1.0108 - 0.2302i

0.5780 - 1.6143i 0.4148 + 0.4498i 1.0783 + 0.8263i

> c=sqrtm (a)

= C

0.6190 + 0.8121i 0.8128 - 0.2263i 1.1623 - 0.4157i

0.3347 + 0.1497i 2.3022 - 0.0417i 1.1475 - 0.0766i

1.0271 - 0.5372i 0.3347 + 0.1497i 1.6461 + 0.2750i

Transpose, inverse operation and determinant operation of 7.

matrices

The transpose operator of the matrix is', 'and the inverse uses the arithmetic function: inv (), and uses the function: det () to determine the size of the determinant of the matrix

"A=[1 20; 25-1; 410; -1]";

C=a'

= C

124

2510

0-1 -1

> b=inv (a)

= b

52 -2

-2 -1 1

0 -2 1

> d=det (a)

= D

One

Special operations of 4.5 matrices

The special operations of matrix include matrix eigenvalue operation, conditional number operation, singular value operation, norm operation,

rank operation, orthogonalization operation, trace operation, pseudo inverse operation, etc. these operations can be conveniently given by MATLAB

Eigenvalue operations of 4.5.1 matrices

In linear algebra, it is very complicated to compute the eigenvalues of matrices. In MATLAB, the matrix eigenvalue operations are computed only by the function eig () or eigs (). The format is as follows E=eig (X) - generates a column vector consisting of the eigenvalues of the matrix X;

[V, D]=eig (X) - generates two matrices V and D, where V is a matrix consisting of the eigenvectors of the matrix X as the column vectors, and D is the diagonal matrix made up of the eigenvalues of the matrix X as the main diagonal elements

The eigs () function uses the iterative method to solve the eigenvalues and eigenvectors of the matrix

D=eigs (X) - generating a column vector consisting of eigenvalues of matrix.X, X must be square, preferably large sparse matrix;

[V, D]=eigs (X) - generates two matrices V and D, where V is a matrix consisting of the eigenvectors of the matrix X as the column vectors, and D is the diagonal matrix made up of the eigenvalues of the matrix X as the main diagonal elements

"A=[1 20; 25-1; 410; -1]";

[b, c]=eig (a)

= b

-0.2440 -0.9107 0.4472

-0.3333 0.3333 0

-0.9107 -0.2440 0.8944

= C

3.732100

0.26790

1

Norm operations of 4.5.2 matrices (vectors)

In order to reflect the characteristics of some matrix (vector), the norm of the concept of linear algebra, it is divided into 2- norm, 1- norm, infinite norm and Frobenius norm. In MATLAB, norm (or normest)

with the function () matrix (vector) norm. The format is as follows.

Norm (X) -- the 2- norm of the matrix (vector) X;

Norm (X, 2) - ibid;

Norm (X, 1) - compute the 1- norm of the matrix (vector) X;

Norm (X, INF) -- the infinite norm of the matrix (vector) X;

Norm (X,'fro') - compute the Frobenius norm of the matrix (vector) X;

Normest (X) -- only the 2- norm of the matrix (vector) X is computed, and the estimate of the 2- norm is applied to the computation of norm (X), which is time-consuming

"X=hilb (4)"

= X

1, 0.5000, 0.3333, 0.2500

0.5000, 0.3333, 0.2500, 0.2000

0.3333, 0.2500, 0.2000, 0.1667

0.2500, 0.2000, 0.1667, 0.1429

"Norm (4)"

= ans

Four

> norm (X)

= ans

One point five Zero Zero two

"Norm (X, 2)

= ans

One point five Zero Zero two

"Norm (X, 1)

= ans

Two point zero eight three three

> norm (X, INF)

= ans

Two point zero eight three three

> norm (X,'fro')

= ans

One point five zero nine seven

> normest (X)

= ans

One point five Zero Zero two

Conditional number operation of 4.5.3 matrix

The condition number of a matrix is a quantity of the "morbid" degree of the judgement matrix. The larger the condition number of the matrix A, the more morbid the A is, and conversely, the more "good" state of the A, for example, the Hilbert matrix is a well-known ill conditioned matrix

Cond (X) - the condition number of the 2- norm of the return matrix X;

Cond (X, P) - returns the conditional number of the P- norm of the matrix X, where P is 1,2, inf or fro;

Rcond (X) - the inverse value used to compute the condition number

of a matrix. When the matrix X is ill conditioned, rcond (X) is close to 0 and X is "good", and rcond (X) is close to 1.

Condest (X) - calculates the estimate of the condition number of the 1- norm of the matrix X

"M=magic (3)"

= M

816

357

492

"H=hilb (4)"

= H

1, 0.5000, 0.3333, 0.2500

0.5000, 0.3333, 0.2500, 0.2000

0.3333, 0.2500, 0.2000, 0.1667

相关文档