- Convert the symbolic functions to MATLAB functions and generate .m files using the matlabFunction command.
- Call the .m files from a MATLAB Function block in Simulink.
Programmatically generating Simulink models from symbolic equations
22 次查看(过去 30 天)
显示 更早的评论
For control design and analysis, I am a big fan of the connect() function in the Control System toolbox. It's quite convenient for building up a large linear dynamic system without having to resort to lots of manual linear algebra (or use of the lft function). I simply define my blocks and the InputName, OutputName properties and MATLAB takes care of the rest.
I would like to do something similar for non-linear dynamical systems. To my knowledge, MATLAB doesn't offer this sort of functionality. So I wrote some primitive scripts that allow me to define non-linear dynamic systems and interconnect them just using symbolic substitution. The resulting blocks have the following fields (example 3 state system shown)
.StateName: {'iL_F2' 'vC_F2' 'vCd_F2'}
.f: [3×1 sym]
.g: [2×1 sym]
.InputName: {'v3' 'i4'}
.OutputName: {'i3' 'v4'}
The equations f and g contain the differential equations and output equations respectively (i.e. d/dt(x) = f(x,u), y = h(x,u)).
These equations are symbolic, but I would like to simulate them in Simulink. Currently I manually paste the differential equations in a block, define my inputs and outputs to make the .InputName, .OutputName properties, and then hook up an integrator to integrate d/dt(x) = f(x,u).
I'd like to do this automatically in code but I'm clueless as to how to populate a model with user-defined differential equations. To be clear, I know the basics of building a Simulink model programmatically and setting parameters. But I'm unclear how to 1) turn my symbolic equations into the right format and 2) get them into a user-defined block.
Any thoughts on this would be appreciated. Even better, any links to existing methods for automatically generating Simulink blocks from non-linear differential equations. I think someone must have already developed a toolbox for doing this, right ?
0 个评论
采纳的回答
Nicolas Schmit
2017-11-16
更多回答(2 个)
Tim Grunert
2018-1-31
In the last year we also the problem that we need to model twice: symbolically for control analysis and in simulink for simulation. To make it more easy we developed a small tool solving this problem. It can be downloaded as free software under: https://github.com/odesca/
0 个评论
Walter Roberson
2017-11-16
You may wish to look at odeFunction() along with the documentation where it shows calculating mass matrices and so on.
2 个评论
Walter Roberson
2017-11-16
I only learned about them a few months ago myself. The steps seem overly complicated sometimes, but they do work.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linearization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!