The basis of a kernel So I am having trouble constructing the basis of the kernel of a matrix, after I doing rref to the matrix. 
For example, I want to find the basis of the kernel of  {$\begin{bmatrix}2&2&0&-2&4\\ 1&1&1&2&1\\2&2&1&1&3\end{bmatrix}$
and rreft(A) = {$\begin{bmatrix}1&1&0&-1&2\\ 0&0&1&3&-1\\0&0&0&0&0\end{bmatrix}$
I try to set the x1,x2,x3 as free variable, the I get 
x1=x1
x2=x2
x3=x3
x4=x1+x2+2x5
x5=x3+3x4
so the basis are [1,0,0,1,0]$^T$, [0,1,0,1,0]$^T$,[0,0,1,0,1]$^T$,[0,0,0,1,3]$^T$,[0,0,0,2,1]$^T$ but I really think I messed them up. 
What the solution of the question says: 
Letting s, t, u be the free variables corresponding to the columns of rref(A).
Then the general solution of Av = 0 is
s$\begin{bmatrix}-1\\ 1\\0\\0\\0\end{bmatrix}$+t$\begin{bmatrix}1\\ 0\\-3\\1\\0\end{bmatrix}$+u$\begin{bmatrix}-2\\ 0\\1\\0\\1\end{bmatrix}$
But how do they get there, I mean I see why they are setting the first,second and the third variables as the free variables, but how do they get to the next step? 
 A: You should set x2, x4 and x5 instead as they correspond to the non-pivot columns. So if we let $x_2=x_2, x_4=x_4,x_5=x_5$ and for $Av=0$, then we have the following:
$x_1=-x_2+x_3-2x_5$ 
$x_2=x_2$ 
$x_3=-3x_4+x_5$
$x_4=x_4$
$x_5=x_5$
Then we can express 
$\begin{bmatrix}x_1\\x_2\\x_3\\x_4\\x_5\end{bmatrix}=x_1\begin{bmatrix}-1\\1\\0\\0\\0\end{bmatrix}+x_4\begin{bmatrix}1\\0\\-3\\1\\0\end{bmatrix}+x_5\begin{bmatrix}-2\\0\\1\\0\\1\end{bmatrix}$
as required.
A: Let's start from you rref (which I'll assume you found correctly).
$$
M = \pmatrix{
1&1&0&-1&2\\ 
0&0&1&3&-1\\
0&0&0&0&0
}
$$
The pivots are in columns $1$ and $3$, so every other column (columns 2,4, and 5) corresponds to a free variable.  With the free variables $x_2,x_4,x_5$, the system of equations that defines the kernel of the matrix (the system $Mx = 0$) looks like this:
$$
x_1 + x_2 - x_4 + 2x_5 = 0\\
x_3 + 3x_4 - x_5 = 0
$$
we can solve these equations for the non-free variables.  In particular, we have
$$
x_1 = -x_2 + x_4 - 2x_5\\
x_3 = -3x_4 + x_5
$$
So, the solution to the system of equations $Mx = 0$ can be written in the form
$$
x = \pmatrix{x_1\\x_2\\x_3\\x_4\\x_5} = \pmatrix{-x_2 + x_4 - 2x_5\\x_2\\-3x_4 + x_5\\x_4\\x_5} = x_2 \pmatrix{-1\\1\\0\\0\\0} + x_4\pmatrix{1\\0\\-3\\1\\0} + x_5\pmatrix{-2\\0\\1\\0\\1}
$$
Importantly, the kernel of the rref matrix $M$ is exactly the same as the kernel of the matrix $A$ that we started with, so we've now answered the question.
