当前位置:网站首页>捡起MATLAB的第(2)天
捡起MATLAB的第(2)天
2022-04-23 15:54:00 【Sola_Ex】
捡起MATLAB的第二天
Matlab
Matlab中预定义的变量
- ans:预设的计算结果的变量名
- eps:Matlab定义的正的极小值 = 2.2204e^(-16)
- pi: 3.14xxxxxxxxxxxxxx
- inf:无穷大
- NaN:无法定义
- i或j:虚数单位
- 。。。。
Matlab赋值
Matlab中的赋值,可以先不定义变量或直接用变量
5+6
ans = 11
a = 5;
b = 6;
a+b
ans = 11
效果一样,关键的是矩阵,
y = [1 2 3 4]; %行向量
y = [6:7:8:9]; %列向量
y' %转置
Matlab四则运算
Matlab的加减乘除与C语言的加减乘除在普通数字的使用上没有异样,如:
ans1 = a+b;
ans2 = a*b;
ans3 = a-b;
ans4 = a/b;
最大最小值函数
- max
- min’
max(x) %输出向量X中的最大值
[Y,I] = max(X) %输出向量X中的最大值及其Y的序号I
min(W) %输出向量W中的最小值
[Z,J] = min(w) %输出向量W中的最小值Z及其Z的序号J
什么是向量(vector)
定义:既有方向又有大小的量叫做向量(包含多种信息/多个元素的量)
建立一个向量
1、直接输入法
如:
x=[1,2,3,4,5]
或
x=[1 2 3 4 5]
2、命令格式
x_star : x_add:x_end
- x_star 起始值
- x_add 增量值
- x_end 结束值
(默认增量为1)
如:
x = 1:5
结果是
x = 1 2 3 4 5
3、线性等分法
linspace(int_start,int_end,n)
- int_start %等分区间的起始值
- int_end %等分区间的结束值
- n %等分个数
向量长度
向量计算中,必须注意向量长度的一致。
命令:
length(x)
如:
x=[1 2 3 4 4];
length(x)
结果显示
ans = 8
向量的加/减法
如:
A = [1 2 3];
B = [4 5 6];
sum = A+B
diff = A-B
结果是:
sum = 5 7 9
diff = -3 -3 -3
向量的乘/除法
向量或者矩阵的乘除法、幂、开方运算,需要在运算符前面加“.”
如:
A = [1 2 3];
B = [4 5 6];
P = A.*B
Q = A./B
向量的幂(power)
"^"在matlab代表插入符号
A = [1 2 3];
A_POWER = A.^4
向量的开平方(square root)
直接在键盘上是没有开方的符号的,所以换一下思想,把开方换成幂来做。
即:
根号a = a.^(1/2),依次类推即可。当然,开平方可以直接用sqrt(x),别的就直接做成幂的形式就好了。
版权声明
本文为[Sola_Ex]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_42312125/article/details/107419470
边栏推荐
- 5分钟,把你的Excel变成在线数据库,神奇的魔方网表excel数据库
- C language --- string + memory function
- How important is the operation and maintenance process? I heard it can save 2 million a year?
- 一刷312-简单重复set-剑指 Offer 03. 数组中重复的数字(e)
- Groupby use of spark operator
- Neodynamic Barcode Professional for WPF V11. 0
- 提取不重复的整数
- MySQL optimistic lock to solve concurrency conflict
- shell脚本中的DATE日期计算
- 为啥禁用外键约束
猜你喜欢
![Merging of Shanzhai version [i]](/img/e7/f301697aea879bcad8cef70ca890cc.png)
Merging of Shanzhai version [i]

MySQL - MySQL查询语句的执行过程

Filter usage of spark operator

Timing model: gated cyclic unit network (Gru)

Website pressure measurement tools Apache AB, webbench, Apache jemeter

Application of Bloom filter in 100 million flow e-commerce system

Implement default page

One brush 314 sword finger offer 09 Implement queue (E) with two stacks

Load Balancer

5分钟,把你的Excel变成在线数据库,神奇的魔方网表excel数据库
随机推荐
Go concurrency and channel
One brush 314 sword finger offer 09 Implement queue (E) with two stacks
New developments: new trends in cooperation between smartmesh and meshbox
王启亨谈Web3.0与价值互联网“通证交换”
APISIX jwt-auth 插件存在错误响应中泄露信息的风险公告(CVE-2022-29266)
PHP function
现在做自媒体能赚钱吗?看完这篇文章你就明白了
Spark 算子之groupBy使用
MetaLife与ESTV建立战略合作伙伴关系并任命其首席执行官Eric Yoon为顾问
MySQL - execution process of MySQL query statement
The principle and common methods of multithreading and the difference between thread and runnable
MySQL Cluster Mode and application scenario
utils. Deprecated in35 may be cancelled due to upgrade. What should I do
Accumulation of applet knowledge points
Distinct use of spark operator
大厂技术实现 | 行业解决方案系列教程
Codejock Suite Pro v20.3.0
WPS brand was upgraded to focus on China. The other two domestic software were banned from going abroad with a low profile
Pgpool II 4.3 Chinese Manual - introductory tutorial
Sortby use of spark operator