0% found this document useful (0 votes)
85 views

Phd:304 Lab Report Advanced Mathematical Physics: Sachin Singh Rawat 16PH-06 (Department of Physics)

The document discusses four topics: 1. Gauss elimination method to solve systems of linear equations. 2. Gram-Schmidt orthogonalization to generate orthonormal basis vectors from non-orthogonal basis vectors. 3. Calculating the determinant of a matrix using expansion along rows/columns or transforming the matrix to echelon form. 4. Defining matrix multiplication where the product of matrices A and B is possible if the number of columns of A equals the number of rows of B.

Uploaded by

sachin rawat
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)
85 views

Phd:304 Lab Report Advanced Mathematical Physics: Sachin Singh Rawat 16PH-06 (Department of Physics)

The document discusses four topics: 1. Gauss elimination method to solve systems of linear equations. 2. Gram-Schmidt orthogonalization to generate orthonormal basis vectors from non-orthogonal basis vectors. 3. Calculating the determinant of a matrix using expansion along rows/columns or transforming the matrix to echelon form. 4. Defining matrix multiplication where the product of matrices A and B is possible if the number of columns of A equals the number of rows of B.

Uploaded by

sachin rawat
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/ 12

PHD:304 LAB REPORT

ADVANCED MATHEMATICAL PHYSICS

Sachin Singh Rawat


16PH-06
(Department Of Physics)
Contents
1 Gauss Elimination 2

2 Gram Schmidt Orthogonalization 5

3 Determinant Of Matrix 8

4 Matrix Multiplication 10

1
1 Gauss Elimination
Aim/Purpose
Solve system of linear equations using Gauss elimination method in octave.

Theory
Gauss elimination method is a direct method to solve system of linear equation.In this
method we convert the augmented matrix into upper triangular matrix.Then, we use back
substitution to calculate the values of variables.This method work as follows:

Consider the system of following equations:


x+y+z =3 (1)
x − 2y + z = 0 (2)
2x + 3y − 2y = 3 (3)
The augmented matrix is

 
1 1 1 3
 1 −2 1 0  (4)
2 3 −2 3

R2 → R2 − R1
R3 → R3 − 2R1
 
1 1 1 3
 0 −3 0 −3  (5)
0 1 −4 −3

R3 → 3R3 + R2
 
1 1 1 3
 0 −3 0 −3  (6)
0 0 −12 −12
Applying back substitution

−12y = −12 ⇒ y = 1
−3x = −3 ⇒ x = 1
x+y+z =3 ⇒ x+1+1=3 ⇒ x=1
x = 1 ,y = 1 ,z = 1

2
Result
Consider the following system of equations:

x1 + x2 − 2x3 + x4 + 3x5 − x6 =4
2x1 − x2 + x3 + 2x4 + x5 − 3x6 = 20
x1 + 3x2 − 3x3 − x4 + 2x5 + x6 = −15
5x1 + 2x2 − x3 − x4 + 2x5 + x6 = −3
−3x1 − x2 + 2x3 + 3x4 + x5 + 3x6 = 16
4x1 + 3x2 + x3 − 6x4 − 3x5 − 2x6 = −27
The solution of above equation generated by the program which is shown in next page are
given by:
x1 = 1 , x2 = −2, x3 = 3
x4 = 4, x5 = 2, x6 = −1

3
Code

gauss elimination method.m


clc ;
clear ;
disp ( ’ Enter augmented matrix i n [ ] :− ’ )
a=input ( ’ ’ )
[ n ,m]= s i z e ( a ) ;
k=1;
for i =1:n
b=a ( i : end , k ) ;
i n d=find ( b==max( b ) ) ;
i n d=i n d ( 1 ) ;
i n d=i −1+i n d ;
temp=a ( i , : ) ;
a ( i , : ) = a ( ind , : ) ;
a ( ind , : ) = temp ;
i f a ( i , k)==0
disp ( ’ unique s o l u t i o n does not e x i s t ’ ) ;
return ;
endif
a( i ,:)= a( i , : ) / a( i , k ) ;
for j=i +1:n
a ( j ,:)= a ( j ,:) − a ( i , : ) ∗ a ( j , k ) ;
endfor
k=k+1;
endfor
for i =1:n
b ( i )=1;
endfor
z=a ( : , end ) ;
for i =1:n
x=a ( n+1−i , 1 : end−1);
k=z ( end+1− i )−x∗b ’ + 1 ;
b ( end+1− i )=k ;
endfor
for i =1:n
f p r i n t f ( ’ x%d= ’ , i ) ;
disp ( b ( i ) ) ;
endfor

4
2 Gram Schmidt Orthogonalization
Aim/Purpose
Form orthonormal set of basis vectors from a set of basis vectors which are not orthonormal
using Gram-Schmidt orthogonalization procedure in octave.

Theory
Gram Schmidt Orthogonalization is a method used to find orthonormal set of basis vectors
from the basis vectors which are not orthonormal.Suppose we have given a set of basis vectors
(|e1 i, |e2 i, |e3 i, ......., |en i) which are not orthonormal and we have to find out orthonormal
basis vectors (|e01 i, |e02 i, |e03 i, ......., |e0n i). The steps are:

(i) Normalize the first basis vector(divide by its norm):


|e1 i
|e01 i =
||e1 ||

(ii) Find the projection of second vector along first, and subtract it off:
|e2 i − he01 |e2 i|e01 i.
This vector is orthogonal to |e01 i; normalize it to get |e02 i.

(iii) Subtract from |e3 i its projection along |e01 i and |e02 i:
|e3 i − he01 |e3 i|e01 i − he02 |e3 i|e02 i.

This is orthogonal to |e01 i and |e02 i. And so on.

5
Result
The the basis vectors vectors which are not orthonaormal:

