0% found this document useful (0 votes)
23 views25 pages

Mat Lab Observation

The document provides details of an experiment course on matrices and calculus integrated lab. It includes 9 experiments covering topics like finding characteristic polynomials and eigenvalues/eigenvectors of matrices, diagonalization of matrices, reduction of quadratic forms, verification of Cayley-Hamilton theorem, solving first order partial differential equations, and finding extrema of functions. For each experiment, the document provides the aim, MATLAB code, and sample output. The course aims to help students learn concepts and applications of matrices and calculus through hands-on experimentation in MATLAB.

Uploaded by

abinash ayyappan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views25 pages

Mat Lab Observation

The document provides details of an experiment course on matrices and calculus integrated lab. It includes 9 experiments covering topics like finding characteristic polynomials and eigenvalues/eigenvectors of matrices, diagonalization of matrices, reduction of quadratic forms, verification of Cayley-Hamilton theorem, solving first order partial differential equations, and finding extrema of functions. For each experiment, the document provides the aim, MATLAB code, and sample output. The course aims to help students learn concepts and applications of matrices and calculus through hands-on experimentation in MATLAB.

Uploaded by

abinash ayyappan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

AN AUTONOMOUS INSTITUTION

REGULATION - 2023

DEPARTMENT OF MATHEMATICS

MATLAB OBSERVATION

FIRST YEAR B.E/B.Tech Degree Courses

(Common to all branches) –Semester I

Course Name: MATRICES AND CALCULUS-LAB INTEGRATED

Course Code: 231MA101

1
Matrices and Calculus - Lab Integrated

Page Remarks
Course No.
Sl.No. Name of Experiment
Outcome

SEMESTER - 1

1 Finding the coefficients of characteristic


CO1
polynomials.
Find the Eigenvalues and Eigenvectors of a
CO1
2 given matrix.
3 Diagonalization of a real asymmetric matrix by
CO1
orthogonal transformation.
Reduction of Quadratic form to a canonical
4 CO1
form
5 Verification of Cayley-Hamilton theorem and its
CO1
applications
6 Solving First order partial differential equations CO3

To find the extreme values of a function of two


7 variables. CO3

Partial derivatives of a function at a given point,


Jacobian of several variables and expansion of a
8 CO3
function in power series using Taylor’s formula

Maxima minima of the given function by the


9 CO3
Lagrangian multiplier method.

2
1.FINDING THE COEFFICIENTS OF CHARACTERISTIC
POLYNOMIALS.

Aim: To find the coefficient of polynomial

MATLAB CODE:
clc

clear all

format compact

A = input("Enter the matrix A;")

Characteristic_Polynomial=poly(A);

disp("The coefficient of Characteristic_Polynomial are ")

disp(Characteristic_Polynomial)

3
Output

4
2. FINDING THE EIGEN VALUES AND EIGEN VECTORS OF A GIVEN
MATRIX.
Aim: To find the eigen values and eigen vectors of a matrix
MATLAB CODE
clc
clear all
format compact
A = input('Enter the matrix A')
Characteristic_Polynomial=poly(A);
Characterstic_Roots =poly(A);
Eigen_values_of_A=eig(A);
[X,D]=eig(A);
disp('The eigen values of A')
disp(eig(A))
disp('The eigen vectors for the corresponding eigenvalues')
disp(X)

5
Output

6
3 . DIAGONALIZATION OF A REAL SYMMETRIC MATRIX BY
ORTHOGONAL TRANFORMATION

Aim: Reduce the real symmetric matrix to diagonal matrix by using orthogonal
transformation.

