Assume you have two affine spaces defined as follows:
$$S_1: v^{*} + \sum \alpha_i \hat{v}_{i}$$
where $v^{*}$ is a vector in $R^n$ and $\alpha$'s are coefficients and $\hat{v}$'s are basis vectors for spanning.
and the second space is defined similarly
$S_1: u^{*} + \sum \beta_j \hat{u}_{i}$
So the question is, how to calculate the intersection of the two spaces in MATLAB. I know how to calculate it by hand: just set $S_1=S_2$ and derive some relationships for $\alpha$ and $\beta$.
The solution (or let's say the output of the matlab script) should be the intersection basis. That is,
$S_1\bigcap S_2 : z^{*} + \sum \gamma_k\hat{z}_k$.
So the output is vectors $z^{*}$ and $\hat{z}_k$. Of course it is not unique.
Let me make it absolutely clear. Here's an example:
$S_1 : \left( \begin{array}{c} 1\\ 1\\ 1 \\ \end{array} \right)+ \alpha_1\left( \begin{array}{c} 1\\ 2\\ 1\\ \end{array} \right)+\alpha_2 \left( \begin{array}{c} 1\\ 1\\ 2\\ \end{array} \right)$.
And
$S_2 : \left( \begin{array}{c} 0\\ 0\\ 1 \\ \end{array} \right)+ \beta_1\left( \begin{array}{c} 0\\ 1\\ 1\\ \end{array} \right)+\beta_2 \left( \begin{array}{c} 1\\ 0\\ 1\\ \end{array} \right)$.
Basically two planes, so the intersection would be a line. And when I work out (on paper!) I come up with the intersection (after row-elimination) :
$S_1\bigcap S_2 : \left( \begin{array}{c} 1\\ 0\\ 2\\ \end{array} \right)+ \gamma_1 \left( \begin{array}{c} 1\\ 1\\ 2\\ \end{array} \right)$.
How can you do the whole procedure automatically in Matlab?

Let U, V be the $n \times (n-1)$ matrices of the spanning vectors of $S_1$ and $S_2$ and let u0, v0 be the particular vectors that are also given. You can find a particular vector z0 in the intersection with the Matlab command
z0 = [U,V]*([U,V]\(v0 - u0))
and you can get a $n \times (n-2)$ matrix of spanning vectors of the intersection with the command
Z = null([null(U),null(V)]) .