MATLAB

(1)Finding the nature of the quatratic equation with matlab

% Finding the nature of the quatratic eqeation
clc
clear all
format rat
disp(‘solution’)
A=input(‘Enter the n x n matrix : ‘)
if A == A’
disp(‘A is symmetric matrix’)
else
disp(‘A is not in quadratic form, verify A’)
end
disp(‘characteristic equation P is’)
P=poly(A)
disp(‘The eigen values are’)
E=eig(A);
E=round(E)
n=numel(E);
s=sign(E);
p=sum(s(:)==1);
N=sum(s(:)==-1);
Z=sum(s(:)==0);
if n==p
disp(‘The given matrix is positive definite’)
elseif n==p+z
disp(‘The given matrix is positive semdefinite’)
elseif n==N
disp(‘The given matrix is negative definite’)
elseif n==N+Z
disp(‘The give matrix is negative semi-indifinite’)
else
disp(‘the given matrix is indifinite’)
end
disp([‘the rank of the matrix is:’,num2str(p+N),”])
disp([‘the index matrix is:’,num2str(p),”])
disp([‘the signature of the matrix is:’,num2str(p-N),”])

OUTPUT

solution
Enter the n x n matrix : [1 1 3;1 5 1;3 1 1]

A =

Columns 1 through 2

   1              1       
   1              5       
   3              1       

Column 3

   3       
   1       
   1       

A is symmetric matrix
characteristic equation P is

P =

Columns 1 through 2

   1             -7       

Columns 3 through 4

   *             36       

The eigen values are

E =

  -2       
   3       
   6       

the given matrix is indifinite
the rank of the matrix is:3
the index matrix is:2
the signature of the matrix is:1

+

PROGRAM 1 (Checked and Corrected)
FINDING EIGEN VALUES AND EIGEN VEC1TORS OF A
GIVEN MATRIX

AIM: To find the eigen values and eigen vectors of a matrix clear all; clc;
A=input(‘Enter the given matrix:’); disp(A); E=eig(A); [V,D]=eig(A);
disp(‘The eigen values of the given matrix are:’)
disp(E);
disp(‘The eigen vectors are’)
X1=V(:,1)
X2=V(:,2)
X3=V(:,3)

OUTPUT

Enter the given matrix:[2 0 -1;0 2 0;-1 0 2]
2 0 -1
0 2 0
-1 0 2

The eigen values of the given matrix are:
1
2
3

The eigen vectors are

X1 =

-0.7071
0
-0.7071

X2 =

 0 
 1 
 0 

X3 =

-0.7071
0
0.7071

PROGRAM 2
DIAGONALOSATION OF A MATRIX USING ELEMENTARY
TRANSFORMATION

Aim: To diagonalise a matrix using similarity transformation clear all; clc; A=input(‘ Enter the given matrix:’); B=A’; if(A==B)
disp(‘The matrix is symmetric’) else
disp(‘The matrix is not symmetric’) end disp(A); E=eig(A);
disp(‘The eigen values of the given matrix is’) disp(E) [V,D]=eig(A);
disp(‘The eigen vectors are’)
X1=V(:,1);
X2=V(:,2);
X3=V(:,3);
M=V; I=inv(M);
disp(‘The modal matrix is :’) disp(M)
disp (‘The inverse of the modal matrix is:’) disp(I); disp(‘The diagonal matrix D=inv(M)AM’)
D=I*A*M;

OUTPUT

Enter the given matrix:[2 1 1;2 3 2;1 1 2]
The matrix is not symmetric
2 1 1 2 3 2
1 1 2

The eigen values of the given matrix is
1.0000
5.0000
1.0000

The eigen vectors are The modal matrix is :
-0.8018 0.4082 -0.3794
0.5345 0.8165 -0.4364
0.2673 0.4082 0.8158

The inverse of the modal matrix is:
-0.9354 0.5406 -0.1459
0.6124 0.6124 0.6124
-0.0000 -0.4835 0.9671

The diagonal matrix D=inv(M)AM

D =

1.0000    0.0000    0.0000 
0.0000    5.0000    0.0000 
  0           -0.0000    1.0000  

PROGRAM 3
DIAGONALISATION OF A SYMMETRIC MATRIX USING ORTHOGONAL TRANSFORMATION

clear all; clc;
A=input(‘Enter the matrix A:’); n=length(A); disp(A);
disp(‘The eigen values of the given matrix are:’); [V,D]=eig(A); disp(diag(real(D))’)
disp(‘The eigen vectors of the corresponding eigen values’) disp(V) for i=1:n v=V(:,i); u(:,i)=v/norm(v) end disp(‘The normalised modal matrix is:’) M=u(:,1:n) disp(‘The Diagonal matrix is:’) D=(M)’A(M)
disp(‘D is the required canonical form of the given matrix A using orthogonal transformation’)

OUTPUT

Enter the matrix A:[8 -6 2;-6 7 -4;2 -4 3]
8 -6 2
-6 7 -4
2 -4 3

The eigen values of the given matrix are:
-0.0000 3.0000 15.0000

The eigen vectors for the corresponding eigen values
0.3333 0.6667 -0.6667
0.6667 0.3333 0.6667
0.6667 -0.6667 -0.3333

