# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="view-in-github" colab_type="text"
# <a href="https://colab.research.google.com/github/Yaniii2021/Linear-Algebra-58019/blob/main/Matrix_Algebra.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + [markdown] id="Lj79fcnLzcxP"
# ##Python program to inverse
#

# + id="vK40mpsBxpWv"
import numpy as np

# + colab={"base_uri": "https://localhost:8080/"} id="SvS3I9LO3FBV" outputId="373d750d-aa0b-4611-e8df-23b167c3a8e6"
A = np.array([[1, 2],
              [4, 7]])

invA = np.linalg.inv(A) # inverse of matrix A

print(invA) # print the inverse of matrix A

# + colab={"base_uri": "https://localhost:8080/"} id="7hsWIzIs30MM" outputId="9c9333df-e78e-4f20-8f96-cf2d8a1f3888"
C = np.dot(A, invA) # get identity matrix
print(C) # print dot product

# + [markdown] id="0dXgkzRu4mkA"
# ##Python Program to Inverse and Transpose a 3x3 Matrix
#
#
#

# + colab={"base_uri": "https://localhost:8080/"} id="2WLGnCGl4kfz" outputId="49c0a867-598d-4d0c-b32a-e5abd3c5de11"
A = np.array([[6, 1, 1],
              [4,-2, 5],
              [2, 8, 7]])

InvOfA = np.linalg.inv(A) # to inverse matrix A

B = np.transpose(A) # to transpose matrix A

print(A)

print()

print(B)

# + colab={"base_uri": "https://localhost:8080/"} id="H7jWI5PN7LUP" outputId="2564cf94-ea5d-4c68-e551-fd31cffd18aa"
dot = np.dot(A, InvOfA) # get dot product of A and its inverse

print(dot)

# + colab={"base_uri": "https://localhost:8080/"} id="c73338sC1CRR" outputId="17c9edba-7dcb-488f-d48a-9bce0f7f4dbe"
# practice
M = np.array([[1,7],
             [-3, 5]])

np.array(M @ np.linalg.inv(M), dtype=int) # get the dot product of M and the inverse of M then convert it to integers to get the identity matrix

# + colab={"base_uri": "https://localhost:8080/"} id="Y9akSpsxzncZ" outputId="e1d327d2-faed-468e-e386-7982b9f483ea"
# practice
A = np.array([[3, 2, 3],
              [4, 19, 6],
              [74, 2, 9]])

B = np.linalg.inv(A)

np.array(A @ B, dtype=int) # get the dot product of A and B then convert it to integers to get the identity matrix

# + [markdown] id="8N8z-jD2AgDR"
# ##Coding Activity 3 - Python Exercise 3
# Create a Python Program to inverse and transpose a 4x4 matrix
#
#
#

# + colab={"base_uri": "https://localhost:8080/"} id="HhafYCzuAkyW" outputId="cd832072-0e30-493e-d313-e32bd79d6174"
A = np.array([[6,1,1,3],
              [4,-2,5,1],
              [2,8,7,6],
              [3,1,9,7] ])

InvA = np.linalg.inv(A) # to inverse matrix A
TransposeA = np.transpose(A) # to transpose matrix A

print('The inverse of Matrix A is: ')
print(InvA) # print inverse of matrix A

print()

print('The tranpose of Matrix A is: ')
print(TransposeA) # print transpose of matrix A

# + [markdown] id="Mrk9uXoiAgA9"
#

StarcoderdataJupyterScriptsDedupFiltered