フィルターのクリア

Programmatically generating Simulink models from symbolic equations

11 ビュー (過去 30 日間)
jdg
jdg 2017 年 11 月 15 日
回答済み: Tim Grunert 2018 年 1 月 31 日
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 ?

採用された回答

Nicolas Schmit
Nicolas Schmit 2017 年 11 月 16 日
  1. Convert the symbolic functions to MATLAB functions and generate .m files using the matlabFunction command.
  2. Call the .m files from a MATLAB Function block in Simulink.
  1 件のコメント
jdg
jdg 2017 年 11 月 16 日
Thank you for the quick response. This seems to be exactly what I need.

サインインしてコメントする。

その他の回答 (2 件)

Tim Grunert
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/

Walter Roberson
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 件のコメント
jdg
jdg 2017 年 11 月 16 日
Thanks! Surprised I never learned of these tools before.
Walter Roberson
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 ExchangeSymbolic Math Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by