how to extract variables from ode45
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
how to extract data from ode45 which is not ouput of ode45?
usingoutputfn i have extracted but it is extracted for 11 points instead of 41?
same way how to extract data from fsolve which is not output of fsolve?
0 comentarios
Respuestas (1)
Bjorn Gustavsson
el 5 de Feb. de 2020
My pedestrian-layman approach to this type of problem is to integrate the ODE, typically with t = t0:dt:tend, then when I have y(t) I call the ODE again (in a loop or with the entire t and y(t)) and extract the extra outputs. Typically somthing like this:
y0 = [0 1 2 3];
t_span = (0:0.1:123)';
[t,y] = ode45(@(t,y) ode_def(t,y,[1],0),t_span,y0)
for i_t = numel(t):-1:1
[~,Pars_of_interest(i1)] = ode_def(t(i_t),y(i_t,:),[1],1);
end
Where the ode_def could be written to return the extra output when the input argument extraoutputs is 1
function varargout = ode_def(t,y,pars,extraoutputs)
dydt = [y(2);-abs(y(1))^3*sign(y(1));-tan(y(4));y(1)+y(3)-y(2)^2];
varargout{1} = dydt;
if extraoutputs == 1
Q = pars(1)+sum(y);
varargout{2} = Q;
end
end
QD-solution perhaps, but a solution that is robust to misinterpretations and lack of understanding of how to use the outputfunction cleanly.
HTH
0 comentarios
Ver también
Categorías
Más información sobre Ordinary Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!