MathGroup Archive 1996

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

Search the Archive

ConstantCoefficient of polynomial

  • To: mathgroup at smc.vnet.net
  • Subject: [mg3368] ConstantCoefficient of polynomial
  • From: wagner at bullwinkle.cs.Colorado.EDU (Dave Wagner)
  • Date: Sat, 2 Mar 1996 04:13:27 -0500
  • Organization: University of Colorado, Boulder
  • Sender: owner-wri-mathgroup at wolfram.com

Whoops, a following to my previous post about finding the constant
coefficient of a polynomial.  I proposed:

In[1]:=
    ConstantCoefficient[poly_Plus] := Select[poly, NumberQ[N[#]]&]

In[3]:=
    ConstantCoefficient[E^2 + Pi + Sqrt[7]x + Sqrt[5]]
Out[3]=
	       2
    Sqrt[5] + E  + Pi

which works fine as long as there IS a constant coefficient.
If not, it does not evaluate (by design):

In[8]:=
    ConstantCoefficient[Sqrt[7]x]
Out[8]=
    ConstantCoefficient[Sqrt[7] x]

This is easily handled by specifying a "catch-all" case that returns 0:

In[9]:=
    ConstantCoefficient[_] := 0
In[10]:=
    ConstantCoefficient[Sqrt[7]x]
Out[10]=
    0

		Dave Wagner
		Principia Consulting
		(303) 786-8371
		dbwagner at princon.com
		http://www.princon.com/princon

==== [MESSAGE SEPARATOR] ====


  • Prev by Date: Re: Constant term in polynomial?
  • Next by Date: ConstantCoefficient of polynomial
  • Previous by thread: Re: Constant term in polynomial?
  • Next by thread: ConstantCoefficient of polynomial