필터 지우기
필터 지우기

Compiling odeset events on simulink, without global variables

조회 수: 2 (최근 30일)
Pedro Lima
Pedro Lima 2022년 10월 13일
편집: Pedro Lima 2022년 11월 2일
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