目录
链接:https://pan.baidu.com/s/1p4-Yaz_gZjJOQZwggrbgeQ
提取码:lxsk
第一部分:计算器功能的实现 int8 int16 int32 int64
数值变量类型可分为 1.numerical uint8 uint16 uint32 uint64
Single
Double
2.logical
3.char
4.cell
5.struct
Scalar function handle(@)
特别的变量与常亮
ans
i,j :complex number
Inf :无穷大
eps: 浮点数精度 eps(1) 默认为1 :最接近1的浮点数 也可以代表精度
NaN: 不是一个数字
Pi: 圆周率 3.14.。。。
>> iskeyword 显示关键字
ans =
'break'
'case'
'catch'
'classdef'
'continue'
'else'
'elseif'
'end'
'for'
'function'
'global'
'if'
'otherwise'
'parfor'
'persistent'
'return'
'spmd'
'switch'
'try'
'while'
优先性:从低到高排列
M-file P-file Mex-file private function subfunction built-in function bariable
>> cos='this string';
>> cos(8)
ans =
r
>> clear
>> cos(8)
ans =
-0.1455
数值显示格式:
如果把A 转换为 什么格式 则使用 format 格式 下一行: A
Style | result | example |
Short | Short ,fixed-decimal format with 4 digits after the decimal point | 3.1416 |
Long | Long ,fixed-decimal format with 15 digits after the decimal point for double values,and 7 digits after the decimal point for single values | 3.14159263589793 |
shortE | Short scientific notation with 4 digits after the decimal point | 3.1416e+00 |
longE | Long scientific notation with 15 digits after the decimal point for double values,and 7 digits after the decimal point for single values | 3.14162324245259e+00 |
Bank | Currency format with 2 digits after the decimal point | 3.14 |
Hex | Currency format with 2 digits after the decimal point | 400921fb5442d1 |
rat | Ratio of small integers | 355/112 |
冒号操作:
用于数组、向量、索引等
>> a=1:5;
b=1:3:100;
c=[1:5; 2:3:15;-2:0.5:0];
str='a':2:'z';
对数组进行操作:(注重区别有点无点)
>> a=[1 2 3; 4 5 4;9 8 7]
a =
1 2 3
4 5 4
9 8 7
>> b=[3 3 3;2 4 9; 1 3 1]
b =
3 3 3
2 4 9
1 3 1
操作:+ - * / ^ . ‘(转置)
x1=a+c;
x2=a/c;
x3=a./c;
x4=a^c;
x5=a.^c;
y1=a+b;
y2=a*b;
y3=a.*b;
y4=a/b;
y5=a./b;
特别的矩阵:
Linspace(): linearly spaced vector (a,b,c) c个数,默认100个, 从a-b
Eye(n):n*n identity matrix
eye(4)
ans =
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
Zeros(n1,n2):n1*n2 zero matrix
Ones(n1,n2):n1*n2 matrix with every entry as 1
ones(3)
ans =
1 1 1
1 1 1
1 1 1
Diag():diagonal matrix 对角线
v = [2 1 -1 -2 -5];
D = diag(v)
2 0 0 0 0
0 1 0 0 0
0 0 -1 0 0
0 0 0 -2 0
0 0 0 0 -5
Rand():uniformly distributed random numbers 随机分布在0-1之间概率矩阵
rand(2)
ans =
7.4313e-01 6.5548e-01
3.9223e-01 1.7119e-01
矩阵常用函数:都是以列为单位 进行操作
Max() sort()
Max(max()) sortrows()
Min() size()
Sum() length()
Mean() find() 查找索引与非零的值