Bonus homework 2

This is yet another one of these bonus assignments. It's a quick exploration of eigenvalues and eigenvectors for some specific matrices following a certain entry-pattern. The matrices I'm interested in

  • are square ($n\times n$ for some positive integer $n$);
  • have a entry $x$ all along the diagonal, and
  • have entry $y$ everywhere else.

Let's just define a Python function that returns such a matrix, given $n$, $x$ and $y$ as parameters.

In [1]:
from sympy import *
init_printing(use_latex='mathjax')

I'll do this by

  • first filling the matrix with $1$ using SymPy's ones function,
  • then scaling that by my desired off-diagonal entry,
  • and then modifying the diagonal by adding some scalar multiple of the identity $n\times n$ matrix, eye($n$).
In [4]:
def mtrx(size, diag_entry, other_entry):
    return other_entry*ones(size) + (diag_entry-other_entry)*eye(size)

Let's try it out:

In [5]:
mtrx(4, 7, 19)
Out[5]:
$\displaystyle \left[\begin{matrix}7 & 19 & 19 & 19\\19 & 7 & 19 & 19\\19 & 19 & 7 & 19\\19 & 19 & 19 & 7\end{matrix}\right]$
In [7]:
mtrx(10,1,5)
Out[7]:
$\displaystyle \left[\begin{matrix}1 & 5 & 5 & 5 & 5 & 5 & 5 & 5 & 5 & 5\\5 & 1 & 5 & 5 & 5 & 5 & 5 & 5 & 5 & 5\\5 & 5 & 1 & 5 & 5 & 5 & 5 & 5 & 5 & 5\\5 & 5 & 5 & 1 & 5 & 5 & 5 & 5 & 5 & 5\\5 & 5 & 5 & 5 & 1 & 5 & 5 & 5 & 5 & 5\\5 & 5 & 5 & 5 & 5 & 1 & 5 & 5 & 5 & 5\\5 & 5 & 5 & 5 & 5 & 5 & 1 & 5 & 5 & 5\\5 & 5 & 5 & 5 & 5 & 5 & 5 & 1 & 5 & 5\\5 & 5 & 5 & 5 & 5 & 5 & 5 & 5 & 1 & 5\\5 & 5 & 5 & 5 & 5 & 5 & 5 & 5 & 5 & 1\end{matrix}\right]$

And so on. Your task:

Tell me, for arbitrary sise $n$, diagonal entry $x$ and off-diagonal entry $y$, the eigenvalues of the matrix matr(n,x,y), and also describe the eigenvectors.


I want the general pattern, that will of course be dependent on $n$, $x$ and $y$. I suggest you explore small cases using SymPy's eigenvals() and eigenvects() methods.