Writing code to implement Runge-Kutta methods 1 and 4 for a second order nonlinear ODE
4 次查看(过去 30 天)
显示 更早的评论
Hi, I am very stuck... I rewrote the equation to where it is written as two 1st order ODE's.
Given: y"(t)+0.05y'(t)+y^3(t)=7.5cos(t)
After re-writing I have:
y_1=y y'_1=y_2
y_2=y' y'_2=-0.05y_2-(y^3_1)+7.5cos(t)
So,
y_(1,i+1)=y_(1,i)+h*y_(2,i) y_(2,i+1)=y_(2,i)+h*(-0.05y_(2,i)-y^3_1+7.5cos(t)
Initial conditions as: y_1(0)=0 and y_2(0)=1
I need to implement these y_1 and y_2 into the Runge Kutta methods for RK1 and RK4.
Thank you!
3 个评论
James Tursa
2016-5-5
@Jan: The usual meaning is RK1 is 1st order Runge Kutta (i.e., Euler Method), and RK4 is 4th order Runge Kutta.
James Tursa
2016-5-5
@Bear12: Are you intending to use MATLAB provided functions for the integration? I.e., ode45? Or are you supposed to write the RK1 and RK4 integration code yourself?
回答(1 个)
Manali Gupta
2019-6-21
Hi,
Attached file trk.m calculates the derivatives of the variables. The RK4 algorithm to solve the set of equations is implemented in solveOde.m.
I hope this helps.
0 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!