Advanced Mathematical Physics | PDF | Determinant | Matrix (Mathematics)
0% found this document useful (0 votes)
193 views

Advanced Mathematical Physics

This document contains code to calculate the inverse of a matrix from first principles by defining a function to calculate the determinant, minor, and cofactor of a matrix. The code defines a 3x3 matrix, calculates its determinant, adjoint, and inverse both using the defined functions and the inbuilt MATLAB functions. It also checks that the inverse matrix multiplied with the original matrix gives the identity matrix.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
193 views

Advanced Mathematical Physics

This document contains code to calculate the inverse of a matrix from first principles by defining a function to calculate the determinant, minor, and cofactor of a matrix. The code defines a 3x3 matrix, calculates its determinant, adjoint, and inverse both using the defined functions and the inbuilt MATLAB functions. It also checks that the inverse matrix multiplied with the original matrix gives the identity matrix.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

 

Teachers Remarks 
COMPUTATIONAL LAB FILE  
SGTB KHALSA COLLEGE 
UNIVERSITY OF DELHI 
 
 
 
Advanced Mathematical Physics  Signature 
 
 
08/29/2020 10:27 
 

Class :  Semester 5 BSc H Physics  Paper :  Advanced Mathematical Physics 

Roll number :  2018PHY1073  Name :  CHITSIMRAN 

Aim : 

To find inverse of a matrix from the first principles. 


 

Code :   

clear;clc;  dett=s; 
A=[0 1 2; 1 2 3;3 1 1 ] ; //defining matrix   end 
function [dett]=determinant(A) //function for determinant  end 
[n,m]=size(A); //dimension of matreix  endfunction 
if n==1   function [minor,cofactor]=mc(A) //function for minor, 
dett=A(1,1); //determinant for 1X1 matrix  cofactors 
else if n==2 then  [n,m]=size(A); 
dett=A(1,1)*A(2,2)-A(1,2)*A(2,1); //determinant for 2X2 matrix  for i=1:n 
else  for j=1:n 
s=0; //inital value  M_ij=A; //definig a matrix 
A_ij=A;  M_ij(i,:)=[] //deleting row 
A_ij(1,:)=[]; //deletinG row  D_ij=M_ij //Storing value of M_ij in D_ij 
for i=1:n  D_ij(:,j)=[] //deleting column 
C_ij=A_ij; //storing value of A_ij in C_ij  minor(i,j)=determinant(D_ij); //minor function 
C_ij(:,i)=[]; //deleting column  cofactor(i,j)=((-1)^(i+j))*minor(i,j) //cofactor function 
s=s+((-1)^(i+1))*A(1,i)*determinant(C_ij); //formula of determinant  end 
for higher matrix  end 
end  endfunction 
    
   

   
 
disp(A,'Orignal matrix=')   
dettt=determinant(A) //putting value of determinant in dettt 
disp(dettt,'determinant=') 
d_in=det(A) //inbuilt value of determinant 
disp(d_in,'determinant inbuilt') 
[m,c]=mc(A) 
adj=(c)' //adjoint formula 
if dettt==0 then 
disp('inverse isnt exist') //inverse doesnt exist as determinant is 0 
else 
inverse=adj/dettt; //if determinant nonzero then inverse exist, 
disp(inverse,'inverse=') 
end 
invv=inv(A); //inbuilt inverse value 
disp(invv,'inverse inbuilt=') 
disp(m,'minor=') //minor 
disp(c,'cofactor=') //cofactor 
disp(adj,'adjoint=') //adjoint 
I=A*inverse //checking up A^-1*A 
disp(I,'A*A^-1=') 
 
   
 
   
 
   
 

Plots :   
 
 
 
 
 
 
 
 
 

Comments : 

 
 
 
 

You might also like