XHG 22xhgxfd
XHG 22xhgxfd
Contents
1 Practical 1 2
1.1 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.5 Meaning of statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 Practical 2 5
2.1 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.1.1 Finding the eigenvalues of matrix 1: . . . . . . . . . . . . . . . . . . . . . . . . 6
2.1.2 Finding the eigenvalues of matrix 2: . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1.3 Finding the eigenvalues of matrix 3: . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2 Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.3 Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3.1 For matrix 1: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3.2 For matrix 2: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3.3 For matrix 3: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.4 Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.4.1 For matrix 1: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.4.2 For matrix 2: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.4.3 For matrix 3: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.5 Meaning of statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3 Practical 3 12
3.1 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.2 Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.3 Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.4 Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.5 Meaning of statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1
ADVANCED MATHEMATICAL PHYSICS PRACTICAL
(DSE 1)
1 Practical 1
Matrix multiplication of two 3 × 3 matrices.
1.1 Theory
A matrix is a rectangular array of numbers enclosed by a pair of brackets [ ] or ( ) subject to certain
rules of operation. A set of mn numbers a11 , a12 , . . . , amn arranged in a rectangular array of m rows
and n columns like:
a11 a12 a13 . . . a1n
a12 a22 a23 . . . a2n
... ... ... ... ...
am1 am2 am3 . . . amn
and subject to certain rules of operation is called a m × n matrix. The numbers a11 , a12 , a13 . . . , amn
are called the elements of the matrix.
The product AB of two matrices A and B is defined only when the number of columns in A is equal
to the number of rows in B. If A be a m × n matrix and B be an n × p matrix, then the number of
columns in A = the number rows in B and the product AB = C is an m × p matrix whose (i,j)th
th
element, say Ci,j element, say Cij is the sum of the products obtained by multiplying the elements
of the i row of A by the corresponding elements of the j th column of B, i.e.
th
n
X
cij = a1j b1j + ai2 b2j + . . . + ain bnj = aik bkj
k=1
When the number of columns in A = the number of rows in B, the product A × B is said to be
defined.
Two 3 × 3 matrices are multiplied in the following manner:
2
1.2 Algorithm
1. Initiation of program.
1.3 Program
import numpy as np
A = np.array([1,2,3,4,5,6,7,8,9]).reshape(3,3)
B = np.array([9,8,7,6,5,4,3,2,1]).reshape(3,3)
C = np.dot(A,B)
3
1.4 Output
Input:
A:
1 2 3
4 5 6
7 8 9
B:
9 8 7
6 5 4
3 2 1
Output:
C:
30 24 18
84 69 54
138 114 90
.reshape(3,3):
np.dot(A,B):
4
2 Practical 2
Find the eigenvalues and eigenvectors of the following:
2 1 1 1 −ι 3 + 4ι 2 −ι 2ι
1 3 2 ι 2 4 ι 4 3
3 1 4 3 − 4ι 4 3 −2ι 3 5
2.1 Theory
Consider the following vector equation:
Ax = λx
The problem of finding non-xero x’s and λ’s that satisfy the given equation is called an eigenvalue
problem.
A is a linear operator whose domain and range lies in the Hilbert space. x is a function in space and
λ is a constant. Since the solutions to an equation of this type yield functions x that are unchanged
by the operator (except for multiplication by a scale factor λ), they are termed eigenvalue equations.
When an eigenvalue equation is reduced to a matrix equation:
Ac = λc
It is called a matrix eigenvalue equation and the vectors c that solve it are called eigenvectors. Once
a matrix eigenvalue problem has been solved, the eigenfunctions of the original problem can be
recovered from their expansion: X
x= ci x i
i
x1 y1
a11 a12 a13 ... a1n
a21 x2 y2
a22 a23 ... a2n
x3 y3
a31
Let a32 a33 ... a3n
=
..
..
. . . ... ... ... ... . .
an1 an2 an3 ... ann xn yn
AX = Y
Where A is the matrix, X and Y are the column vectors. Let X be such a vector which transforms
into λX by means of the transformation given above. Suppose the linear transformation Y = AX
transforms X into a scalar multiple of itself, that is, λX.
AX = Y = λX
AX − λIX = 0
(A − λI)X = 0
Thus the unknown scalar λ is known as the eigenvalue of the matrix A and the corresponding non
zero vector X as eigen vector.
Characteristic Polynomial:
The determinant |A − λI| when expanded will give a polynomial, which is called the characteristic
polynomial of matrix A.
5
Characteristic Equation:
The equation |A − λI| = 0 is called the characteristic equation of the matrix A.
Eigenvalues:
The roots of the characteristic equation are called the eigenvalues.
det(A − λI) = 0
2 − λ 1 1
=⇒ 1 3−λ 2 = 0
3 1 4 − λ
=⇒ −λ3 + 9λ2 − 20λ + 14 = 0
The resultant values of λ are:
1. λ1 ≈ 6.095
2. λ2 ≈ 1.452 + 0.434i
3. λ3 ≈ 1.452 − 0.434i
1. For λ1
x1 ≈ 0.436
x2 ≈ 0.787
x3 ≈ 1
2. For λ2
x1 ≈ −0.582 + 0.280i
x2 ≈ −0.803 − 0.406i
x3 ≈ 1
3. For λ3
x1 ≈ −0.582 − 0.280i
x2 ≈ −0.803 + 0.406i
x3 ≈ 1
6
2.1.2 Finding the eigenvalues of matrix 2:
1 −ι 3 + 4ι
ι 2 4
3 − 4ι 4 3
det(A − λI) = 0
1 − λ −i 3 + 4i
=⇒ i 2−λ 4 = 0
3 − 4i 4 3 − λ
=⇒ −λ3 + 6λ2 + 31λ − 95 = 0
The resultant values of λ are:
1. λ1 ≈ −4.74
2. λ2 ≈ 2.397
3. λ3 ≈ 8.350
1. For λ1
x1 ≈ 0.436
x2 ≈ 0.787
x3 ≈ 1
2. For λ2
x1 ≈ −2.671 + 5.413i
x2 ≈ −3.561 − 6.730i
x3 ≈ 1
3. For λ3
x1 ≈ 0.417 + 0.469i
x2 ≈ 0.556 + 0.066i
x3 ≈ 1
7
2.1.3 Finding the eigenvalues of matrix 3:
2 −ι 2ι
ι 4 3
−2ι 3 5
det(A − λI) = 0
2 − λ −i 2i
=⇒ i 4−λ 3 = 0
−2i 3 5 − λ
=⇒ −λ3 + 11λ2 − 24λ − 11 = 0
The resultant values of λ are:
1. λ1 ≈ −0.387
2. λ2 ≈ 3.692
3. λ3 ≈ 7.696
1. For λ1
x1 ≈ −1.243i
x2 ≈ −0.967
x3 ≈ 1
2. For λ2
x1 ≈ 2.377i
x2 ≈ −2.021
x3 ≈ 1
3. For λ3
x1 ≈ 0.219i
x2 ≈ 0.753
x3 ≈ 1
2.2 Algorithm
1. Initiation of program.
3. The eigenvalues and their corresponding eigenvectors are calculated using the scipy function.
8
2.3 Program
2.3.1 For matrix 1:
import scipy.linalg as sla
A = np.array([2,1,1,1,3,2,3,1,4]).reshape(3,3)
A = np.array([1,-1j,3+4j,1j,2,4,3-4j,4,3]).reshape(3,3)
A = np.array([2,-1j,2j,1j,4,3,-2j,3,5]).reshape(3,3)
9
2.4 Output
the values of eigenvectors calculated manually do not match with the result
obtained from the program as the eigenvectors obtained from python are
normalized eigenvectors.
Output:
0.32432156 + 0.j 0.38999367 − 0.18754126j 0.38999367 + 0.18754126j
0.58499854 + 0.j 0.53799932 + 0.27189591j 0.53799932 − 0.27189591j
0.74336548 + 0.j −0.6703451 + 0.j −0.6703451 − 0.j
Output:
−0.34047711 − 0.52125582j −0.36197444 − 0.50082779j 0.31923315 + 0.3586139j
−0.45396948 + 0.05046476j 0.77952851 + 0.j 0.4256442 + 0.05027272j
0.63539966 + 0.j −0.04787737 + 0.09049361j 0.76536654 + 0.j
10
2.4.3 For matrix 3:
Input:
Output:
6.662e − 01 + 0.000e + 00j 7.255e − 01 + 0.000e + 00j 4.268e − 17 + 1.723e − 01j
−2.7604e − 17 − 5.184e − 01j 1.526e − 16 + 6.168e − 01j 5.922 − 01 − 9.562e − 17j
0.7433 + 0.j −0.670 + 0.j −0.670 − 0.j
.reshape(3,3):
sla.eig(A):
scipy function used to find the eigenvalues and eigenvectors of the matrix.
11
3 Practical 3
To study the Hamiltonian of a simple pendulum using python and further validate
the solution after solving the given equation mathematically by setting the boundary
conditions to get the mathematical solution and plotting them.
3.1 Theory
A function that describes the state of a dynamic system in terms of position coordinates and their
time derivatives and that is equal to the difference between the potential and kinetic energy is called
a Lagrangian.
A function that is used to describe a dynamic system (such as the motion of a particle) in terms of
components of momentum and coordinates of space and time and that is equal to the total energy
of the system when time is not explicitly a part of the function is called a Hamiltonian.
The Hamiltonian Equation of motion are free of constraints. Hence, the generalized parameters can
be taken to be independent of each other. For a simple pendulum, the generalized coordinate is
taken as θ.
Thus, the Hamiltonian for a simple pendulum is given by:
g
θ̈ + θ = 0
l
d
Let D ≡
dt
Then,
q
(D2 + )θ = 0
l
Thus, the characteristic equation is:
q
m2 + =0
l
r
q
m = ±i
l
As the values of m belong to the complex domain(α ± iβ), the solution of the equation is given by:
θ = eαt [C1 cos(βt) + C2 sin(βt)]
r
q
where, α ± iβ = 0 ± i
l
Substituting these values in the above equation,
r r
q q
θ = C1 cos t + C2 sin t
l l
Two boundary conditions are provided for the given problem.
at t = 0s; θ = 10◦
at t = 10s; θ = 10◦
The values of C1 and C2 are obtained using the given boundary conditions.
C1 = 0.1745 C2 = 0.049
Using these values, θ is obtained as:
r r
g g
θ = 0.1745 sin t + 0.049 sin t
l l
By taking a set of values for t, a range of values for θ is obtained. The set of data are plotted along
with the data from the odeint and the Hamiltonian of the system is calculated.
12
3.2 Algorithm
1. Initiation of program.
2. The second order differential equation is reduced to a first order differential equation.
Let, x = θ̇ (1)
=⇒ ẋ = θ̈ (2)
q
∴ ẋ = − θ (3)
l
!
θ̇
x
3. The matrix form of equations 1 and 3 is given by: = q
ẋ − θ
l
4. The initial conditions for length, initial angle and initial displacement taken for the
pendulum are:
Length(l) = 1 m
initial angle = 10◦
initial displacement = 10 m
5. Taking the initial conditions as stated, a solution set for odeint is obtained.
3.3 Program
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
import math
def eq(y0,x0):
t,x = y0
f = [x, -(g/l)*t]
return f
g = 9.81
l = 1.0
#inital conditions
time = np.arange(0,10,0.0005)
initial_angle = 10 #limiting the angle to be in linear range
theta_0 = np.radians(initial_angle)
x_0 = 0.0
13
theta_1 = odeint(eq,[theta_0,x_0],time)
theta_math = [ ]
for i in time :
test_value = 0.1745*math.cos(3.132*i)+0.049*math.sin(3.132*i)
theta_math.append(test_value)
plt.plot(time,theta_1[:,0])
plt.plot(time,theta_math,'--*')
plt.show()
3.4 Output
The plots of the two solutions are seen to be overlapping. Thus the Hamiltonian of the system has
been justified.
The motion is simple harmonic as shown by the plots.
14
3.5 Meaning of statements
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
import math:
np.arange(0,10,0.0005):
odeint:
np.append
15