Convert ODE model in MATLAB to Simulink
3 次查看(过去 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!