Skip to content

Instantly share code, notes, and snippets.

@nlw0
Last active July 28, 2020 16:36
Show Gist options
  • Save nlw0/394950e6de1919daf07a678bdfe9444d to your computer and use it in GitHub Desktop.
Save nlw0/394950e6de1919daf07a678bdfe9444d to your computer and use it in GitHub Desktop.
Eigenvectors from eigenvalues (Julia demo)
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Eigenvectors from eigenvalues\n",
"\n",
"Short Julia notebook demonstrating the interesting property between eigenvectors and eigenvalues [announced](https://terrytao.wordpress.com/2019/08/13/eigenvectors-from-eigenvalues/) recently.\n",
"\n",
"![](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle++%7Cv_%7Bi%2Cj%7D%7C%5E2+%5Cprod_%7Bk%3D1%3B+k+%5Cneq+i%7D%5En+%28%5Clambda_i%28A%29+-+%5Clambda_k%28A%29%29+%3D+%5Cprod_%7Bk%3D1%7D%5E%7Bn-1%7D+%28%5Clambda_i%28A%29+-+%5Clambda_k%28M_j%29%29&bg=ffffff&fg=000000&s=0)\n",
"\n",
"Inspired by a [Python notebook](https://github.com/leopd/geometric-intuition/blob/master/linear-algebra/eigenvectors%20from%20eigenvalues.ipynb), and by [Alan Edelman](https://twitter.com/AlanEdelman1/status/1195819794609659906)."
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"true"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"using LinearAlgebra, RandomMatrices\n",
"\n",
"function eigvec2fromeigval(A)\n",
" n = size(A)[1]\n",
" λ = eigvals(A)\n",
" map((i,j) for j=1:n, i=1:n) do (i,j)\n",
" lhs = prod(λ[i] .- λ[1:n .!= i])\n",
" M = A[1:n .!= j, 1:n .!= j]\n",
" rhs = prod(λ[i] .- eigvals(M))\n",
" rhs / lhs\n",
" end\n",
"end\n",
"\n",
"n = 5\n",
"A = rand(GaussianHermite(2), n)\n",
"v2 = abs2.(eigvecs(A))\n",
"v2hat = eigvec2fromeigval(A)\n",
"v2 ≈ v2hat"
]
}
],
"metadata": {
"@webio": {
"lastCommId": "99296c71b72b4c74ba7473ee0fea85a7",
"lastKernelId": "65d267ba-10cb-4225-8bc8-d129869583aa"
},
"kernelspec": {
"display_name": "Julia 1.4.0-DEV",
"language": "julia",
"name": "julia-1.4"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.4.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment