How to integrate ODE45 solver in state flow?

조회 수: 3 (최근 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 CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by