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

# + [markdown] id="jg0Lc22m7Qpa"
# #Midterm Examination

# + [markdown] id="3PuSQYS-BkPg"
# #Question 1

# + colab={"base_uri": "https://localhost:8080/"} id="p3awMEJQBmMO" outputId="cd34361f-1dc8-4bb5-b142-ca4ee2227b58"
square_matrix = np.identity(5)
print(f'Square Matrix whose length is 5: \n{square_matrix}')

# + [markdown] id="djeB6CEbBuOe"
# #Question 2

# + colab={"base_uri": "https://localhost:8080/"} id="4AS34gPDBvvG" outputId="24ce4a3b-0804-47be-d086-ae69873d9680"
UTMatrix = np.array([[1,2,3],
                    [0,3,1],
                    [0,0,5]])
print(UTMatrix)

# + [markdown] id="Jzd_QInZBwc6"
# #Question 3

# + colab={"base_uri": "https://localhost:8080/"} id="t3TwH9OzCwTw" outputId="ee15edb2-1582-44f1-8a8b-d8d2a5f6aa3d"
#Creates a square matrix that is symmetrical
square_matrix = np.array ([[1,2,3,4,5],
                           [2,1,2,3,4],
                           [3,2,1,2,3],
                           [4,3,2,1,2],
                           [5,4,3,2,1]])
#Prints a square matrix that is a symmetrical
print ('A square matrix that is symmetrical')
print (square_matrix)

# + [markdown] id="D697gyBZ6QHT"
# #Question 4

# + colab={"base_uri": "https://localhost:8080/"} id="M-lrGmkW5KuX" outputId="9bc8d3ac-b064-4d44-b585-356d74a0e135"
import numpy as np

C = np.array ([[1,2,3],[2,3,3],[3,4,-2]])

invC = np.linalg.inv(C) #Inverse of Matrix C

print(invC)

# + [markdown] id="kXTnqhgT6exw"
# #Question 5

# + colab={"base_uri": "https://localhost:8080/"} id="X_cCx8vE6gK5" outputId="42f7e4b6-a6eb-4eca-b68d-992938d779ef"
import numpy as np

C = np.array ([[1,2,3],[2,3,3],[3,4,-2]])

detOfC = np.linalg.det(C)

print("Given matrix of the determinant in Question 4:")
print(int(detOfC))

# + [markdown] id="7DNRwqDB67IR"
# #Question 6

# + colab={"base_uri": "https://localhost:8080/"} id="gvmpUuue68th" outputId="5c1e4291-1fca-4146-e042-4e02f795c1fc"
import numpy as np

Equations = np.array([[5,4,1],
                      [10,9,4],
                      [10,13,15]])

Constants = np.array([[[3.4],
                       [8.8],
                       [19.2]]])

roots = np.linalg.inv(Equations) @ Constants

print(roots)

StarcoderdataJupyterScriptsDedupFiltered