关于s函数编程问题小​弟有地方不懂想请大佬​们给指导一下。

15 views (last 30 days)
doney
doney on 30 Nov 2022
Commented: bc on 10 Dec 2024
小弟刚刚接触s函数所以有很多地方不是很懂,想请大佬们给指导一下,下面是一段s函数的编程,想问一下在mdlDerivatives环节中的sys(1)=x(2)是什么意思啊?x(2)这个状态变量是怎么生成的?
function [sys,x0,str,ts]=s_function(t,x,u,flag)
switch flag,
case 0,
[sys,x0,str,ts]=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 [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 2;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 2;
sizes.NumInputs = 1;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 0;
sys=simsizes(sizes);
x0=[0.5 1.0];
str=[];
ts=[];
function sys=mdlDerivatives(t,x,u)
J=10;
sys(1)=x(2);
sys(2)=1/J*u;
function sys=mdlOutputs(t,x,u)
sys(1)=x(1);
sys(2)=x(2);
  1 Comment
bc
bc on 10 Dec 2024
会了么哥们,我现在也是这个问题,思考一下午了也不会

Sign in to comment.

Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!