Borrar filtros
Borrar filtros

Compiling odeset events on simulink, without global variables

2 visualizaciones (últimos 30 días)
Pedro Lima
Pedro Lima el 13 de Oct. de 2022
Editada: Pedro Lima el 2 de Nov. de 2022
I have a simulink matlab function block where I am trying to use ode23 with an events function, but I get the following error when compiling:
All inputs must be constant.
Function 'npcFullProp_debug.m' (#274.284.325), line 8, column 14:
"odeset('RelTol',1e-6,'Events',@npcEvents)"
@npcEvents is defined as a nested function so it can access 'env_par', a structure from the parent function (npcFullProp_debug).
(Note: Matlab Function Block > guidanceLong.m > npcFullProp_debug.m > ode23)
I had hoped that using the parent function variable would be equivalent to a global variable, as suggested in this similar post: Code generation for event functions and ODE solvers
I also tried to make 'env_par' global, but simulink just gets stuck at t = 0.00 s until I stop the simulation. Still haven't figured out why.
Is there a solution that avoids the use of global variables? (why/why not?) I have been running ode23 in small 10sec arcs and checking the events manually, but this curbs the efficacy of a variable step solver.

Respuestas (1)

Pedro Lima
Pedro Lima el 2 de Nov. de 2022
Editada: Pedro Lima el 2 de Nov. de 2022
For anyone wondering, I ended up implementing "my own" ode23 to get around this issue.
I started with the ode23tx.m in Numerical Computing with MATLAB, and added rudimentary event detection.
Modified ode23 attached. Easily modifiable to work as RKF45 by changing the Butcher tableau, interpolant coefficients (ntrp23), and step control exponent

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by