Advanced MP Pracs 2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Practical:- 01 ->To show that Eigen functions of Hermitian matrices

are orthogonal.

clc;
clear;
clf;
//Orthogonal polynomials as Hermitian Matrices
//ANIKET
a=4
b = 1.5
A = [a 0 0;0 -a 0;0 0 -a]
B=[b 0 0;0 0-1*%i*b; 0 %i*b
0]
disp("Matrix A=",A)
disp("Matrix B =",B )
E = A' //calculates the complex conjugate transpose
F = B' //Calculates the complex conjugate transpose
disp("complex conjugate transpose of A: ",E)
disp("complex conjugate transpose of B : ",F)
if ( A ==E) then
disp("The Matrix A is Hermitian.")
end if(B==F)
then
disp("The Matrix B is Hermitian.")
end
[P,Q]=spec(A)
[H,I]=spec(B)
disp("Eigen functions of A:",P)
disp("Eigen functions of B: ",H)
X=real(P'*P)
Y=real(H'*H)
if ((P(:,1)'*P(:,2) == 0) && (P(:,2)'*P(:,3)==0) && (P(:,3)'* P(:,1)==0))then
disp("The Eigen functions of Hermitian Matrix A are orthogonal.")
else
disp("The Matrix Eigen functions are not orthogonal and the matrix A is not Hermitian")
end
if ((H(:,1)'*H(:,2) == 0) && (H(:,2)'*H(:,3)==0) && (H(:,3)'*H(:,1)==0))then
disp("The Eigen functions of Hermitian Matrix B are orthogonal.")
else
disp("The Matrix Eigen functions are not orthogonal and the matrix B is not Hermitian")
end

OUTPUT:-
"Matrix A "

4. 0. 0.
0. -4. 0.
0. 0. -4.

"Matrix B "

1.5 + 0.i 0. + 0.i 0. + 0.i


0. + 0.i 0. + 0.i 0. - 1.5i
0. + 0.i 0. + 1.5i 0. + 0.i

"complex conjugate transpose of A:"

4. 0. 0.
0. -4. 0.
0. 0. -4.
"complex conjugate transpose of B:"

1.5 + 0.i 0. + 0.i 0. + 0.i


0. + 0.i 0. + 0.i 0. - 1.5i
0. + 0.i 0. + 1.5i 0. + 0.i

"The Matrix A is Hermitian."

"The Matrix B is Hermitian."

"Eigen functions of A : "

0. 0. 1. 1.
0. 0.
0. 1. 0.

"Eigen functions of B:"

0. + 0.i 0. + 0.i 1. + 0.i


0. - 0.70710681 0 - 0.70710681 0. + 0.i
-0.70710681 + 0.i 0.70710681 +0.i 0 . +0.i
"The Eigen functions of Hermitian Matrix A are orthogonal."
"The Eigen functions of Hermitian Matrix B are orthogonal."

Practical:- 02-> To find the largest and smallest Eigenvalues &


Eigenvectors of the matrices.

clc
clear
A=input("Enter the elements of the given matrix ")
acc=input("Enter the tolerance limit ")
// Largest Eigenvalue
X0=input("Enter the initial eigenvector ")
e=max(X0)
X=A*X0'
mprintf("-------------------------------------------------\n")
mprintf(" Eigenvalues Eigenvectors \n")
mprintf("--------------------------------------------------\n")
while(abs(max(X)-e)>acc)
e=max(X)
X0=X/e
X=A*X0
mprintf("%6.4f ( %6.4f %6.4f %6.4f ) \n",e,X(1),X(2),X(3))
end
// Smallest Eigenvalue
X0=input("Enter the initial eigenvector ")
e=max(X0)
B=inv(A)
X=B*X0'
mprintf("-------------------------------------------------\n")
mprintf(" Eigenvalues Eigenvectors \n")
mprintf("--------------------------------------------------\n")
while(abs(max(X)-e)>acc)
e=max(X)
X0=X/e
X=B*X0
mprintf("%6.4f ( %6.4f %6.4f %6.4f ) \n",1.0/e,X(1),X(2),X(3))
end
disp("Using SPEC INBUILT FUNCTION")
[C,D]=spec(A)
disp(clean(C))
disp(clean(D))
OUTPUT:-
Enter the elements of the given matrix [2 1 3; 1 2 3; 3 3 20]
Enter the tolerance limit 0.0001
Enter the initial eigenvector [1 0 0]
------------------------------------------------

Eigenvalues Eigenvectors
-------------------------------------------------
3.0000 (4.6667 4.3333 23.0000)
23.0000 (3.5942 3.5797 21.1739)
21.1739 (3.5086 3.5079 21.0164)
21.0164 (3.5008 3.5008 21.0016)
21.0016 (3.5001 3.5001 21.0001)
21.0001 (3.5000 3.5000 21.0000)
21.0000 (3.5000 3.5000 21.0000)

Enter the initial eigenvector [1 0 0]


------------------------------------------------
Eigenvales Eigenvectors
-------------------------------------------------
1.3548 (0.8379 -0.5169 -0.0530)
1.1934 (0.9042 -0.7127 -0.0319)
1.1060 (0.9471 -0.8412 -0.0176)
1.0559 (0.9720 -0.9161 -0.0093)
1.0288 (0.9856 -0.9569 -0.0048)
1.0146 (0.9927 -0.9781 -0.0024)
1.0073 (0.9963 -0.9890 -0.0012)
1.0037 (0.9982 -0.9945 -0.0006)
1.0018 (0.9991 -0.9972 -0.0003)
1.0009 (0.9995 -0.9986 -0.0002)
1.0005 (0.9998 -0.9993 -0.0001)
1.0002 (0.9999 -0.9997 -0.0000)
1.0001 (0.9999 -0.9998 -0.0000)

"Using SPEC INBUILT FUNCTION"


0.7071068 0.6882472 0.1622214
-0.7071068 0.6882472 0.1622214
0. -0.2294157 0.9733285

1.0. 0.
0. 2. 0.
0. 0. 21.

Practical:- 03-> Determination of the principal axes of moment of


inertia through diagonalization.

//Moment of Inertia Tensor diagonalization


clc;
clear;
clf;
n=input("Enter the number of particles in discrete system: ")
M =[]
for i = 1:n
mi=input("ENTER mass of "+ string(i)+"th particle: ")
M = [M mi]
end
disp("Now Enter the positions of each discrete mass.")
P =[]
for i = 1:n
pos=input("ENTER the matrix of position of each particle:")
P = [P; pos]
end
A=zeros(3,3)
function y = f(i, j)
if ( i ==j) then
y=1
else
y=0
end
endfunction
function y=r(n)
ro = 0
for i=1:3
ro =ro+(P(n,i)* P(n,i))
end
y = ro
endfunction
for i = 1:3
for j = 1:3
for k = 1:n
A(i, j) =A(i,j)+(M(1,k)* ((f(i,j)*(r(k)))-(P(k,i)*P(k,j))))
end
if (i~=j) then
A(i, j) =(-1* A(i,j))
end
end
end

disp("The Moment of Inertia matrix",A)


disp("Moment of Inertia axes and values. ")
[X,Y]=spec(A)
disp(X,Y)

Ques 1-:) Three equal point masses 2 kg are located at (a; 0; 0), (0; a;
2a), and (0; 2a; a). Find the principal moments of inertia about the
origin and a set of principal axes. Let the value of a be equal to 3.

Ques 2:-) A rigid body consists of three point masses of 2 kg, 1 kg, and
4 kg, connected by massless rods. These masses are located at
coordinates (1,-1,1), (2,0,2), and (-1,1,0) in meters, respectively
Compute the inertia tensor of this system. Calculate moment of inertia
along x, y and z-axis.s

OUTPUTS :- Q01
Enter the number of particles in discrete system: 3

ENTER mass of 1th particle : 2

ENTER mass of 2th particle : 2

ENTER mass of 3th particle : 2

"Now Enter the positions of each discrete mass."


ENTER the matrix of position of each particle : [3 0 0]

ENTER the matrix of position of each particle : [0 3 6]

ENTER the matrix of position of each particle : [0 6 3]

"The Moment of Inertia matrix"


180. 0. 0.
0. 108. 72.
0 . 72. 108.

"Moment of Inertia axes and values.

0. 0. 1.
-0.7071068 0.7071068 0.
0.7071068 0.7071068 0.

36. 0. 0. 0.
180. 0.
0. 0. 180.

Q02
Enter the number of particles in discrete system: 3

ENTER mass of 1th particle: 2

ENTER mass of 2th particle : 1

ENTER mass of 3th particle: 4

"Now Enter the positions of each discrete mass."


ENTER the matrix of position of each particle :[1-1 1]

ENTER the matrix of position of each particle : [2 0 2]

ENTER the matrix of position of each particle :[-1 1 0]

"The Moment of Inertia matrix"

12. -6. 6.
-6. 16. -2.
6. -2. 16.

"Moment of Inertia axes and values. "

0.8164966 -1.970D-16 0.5773503 0.4082483


0.7071068 -0.5773503
-0.4082483 0.7071068 0.5773503

6. 0. 0.
0. 14. 0.
0. 0. 24.
Practical:-04-> Vector space of wave functions in Quantum
Mechanics: wave functions for stationary states (say = e^ix + e^(-
ix)) as eigenfunction of Hermitian differential operator (say p =
ih(del/del(x))

//AMP
//wave functions for stationary states as eigenfunction of Hermitian differential operator
clc;
clear;
clf;
disp("Program to show that given stationary state wave function the basis exp(ix) and exp(-1x)
is the eigen functions of Hermitian differential operator (say â_x= -ih(del/del(x)) or not.")
h=1
px=[h 0; 0 -h]

disp(px, "The matrix of hermitian differential operater in the given basis")


disp("Enter the matrix of given stationary state wave function in the given basis")
for i=1:2

w(i) = input ("")


end
W(1)= w(1)/((w(1)*w(1))+(w(2)*w(2)))
X(2) = w(2)/((w(1)*w(1))+(w(2)*w(2)))
disp (W, "The normalized matrix of given wave function is w")
C=px*w
disp(C, "The matrix C obtained after operating the wave function with Hermitian differential
operator")

c(1)=C(1)/((C(1)*C(1))+(C(2)*C(2)))
c(2)=C(2)/((C(1)*C(1))+(C(2)*C(2)))
disp (c, "The normalized matrix c")

if (c(1)=W(1) && c(2)=W(2)) || (c(1)=-W(1) && c (2)=-W(2)) then


disp("Result: The given function is eigenfunction of the hermitian operator")
else
disp("Result: The given function is not eigenfunction of the hermitian operator")
end
OUTPUT:-

Program to show that given stationary state wave function in the basis exp(ix) and, exp(-ix) is
the eigenfunctions of Hermitian differential operator (say â_x=-ih(del/del(x)),
The matrix of Hermitian differential operator in the given basis
1. 0.

0. -1.

Enter the matrix of given stationary state wave function in the given basis
4
1
The normalized matrix of given wave function is w
0.2352941
0.0588235

The matrix C obtained after operating the wave function with Hermitian differential operator
4.
-1.
The normalized matrix c
0.2352941
-0.0588235

Result: The given function is not eigenfunction of the Hermitian operator

SECOND RUN:-
Program to show that the given stationary state wave function the basis exp(ix) and exp(-ix) is
the eigen functions of Hermitian differential operator (say â_x= -ih(del/del(x)).

The matrix of Hermitian differential operator in the given basis 1.


0.
0. -1.

Enter the matrix of given stationary state wave function in the given basis
2
0

The normalized matrix of given wave function is w


0.5
0.
The matrix C obtained after operating the wave function w ith
Hermitian differential operator

2.
0.

The normalized matrix c 0.5


0.

Result: The given function is an eigenfunction of the Hermitian operator.


Practical:- 05-> COMPUTER GRAPHICS BASED PROGRAM

clc;
clear;
clf;
disp("Enter the number of points in polygon: ")
n=int(input("Enter N: "))
disp("Enter the points of polygons one after the other: ")
P=[]
for i=1:n
pos=input("ENTER the matrix of position of "+string(i)+" point:")
P=[P;pos] end
x= P(:,)'
y= P(:,2)'
plot2d(0,0,1,rect=[-10,0,40,40], frameflag=3)
xgrid
xpoly(x, y)
set(gce(), "foreground", color("red"), "closed", "on");

//for translation vector

disp("enter the translation vector: ")


d=input("enter the translating vector")
function y=tran(x)
T=[1 0;0 1]
q=(T*(x'))+d';
y=q'
endfunction
Tr=[]
for i=1:n
p=tran(P(i,:))
Tr=[Tr;p]
end
a=Tr(:,1)'
b=Tr(:,2)'
xpoly(a, b)
set(gce(), "foreground", color("blue"), "closed", "on");
//For Rotating the Polygon by an angle
disp("Enter the angle by which the polygon is rotated:")
the input("Enter the angle: ")
function y=rot(th, x)
T=[cos(th) -1*sin(th); sin(th) cos(th)]
q=T*(x')
y=q';
endfunction
Ro=[]
for i=1:n
p=rot(the,P(i,:))
Ro=[Ro;p]
end
a=Ro(:,1)'
b=Ro(:,2)'
xpoly(a, b)
set(gce(), "foreground", color("magenta"), "closed", "on");

//For Scaling the polygon

disp("Enter the scaling factors of x-axis and y-axis: ")


sx=input("Enter along x-axis: ")
sy=input("Enter along y-axis: ")
function y=scal(x)
T=[sx 0;0 sy]
q=T*(x')
y=q';
endfunction
Sc=[]
for i=1.n
p=scal(P(i,:))
Sc=[Sc ;p]
End
a=Sc(:,1)'
b=Sc(:,2)'
xpoly(a, b)
set(gce(), "foreground", color("orange"), "closed", "on");
legend(["axis", 'Original', 'Translated', 'Rotated by'+string(the)+"
degrees",'Scaled'])

OUTPUT:-
"Enter the number of points in polygons"
Enter N: 4
"Enter the points of polygons one after the other:"
ENTER the matrix of position of 1 point: [ 0 0]

ENTER the matrix of position of 2 point : [4 0]

ENTER the matrix of position of 3 point :[4 4]

ENTER the matrix of position of 4 point : [0 4]

"enter the translation vector:"


enter the translating vector [5 6]

"Enter the angle by which the polygon is rotated:"


Enter the angle: -50

"Enter the scaling factors of x-axis and y-axis: "


Enter along x-axis : 5

Enter along y-axis: 5


Practical:- 06 -> To plot geodesic great circles on a sphere.

//Advanced Mathematical Physics lab


clc;
clear;
clf;
r=1 //radius chosen to be 1 unit
phi=linspace(0,2*%pi,50)//using linspace (..) command we created an array of phi values in
interval [0,pi]
theta=linspace (0,%pi,50)
[th, ph]=meshgrid (theta,phi)
x=r* sin(th).*cos(ph)//coordinate transformation between cartesian and spherical coordinates
y=r*sin(th).*sin (ph)
z=r*cos (th)
surf(x, y, z, "facecol", "yellow", "edge", "green")
xtitle("GEODESIC GREAT CIRCLE Over a SPHERE")
xlabel("x)
ylabel("y")
xlabel("z")
//great circle equation: acos(phi-phi0)=cot(theta) //here a=1
num=input ("Enter the number of great circles to be plotted:")
for(i=1:num)
pho=input("Enter the value of phi0 :")
ph1=ph
th1=acot(cos (ph1-ph0)) //arranging the geodesic great circle equation to get theta
x=r*sin(th1).*cos(ph1)
y=r*sin(th1).*sin(ph1)
z=r*cos(th1)
param3d(x, y, z) //plotting the great circle
e=gce()
e.mark_mode="on"
e.mark_style=4
e.foreground=color('blue') //color index to draw the edges
end

OUTPUT:-
Enter the number of great circles to be plotted: 4
Enter the value of phi0 :1
Enter the value of phi0:2
Enter the value of phi0:5
Enter the value of phi0:7

You might also like