# Computing the unitary operator that diagonalizes a matrix

Hello. I am learning in Mathematica how to obtain the unitary operator that allows us to diagonalize the matrix M. Although with U^{-1}.M.U am able to obtain the answer: why doesn't the program deliver it diagonally? (I had to verify that such a matrix is diagonal) Thank you.

• People here generally like users to post code as copyable Mathematica code instead of just images or TeX, so they can copy-paste it. It makes it convenient for them and more likely you will get someone to help you. You may find the meta Q&A, How to copy code from Mathematica so it looks good on this site, helpful Mar 27, 2023 at 17:38
• @Michael From now on I will copy the code. Mar 27, 2023 at 17:47
• Note that Eigensystem[] on an exact matrix does not (usually) produce normalized eigenvectors. So you need to Normalize[] them, if you want to construct a unitary matrix from them. Mar 27, 2023 at 18:04
• Would that mean adding Normalize[v]? Mar 27, 2023 at 20:11
• To normalize each vector use Map (/@): u = Transpose[Normalize /@ v]. Or search for "normalize" in the documentation for Eigensystem; they show how to use it to diagonalize a matrix, more or less what you're doing here. Mar 27, 2023 at 21:36

why doesn't the program deliver it diagonally?

Mathematica does not simplify automatically (for good reasons). So you just need to simplify the result. That is all.

ClearAll["Global*"]
M = {{2, 3}, {3, 7}}
{lambda, v} = Eigensystem[M]
U = Transpose[v]
(Inverse[U] . M . U) // Simplify // MatrixForm


• You're right. By simplifying you could lose information. Thank you so much. Mar 27, 2023 at 17:46
• @eraldcoil if you are coming from system not symbolic (like Matlab) then Simplify will be new to you which is OK. in Matlab, since everything is numerical (vs. mix of numerical and Symbolics like in Mathematica), the concept of Simplify does not really apply as it is done automatically in Matlab and other systems like it (Fortran, etc..), since things are all numbers. But in CAS system Simplify becomes more important. Be careful that FullSimplify if overdone can slow down things in long computation. But you can add TimeConstrained` to avoid being stuck. Mar 27, 2023 at 17:49