Borrar filtros
Borrar filtros

How to integrate ODE45 solver in state flow?

3 visualizaciones (últimos 30 días)
Amardeep Mishra
Amardeep Mishra el 6 de Mayo de 2021
Respondida: Pavan Guntha el 20 de Ag. de 2021
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!!

Respuestas (1)

Pavan Guntha
Pavan Guntha el 20 de Ag. de 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!


Más información sobre Simulink Functions en Help Center y File Exchange.




Community Treasure Hunt

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

Start Hunting!

Translated by