Convert ODE model in MATLAB to Simulink
조회 수: 2 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Simulink Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!