Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This problem arose in my stereo vision project.

I have two matrices: $$ A = \left( \begin{array}{ccc} \text{x1}*\text{p131}-\text{p111} & \text{x1}*\text{p132}-\text{p112} & \text{x1}*\text{p133}-\text{p113} \\ \text{y1}*\text{p131}-\text{p121} & \text{y1}*\text{p132}-\text{p122} & \text{y1}*\text{p133}-\text{p123} \\ \text{x2}*\text{p231}-\text{p211} & \text{x2}*\text{p232}-\text{p212} & \text{x2}*\text{p233}-\text{p212} \\ \text{y2}*\text{p231}-\text{p221} & \text{y2}*\text{p232}-\text{p222} & \text{y2}*\text{p233}-\text{p223} \end{array} \right) $$ $$B = \left( \begin{array}{c} \text{p114}-\text{x1}*\text{p134} \\ \text{p124}-\text{y1}*\text{p134} \\ \text{p214}-\text{x2}*\text{p234} \\ \text{p224}-\text{y2}*\text{p234} \end{array} \right) $$

I computed the following vector k:

k = Simplify[Inverse[Transpose[A].A].Transpose[A].B]

And mathematica output a huge answer for k (as expected), wich I think it's not necessary for me to type it in here.

Here is where my problem starts. This computation must be done at 120 Hz, where all entries of A and B are known, but only $\text{x1,x2,y1}$ and $\text{y2}$ change from time to time (forcing me to recompute the whole transpose and inverse thing every time they change).

I would like to express the matrix k as $$k = k1*k2 $$ where $k1$ entries are functions only of the $\text{p}_{ijk}$ and $k2$ entries are functions only of $\text{x1,x2,y1}$ and $\text{y2}$.

I suppose mathematica won't directly do that, but maybe I could use it to help me in the process.

To illustrate better what I mean for $k=k1*k2$ let me do an example:

Suppose I have the following vector $k$ $$k=\left( \begin{array}{c} \frac{b+a}{a} \\ a-b \\ 1+a.b \\ \frac{a}{b} \end{array} \right)$$

I could rewrite it as $$ k=\left( \begin{array}{c} 1+\frac{b}{a} \\ a-b \\ 1+a.b \\ \frac{a}{b} \end{array} \right) $$

and then as a matrix multiplication:

$$ k=\left( \begin{array}{c} 0 & 0 & 0 & 0 & 1 & 1\\ 1 & -1 & 0 & 0 & 0 & 0\\ 0 & 0 & 1 & 0 & 0 & 1\\ 0 & 0 & 0 & 1 & 0 & 0 \end{array} \right)*\left( \begin{array}{c} a\\ b\\ a.b\\ \frac{a}{b} \\ \frac{b}{a} \\ 1 \end{array} \right) $$

Where only the second factor depends on $a$ and $b$

Hope I made myself clear. Any help would be appreciated!

share|improve this question
4  
This cannot be done in general. You have presented the normal equations for a least squares fit. To see what's possible, then, consider the simplest possible case where both $A$ and $B$ are $1$ by $1$ matrices of the form $A = xp-q$ and $B = xp'-q'$. Then $k = \frac{xp'-q'}{xp-q}$ obviously cannot be factored in the way you suppose. Therefore it is too much to hope that such a factorization would apply in more complicated situations. You would be better off using standard methods of ordinary least squares fitting compared to this brute-force method. –  whuber Feb 4 '13 at 14:43
2  
A numerical method will be vastly faster than trying precomputing a solution and if the matrix is well conditioned you should get stable results even with simple algorithms like gaussian elimination for computing the inverse numerically. If you are planning on using Mathematica for solving the problem numerically, have a look at the functions PseudoInverse, LeastSquares and LinearSolve. –  Thies Heidecke Feb 4 '13 at 15:32
2  
Keep in mind that you shouldn't invert a matrix when you are trying to solve a system of linear equations. Just use LinearSolve. See: johndcook.com/blog/2010/01/19/dont-invert-that-matrix –  Volker Feb 4 '13 at 16:08
    
Thies Heidecke - Why would a numerical method be faster than precomputing the solution? –  h3now Feb 6 '13 at 1:07
    
whuber - You are indeed right that this does not hold in general, and only in special cases it would be possible. But I believe I'm dealing with one of those cases, since my answer was in terms of Pijk's and $x_i^n$'s, without any divisions. –  h3now Feb 6 '13 at 1:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.