       • To: mathgroup at smc.vnet.net
• Subject: [mg76808] Re: [mg76801] Quadratic form: symbolic transformation
• From: Carl Woll <carlw at wolfram.com>
• Date: Mon, 28 May 2007 00:49:11 -0400 (EDT)
• References: <200705270907.FAA03614@smc.vnet.net>

```Dr. Wolfgang Hintze wrote:

>Hello,
>
>this is a simple question but perhaps I can get here some information
>towards a more apropriate way of using Mathematica.
>
>I take a very simple example: I would like to write the quadratic form
>
>q1 = R*x^2 + R*x + T
>
>in the form
>
>q2 = u*(x+v)^2 + w
>
>How can I find u, v, and w from R, S, and T?
>
>I'm sure there must be some symbolic way (using a sufficient amount of
>
>My (cumbersome) procedure compares coefficients and looks like this
>
>(* writing down lhs == rhs)
>In:=
>q = R*x^2 + S*x + T == u*(x + v)^2 + w
>Out=
>T + S*x + R*x^2 == w + u*(v + x)^2
>
>(* as q must be an identiy in x, i.e. must hold for all x, I compare
>coefficients at x=0 *)
>In:=
>eq1 = q /. {x -> 0}
>Out=
>T == u*v^2 + w
>In:=
>eq2 = D[q, x] /. {x -> 0}
>Out=
>S == 2*u*v
>In:=
>eq3 = D[q, {x, 2}] /. {x -> 0}
>Out=
>2*R == 2*u
>In:=
>t = First[Solve[{eq1, eq2, eq3}, {u, v, w}]]
>Out=
>{w -> (-S^2 + 4*R*T)/(4*R), u -> R, v -> S/(2*R)}
>
>(* writing down the result explicitly *)
>In:=
>q /. t
>Out=
>T + S*x + R*x^2 == (-S^2 + 4*R*T)/(4*R) + R*(S/(2*R) + x)^2
>In:=
>Simplify[q /. t]
>Out=
>True
>
>Thanks in advance for any hints.
>Regards,
>Wolfgang
>
>
>
SolveAlways seems like it should do the trick, but I don't know how to
control which variables are solved for. Looking at the version 6 help
for this function, we discover the following possibilities to accomplish
what you want:

eqn = R x^2 + S x + T == u (x + v)^2 + w;

In:= Solve[! Eliminate[! eqn, x], {u, v, w}]
Out= {{w->(4 R T-S^2)/(4 R),u->R,v->S/(2 R)}}

In:= Solve[Resolve[ForAll[{x}, eqn]], {u, v, w}]
Out= {{w->(4 R T-S^2)/(4 R),u->R,v->S/(2 R)}}

In:= Reduce[ForAll[{x}, eqn], {u, v, w},  Backsubstitution -> True]
Out= (S == 0 && R == 0 && u == 0 && w == T) || (u == R && R != 0 &&
v == S/(2 R) && w == (4 R T - S^2)/(4 R))

Carl Woll
Wolfram Research

```

• Prev by Date: Re: Ellipse equation simplification on Mathematica:
• Next by Date: Re: Integrate bug