当前位置:网站首页>【Matlab】基础运算
【Matlab】基础运算
2022-06-12 23:46:00 【不牌不改】
基本运算
基本算术运算
基本算术运算符:+(加)、-(减)、*(乘)、/(右除)、\(左除)、^(乘方)。
- MATLAB的算术运算是在矩阵意义下进行的。
- 单个数据的算术运算只是矩阵运算的一种特例。
只讲除法运算:
在MATLAB中,有两种矩阵除法运算:右除/和左除\。
如果A矩阵是非奇异方阵,则B/A等效于B×inv(A),A\B等效于inv(A)×B。
奇异矩阵:对应行列式为0的矩阵。
在Matlab中计算线性方程组Ax=b的解时,可以通过左除运算得到,即x=A\b=inv(A)×b。
点运算
点运算符:.*、./、.\和.^。
两矩阵进行点运算是指它们的对应元素进行相关运算,要求两矩阵同型。
关系运算
关系运算符:<(小于)、<=(小于或等于)、>(大于)、>=(大于或等于)、==(等于)、~=(不等于)。
当两个比较量是标量时,直接比较两数的大小。若关系成立,关系表达式结果为1,否则为0。
注意不等于号是~=。
当参与比较的量是两个同型的矩阵时,比较是对两矩阵相同位置的元素按标量关系运算规则逐个进行,最终的关系运算的结果是一个与原矩阵同型的矩阵,它的元素由0或1组成。
当参与比较的一个是标量,而另一个是矩阵时,则把标量与矩阵的每一个元素按标量关系运算规则逐个比较,最终的关系运算的结果是一个与原矩阵同型的矩阵,它的元素由0或1组成。
A = [24 35 13; 22 63 23; 39 47 80];
P = rem(A, 2) == 0
结果如下:
P =
3×3 logical 数组
1 0 0
1 0 0
0 0 1
逻辑运算
逻辑运算符:&(与)、I(或)和~(非)。
设参与逻辑运算的是两个标量a和b,那么运算规则为:
- a&b a、b全为非零时,运算结果为1,否则为0。
- alb a、b中只要有一个为非零时,运算结果为1。
- ~a当a为零时,运算结果为1;当a为非零时,运算结果为0。
在算术运算、关系运算和逻辑运算中,算术运算的优先级最高,逻辑运算优先级最低,但逻辑非运算是单目运算,它的优先级比双目运算要高。这个规则了解即可,通过加括号可以实现自己控制计算顺序。
若参与逻辑运算的是两个同型矩阵,那么将对矩阵相同位置上的元素按标量规则逐个进行运算,最终运算结果是一个与原矩阵同型的矩阵,其元素由1或0组成。
若参与逻辑运算的一个是标量,一个是矩阵,那么将在标量与矩阵中的每个元素之间按标量规则逐个进行运算,最终运算结果是一个与原矩阵同型的矩阵,其元素由1或0组成。
&&和||被称为&和|的short circuit形式。
A&B: 首先判断A的逻辑值,然后判断B的值,然后进行逻辑与的计算。A和B可以为矩阵。
A&&B:首先判断A的逻辑值,如果A的值为假,就可以判断整个表达式的值为假,就不需要再判断B的值。A和B不能是矩阵,只能是标量。
PS:Matlab里面的“|”和“||”运算符也有这样的区别。
边栏推荐
- Printf segment error (core dump): a problem caused by formatted output
- leaflet中如何优雅的解决百度、高德地图的偏移问题
- Examination questions and online simulation examination for safety management personnel of hazardous chemical business units in 2022
- Basic operations of dict and set
- Common message oriented middleware selection
- M_8:设计消息队列存储消息数据的 MySQL 表格
- Design MySQL table structure for message queue to store information data
- 2202 - production de CV
- Theory + practice will help you master the dynamic programming method
- SAP QM qp03 displays an inspection plan with multiple specs inspection features
猜你喜欢

VS2015 DLIB 1916 USER_ ERROR__ inconsistent_ build_ configuration__ see_ dlib_ faq_ 1 USER_ ERROR__ inconsiste

2202 - production de CV

SAP QM qp03 displays an inspection plan with multiple specs inspection features
![[North Asia data recovery] data recovery cases in which the partitions disappear and the partitions are inaccessible after the server reinstalls the system](/img/a9/7726139037860a5f880667cec4b6c2.jpg)
[North Asia data recovery] data recovery cases in which the partitions disappear and the partitions are inaccessible after the server reinstalls the system

Introduction to message oriented middleware (message queue)

Unprecedented analysis of Milvus source code architecture

2022年G3锅炉水处理考题模拟考试平台操作
![Software development tools [3] theoretical basis of software development tools](/img/24/6a3c593931523ceb17e323bc0367b4.jpg)
Software development tools [3] theoretical basis of software development tools

Examination questions and online simulation examination for safety management personnel of hazardous chemical business units in 2022

Ast, really fragrant
随机推荐
2022年危險化學品經營單比特安全管理人員考試試題及在線模擬考試
SAP Business Technology Platform (BTP) workflow function introduction
H5時代leaflet中還在用DivIcon?
So, what is the difference between e.target and e.currenttarget?
leaflet中如何通过透明度控制layerGroup的显示隐藏
Examination questions and online simulation examination for safety management personnel of hazardous chemical business units in 2022
SAP 业务技术平台(BTP) Workflow(工作流)功能介绍
Actual combat | inductance element positioning -- detailed explanation of Halcon and opencv implementation (with source code)
Redis实现短信验证码登录
array
基于Three.js海上风电数字孪生三维效果
leaflet中如何优雅的解决百度、高德地图的偏移问题
2022年电工(初级)操作证考试题库及在线模拟考试
Mgr and greatsql resource summary
SAP UI5 如何通过 manifest.json 文件定义第三方库依赖关系
Using baserecyclerviewadapterhelper to implement tree structure
Xi'an Jiaotong 22nd autumn e-commerce technology online expansion resources (IV) [standard answer]
Start of u-boot S analysis (III)
leaflet如何优雅的展示重叠点位的气泡窗口
Operation of simulation test platform for G3 boiler water treatment test questions in 2022