I’m studying linear algebra and I’ve run into an issue that I’ve figured out how to solve with Julia, but I’m hoping there’s a better way. Given some simple 2 x 2 transformation matrices, I have to determine which vectors in a list are eigenvectors of the matrix. Here’s an example of a couple of simple problems and how I’ve solved them:

```
using LinearAlgebra
T = [1 0; 0 2]
v = ([1,0],[1,-1],[0,2],[0,3])
# Which of the following vectors in v are eigenvectors of T?
# The below function computes the angle between two vectors and checks if it's zero
# or π. My thinking was that if the angle is 0.0 (or close to it, given floating
# point error) or π that the vector must be an eigenvector because it will have the
# same span
function is_eigenvector(x,y)
return (
acos(x'*y/(norm(x)*norm(y))) < 1e-7 ||
round(π, digits=5) < acos(x'*y/(norm(x)*norm(y))) < round(π, digits=4)
) ?
true :
false
end
julia> v[findall(vec -> is_eigenvector(vec, T*vec), v)]
([1, 0], [0, 2], [0, 3])
T = [-3 8; 2 3]
v = ([-1,-1],[1,1],[0,2],[4,-1])
julia> v[findall(vec -> is_eigenvector(vec, T*vec), v)]
([-1, -1], [1, 1], [4, -1])
```

The problem with this approach is that sometimes I get a very, very small number (e.g., `2.1073424255447017e-8`

) due to what I assume is floating-point error so I’m wondering if there’s a better approach to solving this kind of problem. I’ve seen the `eigen`

and `eigvecs`

functions but I don’t understand how to use them in this context since `eigvecs`

for example just returns a matrix:

```
T = [-3 8; 2 3]
v = ([-1,-1],[1,1],[0,2],[4,-1])
julia> eigvecs(T)
2×2 Array{Float64,2}:
-0.970143 -0.707107
0.242536 -0.707107
# Can this output somehow be used to determine that ([-1, -1], [1, 1], [4, -1])
# are eigenvectors?
```