0
votes

I'm trying to build a code which finds the eigenvectors of a matrix given its eigenvalues. I need to write the code myself so inbuilt functions are not an option here.

I already made a simple code to calculate the eigenvalues of a given matrix from which I use these values to calculate the eigenvectors. The problem is that when I solve the homogenous system (A−λI)v=0 where λ is an eigenvalue of A and I is the identity matrix, the code returns an empty set, whereas the analytical solution is x=t where t is some free parameter and y=0. The code I have is this:

import numpy as np
import sympy as sym
from sympy.solvers.solveset import linsolve

A_1 = sym.Matrix([[0,1],[0,1]])
system = A, b = A_1[:,0], A_1[:,-1]
linsolve(system, x, y)

This returns an empty set as I said before. When I print b however I get the vector (1,1) which I'm not sure why python is returning this. I need to emphasize that I'm only looking for non-trivial solutions here as I don't want an eigenvector of zeros.

1
But you are using nothing but inbuilt functions!?mkrieger1
[1,1] is an eigenvector w/eigenvalue 1, to see this do the matrix multiplication of np.array([[0,1],[0,1]])@np.array([1,1]) you'll see that the result isnp.array([1,1]). This is the definition of an eigenvalue.Lucas Roberts
Is your question why linsolve returns an empty set? Or why b is (1, 1)?mkrieger1
The A_1[:,-1] is selecting the last column of A_1 which is [1,1]. This is assigned to b in the second to last line of code.Lucas Roberts
@mkrieger1 What I meant is that I don't want a function which directly gives the eigenvectors and eigenvalues of a given matrix. Maybe I phrased it incorrectly. I know now why b is (1,1) but why is linsolve returning an empty set.Eli

1 Answers

0
votes

I don't think this statement does what you think it does:

system = A, b = A_1[:,0], A_1[:,-1]

That will be parsed like this:

A, b = A_1[:,0], A_1[:,-1]
System = A, b

That first statement is a tuple assignment. A will be assigned A_1[:,0], which is [0,0], and b will be assigned the value of A_1[:,-1], which is [1,1]. system is then assigned a tuple with both values.