how to find out a matrix for a given minimal polynomial I know how to find out the the minimal polynomial for a given matrix.
But I am stuck to do the reverse process. For example how to find out a
 $3\times3$ matrix, whose minimal polynomial is $x^2$.
 A: For a general monic polynomial $p(x)=a_0+a_1x+a_2x^2+\cdots +a_{n-1}x^{n-1}+x^n$ there is the so called companion matrix which looks like this
$$
C_p:=\begin{pmatrix}
0&-a_0 \\ I & -\mathfrak a
\end{pmatrix}
$$
where $I$ is the $(n-1)\times (n-1)$ identity matrix and $\mathfrak a=(a_1,...,a_{n-1})^\top$. $C_p$ is of dimensions $n\times n$ and has the characteristic and minimal polynomial equal to $p$.

Example. Let's take your example $p(x)=x^2$. We write this polynomial in the form
$$p(x)=x^2=0+0\cdot x+1\cdot x^2.$$
We have $a_0=0$ and $\mathfrak a=(0)^\top$. Because $n=2$, this will give us a $2\times 2$ companion matrix
$$C_p=\begin{pmatrix}0&0\\1&0\end{pmatrix}.$$
We can boost this onto a $3\times 3$ matrix by adding a zero line and a zero column:
$$C_p^{3\times 3}=\begin{pmatrix}0&0&\color{lightgray}0\\1&0&\color{lightgray}0\\\color{lightgray}0&\color{lightgray}0&\color{lightgray}0\end{pmatrix}.$$
The charcteristic polynomial will be $-x^3$, but it is not hard to see that the minimal polynomial is still $x^2$ as $[C_p^{3\times 3}]^2=0$.

Fun fact
From what I learned in my lectures on numerical mathematics, we have much better (faster, more stable, ...) algorithms for computing eigenvalues of matrices than for computing roots of polynomials directly. Therefore, in order to compute the roots of a polynomial $p$, we instead create the matrix $C_p$ and use our eigenvalue finding algorithms for these. These eigenvalues are exactly the roots of $p$.
A: Let's say the matrix you are looking for is $A$. Then, by definition, $p(x)=x^2$ is the smallest monic polynomial such that $p(A) = 0$ .
So you need to find a matrix which fullfills this equation.
This will be a good candidate for example:
\begin{align}
A =
\begin{pmatrix}
0 & 0 & 1 \\
0 & 0 & 0 \\
0 & 0 & 0
\end{pmatrix}
\end{align}
You can check that indeed $p(A) = A^2 = 0$ . No polynomial $q(x)$ of smaller degree can have $q(A) = 0$, since it yould have to be of degree $1$ .
$$
q(x) = q_1 x + q_0 ~~~~~ \text{with}~~~~~ q_1 \neq 0 
$$
However
$$
q(A) = q_1 A + q_0 =
\begin{pmatrix}
q_0 & 0 & q_1 \\
0 & q_0 & 0 \\
0 & 0 & q_0
\end{pmatrix}
\neq 0
$$
So $x^2$ is indeed the minimal polynomial of $A$ .
