You are on page 1of 2

//Program to solve Given system of coupled first order differential equations as an eigenvalue problem.

//Vidisha (1433)

A=[3,2;2,3]
[c,d]=spec(A)
disp(d(1,1),"The first eigenvalue is:")
disp(d(2,2),"The second eigenvalue is:")
disp(c(:,1),"The first eigenvector is:")
disp(c(:,2),"The second eigenvector is:")
function w1=f(t)
w1=c(:,1)*%e^((d(1,1))*t)
endfunction
Y1=f(0)
function w2=g(t)
w2=c(:,2)*%e^((d(2,2))*t)
endfunction
Y2=g(0)
M=[Y1,Y2]
disp(M,"The matrix made for t=0 is:")
//Giving initial conditions
B=[3;1] //y1(0)=3,y2(0)=1
//solving system of equations using gaussian elimination
n=length(B)
Aug=[M,B]
//Forward elimination
for j=1:n-1
for i=j+1:n
Aug(i,j:n+1)=Aug(i,j:n+1)-Aug(i,j)/Aug(j,j)*Aug(j,j:n+1)
end
end
//Backward substitution
x=zeros(n,1)
x(n)=Aug(n,n+1)/Aug(n,n)
for i=n-1:-1:1
x(i)=(Aug(i,n+1)-Aug(i,i+1:n)*x(i+1:n))/Aug(i,i)
end
disp(x(1,1),"The value of a=")
disp(x(2,1),"The value of b=")
disp("The first solution y1 is:")
disp("y1="+string(x(1,1))+"*e^"+string(d(1,1))+"*t+"+string(x(2,1))+"*e^"+string(d(2,2))+"*t")
disp("The second solution y2 is:")
disp("y2="+string(x(1,1))+"*e^"+string(d(1,1))+"*t-"+string(x(2,1))+"*e^"+string(d(2,2))+"*t")

OUTPUT:

The first eigenvalue is:

1.

The second eigenvalue is:

5.

The first eigenvector is:

-0.7071068

0.7071068

The second eigenvector is:

0.7071068

0.7071068
The matrix made for t=0 is:

-0.7071068 0.7071068

0.7071068 0.7071068

The value of a=

-1.4142136

The value of b=

2.8284271

The first solution y1 is:

y1=-1.4142136*e^1*t+2.8284271*e^5*t

The second solution y2 is:

y2=-1.4142136*e^1*t-2.8284271*e^5*t

You might also like