Friday, March 15, 2019

[tutorial][python] Determinant matrix

It’s for help us to found out inverse of a matrix. syntax like this


And matrix to use determinant MUST BE square (i.e. have the same number of rows as columns).

You better if have a look of this link:
https://www.mathsisfun.com/algebra/matrix-determinant.html

Example 1

Using determinant to calculate this matrix :


We use this rule to multiply elements in matrix where Blue is positive (+ad) and Red is negative (−bc) :


With python, we can use det() method to get the result.
import numpy as np
from scipy import linalg as la

A = np.array([[3,8],[4,6]])
print(la.det(A))
Result :
-14.0

Example 2

det(A) = | A | = (1*4)-(2*3) = 4 - 6  = - 2.0

Calculation with python :
import numpy as np
from scipy import linalg as la

A = np.array([[1,2],[3,4]])
print(A)
B = la.det(A)
print(B)
Result :
[[1 2]
 [3 4]]
-2.0

Example 3

Let use python with package numpy and linalg to represent the determinant of this 3×3 matrix:


import numpy as np
from scipy import linalg as la

A = np.array([[6,1,1],[4,-2,5],[2,8,7]])
print(A)
B = la.det(A)
print(B)
Result: 
[[ 6  1  1]
 [ 4 -2  5]
 [ 2  8  7]]
-306.0






2 comments :

  1. The blog post "Tutorial: Python Determinant Matrix" by Terrapins Sky offers a concise guide on calculating the determinant of matrices using Python. It provides practical examples utilizing NumPy and SciPy libraries, demonstrating how to compute determinants for both 2x2 and 3x3 matrices. The tutorial emphasizes the importance of square matrices in determinant calculations and illustrates the process with clear code snippets and results. This resource is valuable for beginners seeking to understand matrix operations and their applications in linear algebra.

    Generative AI Training In Hyderabad

    ReplyDelete
  2. Thanks for the clear and detailed tutorial on calculating matrix determinants in Python! The step-by-step breakdown makes it easy to follow and implement. If you're also preparing for exams, I recommend checking out sat coaching online from Fast Prep Academy to stay focused and organized in your study routine.

    ReplyDelete