# Thread: Runge Kutta, linear differential system

1. ## Runge Kutta, linear differential system

I need to make a matlab program to find the solutions for 0<=t<=1 for

x1'(x) = 2x1 -3x2 +4x3 +0x4 -2x5 -2, x1(0)=1
x2'(x) = x1 - 2x2 - 2x3 +x4 +2x5 -1, x2(0)=-1
x3'(x) = 2x1 + 4x2 +3x3 +x4 -x5 -2, x3(0)=1
x4'(x)=-2x1 +0x2 +x3 + 4x4 -3x5 +1, x4(0)=2
x5'(x)=0x1 -x2 +2x3 -3x4 -2x5 +1, x5(0)=3

and I made a program, and I got an output:
w(1)= 94.70989959 w(2)= -5.06974461 w(3)= 81.70881908 w(4)= 7.03658123 w(5)= 12.84918264

but I have no idea how to tell whether or not I'm right. The other examples I've done have been higher order initial value problems that depended on t... so I used the same kind of scheme... but this one doesn't seem to depend on t... so I'm not sure if I'm suppose to do something different or not?

Is there a way to get an exact solution for this for me to check to see if I'm right or?

2. Also, for a different example with a higher order equation, my function looked like:
function a=nonf(t,u)
a=zeros(1,length(u));
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);

Right now my function for this question looks like:

function a=nonff(t,u, coef)
a=zeros(1,length(u));
for i=1:length(u)
sum=0;
for k=1:length(u)
sum=sum+coef(i,k)*u(k);
end
a(i)= sum+coef(i,length(u)+1);
end

Would that be right, or would I need something like
a(1)=u(2);
a(2)=u(3);
a(3)=u(4)
a(4)=u(5)

3. Originally Posted by gummy_ratz
I need to make a matlab program to find the solutions for 0<=t<=1 for

x1'(x) = 2x1 -3x2 +4x3 +0x4 -2x5 -2, x1(0)=1
x2'(x) = x1 - 2x2 - 2x3 +x4 +2x5 -1, x2(0)=-1
x3'(x) = 2x1 + 4x2 +3x3 +x4 -x5 -2, x3(0)=1
x4'(x)=-2x1 +0x2 +x3 + 4x4 -3x5 +1, x4(0)=2
x5'(x)=0x1 -x2 +2x3 -3x4 -2x5 +1, x5(0)=3

and I made a program, and I got an output:
w(1)= 94.70989959 w(2)= -5.06974461 w(3)= 81.70881908 w(4)= 7.03658123 w(5)= 12.84918264

but I have no idea how to tell whether or not I'm right. The other examples I've done have been higher order initial value problems that depended on t... so I used the same kind of scheme... but this one doesn't seem to depend on t... so I'm not sure if I'm suppose to do something different or not?

Is there a way to get an exact solution for this for me to check to see if I'm right or?
A first observation would be: You are asked for a solution on [0,1] not a single point.

A second observation might be: This is a linear 5-th order system, it has a known solution (either in matrix form or by expanding to a single 5-th order linear constant coefficient ODE)

CB

4. Yeah, my program goes from 0<t<1, that was just my final answer for t=1 when I reached convergence within 8 decimal points. I'm taking numerical analysis now, but I haven't taken differential equations yet, so I'm really not sure, what method could I use to solve this system to see if my runge kutta answer matches up?

5. Originally Posted by gummy_ratz
Yeah, my program goes from 0<t<1, that was just my final answer for t=1 when I reached convergence within 8 decimal points. I'm taking numerical analysis now, but I haven't taken differential equations yet, so I'm really not sure, what method could I use to solve this system to see if my runge kutta answer matches up?
Sorry but if you have not done differential equations you are not ready for numerical solution of them. It is not our place to provide a course in DEs.

You could try comparing the RK solution with a solution computed using a simpler method (say Euler) with a smaller step size.

CB

6. Yeah, I know that there's an easy way to get Maple to find the actual solution to higher order differential equations, and I searched to try to find a way to do it for the linear systems, but I couldn't find one, so I just thought I'd check to see if you guys knew. Thanks, anyways.