概述
代码拷过去!可以运行了,记得参数设置界面什么也不用加!初始输入记得加入,不然你的S模块会报错,因为你有个reallog函数!
function [sys,x0,str,ts] = guangfu(t,x,u,flag)
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 1,
sys=mdlDerivatives(t,x,u);
case 2,
sys=mdlUpdate(t,x,u);
case 3,
sys=mdlOutputs(t,x,u);
case 4,
sys=mdlGetTimeOfNextVarHit(t,x,u);
case 9,
sys=mdlTerminate(t,x,u);
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 1;
sizes.NumInputs = 3;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
x0 = [];
str = [];
ts = [0 0];
=============================================================================
% mdlDerivatives
% Return the derivatives for the continuous states.
%=============================================================================
%
function sys=mdlDerivatives(t,x,u)
sys = [];
% end mdlDerivatives
%
%=============================================================================
% mdlUpdate
% Handle discrete state updates, sample time hits, and major time step
% requirements.
%=============================================================================
%
function sys=mdlUpdate(t,x,u)
sys = [];
% end mdlUpdate
%
%=============================================================================
% mdlOutputs
% Return the block outputs.
%=============================================================================
%
function sys=mdlOutputs(t,x,u)
Voco=21.6;
Imo=3.5;
Isco=3.75;
Vmo=17.2;
a=0.0025;
b=0.5;
c=0.00288;
Sref=1000;
Tref=25;
e=2.718;
t1=u(1)-Tref;
s=u(2)/Sref-1;
Isc=Isco*u(2)*(1+a*t1)/Sref;
Voc=Voco*(1-c*t1)*log(e+b*s);
Im=Imo*u(2)*(1+a*t1)/Sref;
Vm=Vmo*(1-c*t1)*log(e+b*s);
C2=(Vm/Voc-1)/(reallog(1-Im/Isc));
C1=(1-Im/Isc)*exp(-Vm/(C2*Voc));
sys=Isc*(1-C1*(exp(u(3)/(C2*Voc))-1));
function sys=mdlGetTimeOfNextVarHit(t,x,u)
sampleTime = 1; % Example, set the next hit to be one second later.
sys = t + sampleTime;
function sys=mdlTerminate(t,x,u)
sys = [];
最后
以上就是耍酷自行车为你收集整理的matlab怎么整合成一个模块,Matlab如何将m文件制定成模块的全部内容,希望文章能够帮你解决matlab怎么整合成一个模块,Matlab如何将m文件制定成模块所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复