# How can I solve a linear equation with many input variables symbolically without taking forever

Background: I have a linear equation whereas T2 and T3 are transformation matrices, Rp is translation vector.

The equation results in 3 linear equations that can be used to solve the coordinates of Rp. Which is what I want to do in Mathematica. In short, I want to express p_x, p_y and p_z in terms of T2 and T3.

Here is my input:

T2 = {{n2x, o2x, a2x, p2x}, {n2y, o2y, a2y, p2y}, {n2z, o2z, a2z,
p2z}, {0, 0, 0, 1}}
T3 = {{n3x, o3x, a3x, p3x}, {n3y, o3y, a3y, p3y}, {n3z, o3z, a3z,
p3z}, {0, 0, 0, 1}}
Rp = {px, py, pz, 1}

eq1 = (IdentityMatrix[4] - T2 . Inverse[T3]) . Rp

Solve[eq1 == ConstantArray[0, {4}], {px, py, pz}, Reals]


Unfortunately, solve takes forever to execute. So far it didn't yield a result. Is this the correct way of solving this problem?

Thanks, Alex

UPDATE: Removed the underscores from my variable names.

• Do not use variable names with underscores. These are used for patterns. Commented Mar 3, 2021 at 14:30
• @DanielHuber Thanks, good to know. Commented Mar 3, 2021 at 15:02
• Remove the domain specification Reals. It can cause difficulty in sorting through ranges of the symbolic terms e.g. to make sure denominators do not vanish. Also you can get a smaller result like so: NullSpace[IdentityMatrix[4] - T2.Inverse[T3], Method -> "OneStepRowReduction"] Commented Mar 3, 2021 at 15:57

myEq = Map[(Simplify[#] == 0) &, eq1]
sol = Solve[myEq, {px, py, pz}];


which gives a result within 3 seconds or so (MMa 12.2, Linux). It takes somewhat longer to check the solution, though

eqSolved = Together /@ (myEq /. sol[[1]])
(*{True,True,True,True}*)


Use //Together//Numerator  to get result in 0.047 seconds.

T2 = {{n2x, o2x, a2x, p2x}, {n2y, o2y, a2y, p2y}, {n2z, o2z, a2z,
p2z}, {0, 0, 0, 1}};
T3 = {{n3x, o3x, a3x, p3x}, {n3y, o3y, a3y, p3y}, {n3z, o3z, a3z,
p3z}, {0, 0, 0, 1}};
Rp = {px, py, pz, 1};

eq1 = (IdentityMatrix[4] - T2.Inverse[T3]).Rp;

ff = (# // Together // Numerator // Simplify &) /@ eq1;

(sol = Solve[Thread[ff == 0], {px, py, pz}]) // Timing

(*   A very large output ...
{0.047, {{px ->......    *)

eq1 /. sol[[1]] // Together // Simplify // Timing

(*   {9.188, {0, 0, 0, 0}}   *)