Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

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

Search the Archive

Re: express a quadratic, in the form (x+a)^2 + b

  • To: mathgroup at smc.vnet.net
  • Subject: [mg84338] Re: [mg84313] express a quadratic, in the form (x+a)^2 + b
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Wed, 19 Dec 2007 23:56:28 -0500 (EST)
  • Reply-to: hanlonr at cox.net

f[quad_, var_: x] :=
 Module[{a, b},
  (var + a)^2 + b /.
   Solve[CoefficientList[#, var] & /@
      (quad == (var + a)^2 + b), {a, b}][[1]]]

f[x^2 + 4 x + 7]

(x + 2)^2 + 3

f[y^2 + 6 y + 7, y]

(y + 3)^2 - 2


Bob Hanlon

---- Joseph Fagan <noemailplease at nowhere.ru> wrote: 
> I'm a Mathematica beginner.
> I wish to express a quadratic, in the form (x+a)^2 + b
> eg to express x^2 + 4x + 7 as (x+2)^2 + 3
> Is there an easy way?
> Thanks
> Joe
> 
> 
> 



  • Prev by Date: Re: Re: pattern
  • Next by Date: Re: pattern
  • Previous by thread: Re: express a quadratic, in the form (x+a)^2 + b
  • Next by thread: Re: express a quadratic, in the form (x+a)^2 + b