|e1 i = [ 1 1 1 ]
|e2 i = [ 1 0 0 ]
|e3 i = [ 0 0 1 ]

The orthogonal basis vectors generated by the program which is shown in next page us-
ing above basis vectors are:

|e1 i = [ 0.57735 0.57735 0.57735 ]


|e2 i = [ 0.81650 − 0.40825 − 0.40825 ]
|e3 i = [ −3.9252 × 10−16 − 7.0711 × 10−01 7.0711 × 10−01 ]

6
Code

gram schmidt orthogonalization.m


clc ; clear ;
n=input ( ’ Enter t h e no o f b a s i s : ’ ) ;
disp ( ’ Enter b a s i s v e c t o r s i n [ ] o f c o r r c t d i m e n s i o n s : ’ )
for i =1:n
f p r i n t f ( ’ a%d ’ , i ) ;
a ( : , i )=input ( ’= ’ ) ;
endfor
[m, n]= s i z e ( a ) ;
i f m!=n
disp ( ’ Dimensions mismatch ’ )
return
endif
for i =1:n
for j =1: i −1
a ( : , i )=a ( : , i )−a ( : , j )∗ a ( : , j ) ’ ∗ a ( : , i ) ;
endfor
k=(a ( : , i ) ’ ∗ a ( : , i ) ) ˆ . 5 ;
a ( : , i )=a ( : , i ) / k ;
endfor
disp ( ’ Orthogonal b a s i s a r e :− ’ ) ;
for i =1:n
f p r i n t f ( ’ b%d ’ , i )
disp ( ’= ’ ) , disp ( a ( : , i ) ) ;
endfor

7
3 Determinant Of Matrix
Aim/Purpose
Write a program to calculate the determinant of matrix using octave.

Theory
Determinant of matrix of order three can be determined by expressing it in terms of second
order determinants. This is known as expansion of determinant along a row (or a column).
There are six ways of expanding a determinant of order 3 corresponding to each three rows
(R1 , R2 and R3 ) and three columns (C1 C2 andc3 ) giving the same value as shown below.
Consider the determinant of square matrix A = [aij ]3×3

a11 a12 a13

i.e., |A| = a21 a22 a23

a31 a32 a33

The determinant can also be calculated by transforming the matrix into echelon form(or
upper triangular form).Then the product of diagonal element gives the determinant of the
matrix.

Result
17 13 8 14 3 13
 
 5 16 13 1 4 5 
4 8 20 6 9 10 
 
The determinant of matrix A = 

12 7 15 20 19 8 


 20 7 7 10 9 6 
2 7 6 5 10 14

generated by program shown in next page is 6800650

8
Code

determinant of matrix.m
clear ; clc ;
disp ( ’ Enter a s q u a r e matix i n [ ] : − ’ )
A=input ( ’ ’ )
[ r c ]= s i z e (A ) ;
i f r != c
disp ( ’ matix must be s q u a r e ’ ) ;
return
endif
for i =1: r
i f A( i , i )!=0
for j=i +1: r
A( j , : ) =A( j , : ) −A( i , : ) ∗ A( j , i ) /A( i , i ) ;
endfor
endif
endfor
c =1;
for i =1: r
c=c ∗A( i , i ) ;
endfor
f p r i n t f ( ’ Thr d e t e r m i n e n t o f matrix = %d\n ’ , c ) ;

9
4 Matrix Multiplication
Aim/Purpose
Write a program to find out the multiplication of two matrices using octave.

Theory
The product of two matrices A and B is defined if no of columns of A is equal to no of rows
of B. Let A = [aij] be a m × n matrix and B = [bjk] be n × p matrix. Then the product of
matrices A and B is the matrix C of order m × p. To get the (i, k)th element of cjk of matrix
C, we take the ith raw of A and k th column of B, multiply them elementwise and take the
sum of all these products. In other words, if A = [aij ]m×n ,B = [bij ]n×p ,then the I th row of A
b1k
 
 b2k 
 . 
 
is [ ai1 ai2 ...ain ] and k th column of of B is  ,
 . 
 . 
bnk
Pn
then cik = ai1 b1k + ai2 b2k + ai3 b3k ... + ain bnk = aij bjk .
j=1

Result
The output for the product of two matrices
10 11 2 3 9 9 16 19 14 19 3 15
   
 10 13 17 4 10 10   8 3 5 2 3 5 
 9 8 8 13 16 1  19 10 16 11 2 14 
   
A=  and B =   is

 11 9 5 1 8 10   17 2 6 16 4 14 
 18 1 4 10 5 18   8 16 14 8 14 8 
13 9 11 6 12 11 4 5 2 4 20 6

445 438 389 390 385 401


 
 775 617 661 587 459 649 
713 562 598 615 363 603
 
C=
 
464 466 417 402 386 418

 
 654 575 487 660 535 619 
731 643 629 622 500 640

10
Code

matrix multiplication.m
%c l e a r ; c l c ;
disp ( ’ M u l t i p l i c a t i o n o f two m a t r i c e s ’ ) ;
A=input ( ’ Enter f i r s t matrix (A) i n [ ] : − ’)
B=input ( ’ Enter second matrix (B) i n [ ] : − ’)
[ rA , cA]= s i z e (A ) ;
[ rB , cB]= s i z e (B ) ;
i f cA!=rB
f p r i n t f ( ’ m u l t i p l i c a t i o n not p o s s i b l e \nno o f column o f f i r s t matrix must be
return
endif
for i =1:rA
for j =1:cB
C( i , j )=0;
for k=1:cA
C( i , j )=C( i , j )+A( i , k )∗B( k , j ) ;
endfor
endfor
endfor
disp ( ’ m u l t i p l i c a t i o n o f two m a t r i c e s A and B = ’ )
disp (C)

11

You might also like