TransWikia.com

Solve for matrix in linear equation

Mathematica Asked by Dan Goldwater on February 4, 2021

I need to find a matrix M such that M.u = v, where u and v are known vectors. I don’t understand how to do this with LinearSolve, which seems only to solve for the vectors and not the matrices in these types of equation.

Is there a function for this?

3 Answers

You may search for a rotation matrix that turns the direction of u into the direction of v. Applying this matrix to u gives a vector in the direction of v, but with a different length. Therefore you must adjust the rotation matrix by multiplying by the length of v and divide by the length of u. THis can be done in MMA by:

{u, v} = RandomReal[{-1, 1}, {2, 3}]
m = RotationMatrix[{u, v}]  Norm[v]/Norm[u]

m maps now u into v:

m.u == v
(*True*)

Answered by Daniel Huber on February 4, 2021

There are too many matrixs satisfy the equation M.u==v.

Without loss general, we can Normalize the vector u and v.

Besides the RotationMatrix which have mention by @Daniel Huber, we can construct the reflect-matrix by hand which also satisfiy the equation M.u==v

u = Normalize[{x, y, z}, Sqrt[#.#] &];
v = Normalize[{a, b, c}, Sqrt[#.#] &];
normal = Normalize[u - v, Sqrt[#.#] &];
M = IdentityMatrix[3] - 2 Outer[Times, normal, normal];
M.u == v // Simplify

True

ReflectionMatrix maybe another choise.

u = Normalize[{x, y, z}, Sqrt[#.#] &];
v = Normalize[{a, b, c}, Sqrt[#.#] &];
normal = Normalize[u - v, Sqrt[#.#] &];
M = Simplify[ReflectionMatrix[normal], normal ∈ Reals];
M.u == v // Simplify

True

For difference dimensions vector u and v,we can also combine the matrixs such as projection matirx and reflection matrix and rotation matirx to construct such matrix.

Answered by cvgmt on February 4, 2021

You can use a fitting procedure to find a solution. It's not going to be unique, though.

u = RandomReal[1, {3}]
v = RandomReal[1, {5}]
mat = Array[x, {Length[v], Length[u]}]
sol = NMinimize[Total[(mat.u - v)^2], Flatten[mat]];
mat /. Last[sol]

Check that the residuals are 0:

mat.u - v /. Last[sol]

Answered by Sjoerd Smit on February 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP