How to specifiy time in step size using ODE45?

75 次查看(过去 30 天)
Hello, I was looking for some help with my homework. Right now my attached code answers the following ode, where the unit step (de) is equal to one degree. I need to make the step size last for a duration of one second. I was wondering how I specify the length of the unit step. For clarification the code is setting up two constant matrices A (4x4) and B(4x1) to take the form: y'=(A*y)+ (B*de). Any help is appreciated. Thanks.
clear,clc
l1 = [-0.0453,0.0363,0,-0.183];
l2 = [-0.3717,-2.0354,1,0];
l3 = [0.3398,-7.0301,-2.9767,0];
l4 = [0,0,1,0];
A = [l1;l2;l3;l4];
B = [0;-0.1609;-11.8674;0];
de = 1;
y0 = [0;0;0;0];
F = @(t,y) A*y+B*de;
[t,y] = ode45(F,[0 200], y0,options);

采纳的回答

Walter Roberson
Walter Roberson 2017-1-10
All of the ode*() routines are variable step. There is no way to set the actual step size, only the minimum step size.
When you specify tspan as a vector with exactly two values, then the ode routines report outputs for a variety of time points between the two, choosing the time points as needed to meet integration tolerances. The time points reported on are often not exactly the same as the time points that the ode function is called upon: the ode routines use the information from the steps actually taken in order to make projections.
When you specify tspan as a vector with more than two values, then the ode routines report outputs only for the values given in the vector. The ode routines will evaluate at a number of time points, choosing the time points as needed to meet integration tolerances, but they will only report about the points in the tspan in this case. The time points in the tspan are not necessarily evaluated at precisely: the ode routines use the information from the steps actually taken in order to make projections.
I am confused by your mention that your time step is "de" and that it is equal to one degree, and that you want your time step to last for the duration of 1 second. You seem to be mixing units there??
Is it possible that what you mean is that you want to evaluate
A*y + B * (de * (floor(t)+1))
? That is, you want B * de for time 0 to 1, and B * de * 2 for time 1 to 2, and B * de * 3 for time 2 to 3, and so on? If that is correct, then because such steps are not differentiable, you would have to use a series of calls:
y_in = y0;
for tstart = 0 : 199
F = @(t,y) A*y+B*de*(tstart+1);
tspan = [tstart tstart+1/2 tstart+1]; %3+ points to avoid reporting on the intermediates
[temp_t, temp_y] = ode45(F,tspan, y_in);
t(tstart+1) = temp_t(end);
y_in = temp_y(end, :);
y(tstart+1, :) = y_in;
end
That is, integrate for the first time step, get the boundary value produced, update the weight for B, use the produced boundary values as the initial conditions, integrate for 1 second; and so on.
  4 个评论
Nick
Nick 2017-1-10
That is perfect. Thanks a lot for the help!!
Walter Roberson
Walter Roberson 2017-1-10
Opps, I just noticed that I overwrote y0. Should be something like
[t01, y01] = ode45(F0,tspan0, y0);
[t_rest, y_rest] = ode45(F_rest, tspan_rest, y01(end,:));
t = [t01; t_rest];
y = [y01; y_rest];

请先登录,再进行评论。

更多回答(0 个)

类别

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