1.If ode45 uses adaptive time step, how can we control that in your code. 2.You have specified deltaT in code. Does the solver use that interval to decide the time interval for integration?3.4. If not, then what is the utility of deltaT in code

24 views (last 30 days)
x0=0.1
y0=0.2
dt=0.1
T0=0
Tf=40
dif=@(t,y)[y(1)-y(1)*y(2);y(1)*y(2)-y(2)];
Y0=[x0,y0];
tspan=(T0:dt:Tf);
[T,Y] = ode45(dif,tspan,Y0);
nums=[T,Y(:,1),Y(:,2)];
csvwrite('datalist.csv',nums);
cHeader = {'t' 'x' 'y' 'List of Data Generated by ode45'};
commaHeader = [cHeader;repmat({','},1,numel(cHeader))];
commaHeader = commaHeader(:)';
textHeader = cell2mat(commaHeader);
fid = fopen('datalist.csv','w');
fprintf(fid,'%s\n',textHeader)
fclose(fid)
dlmwrite('datalist.csv',nums,'-append');
fprintf('Data has been generated');

Answers (1)

Steven Lord
Steven Lord on 26 Jun 2020
If ode45 uses adaptive time step, how can we control that in your code.
You don't, at least not directly. You let ode45 take the steps that it needs to take to evaluate the solution of your system of ODEs while satisfying the tolerances you specified (or the default tolerances.)
You have specified deltaT in code. Does the solver use that interval to decide the time interval for integration?
If by "the time interval" you mean the beginning and end of the time interval over which to solve the system of ODEs, yes.
If by "the time interval" you mean the exact times to which the ODE solver steps while trying to solve the system of ODEs, no.
If by "the time interval" you mean the times at which the ODE solver evaluates the solution it's computed to generate the output that it returns to its caller, yes.
If not, then what is the utility of deltaT in code
Let's say you're planning a trip via a travel agency. You tell the travel agent "I live at A. On my trip I want to stop at locations X, Y, and Z along the way. I need to end up at B at the end of the trip." The travel agent will make whatever arrangements he or she needs to make to get you to X, Y, and Z safely. It may be that you need to spend a couple of hours in a layover between X and Y. It may be that due to construction you can't go directly from Y to Z but need to go to W and V inbetween. But all you really care about is getting pictures / souveniers at X, Y, and Z.
You are the function that calls ode45. The list of stops [A, X, Y, Z, B] is the time span vector. The travel agent is ode45, making whatever arrangement it needs to internally (the layover between X and Y, the intermediate stops at W and V) to get you from A to B.
The analogy's not perfect; in reality ode45 likely will do its internal calculations passing by X, Y, and Z without hitting them exactly and will interpolate the solution to give the value of the solution at X, Y, and Z.
  1 Comment
John D'Errico
John D'Errico on 26 Jun 2020
Edited: John D'Errico on 26 Jun 2020
I would claim that is a very good analogy by Steve. Of course, it does give me visions of the train conductor on a train from Denver to Boston announcing the passage through Cleveland as "We are passing the Cleveland station right now. Anyone wanting to get off in Cleveland must be prepared to jump quickly. We will throw your bags off as you jump." This said as the train zips through the station at top speed, not slowing down a bit.
Just remember, in order to go to Cleveland, practice a jump and roll motion. And hey - it could be worse. You could have been on the plane between Denver and Boston.

Sign in to comment.

Categories

Find more on Stochastic Differential Equation (SDE) Models in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!