# Finding eigenvalues of tridiagonal matrix using MATLAB

$$\begin{bmatrix} -1 & 1 & 0 &\dots &\dots &\dots &0\\ 1 & -2 & 1 & \ddots & & & \vdots\\ 0 & 1 & -2 & \ddots & \ddots & & \vdots\\ \vdots & \ddots & \ddots & \ddots & \ddots & \ddots & \vdots\\ \vdots & & \ddots & \ddots & -2 & 1 & 0\\ \vdots & & & \ddots & 1 & -2 & 1\\ 0 & \dots & \dots & \dots & 0 & 1 & -1\\ \end{bmatrix}\in \mathbb{R}^{N\times N}$$

Is the matrix I'm trying to solve. I'm trying to figure out what to do in MATLAB, but I'm not familiar with the program to use it. What is the process one would to to solve for the eigen values for this matrix?

Using diag you can create your matrix 1. Using eig you can determine the eigenvalues 2. Here is the code:

n = 4;
A = diag(-2*ones(n,1))+ diag(ones(n-1,1),1) + diag(ones(n-1,1),-1);
A(1,1) = -1;A(n,n) = -1;
eig(A)


You can alter $n$ to change the size of the matrix. Because we are using MATLAB we can easily visualize the eigenvalues for different $n$. With this code:

for n = 1:50
A = diag(-2*ones(n,1))+ diag(ones(n-1,1),1) + diag(ones(n-1,1),-1);
A(1,1) = -1;A(n,n) = -1;
plot(eig(A),n,’o’)
hold  on
end


We can create this picture, with the eigenvalues on the x-axis and the size of the matrix on the y-axis. You can see a pattern, you can prove why this is.

• Thank you for the help. The figure that is generated by the 2nd code doesn't have a plot on my end. It's just the axis and blank space. Does the pattern have something to do with the Helmholtz equation? – Peetrius Nov 12 '17 at 1:53
• Nice plot. One can also use A = toeplitz([-2 1 zeros(1,n-2)]); and then fix the top left and bottom right corners with A([1,end],[1,end]) = -1;. – Fabio Somenzi Nov 12 '17 at 7:32
• @Peetrius I forgot to add ‘o’ in line 5. And I don’t think it has anything to do with the Helmholtz equation, why do you think it does? – Tobias Molenaar Nov 12 '17 at 10:52
• This particular problem is part of a section of the book related to it. – Peetrius Nov 13 '17 at 4:26