How to solve Differential Equations in Simulink level 2 s function

equations:
dx/dt=V*cos(theta)*cos(psi)
dy/dt=V*sin(theta)
dz/dt=-V*cos(theta)*sin(psi)
According to the s function demo--- msfcndemo_limintm.mdl.
I wrote my s function code
...........
%%Setup Dwork
block.NumContStates = 3;
.........
function InitConditions(block)
%%Initialize Dwork
block.ContStates(1).Data = 0;
block.ContStates(2).Data = 0;
block.ContStates(3).Data = 0;
.......................
function Output(block)
block.OutputPort(1).Data = block.ContStates(1).Data;
block.OutputPort(2).Data = block.ContStates(2).Data;
block.OutputPort(3).Data = block.ContStates(3).Data;
%endfunction
function Derivative(block)
..................
block.Derivatives(1).Data =V*cos(theta)*cos(psi)
block.Derivatives(2).Data =V*sin(theta)
block.Derivatives(3).Data =-V*cos(theta)*sin(psi)
..................
when we run this model, the Error is: no ContStates method;

답변 (2개)

Change your InitConditions callback to:
function InitConditions(block)
%%Initialize Dwork
block.ContStates.Data(1) = 0;
block.ContStates.Data(2) = 0;
block.ContStates.Data(3) = 0;
Everything else looks good.

댓글 수: 3

How should be define, if one state has more than one dimension?
Thanks; It is possible to solve a differencial ecuation of order two in a Matlab level 2 S-function? thank you very much.

댓글을 달려면 로그인하십시오.

knight
knight 2011년 8월 18일

0 개 추천

Thanks Kaustubha Govind, Change the Initconditions callback and Derivatives callback to:
......................
function InitConditions(block)
%% Initialize Dwork
block.ContStates.Data(1) = 0;
block.ContStates.Data(2) = 0;
block.ContStates.Data(3) = 0;
function Derivative(block)
..................
block.Derivatives.Data(1) =V*cos(theta)*cos(psi)
block.Derivatives.Data(2) =V*sin(theta)
block.Derivatives.Data(3)=-V*cos(theta)*sin(psi)
..................
It's ok.

제품

질문:

2011년 8월 17일

댓글:

2017년 11월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by