Crossposted [from StackOverflow](https://stackoverflow.com/q/62583210/12820864). The generalised diagonalization of two matrices $A$ and $B$ can be done in Matlab via



```
[V,D] = eig(A,B);

```

where the columns of $V$ are are the generalised eigenvectors of the pair ($A$, $B$), while $D$ is a diagonal matrix containing the corresponding generalised eigenvalues.


First, is it correct to assume that the generalised eigenvectors $V$ are also simultaneous eigenvectors of both $A$ and $B$, under the assumption that $A$ and $B$ commute?


If so, I could compute the respective eigenvalues of $A$ and $B$ (in the same order as the eigenvectors in $V$) as follows



```
eigA = V\A*V;
eigB = V\B*V;

```

However, is there a simpler way to achieve this, i.e. without having to compute the inverse of $V$ as in the snippet above?



Simultaneous diagonalization in Matlab
From comments: OP mentions that his matrices are Toeplitz tridiagonal; in particular, they can all be written as $\alpha L + \beta I$, where $L$ is the finite-difference matrix `tridiag(-1,2,-1)`.


So the problem has a closed-form solution: the eigenvalues of $L$ are given by $\lambda\_k = 2(1-\cos \frac{k\pi}{n+1})$, and its eigenvectors are $(v\_k)\_j = \sin \frac{jk\pi}{n+1}$. (From <https://en.wikipedia.org/wiki/Tridiagonal_matrix#Eigenvalues> and <https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors_of_the_second_derivative#Pure_Dirichlet_boundary_conditions_2> ).


