Вы находитесь на странице: 1из 12

ASSIGNMENT-1 (A ):

Write a Program to find the following from the given matrix


A = [7 -2 2 ; -2 1 4 ; -2 4 1 ];
(i) Eigen Values of A
(ii) Eigen Vectors of A
(iii) Sum of the Eigen Values of A
(iv) Product of the Eigen Values of A
(v) Eigen Values and Eigen Vectors of A2
(vi) Eigen values and Eigen Vectors of A-1

CODING:
clc
clear all
A =[7 -2 2 ; -2 1 4 ; -2 4 1 ];
[v,d]=eig(A);
disp('Eigen Values of the Matrix A:')
eigenvalues = diag(d)
disp('Eigen Vectors of Matrix A:')
x1 = v(:,1)
x2 = v(:,2)
x3 = v(:,3)
disp('Sum of the Eigen Values of A')
sumofeigenvalues=sum(eig(A))
disp('Product of Eigen Values of A:')
product=prod(eig(A))
[v1,d1]=eig(A*A);
disp('Eigen Values of the Matrix A*A:')
eigenvalues = diag(d1)
disp('Eigen Vectors of Matrix A*A:')
x1 = v1(:,1)
x2 = v1(:,2)
x3 = v1(:,3)
[v2,d2]=eig(inv(A));
disp('Eigen Values of the Inverse of the Matrix A:')
eigenvalues = diag(d2)
disp('Eigen Vectors of the inverse of the Matrix A:')
x1 = v2(:,1)
x2 = v2(:,2)
x3 = v2(:,3)
OUTPUT:
eigenvalues = 7 5 -3

Eigen Vectors of Matrix A: x1 = [ 0.5774 -0.5774 -0.5774]

x2 =[ 0.0000 -0.7071 -0.7071 ]

x3 = [ -0.2709 -0.7450 0.6096]

Sum of the Eigen Values of A= 9

Product of Eigen Values of A = -105

Eigen Values of the Matrix A*A: 25 49 9

Eigen Vectors of Matrix A*A: x1 =[ 0 -0.7071 -0.7071]

x2 =[ -0.5774 0.5774 0.5774]

x3 =[ -0.2709 -0.7450 0.6096]

Eigen Values of the Inverse of the Matrix A: 0.1429 0.2 - 0.3333

Eigen Vectors of the inverse of the Matrix A: x1 =[ -0.5774 0.5774 0.5774]

x2 =[ -0.0000 0.7071 0.7071]

x3 =[ -0.2709 -0.7450 0.6096]


ASSIGNMENT- 1 ( B ):
Write a Program to find the Modal matrix and Diagonal matrix and hence
diagonalise the Matrix A=[7 -2 0; -2 6-2 ;0 -2 5 ]

