Simulink - Change continuous state value at a given time point

11 ビュー (過去 30 日間)
Jan-Ulrich Schad
Jan-Ulrich Schad 2012 年 5 月 25 日
コメント済み: Christian 2013 年 12 月 2 日
Hello, I have a model with a Level-2 MATLAB S-Function simulating continuous states. At a given time point I want one of the continuous state values to increase by a given value. It is even not really important, that the value changes on exactly that time point.
I tried to solve it with a signal, that changes from 0 to the value at the time point and then used the Difference, or the Memory block to get the signal to only be the value at one timestep, otherwise 0. Then added the value to the continuous state in the s-function output. But with this method the value is somehow integrated and the increase of the continuous state much too high.
I am glad for any help.

採用された回答

Guy Rouleau
Guy Rouleau 2012 年 5 月 25 日
If you want to generate a "jump" in your continuous state, you must reset the block. This can be done in many ways. For example placing your block in an Enabled subsystem and turning it off for one sample and then on again. That way you should be able to reset your state to a desired value, for example coming from an input port or any other computation.
  3 件のコメント
Jan-Ulrich Schad
Jan-Ulrich Schad 2012 年 6 月 1 日
I tried it now and it works as I explained. One has to make sure the input signal to the enabled subsystem with the s-function has to have the value to change the continuous state one time step ahead of disabling the subsystem.
Christian
Christian 2013 年 12 月 2 日
Hello, I am struggeling with a similar problem and the given solution is generally working in my model as well. Thank you very much for that.
However, it seems that after re-enabling the subsystem, the solver continues running with larger time steps than it did when the simulation initially started. This causes in some cases too large gradients and a "crash" of my simulation.
I have found out that there is the "ssSetSolverNeedsReset"-function for CS-functions to reset the solver. Is there something similar for Matlab S-functions?
Thanks for any help.

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

その他の回答 (1 件)

Kaustubha Govind
Kaustubha Govind 2012 年 5 月 25 日
I'm curious about why you chose to use continuous states instead of discrete states if you do not need the state to be integrated. See my answer here for a brief explanation of continuous and discrete states in Simulink.
  2 件のコメント
Jan-Ulrich Schad
Jan-Ulrich Schad 2012 年 5 月 25 日
The continuous states are just usual continuous states. But the value that is added to one of the continuous states is "backpropagated?" by the solver. Since, when I use Euler instead of ode54, the value is added correctly.
Jan-Ulrich Schad
Jan-Ulrich Schad 2012 年 5 月 25 日
The continuous states are integrated to answer your question.

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

カテゴリ

Help Center および File ExchangeSimulink についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by