Borrar filtros
Borrar filtros

Runge-kutta calculation giving lower order of accuracy than expected

5 visualizaciones (últimos 30 días)
I'm solving an ODE: y'' + (y^2 − 1)*y' + y = 0, y(0) = 1, y'(0) = 0, t ∈ [0, 1] using RK method with uk = u(k−1) +(h/6)*(K1 + K2 + 4K3)
K1 = f(t(k−1), u(k−1))
K2 = f(t(k−1) + h, u(k−1) + hK1)
K3 = f(t(k−1) + h∕2, u(k−1) + hK1∕4 + hK2∕4)
The program give the correct solution to the problem but when experimenting with different step sizes N the convergence appears to be of order 1, doubling the steps only halves the error. Shouldn't the convergence be much faster than this? Any ideas what I could be doing wrong? In the code I split the ODE into a system of 2 first order ODE
t=0; tslut=100; T=t;
N=4000; h=tslut/N;
y0=1; u1=y0;
dy0=0; u2=dy0;
for k=2:N+1
%The K values
K11 = u2(k-1);
K12 = u2(k-1)+h*K11;
K13 = u2(k-1)+h*K11/4+h*K12/4;
K21 = -(u1(k-1)^2-1)*u2(k-1)-u1(k-1);
K22 = -((u1(k-1)+h*K21)^2-1)*(u2(k-1)+h*K21)-(u1(k-1)+h*K21);
K23 = -((u1(k-1)+h*K21/4+h*K22/4)^2-1)*(u2(k-1)+h*K21/4+h*K22/4)-(u1(k-1)+h*K21/4+h*K22/4);
%Iterating over u1 and u2 using RK method
u1(k)=u1(k-1)+(h/6)*(K11+K12+K13);
u2(k)=u2(k-1)+(h/6)*(K21+K22+K23);
t=t+h;
T=[T;t];
end
plot(T,u1)
u1(end)

Respuestas (1)

Abraham Boayue
Abraham Boayue el 2 de Abr. de 2018
Try using a higher order to see if your result will improve. RK4 usually gives better convergence. Check this link https://www.mathworks.com/matlabcentral/answers/386695-how-to-solve-this#answer_308949
  1 comentario
Oscar Ungsgård
Oscar Ungsgård el 2 de Abr. de 2018
Hey, thanks for the answer!
The problem specifically stated that this form of RK be used and asked that you find the order of accuracy. I'm coming up with an order of accuracy of 1 which I know can't be correct. I'm sure RK4 will provide better results but do you see any reason why my solution shouldn't work optimally?

Iniciar sesión para comentar.

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by