马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
我最近碰到一个这样的问题.在编写s-function时.一般都是输出是多维的..但如果输入也是多维的..应该怎么写呢?
比如说这个例题: y''(t)+25y'(t)=0.5r'(t) 程序如下: 高手帮看下哪里错了?
function [sys,x0,str,ts] = twoinput(t,x,u,flag)
A=[0 1
0 -5];
B=[0 0
0 0.1];
C=[1 0];
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes(A,B,C);
case 1,
sys=mdlDerivatives(t,x,u,A,B);
case 2,
sys=mdlUpdate(t,x,u);
case 3,
sys=mdlOutputs(t,x,u,C);
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(A,B,C)
sizes = simsizes;
sizes.NumContStates = 1;
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 = [0];
str = [];% str is always an empty matrix
ts = [0 0];% initialize the array of sample times
function sys=mdlDerivatives(t,x,u,A,B)
sys = A*x+B*u;
function sys=mdlUpdate(t,x,u)
sys = [];
function sys=mdlOutputs(t,x,u,C)
sys = C*x;
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 = [];
% end mdlTerminate
[ 本帖最后由 16443 于 2008-6-30 11:11 编辑 ] |