声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1693|回复: 0

[控制系统类] 我也问一个关于sfunction 的问题,请高手指点!

[复制链接]
发表于 2008-3-19 18:12 | 显示全部楼层 |阅读模式

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

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

x
这是我编的s函数,
function [sys,x0,str,ts]=system1(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 9,
        sys=mdlTerminate(t,x,u);
    otherwise
        error(['Unhandled flag=',num2str(flag)]);
end

function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates=3;
sizes.NumDiscStates=0;
sizes.NumOutputs=1;
sizes.NumInputs=1;
sizes.DirFeedthrough=1;
sizes.NumSampleTimes=1;
sys=simsizes(sizes);
x0=[1;
    1;
    1];
str=[];
ts=[0,0];

function sys=mdlDerivatives(t,x,u)
dx(1)=-u*x(2)+x(3);
dx(2)=(u*u-1)*x(2)+u*x(3);
dx(3)=-x(3)+x(1)*x(1)+0.5;
sys=dx;

function sys=mdlUpdate(t,x,u)
sys=[];

function sys=mdlOutputs(t,x,u)
sys=x(1);
function sys=mdlTerminate(t,x,u)
sys=[];

命令窗口老是有警告:
Warning: Unable to reduce the step size without violating minimum step size of 0.01 at time 2.805106062496166.  Continuing simulation with the step size restricted to 0.01 and using an effective relative error tolerance of 2.569641885883541e+040, which is greater than the specified relative error tolerance of 0.001.

还提示sfunction有问题,说是State derivatives returned by S-function 'system1' in 'fz/S-Function' during flag=1 call must be a real vector of length 3.
我实在找不出什么原因,请高手指教!
回复
分享到:

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-9-21 04:32 , Processed in 0.073283 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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