# Runge Kutta

• Nov 8th 2010, 05:28 PM
gummy_ratz
Runge Kutta
Hi, I'm trying to solve

y''' - 2sin(t)y'' - yy' - y = 2cos(t) where y(0)=0, y'(0) = 1, y''(0) = 2 on 0<=t<=1 using the Runge Kutta method in Matlab, but I'm having a really hard time. I have the scheme to solve an equation like y(-2t + 1/t), but I'm not sure what to do for the higher order system. My textbook talks about it breifly, saying something about breaking it down into separate equations, but I'm lost. Please help!
• Nov 8th 2010, 08:08 PM
CaptainBlack
Quote:

Originally Posted by gummy_ratz
Hi, I'm trying to solve

y''' - 2sin(t)y'' - yy' - y = 2cos(t) where y(0)=0, y'(0) = 1, y''(0) = 2 on 0<=t<=1 using the Runge Kutta method in Matlab, but I'm having a really hard time. I have the scheme to solve an equation like y(-2t + 1/t), but I'm not sure what to do for the higher order system. My textbook talks about it breifly, saying something about breaking it down into separate equations, but I'm lost. Please help!

Introduce the state vector:

$\displaystyle {\rm{X}}(t)=\left[\begin{array}{c} y(t)\\y'(t)\\y''(t) \end{array}\right]$

Then:

$\displaystyle {\rm{X}}'(t)=\left[\begin{array}{c} y'(t)\\y''(t)\\y'''(t) \end{array}\right] =\left[\begin{array}{c} {\rm{X}}_2(t)\\{\rm{X}}_3(t)\\2\cos(t)+{\rm{X}}_1( t)+{\rm{X}}_1(t){\rm{X}}_2(t)+2\sin(t){\rm{X}}_3(t ) \end{array}\right]$

Now you apply the RK method to this first order vector ODE.

CB
• Nov 9th 2010, 01:39 PM
gummy_ratz
Okay thanks. I'm trying to find the actual solution in Matlab, but it's not working... it says "Warning, explicit solution cannot be found." Do you know how I might find the actual solution? When I try to find the solution on there for the example in the book it works fine, but both Matlab and Maple won't solve this equation for me. I did out the first step on paper when j=0, and I just kind of want to find out if I'm doing it right before I write out the whole program.
• Nov 9th 2010, 02:00 PM
CaptainBlack
Quote:

Originally Posted by gummy_ratz
Okay thanks. I'm trying to find the actual solution in Matlab, but it's not working... it says "Warning, explicit solution cannot be found." Do you know how I might find the actual solution? When I try to find the solution on there for the example in the book it works fine, but both Matlab and Maple won't solve this equation for me. I did out the first step on paper when j=0, and I just kind of want to find out if I'm doing it right before I write out the whole program.

The thread title was "Runge-Kutta", that is a numerical method. It will find a numerical solution even if there is not known closed form solution.

CB
• Nov 10th 2010, 12:59 PM
gummy_ratz
Ohh okay, thanks. I think I got it working, but I think I'm suppose to have a function like

function a=f(t,u)
a=zeros(1,3);a(1)=u(2);
a(2)=u(3);
a(3)=2.0*cos(t)+u(1)+u(1)*u(2)+2.0*sin(t)*u(3);

instead of writing it all out, but I'm not sure how to go about this in Matlab. How would I assign a value to u(2) and u(3)?
• Nov 10th 2010, 02:24 PM
CaptainBlack
Quote:

Originally Posted by gummy_ratz
Ohh okay, thanks. I think I got it working, but I think I'm suppose to have a function like

function a=f(t,u)
a=zeros(1,3);a(1)=u(2);
a(2)=u(3);
a(3)=2.0*cos(t)+u(1)+u(1)*u(2)+2.0*sin(t)*u(3);

instead of writing it all out, but I'm not sure how to go about this in Matlab. How would I assign a value to u(2) and u(3)?

The initial conditions will provide the initial value of the state vector, and that is what you need to start the process, RK will then step forward etc.

CB