MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Quadratic form: symbolic transformation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg76846] Re: Quadratic form: symbolic transformation
  • From: siewsk at bp.com
  • Date: Mon, 28 May 2007 01:09:07 -0400 (EDT)
  • References: <f3bj37$40i$1@smc.vnet.net>

On May 27, 7:30 pm, "Dr. Wolfgang Hintze" <w... at snafu.de> 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
> _'s) to answer this question.
>
> My (cumbersome) procedure compares coefficients and looks like this
>
> (* writing down lhs == rhs)
> In[112]:=
> q = R*x^2 + S*x + T == u*(x + v)^2 + w
> Out[112]=
> 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[113]:=
> eq1 = q /. {x -> 0}
> Out[113]=
> T == u*v^2 + w
> In[114]:=
> eq2 = D[q, x] /. {x -> 0}
> Out[114]=
> S == 2*u*v
> In[115]:=
> eq3 = D[q, {x, 2}] /. {x -> 0}
> Out[115]=
> 2*R == 2*u
> In[119]:=
> t = First[Solve[{eq1, eq2, eq3}, {u, v, w}]]
> Out[119]=
> {w -> (-S^2 + 4*R*T)/(4*R), u -> R, v -> S/(2*R)}
>
> (* writing down the result explicitly *)
> In[120]:=
> q /. t
> Out[120]=
> T + S*x + R*x^2 == (-S^2 + 4*R*T)/(4*R) + R*(S/(2*R) + x)^2
> In[122]:=
> Simplify[q /. t]
> Out[122]=
> True
>
> Thanks in advance for any hints.
> Regards,
> Wolfgang

See the steps below.

The idea is to match the coefficient of x^2 of equation 1 with
coefficient of x^2 of equation 2. The same for x^1 and x^0.

In[1]:=
eqn1 = R*x^2 + S*x + T

Out[1]=
T + S*x + R*x^2

In[2]:=
eqn2 = ExpandAll[u*(x + v)^2 + w]

Out[2]=
u*v^2 + w + 2*u*v*x + u*x^2

In[3]:=
CoefficientList[eqn1, x] == CoefficientList[eqn2, x]

Out[3]=
{T, S, R} == {u*v^2 + w, 2*u*v, u}

In[4]:=
eqn3 = Thread[CoefficientList[eqn1, x] ==
    CoefficientList[eqn2, x]]

Out[4]=
{T == u*v^2 + w, S == 2*u*v, R == u}

In[5]:=
Solve[eqn3, {u, v, w}]

Out[5]=
{{w -> (-S^2 + 4*R*T)/(4*R), u -> R, v -> S/(2*R)}}



  • Prev by Date: Re: Integrate bug
  • Next by Date: Re: Re: Manipulate (from Wolfram Demonstrations)
  • Previous by thread: Re: Quadratic form: symbolic transformation
  • Next by thread: Re: Quadratic form: symbolic transformation