Clear Filters
Clear Filters

How to integrate ODE45 solver in state flow?

5 views (last 30 days)
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!!

Answers (1)

Pavan Guntha
Pavan Guntha on 20 Aug 2021
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!


Find more on Simulink Functions in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!