Originally Posted by

**Maccaman** Hello,

I need to solve a second order differential equation in Matlab.....which sucks because I HATE using Matlab.(Headbang)

Anyway, I cannot use the built-in matlab functions ode45, ode23s, ect, I have to employ the use of the fourth order Runge Kutta method......which I can do for a first order differential equation, but I cant think of how to use it for a 2nd order DE. I think that I first have to transform the 2nd order DE into a system of 1st order DE's.

Here is my matlab code for an IVP (1st order) using fourth order Runge Kutta method.

function y = rk4step(f,t,x,h)

% f - Matlab inline function f(t,y)

% t - initial time

% x - initial condition

% h - stepsize

h2 = h / 2;

k1 = f(t, x);

k2 = f(t + h2, x + h2 * k1);

k3 = f(t + h2, x + h2 * k2);

k4 = f(t + h, x + h * k3);

y = x + (k1 + 2 * k2 + 2 * k3 + k4) * h / 6

Should I transform the system of first order DE's into a vector and go from there?