为了积分结果不出现sin cos在坟墓出现
用数值积分法积分前先化简,使dL dD 的分母不出现sin 、cos
dL=(a0alpha)(0.5rhoVta2*CUt2)©
dD=(Cd)(0.5rhoVta2*CUt2)*©
把CUt^2乘到alpha即可化简成分母无sin、cos
结构体数组赋值:
mpcobj.MV =struct(‘Min’,{-0.2,-0.2,-0.2,-0.2},‘Min’,{0.2,0.2,0.2,0.2})
matlab函数调用工作空间的变量要在参数中传递进来
- Its prediction model must be an LTI discrete-time, state-space object with no delays. Use the absorbDelay command to convert delays to discrete states.
- matlab func不允许出现定义了输入参数(端口)却不使用的情况,会报错,如下:
- 逆矩阵,伪逆矩阵,广义逆
inv:
inv(A)B
实际上可以写成A\B
Binv(A)
实际上可以写成B/A
这样比求逆之后带入精度要高
A\B=pinv(A)B
A/B=Apinv(B)
pinv:
X=pinv(A),X=pinv(A,tol),其中tol为误差
pinv是求广义逆
先搞清楚什么是伪逆。
对于方阵A,若有方阵B,使得:A·B=B·A=I,则称B为A的逆矩阵。
如果矩阵A不是一个方阵,或者A是一个非满秩的方阵时,矩阵A没有逆矩阵,但可以找到一个与A的转置矩阵A’同型的矩阵B,使得:
A·B·A=A
B·A·B=B
此时称矩阵B为矩阵A的伪逆,也称为广义逆矩阵。因此伪逆阵与原阵相乘不一定是单位阵。
当A可逆时,B就是A的逆矩阵,否则就是广义逆。
满足上面关系的A,B矩阵,有很多和逆矩阵相似的性质。
如果A为非奇异矩阵的话,虽然计算结果相同,但是pinv会消耗大量的计算时间。
在其他情况下,pinv具有inv的部分特性,但是不完全相同。
- 保留小数位数
一、取整函数
1.向零取整(截尾取整)
fix-向零取整(Round towards zero);
fix(3.6)
ans = 3
2.向负无穷取整(不超过x 的最大整数-高斯取整)
floor-向负无穷取整(Round towards minus infinity);
floor(-3.6)
ans = -4
3.向正无穷取整(大于x 的最小整数)
ceil-向正无穷取整(Round towards plus infinity);
ceil(-3.6)
ans = -3
4.向最近整数取整,四舍五入(四舍五入取整)
round-向最近整数取整,四舍五入(Round towards nearest integer);
round(3.5)
ans = 4
二、在小数点后某一位四舍五入,即保留几位小数,也经常用到。
1.数值型 roundn—任意位位置四舍五入
a=123.4567890;
a=roundn(a,-4)
a = 123.4568
其中roundn函数功能如下:
y = ROUNDN(x) rounds the input data x to the nearest hundredth. %不指定n,精确到百分位 y = ROUNDN(x,n) rounds the input data x at the specified power %精确到小数点后指定位数n
2.符号型
digits(4)
vpa(…)
必须说明:vpa命令不能识别整数与小数,只算总位数,因此对它来说小数整数无论哪个都占一位,例如对9.3154保留两位小数时就得写成:
a=9.3154;
digits(3)
b=vpa(a)
b= 9.32
其中b为符号型变量;
3.字符型
a=12.34567;
b = sprintf(’%8.2f’,a)
b = 12.35 其中b为字符型变量。
matlab文本输出
两个函数:disp
fprintf
1、函数disp只带一个变量,他可以是自负矩阵或数值矩阵,要输出简单的文字信息,只需要用单引号将信息括起来:
disp(‘my favorite color is red’);
或者
yourname=input(‘enter your name’,’s’);
disp([‘your name is’,youname]);
例如
yourname = input('enter your name ',‘s’);
enter your name panrq
disp(['your name is ',yourname]);
your name is panrq
选择带数值变量值的文本信息时,需要用函数num2str将数值变量的类型转换字符型
x=98;
outstring = ['x = ',num2str(x)];
disp(outstring);
x = 98
disp(['x = ',num2str(x)]);
x = 98
disp函数只能带一个变量,表格中的各列需奥组合成一个矩阵,如下面的程序所示。
x=0:pi/5:pi;y=sin(x);
disp([x’ y’]);
0 0
0.6283 0.5878
1.2566 0.9511
1.8850 0.9511
2.5133 0.5878
3.1416 0.0000
Format命令
控制显示模式,直到下一个format出现前,这条format命令一直有效。
x=1.23456789;
format short;disp(pi);
3.1416
format long;disp(pi);
3.141592653589793
format short e;disp(pi);
3.1416e+000
format +;disp(pi);
format bank;disp(pi);
3.14
2、函数fprintf
fprintf(format);
fprintf(format,variables);
fprintf(fid,format,variables);
例如:
fprintf(‘i am concreten’);
i am concrete
a=3;b=‘s’;
fprintf(‘this is a %d and %s n’,a,b);
this is a 3 and s
- 判断变量的类型
class(var)