Compiling odeset events on simulink, without global variables

2 次查看(过去 30 天)
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.

回答(1 个)

Pedro Lima
Pedro Lima 2022-11-2
编辑:Pedro Lima 2022-11-2
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

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by