MathGroup Archive 1996

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

Search the Archive

Re: Constant term in polynomial?

  • Subject: [mg3349] Re: [mg3326] Constant term in polynomial?
  • From: ptk at imada.ou.dk (Peder Thusgaard Ruhoff)
  • Date: 29 Feb 1996 12:36:55 -0600
  • Approved: usenet@wri.com
  • Distribution: local
  • Newsgroups: wri.mathgroup
  • Organization: Wolfram Research, Inc.
  • Sender: daemon at wri.com

On Mon, 26 Feb 1996, Ronald Bruck <bruck at mtha.usc.edu> wrote:
> 
> Arrgh, I feel stupid asking this question, but I can't think how to do it:
> how do I find the constant term in a polynomial in several variables in
> Mathematica?  For example, the "7" in 7 + 3 x y + y^2 ?
> 
> I suppose one way would be to use
> 
>    Coefficient[Coefficient[7 + 3 x y + y^2,x,0],y,0].
> 
> But that's incredibly clunky, especially since I may have fifty or more
> variables in my real-life problem.
>
  ... many lines deleted ... 
> 
> --Ron Bruck
> 
> 
> 
> 

Dear Ron,

One way to solve your problem is to define a function PolynomialConstant
in the following way (based on an idea in Bahder, Mathematica for 
Scientists and Engineers, page 345)

===========================================================================

In[1]:= PolynomialConstant[expr_, vars_List] /; PolynomialQ[expr, vars] :=
            Fold[Coefficient[#1, #2, 0]&, expr, vars]

In[2]:= PolynomialConstant[expr_, var_] /; PolynomialQ[expr, var] :=
            Coefficient[expr, var, 0]

===========================================================================


Some examples

===========================================================================

In[3]:= PolynomialConstant[7 + 3 x y + y^2, {x, y}]

Out[3]= 7

In[4]:= PolynomialConstant[(x + y + 1)^10, {x, y}]

Out[4]= 1

In[5]:= PolynomialConstant[(x + y + 1)^10, x]

                       2        3        4        5        6        7
Out[5]= 1 + 10 y + 45 y  + 120 y  + 210 y  + 252 y  + 210 y  + 120 y  + 
 
         8       9    10
>    45 y  + 10 y  + y

In[6]:= PolynomialConstant[x y z, {x, y, z}]

Out[6]= 0

In[7]:= PolynomialConstant[Sin[x]^3 + y + 5 z, {Sin[x], y}]

Out[7]= 5 z

===========================================================================

You can also try to solve your problem using the built-in function 
CoefficientList.


Hope this helps,

Peder

------------------------------------------------------------------------------
Peder Thusgaard Ruhoff                     Phone: (+45) 66 15 86 96, ext. 2411
Department of Information Technology       Fax:   (+45) 65 93 26 91
Odense University, Campusvej 55            Email: ptk at imada.ou.dk
DK-5230 Odense M, DENMARK

  "It is important for him who wants to discover not to confine himself
   to one chapter of science, but to keep in touch with various others."
                                                            - Jacques Hadamard
------------------------------------------------------------------------------



  • Prev by Date: Re: Constant term in polynomial?
  • Next by Date: Re: Mathematica on MacOS 7.52
  • Previous by thread: Re: Constant term in polynomial?
  • Next by thread: [Q] Erfi - what is it?