## Writing code to implement Runge-Kutta methods 1 and 4 for a second order nonlinear ODE

Bear12

### Bear12 (view profile)

님이 질문을 제출함. 5 May 2016
최근 활동 Manali Gupta

### Manali Gupta (view profile)

님이 답변함. 21 Jun 2019
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!

Jan

### Jan (view profile)

5 May 2016
Please use the "{} Code" button to format your equations. Currently they are not readable. Are you aware that we cannot guiess what "RK1" and "RK4" means? Did you search for the thousands of examples for Runge-Kutta integrators written in Matlab?
James Tursa

### James Tursa (view profile)

5 May 2016
@Jan: The usual meaning is RK1 is 1st order Runge Kutta (i.e., Euler Method), and RK4 is 4th order Runge Kutta.
James Tursa

### James Tursa (view profile)

5 May 2016
@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?

로그인 to comment.

## 답변 수: 1

Manali Gupta

### Manali Gupta (view profile)

님의 답변 21 Jun 2019

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.

로그인 to comment.