how to extract variables from ode45

조회 수: 1 (최근 30일)
chirag patel
chirag patel 2020년 2월 5일
답변: Bjorn Gustavsson 2020년 2월 5일
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?

답변 (1개)

Bjorn Gustavsson
Bjorn Gustavsson 2020년 2월 5일
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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by