MathGroup Archive 2010

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

Search the Archive

Re: Matrix Form of Quadratic Equations

  • To: mathgroup at smc.vnet.net
  • Subject: [mg114243] Re: Matrix Form of Quadratic Equations
  • From: Simon <simonjtyler at gmail.com>
  • Date: Sun, 28 Nov 2010 06:54:57 -0500 (EST)
  • References: <ico2b2$nq6$1@smc.vnet.net>

On Nov 26, 6:32 pm, Ari <ari... at finly.net> wrote:
> Hello,
>
> Could anyone guide me how to build a mathematica module to form a Matrix =
form from a quadratic equations?
> For example, x^2 + y^2 - 2 x y will output
> {{1, -1}, {-1, 1}} ?
>
> Thanks

Hi there,

I was sure that you would be inundated with answers... but none
arrived.
So here's my quick answer.

Define quad:

In[1]:= quad = a x^2+b x y+c y^2;

Then either calculate the Hessian (http://mathworld.wolfram.com/
Hessian.html)

In[2]:= 1/2D[quad,{{x,y},2}]
        {x,y}.%.{x,y}==quad//Expand
Out[2]= {{a,b/2},{b/2,c}}
Out[3]= True

Or extract the coefficients using CoefficientList[]

In[4]:= CoefficientList[quad,{x,y}]
         Extract[%,1+{{2,0},{1,1},{0,2}}]
         {x^2,x y, y^2}.%==quad
Out[4]= {{0,0,c},{0,b,0},{a,0,0}}
Out[5]= {a,b,c}
Out[6]= True

In terms of how to "build a mathematica module to form a Matrix form
from a quadratic equations", it's probably good to use a general
approach like

Hessian[f_, x_List?VectorQ] := D[f, {x, 2}]
Hessian[f_, x_List?VectorQ, x0_List?VectorQ] /;
  Length[x] === Length[x0] := Hessian[f, x] /. Thread[x -> x0]
Hessian[f_, x_List?VectorQ, x0_?NumericQ] :=
 Hessian[f, x] /. Thread[x -> x0]

Simon


  • Prev by Date: Re: How do I take every 3rd number from a text file?
  • Next by Date: Creating rounded blobs in Mathematica 8
  • Previous by thread: Re: Matrix Form of Quadratic Equations
  • Next by thread: Re: Matrix Form of Quadratic Equations