Scaling a matrix to make its eigenvalues fall within a certain interval

I found out that the following transformation works, $$Ms=\frac{M−((b+a)/2) I}{(b−a)/2}$$ where I is a Identity matrix.
$M_s$ also has the same eigenvectors as the original matrix $M$.


So the added constraint to your problem is that eigenvalues $a$ and $b$ must be mapped to $-1$ and $1$. One possible solution is what follows.

If T is the diagonalizing matrix of M, then

$M=TDT^{-1}$, where $D=\begin{bmatrix} a&0&0&\dots\\ 0&b&0&\dots\\ 0&0&c&\dots\\ \vdots&\vdots&\vdots&\ddots \end{bmatrix} $

The rescaling transformation for a diagonal D matrix that maps eigenvalues $a$ and $b$ to $-1$ and $1$ would be $R_D$ such that the following holds (let's call $D_1$ the output of such a rescaling):

$D_1 = R_DD$, where $R_D = \begin{bmatrix} -1/a&0&0&\dots\\ 0&1/b&0&\dots\\ 0&0&1&\dots\\ \vdots&\vdots&\vdots&\ddots \end{bmatrix}$

Now let's call $M_1$ the rescaling of M such that eigenvalues $a$ and $b$ are mapped to $-1$ and $1$. It must be:

$M_1 = TD_1T^{-1} = TR_DDT^{-1} = TR_DT^{-1}TDT^{-1} = R_MM$.

So the rescaling transformation you are looking for is given by the multiplication on the left by the matrix:

$R_M = TR_DT^{-1}$