I have matrix $$ M = \begin{bmatrix}0&r\\k^{-1}&0\end{bmatrix} $$ where $k,r$ are real constants.The book says that a matrix $P$ can diagonalize $M$ such that $M=P^{-1}DP$ where $D=$ diagonal matrix with eigenvalues of $M$. The book gives explicit form of matrix $P$ as $$ P = \begin{bmatrix}(kr)^{-1/4}&(kr)^{1/4}\\-(kr)^{-1/4}&(kr)^{1/4}\end{bmatrix} $$ I checked that this P matrix does as the book says, i.e. $M=P^{-1}DP$
I want to derive vector $P$ by myself. So, first I find the eigenvalues of $M$ which are exactly like the books says $\pm\sqrt{r/k}$. Next, I find the eigenvectors $\phi_{1,2}$ which are $$ \phi_1 = N\begin{bmatrix}(kr)^{1/2}\\1\end{bmatrix};\quad \phi_2 = N\begin{bmatrix}-(kr)^{1/2}\\1\end{bmatrix} $$ where $N=(kr+1)^{-1/2}$ is normalization constant. From here I construct $P$ matrix as $$ P = \begin{bmatrix}\phi_1&\phi_2\end{bmatrix} = N\begin{bmatrix}(kr)^{1/2}&-(kr)^{1/2}\\1&1\end{bmatrix}\\ P = \frac{N}{(kr)^{-1/4}}\begin{bmatrix}(kr)^{1/4}&-(kr)^{1/4}\\(kr)^{-1/4}&(kr)^{-1/4}\end{bmatrix} $$ Why my $P$ matrix is not equal to $P$ matrix given in the book? In fact my $P$ matrix does not obey $M=P^{-1}DP$ equation. I have checked it using MATLAB and other online tools but still the result is same. What am I missing here?
The reason that you’re ending up with a very different matrix is that the columns of the book’s matrix $P$ are not eigenvectors of $M$. You have to be very careful about where the inverse factor goes in the diagonalization equation.
We can write the fundamental eigenvector equation $M\mathbf v=\lambda\mathbf v$ in “bulk” form as $MP=PD$, from which we get $M=PDP^{-1}$, not $P^{-1}DP$ as you have in your question. So, you should really be comparing your matrix to $$\begin{bmatrix}(kr)^{-1/4} & (kr)^{1/4} \\ -(kr)^{-1/4} & (kr)^{1/4}\end{bmatrix}^{-1} = \frac12 \begin{bmatrix} (kr)^{1/4} & -(kr)^{1/4} \\ (kr)^{-1/4} & (kr)^{-1/4}\end{bmatrix}.$$ Aside from an irrelevant scalar factor—remember that any nonzero scalar multiple of an eigenvector is also an eigenvector with the same eigenvalue—this looks the same as the matrix you constructed.
I should note that $k$ and $r$ can’t be arbitrary real constants. We must obviously have $k\ne0$, but we must also have $r=0$, otherwise both you and the book have several divisions by zero. In fact, when $r=0$, the matrix isn’t even diagonalizable. Also, we must have $kr\gt0$, otherwise, none of those fourth roots are defined.