当前位置:网站首页>捡起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
边栏推荐
猜你喜欢

GRBL学习(一)

多线程原理和常用方法以及Thread和Runnable的区别

Multi level cache usage

Import address table analysis (calculated according to the library file name: number of imported functions, function serial number and function name)

MySQL optimistic lock to solve concurrency conflict

多级缓存使用

保姆级Anaconda安装教程

Large factory technology implementation | industry solution series tutorials

Website pressure measurement tools Apache AB, webbench, Apache jemeter

Cap theorem
随机推荐
Upgrade MySQL 5.1 to 5.611
[self entertainment] construction notes week 2
Upgrade MySQL 5.1 to 5.68
一文读懂串口及各种电平信号含义
C语言自编字符串处理函数——字符串分割、字符串填充等
CVPR 2022 quality paper sharing
Config组件学习笔记
【第5节 if和for】
时序模型:门控循环单元网络(GRU)
PS add texture to picture
R语言中绘制ROC曲线方法二:pROC包
王启亨谈Web3.0与价值互联网“通证交换”
Method 2 of drawing ROC curve in R language: proc package
MySQL - execution process of MySQL query statement
Extract non duplicate integers
Partitionby of spark operator
Intersection, union and difference sets of spark operators
为啥禁用外键约束
MySQL Cluster Mode and application scenario
s16.基于镜像仓库一键安装containerd脚本