Find the Schur decomposition for the matrix $$ A=\begin{bmatrix}1&1\\ -2&-1\end{bmatrix}$$
I have attempted to do as the question asks via finding the eigenvectors ($u_1=(-1-i,2)^T$ corresponding to $\lambda_1=i$ and $u_2=(-1+i,2)$ corresponding to $\lambda_2=-i$), using Gram-Schmidt and then make the obtained vectors orthonormal and finally obtain $U=[v_1\ v_2],$ where $v_1$ and $v_2$ are the orthonomal vectors obtained. However in my attempts of this I am running into issues (complex vectors for example when solution shouldn't have complex entries according to the MATLAB decomposition). I would appreciate if anyone could help.
Recall that in the proof of Schur decomposition, we used induction. Generally speaking, we will do it recursively to find a Schur decomposition of some square matrix.
For this one, you have obtained the eigenvalues and the corresponding eigenvectors. A nice job. Then you can start with any eigenvalue, say $\lambda_1=i$. The corresponding eigenvector is $u_1=[-1-i,2]^T$. Nonetheless, you have to normalize it: \begin{align} ||u_1||&=\sqrt{|-1-i|^2+|2|^2}=\sqrt{2+4}=\sqrt{6}. \\ v_1&=\frac{u_1}{||u_1||}=\frac{1}{\sqrt{6}}[-1-i,2]^T. \end{align} Here $|c|$ is the modular of a complex number $c$. Next, you will have to find a unitary matrix $U_1=[u_{11}\ u_{12}]$ where $u_{11}=v_1$. In general, this unitary matrix $U_1$ is not unique. Anyway, here we can easily find one: $$U_1=\frac{1}{\sqrt{6}}\begin{bmatrix} -1-i & 2 \\ 2 & 1-i \end{bmatrix}.$$ Now we can see that $$U_1^*AU_1=\frac{1}{6}\begin{bmatrix} -1+i & 2 \\ 2 & 1+i \end{bmatrix}\begin{bmatrix} 1 & 1 \\ -2 & -1 \end{bmatrix}\begin{bmatrix} -1-i & 2 \\ 2 & 1-i \end{bmatrix}=\begin{bmatrix} i & -2+i \\ 0 & -i \end{bmatrix}.$$It seems that we are done now. But for matrices of order at least $3$, we will have a matrix of the form: $$\begin{bmatrix} \lambda_1 & * \\ 0 & A_{(n-1)\times(n-1)} \end{bmatrix}$$Then we apply almost the same step to the block $A_{(n-1)\times(n-1)}$.
As for the MATLAB output, according to the manual, if a matrix has real and complex eigenvalues, you have to set the flag to be complex to get a triangular matrix. In addition, the Schur decomposition of a matrix is not unique, so the MATLAB output might be different from what we obtained here.