Check matrix calculation results based on python

In view of the large amount of linear algebra calculations in the recent review, and the 1800 answer often ignores some inverse matrix and determinant calculation answers, a simple calculation program for the matrix is written in Python to facilitate the checking of error steps.

1、 Determinant

You can change the order by yourself

from numpy import*

# Find the determinant,Suggestion: take the whole number before the decimal point

A =array([[3,1,1,1],[1,3,1,1],[1,1,3,1],[1,1,1,3]])

B = linalg.det(A)print(B)
# 48.000000000000014 Correct answer: 48

2、 Matrix multiplication

Pay attention to the same internal standard

from numpy import*

# Multiply matrices

A =array([[1,-1,1],[1,1,0],[-1,0,1]])

B =array([[3,0,0],[0,0,0],[0,0,0]])
# N=AB
N =dot(A, B)

# N=BA, then N=dot(B, A)print(N)

# correct answer:
# [300]
# [300]
# [-300]

3、 Inverse matrix

Judge for yourself |A|≠0, where A∗ = A−1 · |A|

from numpy import*
# Inverse matrix,Suggestion: take one digit after the decimal point and turn it into a fraction

A =mat([[1,-1,1],[1,1,0],[-1,0,1]])

B = A.I
print(B)

# [0.333333330.33333333-0.33333333]
# [-0.333333330.666666670.33333333]
# [0.333333330.333333330.66666667]
# 0.333 ≈ 1/3 ,0.667≈ 2/3

The above is the whole content of this article, I hope it will be helpful to everyone's study.

Recommended Posts

Check matrix calculation results based on python
Draw personal footprint map based on Python
How to program based on interfaces in Python
Python implements SSL sending based on QQ mailbox
Detailed explanation of data types based on Python
Diagram of using Python process based on FME
Implementation of business card management system based on python
Solve the problem of convex hull based on python
Detailed explanation of the remaining problem based on python (%)
Install Python3 on Ubuntu 14.04
Install Python3 on Ubuntu 16.04
Install Python3.7 on Ubuntu
python Tic-Tac-Toe-text version (on)