Phd:304 Lab Report Advanced Mathematical Physics: Sachin Singh Rawat 16PH-06 (Department of Physics)
Phd:304 Lab Report Advanced Mathematical Physics: Sachin Singh Rawat 16PH-06 (Department of Physics)
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:
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
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:
(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.
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:
6
Code
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
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
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