1. ## Optimization Problem

Firstly I dont know if this belongs in this forum but its my first post!

Now down to bussiness:
I have a 56x4 matrix and another 56x4 matrix which and i want to make a 4x4 transformation matrix.
I can simply make the matrix by doing MatrixA/MatrixB
However, I would like to try to optimize two variables:
- the accuracy of the transformation matrix converting MatrixA to MatrixB
and
- minimize the Sum(TransformationMatrix.^2)

How would I go about doing this?
The only way i can think of doing this is by getting MatrixA/MatrixB and randomly varying it, testing the accuracy and the Sum(TransformationMatrix.^2)

Is there a more elegant or better way to do this? I'm coding it so its fine if its iterative.

2. i don't think there's enough information there to really understand your problem, but from what little i can gather, linear least squares may be relevant to your interests

Linear least squares - Wikipedia, the free encyclopedia

3. This is probably just a repeat of what you will find on the wiki page.

Let A be your first 54x4 matrix, B the second and X be the 4x4 solution. I think you are trying to find a solution to:

$AX=B$
$\therefore A^TAX=A^TB$
$\therefore (A^TA)^{-1}(A^TA)X=(A^TA)^{-1}A^TB$
$\therefore X=(A^TA)^{-1}A^TB$

You will need to look more closely at the wiki page to learn why this is a least squares solution.
$(A^TA)^{-1}A^T$ is known as a pseudo inverse of A (you may want to google pseudo inverse).