# Convert an expression from one form to another

I have this expression

-0.433284-0.758719 x+0.00289158 x^2-0.443672 y+0.00149027 y^2

I want to express it in terms of $$\frac{(x-h)^2}{b^2}+\frac{(y-k)^2}{a^2}$$. Using Solve gave me a big mess:

Solve[-0.433284-0.758719 xP+0.00289158 xP^2-0.443672 yP+0.00149027 yP^2==(xP-h)^2/b^2+(yP-k)^2/a^2,{a,b,h,k}]

What can I do to get it in the form I wanted?

There are two problems. One is that you want SolveAlways to find values for the parameters for which the expressions are equivalent. The second is that, as stated, it's not possible because the system is overdetermined. You'll want to allow for a constant term in your second expression.

expr1 = -0.433284 - 0.758719 x + 0.00289158 x^2 - 0.443672 y +
0.00149027 y^2;
expr2 = (x - h)^2/b^2 + (y - k)^2/a^2 - c;

Now we find the parameter sets that work.

solns = SolveAlways[expr1 == expr2, {x, y}];
viable = Select[solns,
FreeQ[{a, b, c, h, k} /. #, a | b | c | h | k] &];

(* Out[337]= {-83.2248525772 + 0.00289158 (-131.194537243 + x)^2 +
0.00149027 (-148.856247526 + y)^2, -83.2248525772 +
0.00289158 (-131.194537243 + x)^2 +
0.00149027 (-148.856247526 + y)^2, -83.2248525772 +
0.00289158 (-131.194537243 + x)^2 +
0.00149027 (-148.856247526 + y)^2, -83.2248525772 +
0.00289158 (-131.194537243 + x)^2 +
0.00149027 (-148.856247526 + y)^2} *)

This particular problem can dealt with algebraically by completing squares, equating coefficients and subtracting constants. (I am making the assumptions this is a left hand side whose right hand side is 0).

pol = -0.433284 - 0.758719 x + 0.00289158 x^2 - 0.443672 y +
0.00149027 y^2;
cr = CoefficientRules[pol, {x, y}]
{p, q, r, s, t} = cr[[All, 2]];
{h, k} = 0.5 {-q/p, -s/r}
cons = p h^2 + r k^2

This yields for {h,k}:=

{131.195, 148.856}

The rearranged polynomial:

trp[x_, y_] := p (x - h)^2 + r (y - k)^2 - cons + t

and note:

Expand[trp[x, y]] == pol

yields True.

If the aim is to get to $\frac{(x-h)^2}{a^2}+\frac{(y-k)^2}{b^2}=1$

{a, b} = Sqrt[
1/Coefficient[(trp[x + h, y + k] + cons - t)/(cons - t), {x^2,
y^2}]]

This yields:

{169.652, 236.316}

The boolean is hampered by numericals but to show the rearrangement is equivalent:

stf[x_, y_] := (x - h)^2/a^2 + (y - k)^2/b^2 - 1

Putting it all together:

StringForm[
"\!$$\*FractionBox[SuperscriptBox[\((x - 1)$$, $$2$$], \
SuperscriptBox[$$2$$, \
$$2$$]]\)+\!$$\*FractionBox[SuperscriptBox[\((y - 3)$$, $$2$$], \
SuperscriptBox[$$4$$, $$2$$]]\)=1", h, a, k, b]]

Visualizing: