필터 지우기
필터 지우기

Convert ODE model in MATLAB to Simulink

조회 수: 2 (최근 30일)
Javier Guiterrez
Javier Guiterrez 2012년 2월 13일
Hello
I have a ODE model in MATLAB but now I want to create a control system for it in SIMULINK. Which is the best way to use it inside simulink? Now I have a .m file that calls (with the solver ode45: [t,y] = ode45(@car,tpo,x0,[]);) to another m file where the ode are defined (car.m). So what I want is to convert the ca.m where 16 differential equations are defined to simulink with the least effort possible. I know that I can rewrite them in simulink with blocks but I want to know if there exists a more direct way to use the m code.
Thank you in advance

채택된 답변

Seth DeLand
Seth DeLand 2012년 2월 13일
Hi Javier,
The easiest way I can think of to convert would be to use a Level 2 MATLAB S-function in Simulink. If you've never used S-functions before, this is a good place to get started: http://www.mathworks.com/help/toolbox/simulink/sfg/f6-12629.html
You can use the same code that you used in car.m for calculating the derivatives in your S-function (this will be in the Derivative function in the S-function). The msfcn_limintm.m S-function gives an example of how this can be done.
Because the outputs of the ODE solver are just the states, the Output function of you S-function should just grab the values of the states and set those as the outputs. This is also done in the msfcn_limintm.m example.
  댓글 수: 1
Javier Guiterrez
Javier Guiterrez 2012년 2월 15일
Now I have checked it and it works. My current problem is that I make severeal precalculations previous to the derivatives because the coeficients of the ODE are time varying. Apart from the states I want to export some of these values calculated in the derivatives subfunctions. I have enlarged the output number and introduced it as input and out parameters of the different subfunctions inside the m file of the S-function, but the first time it appears (as an output parameter of the derivatives it says that it does not exist)
For example: [sys,g]=derivatives(t,x,u)
sys=output(t,x,u,g)
In the first call to derivatives it says that it is not defined yet.
Is it possible to do this? Thank you in advance

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by