squarematrix.py

Created by wperez274

Created on September 09, 2023

926 Bytes


print("\n\n")
# Get user input for matrix elements
a = int(input("Enter the value of a: "))
b = int(input("Enter the value of b: "))
c = int(input("Enter the value of c: "))
d = int(input("Enter the value of d: "))

# Calculate the determinant
det = a * d - b * c


# Check if the matrix is invertible (det != 0)
if det == 0:
    print("The matrix is not invertible (det = 0)")
else:
    # Calculate the inverse
    inv_a = d / det
    inv_b = -b / det
    inv_c = -c / det
    inv_d = a / det
    
    

print("\nOriginal Matrix:")
print("xxxxxxxxxxxxxxxxxx\n")
print("[",a," ",b,"]")

print("[",c," ",d,"]")
print("\nxxxxxxxxxxxxxxxxxx")

# Display the determinant
print("===================\n")
print("det = ", det,"\n")
print("===================\n")

print("Inverse:")
print("********************\n")
print("[",inv_a," ",inv_b,"]")

print("[",inv_c," ",inv_d,"]")
print("\n********************")

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 cookies policy.