ConstantCoefficient of polynomial
- Subject: [mg3368] ConstantCoefficient of polynomial
- From: wagner at bullwinkle.cs.Colorado.EDU (Dave Wagner)
- Date: 2 Mar 1996 14:43:53 -0600
- Approved: usenet@wri.com
- Distribution: local
- Newsgroups: wri.mathgroup
- Organization: University of Colorado, Boulder
- Sender: daemon at wri.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