MATLAB Code
clc
clear all
format compact
A=input('Enter the matrix A:');
disp('Coefficient of Characteristic Polynomial ')
p=poly(A);
disp('Eigen Values of A:')
E=round(eig(A));
[r,c]=size(A);
[X,D]=eig(A);
disp('The eigen vectors for the corresponding eigenvalues')
disp(round(X))
% Diagonalization of the real symmetric matrix A having distinct eigenvalues by
orthogonal transformation
for i=1:r x=X(:,i);
u(:,i)=x/norm(x);
end
disp('Normalised modal matrix')
N=u(:,1:r);
disp(N)
disp('D=transpose(N)*A*N');
D=(N)'*A*(N);
disp('D =')
disp(round(D));
D1=round(D);
disp('Thus A is reduced to the diagonal matrix D,whose diagonal elements are
eigen values of the matrix A.');

7
Output

8
4. REDUCTION OF QUADRATIC FORM TO A CANONICAL FORM AND
FINDING NATURE, INDEX, SIGNATURE AND RANK

Aim:To find nature, index, rank & signature of the given form

MATLAB code:

clc
clear
syms y1 y2 y3
format compact
a11=input('Enter coefficient of x^2:');
a12=input('Enter coefficient of xy/2:');
a13=input('Enter coefficient of xz/2:');
a21=input('Enter coefficient of yx/2:');
a22=input('Enter coefficient of y^2:');
a23=input('Enter coefficient of yz/2:');
a31=input('Enter coefficient of zx/2:');
a32=input('Enter coefficient of zy/2:');
a33=input('Enter coefficient of z^2:');
A=[a11 a12 a13;a21 a22 a23;a31 a32 a33]
%A=input('Enter the matrix A:')
Y=[real(y1); real(y2); real(y3)];
[r,c]=size(A);
[X,D]=eig(A);
disp('The eigen vectors for the corresponding eigenvalues')
disp(round(X))
% Diagonalization of the real symmetric matrix A having distinct eigenvalues by
orthogonal transformation
for i=1: r,
x=X(:,i);
u(:,i)=x/norm(x);

9
end
disp('Orthogonal matrix associated with A is the matrix')
P1=u(:,1: r);
disp(round(P1))
disp('D=transpose(P1)*A*P1');
D=(P1)'*A*(P1);
disp('D =')
disp(round(D));
D1=round(D);
disp('Thus A is reduced to the diagonal matrix D through P1 by orthogonal
transformation.');
disp('Canonical Form = transpose(Y)*D*Y ');
Canonical_form=Y'*D1*Y
%Nature of the quadratic form
B=eig(A)
n=length(B)
pos = 0;
neg = 0;
zro = 0;
for i = 1: n
if(B(i)>0)
pos=pos+1;
else if(B(i)<0)
neg=neg+1;
else
zr0=zro+1;
end
end
end
pos
neg

10
zro
disp('Nature of the quadratic form')
if(pos==n)
disp('POSITIVE DEFINITE')
else if(neg==n)
disp('NEGATIVE DEFINITE')
else if(pos<n&&zro>=1)
disp('POSITIVE SEMI-DEFINITE')
else if(neg<n&&zro>=1)
disp('NEGATIVE SEMI-DEFINITE')
else
disp('indefinite') end
end
end
end
disp('Rank of the quadratic form=')
disp(pos+neg)
disp('Index of the quadratic form=')
disp(pos)
disp('Signature of the quadratic form=')
disp(abs(pos-neg))

11
Output

12
5. VERIFICATION OF CAYLEY-HAMILTON THEOREM AND ITS APPLICATIONS

Aim:
To Verify Cayley – Hamilton theorem and hence find its inverse and
powers.
MATLAB Code:
clear all
clc
format compact
A=input('Enter the matrix A:');
n=length(A);
c=poly(A) %Coefficients of the characteristic polynomial
CHT= polyvalm(c,A)
P=zeros(n,n); % Initialization purpose
for i=1:n+1
P=P+c(i)*A^(n+1-i); % Characteristic equation
end
Determinant=det(A)
if det(A)~= 0
inv_A=zeros(n,n);
pow_A=zeros(n,n);
for j=1:n
inv_A= inv_A - ((1/c(n+1))*(c(j)*A^(n-j)));
pow_A=pow_A-((1/c(1))*(c(j+1)*A^(n+1-j)));
end
inv_A
pow_A
else
for k=1:n
pow_A=pow_A-((1/c(1))*(c(k+1)+A^(n+1-k)));
end
13
pow_A
disp( 'A is a singular matrix')
end

14
Output

15
6. SOLVING FIRST ORDER PARTIAL DIFFERENTIAL

EQUATION (Method of Multipliers)

Aim: To find the solution of the first order partial differential equation.

MATLAB Code:

clc
clear all
syms P Q R r
P=input("Enter the coefficient of p interms of x,y, z (P) ;")
Q=input("Enter the coefficient of q interms of x,y, z (Q);")
R=input("Enter the coefficient of r interms of x,y, z(R);")
r=simplify(P+Q+R);
r1=simplify(x*P+y*Q+z*R);
r2=simplify(P/x+Q/y+R/z);
r3= simplify(y*P+x*Q+R);
r4= simplify(x*P+y*Q+R);
r5= simplify(P+x*Q+y*R);
r6=simplify(P/(x^2)+Q/(y^2)+R/(z^2));
r7=simplify(2*P+3*Q+4*R);
r8=simplify(l*P+m*Q+n*R);
N=[num];
%num =0;num1=0;num2=0;num3=0;num4=0;num5=0;
if(r==0)
num=int(1, x) +int(1, y) +int(1, z);
N1=[num];
N=[N,N1];
end
if(r1==0)
num1=int(x, x) +int(y, y)+int(z, z);
N1=[num1];
N=[N,N1];
end
if(r2==0)
num2=simplify(exp(int(1/x, x) +int(1/y, y)+int(1/z, z)));
N1=[num2];
N=[N,N1];
end
if(r3==0)
num3=simplify(int(y, x) +int(x, y) +int(1, z))
16
N1=[num3];
N=[N,N1];
end
if(r4==0)
num4=simplify(int(x, x) +int(y, y) +int(1, z));
N1=[num4];
N=[N,N1];
end
if(r5==0)
num5=simplify(int(1, x) +int(y, y) +int(zop, z));
N=[num5];
N=[N,N1]
end
if(r6==0)
num6=simplify((int(1/(x^2), x)+int(1/(y^2),y)+int(1/(z^2),z)));
N=[num6];
N=[N,N1]
end
if(r7==0)
num7=simplify((int(2, x)+int(3,y)+int(4,z)));
N=[num7];
N=[N,N1]
end
if(r8==0)
num8=simplify((int(l, x)+int(m,y)+int(n,z)));
N=[num8];
N=[N,N1]
end
disp("Complete solution")
disp(N)
disp("=0")

17
Output

18
7. MAXIMA AND MINIMA OF A FUNCTION OF TWO VARIABLES

Aim: To find the extreme values of a function of two variables.

MATLAB Code:

clc
clear all
syms x y real
f=input('Enter the function f(x,y):');
fx=diff(f,x);
fy=diff(f,y);
[ax ay]=solve(fx,fy);
fxx= diff(fx,x);
fxy=diff(fx,y);
fyy=diff(fy,y);
D=fxx*fyy - fxy^2;
Figure
ezsurf(f,[min(double(ax))-.5,max(double(ax))+.5, min(double(ay))-
.5,max(double(ay))+.5]);
colormap winter
shading interp
for i = 1:1:size(ax)
T1=subs(subs(D,x,ax(i)),y,ay(i));
T2=subs(subs(fxx,x,ax(i)),y,ay(i));
T3=subs(subs(f,x,ax(i)),y,ay(i));
if (double(T1) == 0)
sprintf('The point (%d,%d) needs further investigation',
double(ax(i)),double(ay(i)))
elseif (double(T1) < 0)
sprintf('The point (%d,%d) is a saddle point',
double(ax(i)),double(ay(i)))
st = 'y.';
else
if (double(T2) < 0)
sprintf('The maximum value of the function is %d at the point
(%d,%d)',double(T3),double(ax(i)), double(ay(i)))
st = 'r+';
else
sprintf('The minimum value of the function is %d at the point (%d,%d)',
double(T3), double(ax(i)),double(ay(i)))
st = 'k*';
end
end
hold on
19
plot3(double(ax(i)),double(ay(i)),double(T3),st,'markersize',20);
end

20
Output

21
8. PARTIAL DERIVATIVES OF A FUNCTION AT A GIVEN POINT,
JACOBIAN OF SEVERAL VARIABLES AND EXPANSION OF A
FUNCTION IN POWER SERIES USING TAYLOR’S FORMULA

Aim: To find the partial derivatives of a function at a given point, Jacobian of


several variables and Expansion of a function in power series using Taylor’s
formula.

MATLAB Code:

clc
clear all
format compact
syms x y real
f=input('Enter the first function f=');
fx=diff(f,x)
fy=diff(f,y)
fxx=diff(fx,x)
fyy=diff(fy,y)
fxy=diff(fx,y)
f_at_point= subs(f,[x,y],[1,1])
fxx_at_point = subs(fxx,[x,y],[1,1])
fxy_at_point= subs(fxy,[x,y],[1,1])
fy_at_point= subs(fy,[x,y],[1,1])
fyy_at_point= subs(fyy,[x,y],[1,1])
g=input('Enter the second function g=')
J=jacobian([f,g],[x,y])
detJ= simplify(det(J))
disp('Maclaurin series of first function f')
t0=taylor(f,[x,y],[0,0],'order',3)
pretty(t0)
disp('Taylor series of second function f')
t=taylor(f,[x,y],[1,1],'order',3)
pretty(t)

22
Output

23
9. MAXIMA & MINIMA OF GIVEN FUNCTION BY LAGRANGE'S
MULTIPLIER METHOD

Aim: To find the extreme values of a function of two variables with constraints.

MATLAB Code:

clc
clear all
format compact
syms x y lamda
f=input("Enter the function f(x,y)=")
g=input("Enter the Constraint g(x,y)=")
L=f + lamda*g
Lx = diff(L,x)
Ly = diff(L,y)
Llamda = diff(L,lamda) [ax,ay, Llamda]=solve(Lx,Ly,Llamda)
for i=1:length(ax)
d=subs(subs(f,x,ax),y,ay)
sort(d)
end
f_Min=d(1)
f_Max=d(end)

24
Output

25

You might also like