求助:关于matlab精度问题
本人编写了一个s函数,里面用到一个方程,方程的系数里有7e-5,运行时候总是提示"Input argument 'flag' is undefined"程序如下:
function = my_shuixiang(t,x,u,flag)
switch flag,
case 0,
=mdlInitializeSizes;
case 1,
sys=mdlDerivatives(t,x,u);
case 3,
sys=mdlOutputs(t,x,u);
case {2,4,9}
sys=[];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function =mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates= 2;
sizes.NumDiscStates= 0;
sizes.NumOutputs = 1;
sizes.NumInputs = 1;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1; % At least one sample time is needed
sys = simsizes(sizes);
x0= ;
str = [];
ts= ;
function sys=mdlDerivatives(t,x,u)
if x(1)<0.001
sys(1)=0.001;
end
if x(2)<0.001
sys(2)=0.001;
end
sys(1)=x(2);
sys(2)=-0.31*(7e-5)*sqrt(2*9.8)*x(2)/0.02/sqrt(x(1))-9.8*(0.62*(7e-5))^2/0.02/0.02+(0.62*(7e-5))^2*9.8*(6e-5)*u/(0.02*0.02*(0.02*x(2)+0.62*(7e-5)*sqrt(19.6*x(1))));
function sys=mdlOutputs(t,x,u)
sys(1)=x(1);
当我把里面的7e-5和6e-5换成7e-4和6e-4的时候,程序顺利运行,我怀疑是精度不够,怎么调整精度?
那位给个建议
页:
[1]