0% found this document useful (0 votes)
1 views1 page

Determinant Inverse Matrix Program

The document contains a Python program that calculates the determinant and inverse of a matrix using custom functions. It defines a 3x3 matrix and includes functions for computing the determinant and adjoint, which are used to find the inverse. Additionally, it verifies the results using NumPy's built-in functions for determinant and inverse.

Uploaded by

amalpahe
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)
1 views1 page

Determinant Inverse Matrix Program

The document contains a Python program that calculates the determinant and inverse of a matrix using custom functions. It defines a 3x3 matrix and includes functions for computing the determinant and adjoint, which are used to find the inverse. Additionally, it verifies the results using NumPy's built-in functions for determinant and inverse.

Uploaded by

amalpahe
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

Determinant and Inverse of a Matrix (Python

Program)
from numpy import *

# Define matrix
a = array([[1,2,3],
[6,4,4],
[-10,1,3]])

print(a)

# Function to find determinant


def de_t(a):

# Determinant of 2×2 matrix


if len(a) == 2:
return a[0,0]*a[1,1] - a[0,1]*a[1,0]

else:
det = 0

# Cofactor expansion along first row


for i in range(len(a)):
det += ((-1)**i) * a[0,i] * de_t(delete(delete(a,0,0),i,1))

return det

# Function to find adjoint matrix


def ad_j(a):

# Create zero matrix


b = zeros((len(a),len(a)))

# Calculate cofactors
for i in range(len(a)):
for j in range(len(a)):

# Store transpose of cofactor matrix


b[j,i] = ((-1)**(i+j)) * de_t(delete(delete(a,i,0),j,1))

return b

print("determinant =", de_t(a))

# Inverse = Adjoint / Determinant


print("inverse =", ad_j(a)*(1/de_t(a)))

# Verification using NumPy


print([Link](a))
print([Link](a))

You might also like