TransWikia.com

How to define a function to decouple equations and transform them into standard form

Mathematica Asked on March 21, 2021

I want to convert this expression($frac{x-a 2}{a 1}=frac{y-b 2}{b 1}=frac{z-c 2}{c 1}$) of the linear equation into a standard form $left{begin{matrix}
text { b1 } * x-a 1 * y=a 2 * b 1-a 1 * b 2
text { c1 } * y-b 1 * z=b 2 * c 1-b 1 * c 2
text { c1 } * x-a 1 * z=a 2 * c 1-a 1 * c 2
end{matrix}right.$

(x - a2)/a1 == (y - b2)/b1 == (z - c2)/c1

What can I do to quickly decouple $frac{x-a 2}{a 1}=frac{y-b 2}{b 1}=frac{z-c 2}{c 1}$ into the following desired format?

{b1*x - a1*y == a2*b1 - a1*b2,
 c1*y - b1*z == b2*c1 - b1*c2,
 c1*x - a1*z == a2*c1 - a1*c2}

One Answer

eqns = (x - a2)/a1 == (y - b2)/b1 == (z - c2)/c1;
vars = {x, y, z};

(* break up into pairwise equations and subtract rhs - lhs *)
pairwise = (Subsets[eqns, {2}]) /. Equal -> Subtract;

(* eliminate fractions *)
nofrac = #*Denominator[#] & /@ Together[pairwise]

(* move terms involving variables onto lhs and put constant terms on right *)
Total[Most[#]] == If[FreeQ[Last[#], Alternatives@@vars], -Last[#], 0] & /@ 
 (MonomialList[#, vars] & /@ nofrac)

(* result:
 {b1 x - a1 y == a2 b1 - a1 b2,
  c1 x - a1 z == a2 c1 - a1 c2, 
  c1 y - b1 z == b2 c1 - b1 c2} *)

That last part could be simplified a bit using CoefficientArrays:

#[[2]].vars == -#[[1]] & /@ (CoefficientArrays[#, vars] & /@ nofrac)

Correct answer by flinty on March 21, 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