8
$\begingroup$

I use

myeq = CoplanarPoints[{{7, 4, 2}, {8, 1, 5}, {9, 6, 3}, {x, y, z}}]

9 x == 27 + 5 y + 8 z

I am trying to write myeq in the form $9x-5y-8z-27 = 0$. I tried

TraditionalForm[myeq]

or

PolynomialForm[myeq]

and

PolynomialForm[myeq, TraditionalOrder -> True]

I can not get the form $9x-5y-8z-27=0$.

How can I write the equation 9 x == 5 y + 8 z + 27 in the form 9x - 5y - 8z - 27 = 0?

$\endgroup$
3
  • 2
    $\begingroup$ TraditionalForm[Subtract@@myeq == 0]? $\endgroup$
    – MarcoB
    Jan 6 at 2:45
  • $\begingroup$ Your method is true for my question. But this is not true myeq = CoplanarPoints[{{7, 4, 2}, {8, 1, 5}, {9, 3, 6}, {x, y, z}}]; TraditionalForm[Subtract @@ myeq == 0] $\endgroup$ Jan 6 at 3:16
  • $\begingroup$ SubtractSides[myeq] or if you prefer SubtractSides[Reverse@myeq] $\endgroup$
    – Bob Hanlon
    Jan 6 at 8:03

5 Answers 5

7
$\begingroup$

Another way using ReplaceAll:

TraditionalForm[myeq /. a_ == b_ :>ExpandAll[a - b] == 0]

(*9 x-5 y-8 z-27==0*)

The second example:

myeq = CoplanarPoints[{{7, 4, 2}, {8, 1, 5}, {9, 3, 6}, {x, y, z}}];

TraditionalForm[myeq /. a_ == b_ :>ExpandAll[a - b] == 0]

(*9 x-2 y-5 z-45==0*)
$\endgroup$
2
  • 1
    $\begingroup$ This is not true when I use your code myeq = CoplanarPoints[{{7, 4, 2}, {8, 1, 5}, {9, 3, 6}, {x, y, z}}]; TraditionalForm[myeq /. a_ == b_ :> a - b == 0] $\endgroup$ Jan 6 at 3:17
  • $\begingroup$ I tried myeq = Expand[ CoplanarPoints[{{7, 4, 2}, {8, 1, 5}, {9, 3, 6}, {x, y, z}}]]; TraditionalForm[myeq /. a_ == b_ :> a - b == 0] it works. $\endgroup$ Jan 6 at 3:19
11
$\begingroup$

SubtractSides was added some versions back for this common operation. Combine with ExpandAll if you want it expanded:

eqn = CoplanarPoints[{{7, 4, 2}, {8, 1, 5}, {9, 3, 6}, {x, y, z}}]

(* 9 x == 2 y + 5 (9 + z) *)

ExpandAll@SubtractSides@eqn

(* -45 + 9 x - 2 y - 5 z == 0 *)

If you really want fine control over output formatting, you might want to break down the equation algebraically and use boxes for the output:

Flatten@Reverse[
    {1, {x, y, z}} CoefficientArrays[eqn, {x, y, z}]] // 
  DeleteCases[0] // Replace[{
   List[a__] :> RawBoxes@MakeBoxes[Plus[a] == 0, StandardForm],
   List[] :> True}]

(* 9 x - 2 y - 5 z - 45 == 0 *)

List[] can occur if everything in the equation cancels out. Of course, if TraditionalForm work for you, it's easier than boxes. In a simple Defer works, too:

Flatten@Reverse[
    {1, {x, y, z}} CoefficientArrays[eqn, {x, y, z}]] // 
  DeleteCases[0] // Replace[{
   List[a__] :> Defer[Plus[a] == 0],
   List[] :> True}]

(* 9 x - 2 y - 5 z - 45 == 0 *)
$\endgroup$
1
  • $\begingroup$ I use eqn = CoplanarPoints[{{7, 4, 2}, {8, 1, 5}, {9, 3, 6}, {x, y, z}}]; TraditionalForm@ExpandAll@SubtractSides@eqn It works. Thank you very much. $\endgroup$ Jan 6 at 7:45
6
$\begingroup$

I use two functions for this sort of thing:

lhs[eq_Equal] := Expand[eq[[1]]]
rhs[eq_Equal] := Expand[eq[[2]] ]

Example 1

myeq=CoplanarPoints[{{7,4,2},{8,1,5},{9,6,3},{x,y,z}}];
myeq = lhs[myeq] - rhs[myeq] == 0;
TraditionalForm[%]

Mathematica graphics

Example 2

myeq = CoplanarPoints[{{7, 4, 2}, {8, 1, 5}, {9, 3, 6}, {x, y, z}}] 
TraditionalForm[lhs[myeq] - rhs[myeq] == 0]

Mathematica graphics

I prefer rhs and lhs since it is more explicit and more clear for me than other methods (even though other methods might require less typing).

$\endgroup$
5
  • $\begingroup$ With your Example 2, I only get 9 x == 2 y + 5 (9 + z). I have to add myeq = CoplanarPoints[{{7, 4, 2}, {8, 1, 5}, {9, 3, 6}, {x, y, z}}]; TraditionalForm[Expand[lhs[myeq] - rhs[myeq]] == 0] $\endgroup$ Jan 6 at 3:59
  • $\begingroup$ @ThuyNguyen This is strange. in my V 13.3.1 it works as is. Here is screen shot !Mathematica graphics make sure to use the updated code with the Expand in it. $\endgroup$
    – Nasser
    Jan 6 at 4:05
  • $\begingroup$ @ThuyNguyen which version of Mathematica are you using? Try from clean kernel if you have not done this. $\endgroup$
    – Nasser
    Jan 6 at 4:10
  • $\begingroup$ Old version. I try that. Thanks again. $\endgroup$ Jan 6 at 4:12
  • $\begingroup$ With your Example 2, I get the same your result without using Expand $\endgroup$ Jan 6 at 7:35
4
$\begingroup$

One simple method is using SubtractSides or AddSides

eq = 9 x == 5 y + 8 z + 27;
eqZeroForm = SubtractSides[eq, Last[eq]]
eqZeroForm1 = SubtractSides[eq, First[eq]]
eqZeroForm2 = AddSides[eq, -First[eq]]
eqZeroForm3 = AddSides[eq, -Last[eq]]
$\endgroup$
4
$\begingroup$
myeq = CoplanarPoints[{{7, 4, 2}, {8, 1, 5}, {9, 6, 3}, {x, y, z}}]

9 x == 27 + 5 y + 8 z

(myeq /. Equal :> Subtract) == 0

-27 + 9 x - 5 y - 8 z == 0

$\endgroup$

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.