invthree.py

Created by ews31415

Created on November 13, 2020

701 Bytes

Inverse and Determinant of a 3 x 3 matrix


from math import *

# 2020-11-12 EWS
print("3x3 Matrix Inverse")
print("[[a1,a2,a3]")
print("[b1,b2,b3]")
print("[c1,c2,c3]]")
a1=float(input('a1: '))
a2=float(input('a2: '))
a3=float(input('a3: '))
b1=float(input('b1: '))
b2=float(input('b2: '))
b3=float(input('b3: '))
c1=float(input('c1: '))
c2=float(input('c2: '))
c3=float(input('c3: '))
# determinant
d=a1*(b2*c3-b3*c2)-a2*(b1*c3-b3*c1)+a3*(b1*c2-b2*c1)
# inverse
d1=(b2*c3-c2*b3)/d
d2=-(a2*c3-c2*a3)/d
d3=(a2*b3-a3*b2)/d
e1=-(b1*c3-c1*b3)/d
e2=(a1*c3-c1*a3)/d
e3=-(a1*b3-a3*b1)/d
f1=(b1*c2-b2*c1)/d
f2=-(a1*c2-a2*c1)/d
f3=(a1*b2-a2*b1)/d
print("det=")
print(d)
print("inv=")
print([d1,d2,d3])
print([e1,e2,e3])
print([f1,f2,f3])

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.