CODING:
clc
clear all
A=[7 -2 0 ; -2 6 -2 ; 0 -2 5 ] ;
disp('Given Matrix A:')
disp(A)
[P,D] =eig(A);
disp('Modal Matrix P:')
disp(P)
disp('Diagonal Matrix D:')
disp(D)
disp('Diagonalising the given Matrix A into a
Diagonal Matrix by Similarity Transformation:')
D1 = inv(P)*A*P
disp('Diagonal Matrix D and Diagonalised Matrix D1 of
the given Matrix A are same.')
OUTPUT:

Given Matrix A: 7 -2 0

-2 6 -2

0 -2 5

Modal Matrix P: -0.3333 0.6667 -0.6667

-0.6667 0.3333 0.6667

-0.6667 -0.6667 -0.3333

Diagonal Matrix D: 3 0 0

0 6 0

0 0 9

Diagonalising the given Matrix A into a Diagonal Matrix by Similarity


Transformation:

D1 = 3 0 0

0 6 0

0 0 9

Diagonal Matrix D and Diagonalised Matrix D1 of the given Matrix A are


same.
ASSIGNMENT-2:
Write a Program for a Fourier series up to six terms and visualise the series
for the function f(x) =abs(cos(x)) in – π < x < π
clear all
clc
syms x k lower upper L n
f = input('Enter the function: ');
lower = input('Enter the lower limit: ');
upper = input('Enter the upper limit: ');
L = (upper-lower)/2;
n = input('Enter the no. of terms required: ');
ak = @(f,x,k)int((f*cos(k*pi*x/L)/L),x,lower,upper);
bk = @(f,x,k)int((f*sin(k*pi*x/L)/L),x,lower,upper);
sum = ak(f,x,0)/2;
for k=1:n-1
sum = sum +
ak(f,x,k)*cos(k*pi*x/L)+bk(f,x,k)*sin(k*pi*x/L);
ezplot(f,[lower upper])
hold on
ezplot(sum,[lower upper])
hold on
end
series=sum
OUTPUT:
Enter the function: abs(cos(x))

Enter the lower limit: - pi

Enter the upper limit: pi

Enter the no. of terms required: 6

series =(4*cos(2*x))/(3*pi) - (4*cos(4*x))/(15*pi) + 2/pi

(4 cos(2 x))/(3 ) - (4 cos(4 x))/(15 ) + 2/ 

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

-3 -2 -1 0 1 2 3
x
ASSIGNMENT-3:
Write a program for the Power series solution of the differential equation

(1+x^2)y"+x*y -y=0 with y(0)=2 and dy(0)=3 up to four


terms and give the graph for the power series.

CODING:
clc
clear all
syms x a0 a1 a2 a3 ;
a = [a0 a1 a2 a3 ];
disp('Given equation:(1+x^2)y"+x*y -y=0 with y(0)=2
and dy(0)=3')
y = sum(a.*x.^[0:3])
dy = diff(y);
d2y=diff(dy);
ode = collect((1+x^2)*d2y+x*dy-y,x)
c=coeffs(ode,x)
cx0=c(1);
cx1=c(2);
a0=strcat(char(subs(y,x,0)),'=2');
a1=strcat(char(subs(dy,x,0)),'=3');
[a0 a1 a2 a3 ] = solve(a0,a1,cx0,cx1)
solution=subs(y)
fplot(char(solution),[-4 4],'r--')
OUTPUT:
Given equation: ( 1+x^2)y"+x*y -y=0 with y(0)=2 and dy(0)=3

y = a3*x^3 + a2*x^2 + a1*x + a0

ode =8*a3*x^3 + 3*a2*x^2 + 6*a3*x - a0 + 2*a2

c =[ 2*a2 - a0, 6*a3, 3*a2, 8*a3]

a0 =2 ; a1 =3 ; a2 =1 ; a3 =0

solution = x^2 + 3*x + 2

GRAPH:

30

25

20

15

10

-5
-4 -3 -2 -1 0 1 2 3 4
ASSIGNMENT-4:

Write a program to solve the differential equation y” – 3 y’ +2 y =x2 with


y(0) =0 , y’(0) = 0 using the method of variation of parameters.

CODING:
clear all
clc
syms A B x m
p=input('Enter the coefficients a , b , c :');
X = input( 'Enter the RHS function f(x):');
a = p(1);
b = p(2);
c = p(3);
d = b^2 - 4*a*c;
m = subs(solve('a*m^2+b*m+c'));
if(d>0)
CF=A*exp(m(1)*x) +B*exp(m(2)*x);
y1= exp(m(1)*x);
y2=exp(m(2)*x);
elseif(d == 0)
CF = (A + B *x) *exp(m(1)*x);
y1=exp(m(1)*x);
y2=x*exp(m(1)*x);
else alfa=real(m(1));
beta=imag(m(1));
CF=exp(alfa*x)*(A*cos(beta*x)+B*sin(beta*x));
y1=exp(alfa*x)*cos(beta*x);
y2= exp(alfa*x)*sin(beta*x);
end
W=y1*diff(y2,x)-y2*diff(y1,x);
u=int(-y2*X/W,x);
v=int(y1*X/W,x);
PI=u*y1+v*y2;
y=CF+PI;
dy=diff(y);
cond=input('Enter the initial conditions x0,y(x0) and
Dy(x0) : ');
eq1=(subs(y,x,cond(1))-cond(2));
eq2=(subs(dy,x,cond(1))-cond(3));
[A B]=solve(eq1, eq2);
Y=subs(CF+PI)
OUTPUT:
Enter the coefficients a , b , c : [1 -3 2]

Enter the RHS function f(x): x^2

Enter the initial conditions x0,y(x0) and Dy(x0) : [0 0 0]

Y = (3*x)/2 + exp(2*x)/4 - 2*exp(x) + x^2/2 + 7/4


ASSIGNMENT-5 (A):
Write a program to solve the differential equation
(d2y / dt2 ) + 4 (dy / dt ) + 4 y = 3 sin t + 4 cos t with the initial conditions
(dy/dt) = 2 at t = 0 and y(0) = 1 and visualise the solution

CODING:
Clc
clear all
eqn=input('Enter the equation: ');
cond=input('Enter the conditions: ');
y=dsolve(eqn,cond,'x');
soln=['y(x)=', char(simplify(y))];
disp(soln)
ezplot(y)

OUTPUT: Enter the equation: 'D2y+4*Dy+4*y=3*sin(x)+4*cos(x)'

Enter the conditions: 'y(0)=1, Dy(0)=2'

y(x)=exp(-2*x) + sin(x) + 3*x*exp(-2*x)

GRAPH:

5
x 10 exp(-2 x) + sin(x) + 3 x exp(-2 x) +...- 2 x sin(x)

-0.5

-1

-1.5

-2

-2.5

-3

-3.5
-6 -4 -2 0 2 4 6
x
ASSIGNMENT-5 ( B ):
Solve Y"-3Y'+2Y=0 WITH Y(0)=1 AND Y'(0)=-1,using Laplace
transform

CODING:
clc
clear all
syms t s LOFY
y2 = diff(sym('y(t)'),2);
y1 = diff(sym('y(t)'), 1);
y0 = sym('y(t)');
LTY=laplace(y2 - 3*y1 +2*y0);
LTY=subs(LTY,{'laplace(y(t),t,s)','y(0)','D(y)(0)'},
{LOFY, 1,-1});
eq=collect(LTY,LOFY);
LOFY=simplify(solve(eq,LOFY))
Y=simplify(ilaplace(LOFY))
ezplot(Y)

OUTPUT:
LOFY = (s - 4)/(s^2 - 3*s + 2)

Y = - exp(t)*(2*exp(t) - 3)

GRAPH:
4
x 10 -exp(t) (2 exp(t) - 3)

-1

-2

-3

-4

-5

-6
-4 -2 0 2 4 6
t

Вам также может понравиться