The normalised modal matrix is:

M =

0.3333    0.6667   -0.6667 
0.6667    0.3333    0.6667 
0.6667   -0.6667   -0.3333 

Diagonal matrix is

D =

0.0000    0.0000   -0.0000 

-0.0000 3.0000 -0.0000
-0.0000 -0.0000 15.0000

D is the required canonical form of the given matrix A using orthogonal transformation

                                PROGRAM 4 

NATURE OF A QUADRATIC FORM

clear all;
clc;
disp(‘To find the QF of_ _ _ _ _ _’)
A=input(‘Enter the matrix of Quadratic form:’); disp(A); E=eig(A);
disp(‘The eigen values of the given matrix are:’) disp(E) E1=round(E(1))
E2=round(E(2)) E3=round(E(3)) if (E1>0&&E2>0&&E3>0) disp(‘The QF is positive definite’) disp(‘Rank=3’) disp(‘Index=3’) disp(‘Signature=3’)

elseif(E1<0&&E2<0&&E3<0) disp(‘The QP is negative definite’) disp(‘Rank=3’) disp(‘Index=0’) disp(‘Signature=-3’)

elseif(E1==0&&E2>0&&E3>0)||(E1>0&&E2==0&&E3>0)||(E1>0&& E2>0&&E3==0)
disp(‘The QF IS positive semi definite’) disp(‘Rank=2’) disp(‘Index=2’) disp(‘Signature=2’)

elseif(E1>0&&E2==0&&E3==0)||(E1==0&&E2>0&&E3==0)||(E1== 0&&E2==0&&E3>0)
disp(‘The QF is positive semi definite’) disp(‘Rank=1’) disp(‘Index=1’) disp(‘Signature=1’)

elseif(E1==0&&E2<0&&E3<0)||(E1<0&&E2==0&&E3<0)||(E1<0&& E2<0&&E3==0)
disp(‘The QF is negative semi definite’) disp(‘Rank=2’) disp(‘Index=0’) disp(‘Signature=-2’)

elseif(E1<0&&E2==0&&E3==0)||(E1==0&&E2<0&&E3==0)||(E1== 0&&E2==0&&E3<0) disp(‘The QF is negative semi definite’) disp(‘Rank=1’) disp(‘Index=0’) disp(‘Signature=-1’) elseif(E1<0&&E2>0&&E3<0)||(E1>0&&E2>0&&E3<0)||(E1>0&&E2
<0&&E3>0)||
disp(‘The QF is indefinite’) disp(‘Rank=3’) disp(‘Index=2’) disp(‘signature=1’)
else(E1>0&&E2<0&&E3==0)||(E1>0&&E2==0&&E3<0)||(E1==0&&E 2>0&&E3<0)
disp(‘The QF is indefinite’) disp(‘Rank=2’) disp(‘Index=1’) disp(‘Signature=0’) end

OUTPUT

To find the QF of ————–
Enter the matrix of Quadratic form:[2 1 -1;1 2 -1;-1 -1 2]
2 1 -1
1 2 -1
-1 -1 2

The eigen values of the given matrix is
1.0000
1.0000
4.0000

E1 =

 1 

E2 =

 1 

E3 =

 4 

The QF is positive definite
Rank=3
Index=3
Signature=3

PROGRAM 5
PLOTTING THE TERMS OF A FINITE SEQUENCE

s=zeros(1,10); for n=1:10 s(1,n)=1/(n+1);
disp([num2str(n),’term=’,num2str(s(1,n))]); end
plot(s,’*’)

OUTPUT

output:
1term=0.5 2term=0.33333 3term=0.25
4term=0.2 5term=0.16667 6term=0.14286
7term=0.125 8term=0.11111 9term=0.1 10term=0.090909

FINDING FIBBRATIO IN SEQUENCE

clc
clear all
fibb=zeros(1,30);
fibb(1,1)=1 ;
fibb(1,2)=1 ;
for n=3:30
fibb(1,n)=fibb(1,n-1)+fibb(1,n-2);
end
for n=1:30
disp([num2str(n),’term=’,num2str(fibb(1,n))])
end
fibbratio=zeros(1,29);
for n=1:29
fibbratio(1,n)=fibb(1,n+1)/fibb(1,n);
end
for m=1:29
disp([num2str(n),’ratio=’,num2str(fibbratio(1,n))])
end
plot(fibbratio,’-‘)
subplot(2,1,1);
plot(fibb,’b‘); title(‘fibbonacci Sequence’); subplot(2,1,2); plot(fibbratio,’r‘);
title(‘fibbonacci Ratio’);

OUTPUT

1term=1
2term=1
3term=2
4term=3
5term=5
6term=8
7term=13
8term=21
9term=34
10term=55
11term=89
12term=144
13term=233
14term=377
15term=610
16term=987
17term=1597
18term=2584
19term=4181
20term=6765
21term=10946
22term=17711
23term=28657
24term=46368
25term=75025
26term=121393
27term=196418
28term=317811
29term=514229
30term=832040
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618
29ratio=1.618

Design a site like this with WordPress.com
Get started