# How to simplify an equation corresponding to an ellipsoid? [duplicate]

The equation

29/36 - x/2 + x^2/4 + y/9 + y^2/36 - (4 z)/9 + z^2/9 == 1

is equivalent to

1/4 (-1 + x)^2 + 1/36 (2 + y)^2 + 1/9 (-2 + z)^2 == 1

This describes an ellipsoid. Using Expand on the second one give us the first one easily. But is there any way to go the other direction in Mathematica?

• FullSimplify gives 9 (-2 + x) x + y (4 + y) + 4 (-4 + z) z == 7 which is even more compact and DivideSides[FullSimplify[...]] gives 1/7 (9 (-2 + x) x + y (4 + y) + 4 (-4 + z) z) == 1 Sep 10, 2020 at 16:19

You could use ReplaceRepeatedand completing squares:

29/36 - x/2 + x^2/4 + y/9 + y^2/36 - (4 z)/9 + z^2/9 == 1 //.
a_ *s_^2 + b_ *s_ + rest__ :> a (s + b/(2 a))^2 - b^2/(4 a) + rest
(*1/4 (-1 + x)^2 + 1/36 (2 + y)^2 + 1/9 (-2 + z)^2 == 1*)

Apart from FullSimplify in my comment, you can also use SolveAlways to get the constants that make the two forms match:

eqn = 29/36 - x/2 + x^2/4 + y/9 + y^2/36 - (4 z)/9 + z^2/9 == 1;
otherform = a (b + x)^2 + c (d + y)^2 + e (f + z)^2 == 1;
sol = SolveAlways[First[eqn] == First[otherform], {x, y, z}]

(* {{a -> 1/4, c -> 1/36, e -> 1/9, f -> -2, d -> 2, b -> -1}} *)

otherform /. First[sol]

(* 1/4 (-1 + x)^2 + 1/36 (2 + y)^2 + 1/9 (-2 + z)^2 == 1 *)