Runge-kutta calculation giving lower order of accuracy than expected
4 ビュー (過去 30 日間)
古いコメントを表示
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)
0 件のコメント
回答 (1 件)
Abraham Boayue
2018 年 4 月 2 日
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
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!