# ---
# 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/RiriLumin22/Linear-Algebra-58019/blob/main/Linear_Transformation.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + [markdown] id="CT5xFw9HQynC"
# ##**To find the inverse of matrix, the matrix is passed to the linalg.inv() method of the Numpy module:**##

# + colab={"base_uri": "https://localhost:8080/"} id="215nIZM3O_O9" outputId="54ab6cc1-9f37-48b9-8564-c34022a23f8d"
import numpy as np
A = np.array([[4,3],[-5,9]]) #creation of matrix A
print(A)
inv_A = np.linalg.inv(A)
print(inv_A)

# + colab={"base_uri": "https://localhost:8080/"} id="sRfgLyWrPBzl" outputId="abc9a607-32b5-4a90-cf82-789c668c51db"
B = np.array([[20],[26]])
print(B)

# + colab={"base_uri": "https://localhost:8080/"} id="LRSFXD6NPEXN" outputId="845e4656-4bd4-4f15-da55-d10fab940d2c"
X = np.linalg.inv(A).dot(B)
print(X)

# + colab={"base_uri": "https://localhost:8080/"} id="PzdyaPS0PGRe" outputId="30023eac-2bd7-470e-e34d-47c869b2a541"
X = np.dot(inv_A,B)
print(X)

# + [markdown] id="nhwkSYqTPJYl"
# ##**ACTIVITY (Let's now solve a system of three linear equations:)**##

# + colab={"base_uri": "https://localhost:8080/"} id="NlQJbyVUPItd" outputId="7e76001e-0989-4825-a9c9-7e7853337264"
import numpy as np
A = np.array([[4,3,2],[-2,2,3],[3,-5,2]]) #creation of matrix A
print(A)
print()
inv_A = np.linalg.inv(A)
print(inv_A)

# + colab={"base_uri": "https://localhost:8080/"} id="b50nCNEIPPWu" outputId="2d70f171-633d-4f48-cf8b-b3cc91115c30"
import numpy as np
B= np.array([[25],[-10],[-4]])
print(B)

# + colab={"base_uri": "https://localhost:8080/"} id="hUQ2OzAZPR2G" outputId="66109754-c210-41a6-8366-1d78954c38dd"
X = np.linalg.inv(A).dot(B)
print(X)

# + colab={"base_uri": "https://localhost:8080/"} id="wMJH-tORPUWy" outputId="2eaee757-ea93-4236-a596-8eab3685bc54"
X = np.dot(inv_A,B)
print(X)

# + [markdown] id="gj_GmWwgPW8P"
# ##**APPLICATION**##

# + colab={"base_uri": "https://localhost:8080/"} id="fmCsH-drPZ5Y" outputId="394dae46-37fa-4f04-dcff-a5894efadd5d"
import numpy as np
A = np.array([[20,10],[17,22]]) #creation of matrix A
print(A)
print()
inv_A = np.linalg.inv(A)
print(inv_A)

# + colab={"base_uri": "https://localhost:8080/"} id="-NWsMSy8PskA" outputId="26b1914a-2188-4e99-d1ea-cd3f68fe7ac1"
import numpy as np
B= np.array([[350],[500]]) #creation of matrix B
print(B)

# + colab={"base_uri": "https://localhost:8080/"} id="EupK7DI-P7eM" outputId="c5bc6f15-7b2d-4543-b0fa-e451635ce179"
X = np.linalg.inv(A).dot(B)
print(X)

# + colab={"base_uri": "https://localhost:8080/"} id="-GkUMpwSP4Es" outputId="7346c729-8e0c-4293-d199-88fbbe81ea07"
X = np.dot(inv_A,B)
print(X)

# + [markdown] id="FXHQiIehRNRT"
# ##**To check if the answer is correct**##

# + colab={"base_uri": "https://localhost:8080/"} id="lOGsuuzyRMuw" outputId="6f691aa6-67bc-4691-c012-5661842def41"
B = np.dot(A,X)
print(B)

StarcoderdataJupyterScriptsDedupFiltered