How can i prove Runge-Kutta method depends on time steps?

3 次查看(过去 30 天)
Ode45 in matlab uses adaptive time steps. My assignment is to prove that the error from solution obtained by Runge-Kutta method depends on the time stepping. I tried to use ode45 in a loop to calculate the value of the vector 'm' at each time step, but i've no control on the number of steps used by the ode45, even though i'm sending only two time values.
Is there any way that i could use ode45 to obtain a solution dependent on the time steps explicitly mentioned in the code, perhaps by making ode45 to take fixed time steps instead of adaptive? Or if there is no other way to solve this problem other than writing my own Runge-Kutta function with fixed time steps? I've attached the code as follows:
time = linspace(0,tmax,tcount)
for RK=1:length(time)-1
t = [time(RK) time(RK+1)];
[t1,m1] = ode45(@(t1,y1)myfun(t1,y1, s), t, m); % s is a structure of constant values
disp(length(m1))
RK_m(RK,:)=m1';
end

采纳的回答

José-Luis
José-Luis 2016-12-12
编辑:José-Luis 2016-12-13
No, a variable-step size is always used for ode45 as per the documentation.
The Mathworks support team has provided code for ode4 (see this link) that can use a fixed step size and looks suitable for your problem.

更多回答(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