How to integrate ODE45 solver in state flow?

1 回表示 (過去 30 日間)
Amardeep Mishra
Amardeep Mishra 2021 年 5 月 6 日
回答済み: Pavan Guntha 2021 年 8 月 20 日
Hi!
I am trying to build a state flow model in matlab and one of the charts (in state flow) requires solving a system of differential equations. I am trying to embed ode45 in that. However for some reason it is throwing a lot of errors. Is there a formal way to embed ode45 solver into state flow? Please highlight with some link or example. Thanks and regards!!

回答 (1 件)

Pavan Guntha
Pavan Guntha 2021 年 8 月 20 日
Hello Amardeep,
I understand that the issue is with solving a system of differential equations within stateflow. One workaround might be to create a MATLAB function in a separate '.m' file containing the logic for solving the differential equations and call the function within the Stateflow by declaring it using 'code.extrinsic()'. During simulation, the code generator produces the code for the call to an extrinsic function but does not produce the function’s internal code. You could look at the following MATLAB code & Stateflow chart.
function [t,y] = differentialEquation(tspan)
y0 = 0;
[t,y] = ode45(@(t,y) 2*t, tspan, y0);
This function is called within the state 'ON' in the following Stateflow chart by declaring it as 'coder.extrinsic()'.
You could refer this for more information regarding coder.extrinsic()”.
Hope this helps!

カテゴリ

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

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by