- 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
11 ビュー (過去 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 で Symbolic Math Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!