Created
September 17, 2018 13:30
-
-
Save NikhilPeri/0097ef6000795265493c7aa67263399f to your computer and use it in GitHub Desktop.
script so I dont have to do the first linear systems assignment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
print "Question 1" | |
a = np.array([ | |
[1, 2, 3, 4], | |
[1, 1, 1, 1], | |
[1, 2, 1, 2], | |
[1, 2, 1, 1] | |
]) | |
b = np.array([ | |
[-4, 2, -3, 1], | |
[1, 1, -1, -1], | |
[-1, -1, 1, 2], | |
[0, 0, 7, 13], | |
]) | |
print "A + B = {}".format(a + b) | |
print "A * B = {}".format(np.matmul(a, b)) | |
print "B * A = {}".format(np.matmul(b, a)) | |
print "det(A) = {}".format(np.linalg.det(a)) | |
print "rank(A) = {}".format(np.linalg.matrix_rank(a)) | |
print "rank(B) = {}".format(np.linalg.matrix_rank(b)) | |
print "trace(A) = {}".format(np.trace(a)) | |
print "\nQuestion 2" | |
s = str(input('type your student number: ')) | |
n = np.array([ | |
[int(s[0]), int(s[1]), int(s[2])], | |
[int(s[3]), int(s[0]), int(s[4])], | |
[int(s[5]), int(s[6]), int(s[0])], | |
]) | |
print "N = {}".format(n) | |
print "det(N) = {}".format(np.linalg.det(n)) | |
print "inv(N) = 1/{} *{}".format(np.linalg.det(n),np.linalg.det(n)* np.linalg.inv(n)) | |
print "characteristic coeffs {}".format(np.poly(n)) | |
print "\nQuestion 3" | |
x= np.array([ | |
[2, -1, 0], | |
[-1, 2, -1], | |
[0, -1, 2] | |
]) | |
print "characteristic coeff {}".format(np.poly(x)) | |
print "eigin values {}".format(np.linalg.eig(x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment