Missing state variable at last step integration when using OutputFcn option
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (0)
Vedere anche
Categorie
Scopri di più su Numerical Integration and Differential Equations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!