ode45 MATLAB ODE solver

조회 수: 21 (최근 30일)
Ahmad Alalyani
Ahmad Alalyani 2018년 8월 15일
댓글: Walter Roberson 2018년 8월 16일
Hello I am using the MATLAB ODE solver ode45. But, the integration was not completed, and I still want to continue. So, How can I force the ode45 solver to continue???
  댓글 수: 3
Ahmad Alalyani
Ahmad Alalyani 2018년 8월 16일
편집: Walter Roberson 2018년 8월 16일
Here is the code I want to run.
function [g] = T(r)
global r
t0=1;
tfinal=5;
tspan=[t0 tfinal];
y0=[0;0;0;0];
while t0 < tfinal
[t,y]=ode45('F1',tspan,y0);
t0 = t(fix(length(t)/2));
%reset tspan for the next call to ode45 to integrate F2
tspan = [t0 tfinal];
[t,y]=ode45('F2',tspan,y0);
t0 = t(fix(length(t)/2));
%reset tspan for the next call to ode45 to integrate F1
tspan=[t0 tfinal];
%end of while loop
end
g = ...
********************************************************
The question is how to force ode45 to complete the integration across [1,5] before I pick t0 as, t0 = t(fix(length(t)/2)), and reset tspan to move to the next call to ode45?
Walter Roberson
Walter Roberson 2018년 8월 16일
Why are you continuing on from half way through the timespan it integrated over? Why not from the last time it integrated for?
Why are you passing in r and also declaring r to be global? MATLAB releases are changing with regards to what will happen for that situation. In some releases, the result would be to replace the passed in parameter 'r' with the current value of the global variable, which would probably be [] .

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2018년 8월 15일
maxtries = 500;
first_time = 0; %or as appropriate
end_time = 10; %or as appropriate
tspan = [first_time, end_time];
y0 = [-1 3]; %set as appropriate
for counter = 1 : maxtries
[this_t, this_y] = ode45(fun, tspan, y0);
if counter == 1
t{counter} = this_t; y{counter} = this_y;
else
t{counter} = this_t(2:end); y{counter} = this_y(2:end,:);
end
ended_at = this_t(end);
if ended_at >= tspan(end)
break; %got to end of time span we wanted
end
tspan = [ended_at, end_time];
x0 = this_y(end,:);
end
overall_t = cell2mat(t);
overall_y = cell2mat(y);
  댓글 수: 2
madhan ravi
madhan ravi 2018년 8월 16일
Your brilliance is extraordinary Sir Walter I admire your work.
Ahmad Alalyani
Ahmad Alalyani 2018년 8월 16일
Dear Sir Walter
Here is the code I want to run.
function [g] = T(r)
global r
t0=1;
tfinal=5;
tspan=[t0 tfinal];
y0=[0;0;0;0];
while t0 < tfinal
[t,y]=ode45('F1',tspan,y0);
t0 = t(fix(length(t)/2));
%reset tspan for the next call to ode45 to integrate F2
tspan = [t0 tfinal];
[t,y]=ode45('F2',tspan,y0);
t0 = t(fix(length(t)/2));
%reset tspan for the next call to ode45 to integrate F1
tspan=[t0 tfinal];
%end of while loop
end
g = ...
**********************************************************
The question is how to force ode45 to complete the integration across [1,5] before I pick t0 as, t0 = t(fix(length(t)/2)), and reset tspan to move to the next call to ode45?

댓글을 달려면 로그인하십시오.

카테고리

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