Differential equation in embedded block in simulink ?

Dears all,
I have a simulink with several degreees of freedom (springs, mass and damping). I try to replace a part of it by an embedded function containing a differential equation coded with matrix mass, stiffness and damping.
My problem is to make simulink understand that in the embedded function there is a differential equation (X ==> dX)
If the embedded function is not link with other simulink object, i can't put an integrator on the output and feed it into the input of the block.
If i replace one spring (with little mass on each extremity) and try to say displacement on my first mass is the same that displacement on the mass before in the simulink model (X(n-1)=X(n)) that is feeding my embedded function with the output of the mass before in simulink. The model does'nt run well. I think it's because i can't loop the output of the emebedded block in its input so simulink doesn't understand that its a differential equation.
Is there any solution ?
I hope my question is understandable....
Thanks a lot for your help.

 採用された回答

Kaustubha Govind
Kaustubha Govind 2012 年 3 月 13 日

2 投票

I don't think the Embedded MATLAB Function block is a good choice to solver differential equations. I would recommend using S-Functions instead. For a MATLAB S-function demo that uses continuous states to implement an integrator block, type this at the MATLAB prompt:
>> msfcndemo_limintm
You should be able to use this as an example to implement your own differential equation block.

2 件のコメント

Jean Sébastien
Jean Sébastien 2012 年 3 月 14 日
Hi Kaustubha Govind,
First thank you for your answer.
I'am investigating in the sfunction level 2 as you adviced me yesterday. Is there any mean to put a variable name as parameter in the dialog box ?
I want to put a matrix as parameters :
For example : Matrix_K=[1000 -1000;-1000 1000] and i wanna put in the sfunction level 2 dialogbox parameter Matrix_K (and not [1000 -1000;-1000 1000]). Is it possible ?
Thx for your answer
Guy Rouleau
Guy Rouleau 2012 年 3 月 14 日
Yes, the s-function will not make difference between K and [1;2;3;4] is K is defined in the MATLAB workspace.

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

その他の回答 (1 件)

Guy Rouleau
Guy Rouleau 2012 年 3 月 14 日

2 投票

If you need to generate code and consequently use the EML block, you might want to use the trick described here:
The trick is to generate Dx in the EML block, feed that to an integrator that will compute x and feed that back to your EML block.

1 件のコメント

Rishabh singh
Rishabh singh 2020 年 5 月 19 日
thank you sir, your trick was helpful for me.

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

カテゴリ

ヘルプ センター および File ExchangeSimulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by