Missing state variable at last step integration when using OutputFcn option

I'm trying to integrate a state-space model of a fluid-mechanical system. I call the integration like this
options = odeset();
[tt, state] = ode113(@fluidmech_system, tspan, state0, options, data);
and the @fluydmech_system functions calls another function
persistent sol
[sol] = computeVariables( t, X, data );
which solves an 8x8 algebraic implicit system using fsolve to retrieve some quantities needed to solve the state-space system. Everything works fine when I run the code like this, but I would like to save those quantities to the base workspace to plot them. Trying to use the OutputFcn option to do this, the code fails at the very last step of the integration with error
Index exceeds the number of array elements (0).
Error in computeVariables (line 21)
if X(3) >= acc.v0 % full accumulator
seems like the state vector X is not defined anymore. How can I solve the problem? The following is the code of the output function
function status = myOutputFcn(t, X, flag, data)
[sol] = computeVariables( t, X, data );
%solution stack
persistent sol_save
switch flag
case 'init'
sol_save = sol;
case ''
sol_save = [sol_save; sol];
case 'done' % when it's done
assignin('base','sol_save',sol_save); % get the data to the workspace.
end
status = 0;
end

답변 (0개)

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

제품

릴리스

R2018b

질문:

2018년 11월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by