MSCA 37016 Assignment 4 Zewen Li

# Question 1
# A = [[4,0,-2],[2,5,4],[0,0,5]]
# 1. (4-𝜆)[(5-𝜆)(5-𝜆)-4*0]-0*[2*(5-𝜆)-4*0]+(-2)*[2*0-(5-𝜆)*0] =>
# (5-𝜆)**2*(4-𝜆) = 0(Characteristic equation)
# 2. Solve the equation in part 1, we get 𝜆 = 5, 𝜆 = 5, or 𝜆 = 4
# 3. a. See below
# b. 5+5+4 = 4+5+5 = 20. Sum of eigenvalues = trace(A) check!
# Det(A) = 4*5*5 + 0+0-0-0-0 = 20 = sum of eigenvalues! check!
# 4. No, because to be positive definite matirx, it has to be
# symmetric matrix first, and AT =! A in this case, so it is defnitely
# not a positive definite matrix.

# Code for question 1, part 3
import numpy as np
from numpy import linalg as la
A = np.array([[4,0,-2],[2,5,4],[0,0,5]])
EA = la.eig(A)
EA

# Question 4
# A = [[-3,3],[1,1]]
# a. AT = [[-3,1],[3,1]], AAT = [[(-3)*(-3)+3*3,(-3)*1+3*1],[1*(-3)+1*3,1*1+1*1]]
# = [[18,0],[0,2]]
# Its(AAT = B) eigenvalue: |B-𝜆I| = [[18-𝜆,0],[0,2-𝜆]] => (18-𝜆)(2-𝜆) = 0 =>
# 𝜆 = 18 or 𝜆 = 2
# b. ATA = [[10,-8],[-8,10]]. (10-𝜆)**2 - 64 = 0 => 𝜆 = 2 or 𝜆 = 18
# c. Singular values = sqrt(2) and sqrt(18) = 1.41421 and 4.24264
# d. (AAT)/(2-1) = [[18,0],[0,2]], T = trace(AAT) = 18+2 = 20