Re: Quadratic form: symbolic transformation
- 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[1]:=
q1 = r*x^2 + s*x + t;
q2 = u*(x + v)^2 + w;
eqns = LogicalExpand[q1 - q2 + O[x]^3 == 0]
Out[3]=
r - u == 0 && s - 2*u*v == 0 && t - u*v^2 - w == 0
In[4]:=
sol1 = Solve[eqns, {u, v, w}, x]
Out[4]=
{{w -> (-s^2 + 4*r*t)/(4*r), u -> r, v -> s/(2*r)}}
In[5]:= (* Test: *)
Simplify[q1 == q2 /. sol1[[1]]]
Out[5]=
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[6]:=
sol2 = Solve[Apply[Equal, First[SolveAlways[q1 == q2, x]], {1}], {u, v, w}]
Out[6]=
{{w -> (-s^2 + 4*r*t)/(4*r), u -> r, v -> s/(2*r)}}
In[7]:=
sol1 === sol2
Out[7]=
True
To get a case differentiation (r==0,r!=0) automagically, use Reduce:
In[8]:=
redu = Reduce[ForAll[x, q1 == q2], {u, v, w}, Reals, Backsubstitution -> True]
Out[8]=
(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