matlab 矩阵 幂运算符,matlab基础知识(6):矩阵(2:数学运算,矩阵运算)
数学运算
加减法运算
只要直接相加相减即可。
乘法运算
1.数乘运算
A=[1,2,3;4,5,6];
5*A
ans =
5 10 15
20 25 30
2.矩阵乘法
A=[1,2,3;4,5,6];
B=[1,2;3,4;5,6];
A*B
ans =
22 28
49 64
3.矩阵点乘
将矩阵的相同位置的元素进行相乘运算
A=[1,2;3,4];
B=[1,2;3,4];
A.*B
ans =
1 4
9 16
除法运算
1.左除运算A\B
此时A的行数必须与B的行数一致,解相当于A*X=B方程组的解
A=[1,-1;1,1];
B=[1;3];
A\B
ans =
2
1
A.\B
ans =
1 -1
3 3
注意到“.\‘符号代表的是对应元素相除。
2.右除运算B\A
此时A的列与B的列相等,解相当于X*B=A的解
A =
8 1 6
3 5 7
4 9 2
B=[1,2,3;3,4,5];
A/B
ans =
-4.5000 3.5000
1.5000 0.5000
-4.5000 3.5000
矩阵运算
矩阵求幂
矩阵的幂运算是将矩阵中每个元素进行乘方运算,用".^"表示。
A=[1,2,3;2,3,4];
A.^2
ans =
1 4 9
4 9 16
矩阵求逆
使用inv()命令来进行求逆
A=magic(3)
A =
8 1 6
3 5 7
4 9 2
B=inv(A)
B =
0.1472 -0.1444 0.0639
-0.0611 0.0222 0.1056
-0.0194 0.1889 -0.1028
矩阵范数和条件数
1.矩阵的范数
矩阵的范数是向量或者矩阵大小的一种度量,对于向量

,有:
x的

-范数:

x的1-范数:

x的2-范数:

对于矩阵

,常用矩阵范数如下:
A的行范数(

-范数):

A的列范数(1-范数):

A的欧式范数(2-范数):

,其中

为矩阵的最大特征值。
通过调用norm函数来计算矩阵的范数其语法格式为norm(A,p)其中当参数p取值为2时,则对应的是2-范数;此外在不希望获得精确结果的情况下(例如需要快速估算)可以使用normest(A)来代替
A=[1,2,3;4,5,6;7,8,9];
norm(A,1)
ans =
18
norm(A,2)
ans =
16.8481
norm(A)
ans =
16.8481
normest(A)
ans =
16.8481
2.矩阵的条件数
The condition number of a matrix measures its degree of ill-conditioning. Typically, a matrix is considered ill-conditioned if it is extremely sensitive to small perturbations in the initial values. The condition number, denoted as cond(A,p), serves as a measure of this property, aligning with the principles used in norm functions.
cond(A,1)
ans =
4.5396e+17
cond(A,2)
ans =
5.0523e+16
cond(A)
ans =
5.0523e+16
condest(A)
ans =
4.5396e+17

