当前位置:网站首页>【Matlab】矩阵变换与矩阵求值
【Matlab】矩阵变换与矩阵求值
2022-06-12 23:46:00 【不牌不改】
矩阵变换与矩阵求值
对角矩阵:只有对角线上有非零元素的矩阵。
数量矩阵:对角线上的元素相等的对角矩阵。
单位矩阵:对角线上的元素都为1的对角矩阵。
diag函数
提取矩阵的对角线元素
diag(A):提取矩阵A主对角线元素,产生一个列向量。
diag(A,k):提取矩阵A第k条对角线的元素,产生一个列向量。
构造对角矩阵
diag(V):以向量V为主对角线元素,产生对角矩阵。
diag(V,k):以向量V为第k条对角线元素,产生对角矩阵。
上三角阵:矩阵的对角线以下的元素全为零的矩阵。
下三角阵:对角线以上的元素全为零的矩阵。
triu函数与tril函数
triu(A):提取矩阵A的主对角线及以上的元素。
triu(A,k):提取矩阵A的第k条对角线及以上的元素。
得到的矩阵与原矩阵A同型,未被提取的元素所在位置为0。
在MATLAB中,提取矩阵A的下三角矩阵的函数是tril,其用法与triu函数完全相同。
转置
在矩阵后加单引号'
实现转置。会这一种用法即可。
旋转
rot90(A,k):将矩阵A逆时针方向旋转90°的k倍,当k为1时可省略。
翻转
fliplr(A):对矩阵A实施左右翻转。
flipud(A):对矩阵A实施上下翻转。
通过翻转可以实现分别求主副对角线之和。
inv函数
求逆矩阵,一般用于解线性方程组。
det函数
把一个方阵看作一个行列式,并对其按行列式的规则求值,这个值就称为方阵所对应的行列式的值。
det(A):求方阵A所对应的行列式的值。
rank函数
矩阵线性无关的行数或列数称为矩阵的秩。
rank(A):求矩阵A的秩。
for i = 3:20
r(i) = rank(magic(i));
end
bar(r) % 柱状图,索引为x轴坐标,值为y轴坐标
grid on % 生成网格
axis([2, 21, 0, 20]) % 设置xy轴范围
没用的结论:
奇数阶魔方阵秩为n,即奇数阶魔方阵是满秩矩阵。
一重偶数阶魔方阵秩为n/2+2( n是2的倍数,但非4的倍数)。
双重偶数阶魔方阵秩均为3(阶数是4的倍数)。
axis( [xmin xmax ymin ymax] )
设置当前坐标轴 x轴 和 y轴的限制范围
axis off
去掉坐标轴
V=axis
返回包含当前坐标范围的一个行向量
axis ij
将坐标轴设置为矩阵模式。此时水平坐标轴从左到右取值,垂直坐标从上到下
axis equal
设置屏幕高宽比,使得每个坐标轴的具有均匀的刻度间隔
axis square
将坐标轴设置为正方形
trace函数
矩阵的迹等于矩阵的对角线元素之和,也等于矩阵的特征值之和。
trace(A):求矩阵A的迹。
trace(A)
sum(diag(A))
% 二者等价
eig函数
E=eig(A)∶求矩阵A的全部特征值,构成向量E。
[X,D]=eig(A)∶求矩阵A的全部特征值,构成对角阵D,并产生矩阵X,X各列是相应的特征向量。
A = [1 1 0; 1 0 5; 1 10 2];
[X D] = eig(A)
结果如下:
X =
0.0722 0.9751 0.0886
0.5234 -0.0750 -0.6356
0.8490 -0.2089 0.7669
D =
8.2493 0 0
0 0.9231 0
0 0 -6.1723
D中的主对角线上的数为特征值,每一列的特征值对应的特征向量为X中的同列元素。
即,8.2493对应的特征向量为(0.0722 0.5234 0.8490)。
验证如下:
A = [1 1 0; 1 0 5; 1 10 2];
[X D] = eig(A);
D = ones(length(D)) * D
roundn(A*X, -4) == roundn(D.*X, -4)
结果如下:
D =
8.2493 0.9231 -6.1723
8.2493 0.9231 -6.1723
8.2493 0.9231 -6.1723
ans =
3×3 logical 数组
1 1 1
1 1 1
1 1 1
先将D的每一列元素都设置为所在列对应的特征值,让D方阵左乘一个全1方阵即可。
根据特征值和特征向量的定义, A x = λ x Ax = \lambda x Ax=λx;
左侧:将A方阵与X矩阵进行矩阵乘法,即*
;
右侧:将新得到的D矩阵与X矩阵对应位置相乘,即.*
;
判断二者对应位置是否相等即可。
但需要注意,二者计算得到的都是浮点数,存在一定的精度误差,所以直接判等是不相等的,因此我们保留小数点后四位,再进行判等,得到全1的逻辑矩阵。
roundn函数讲解
roundn函数是四舍五入函数,调用格式为:roundn(number, n)
或roundn(A, n)
。其中number
和A
分别表示数字和由数字构成的矩阵,n
表示要保留的位数,当n
为正数时表示四舍五入保留到小数点前第几位,当n
为负数时表示四舍五入保留到小数点后第几位。
边栏推荐
- For product managers, which of the two certificates, PMP and NPDP, is more authoritative?
- It is meaningful to define genus, and D can use it to explain semantics
- NCF 的Dapr应用实例的运行
- Pytorch common parameter initialization methods: [uniform distribution, normal (Gaussian) distribution, Xavier, Kaiming, orthogonal matrix, sparse matrix, constant, identity matrix, zero filling]
- Redis realizes SMS verification code login
- TCP与UDP
- 如何实现OSM地图本地发布并自定义配图
- Deep feature synthesis and genetic feature generation, comparison of two automatic feature generation strategies
- leaflet中如何优雅的解决百度、高德地图的偏移问题
- KConfig
猜你喜欢
數組
How to package a colorpicker component for color selection?
SAP QM qp03 displays an inspection plan with multiple specs inspection features
CS for mobile security [nethunter]
[opencv learning] perspective transformation matrix
leaflet如何加载10万条数据
Chapter 8 - shared model JUC
Develop a web office suite from scratch (5): mouse hover over text
Test platform series (97) perfect the case part
线上真实排队系统重构案例分享——实战篇
随机推荐
2022 questions d'examen pour le personnel de gestion de la sécurité de l'unit é de gestion des produits chimiques dangereux et examen de simulation en ligne
Pytorch loading model error resolution
Gradient accumulation in pytorch [during the experiment, due to the limitation of GPU video memory, the batch\u size can no longer be increased. To solve this problem, the gradient accumulation method
Talent Weekly - 5
SAP 业务技术平台(BTP) Workflow(工作流)功能介绍
Hongmeng starts 2
2022年R2移动式压力容器充装考试题及在线模拟考试
〖Kubernetes指南⑤〗Label快速入门
KConfig
Enterprise wechat H5_ Authentication, H5 application web page authorization login to obtain identity
Buuctf-[ciscn 2019 preliminary]love math
[North Asia data recovery] data recovery cases in which the partitions disappear and the partitions are inaccessible after the server reinstalls the system
Sequence maximum return
Develop a web office suite from scratch (5): mouse hover over text
基于Three.js海上风电数字孪生三维效果
數組
Using baserecyclerviewadapterhelper to implement tree structure
Basic operations of dict and set
How to get Matplotlib figure size
Access static variables within class in swift