声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 755|回复: 0

[综合讨论] sifunction中多维输入的问题?

[复制链接]
发表于 2008-6-29 13:50 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

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 编辑 ]
回复
分享到:

使用道具 举报

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-23 07:31 , Processed in 0.062859 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表