0
$\begingroup$

I want to find a matrix corresponding to certain transformations I already know. Basically I have a set of vectors $x_i$ and I need the matrix $m$ that transforms $x_i$ to another set of vectors $b_i$ that I also know. The issue I have is that there appears to be a displacement, a shear and a rotation component. I have tried the following already:

x1 = {{205, 1096, 0, 0},{0, 0, 205, 1096}}
b1 = {438, 1170}
x2 = {{5573, 3164, 0, 0},{0, 0, 5573, 3164}}
b2 = {5175, 2993}
m = {m11, m12, m21, m22}
Solve[{x1 . m == b1, x2 . m == b2}, m]

By rewriting $x_i = \begin{pmatrix} x_{i1} & x_{i2} & 0 & 0\\ 0 & 0 & x_{i1} & x_{i2} \end{pmatrix}$ and solving for $m$. This however does not map the rest of the points correctly.

$\endgroup$
2
  • 4
    $\begingroup$ Transpose and use LinearSolve to find $m$. $\endgroup$
    – yarchik
    Commented Apr 12 at 23:24
  • $\begingroup$ Maybe FindGeometricTransform is what you want. $\endgroup$
    – wioiw
    Commented Apr 28 at 17:24

2 Answers 2

1
$\begingroup$
x1 = {{205, 1096, 0, 0}, {0, 0, 205, 1096}};
b1 = {438, 1170};
x2 = {{5573, 3164, 0, 0}, {0, 0, 5573, 3164}};
b2 = {5175, 2993};

m = LeastSquares[Join[x1, x2], Join[b1, b2]]
(*    {357164/454949, 460033/1819796, -105388/1364847, 5906845/5459388}    *)

check:

x1 . m == b1
(*    True    *)

x2 . m == b2
(*    True    *)

If you have more conditions (an over-determined system), LeastSquares still gives you the best $m$ in the sense of least squared errors.

$\endgroup$
1
  • $\begingroup$ Thank you for the suggestion, however, for my application the transformation does not seem linear i.e. depending on the position in the coordinate system, the transformation is different. I will rephrase my original post accordingly. $\endgroup$
    – avnar
    Commented Apr 13 at 8:54
0
$\begingroup$

For vectors x and b, this has no unique solution because m has n^2 entries and b and x only define n equations. Nevertheles, here is what you can do for an example with n==2:

With given x and b:

n=2; SeedRandom[1]; x = RandomReal[{-1, 1}, n]; b = RandomReal[{-1, 1}, n];

Define a symbolic matrix:

m = Array[Subscript[a, #1, #2] &, {n,n}]

You can solve the equation:

sol=Solve[m . x == b, Flatten[m]][[1]]

{Subscript[a, 1, 2] -> -0.399097 - 0.595584 Subscript[a, 1, 1], 
 Subscript[a, 2, 2] -> -0.27952 - 0.595584 Subscript[a, 2, 1]}

Now for arbitrary a11 and a21:

msol= m/. sol /. {Subscript[a, 1, 1]->1,Subscript[a, 2, 1]->2}

{{1, -0.994681}, {2, -1.47069}}

Now let us test the solution:

msol . x == b

True
$\endgroup$
1
  • $\begingroup$ Thanks for your answer, I have many vectors $x_i$ and $b_i$, so there should be a unique solution. I also rephrased the question, I hope my issue is clearer now. $\endgroup$
    – avnar
    Commented Apr 13 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.