       • To: mathgroup at smc.vnet.net
• Subject: [mg76817] Re: Quadratic form: symbolic transformation
• From: Peter Pein <petsie at dordos.net>
• Date: Mon, 28 May 2007 00:53:59 -0400 (EDT)
• References: <f3bj37\$40i\$1@smc.vnet.net>

```Dr. Wolfgang Hintze schrieb:
> 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?
>
...

>
> Thanks in advance for any hints.
> Regards,
> Wolfgang
>
>

Hello Wolfgang,

there are (as usual) different ways to do this.

I guess there is a typo in the definition of q1?

In:=
q1 = r*x^2 + s*x + t;
q2 = u*(x + v)^2 + w;
eqns = LogicalExpand[q1 - q2 + O[x]^3 == 0]

Out=
r - u == 0 && s - 2*u*v == 0 && t - u*v^2 - w == 0

In:=
sol1 = Solve[eqns, {u, v, w}, x]
Out=
{{w -> (-s^2 + 4*r*t)/(4*r), u -> r, v -> s/(2*r)}}

In:= (* Test: *)
Simplify[q1 == q2 /. sol1[]]
Out=
True

SolveAlways[q1 == q2, x] solves for all x, but the output is:
{{r -> u, s -> 2*u*v, t -> u*v^2 + w}}. To get the solution for {u,v,w},
convert the rules to equations and do a simple Solve afterwards.

In:=
sol2 = Solve[Apply[Equal, First[SolveAlways[q1 == q2, x]], {1}], {u, v, w}]
Out=
{{w -> (-s^2 + 4*r*t)/(4*r), u -> r, v -> s/(2*r)}}

In:=
sol1 === sol2
Out=
True

To get a case differentiation (r==0,r!=0) automagically, use Reduce:

In:=
redu = Reduce[ForAll[x, q1 == q2], {u, v, w}, Reals, Backsubstitution -> True]
Out=
(s < 0 && r < 0 && u == r && v == s/(2*r) && w == (-s^2 + 4*r*t)/(4*r)) ||
(s < 0 && r > 0 && u == r && v == s/(2*r) && w == (-s^2 + 4*r*t)/(4*r)) ||
(s == 0 && r < 0 && u == r && v == 0 && w == t) ||
(s == 0 && r == 0 && u == 0 && w == t) ||
(s == 0 && r > 0 && u == r && v == 0 && w == t) ||
(s > 0 && r < 0 && u == r && v == s/(2*r) && w == (-s^2 + 4*r*t)/(4*r)) ||
(s > 0 && r > 0 && u == r && v == s/(2*r) && w == (-s^2 + 4*r*t)/(4*r))

Hope that helps,
Peter

```

• Prev by Date: More on Style Sheets in Version 6.0
• Next by Date: Re: Mathematica 6.0 easier for me ... (small review)