Skip to content

Instantly share code, notes, and snippets.

@quantum9Innovation
Created April 5, 2025 00:43
Show Gist options
  • Select an option

  • Save quantum9Innovation/cc9a802681d26e07f7ee3be44e7918f0 to your computer and use it in GitHub Desktop.

Select an option

Save quantum9Innovation/cc9a802681d26e07f7ee3be44e7918f0 to your computer and use it in GitHub Desktop.
ES.1803 pset 6 problem 1 checker
import numpy as np
import sympy as sp
a = [[0, 0, 1, 0], [0, 0, 0, 1], [-5, 1, 0, 0], [1, -4, 0, 0]]
b = [[1, 2, 3], [0, 2, 1], [4, 2, 0]]
A = np.array(a)
B = np.array(b)
A_sp = sp.Matrix(a)
B_sp = sp.Matrix(b)
b = np.array([2, 0, 5, 0])
# a
Ab = A @ b
print("a.")
print(Ab)
print("===")
# b
# (dimensions error)
# BA = B @ A
# print("b.")
# print(BA)
# print("===")
# c
det_A = np.linalg.det(A)
print("c.")
print(det_A)
print("===")
# d
inv_A = np.linalg.inv(A)
print("d.")
print(inv_A)
print("===")
# e
x = inv_A @ b
print("e.")
print(x)
print("===")
# f
rref_A, _ = A_sp.rref()
rref_B, _ = B_sp.rref()
print("f.")
print(rref_A)
print(rref_B)
print("===")
# g
AT = A.T
BT = B.T
print("g.")
print(AT)
print(BT)
print("===")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment