MathGroup Archive 1998

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

Search the Archive

Re: problem with Coefficient


  • To: mathgroup@smc.vnet.net
  • Subject: [mg12174] Re: problem with Coefficient
  • From: Alois Steindl <asteindl@mch2ws1.tuwien.ac.at>
  • Date: Fri, 1 May 1998 03:08:26 -0400
  • Organization: Inst. f. Mechanics II, TU Vienna
  • References: <199804240552.BAA13217@smc.vnet.net.> <6i0shr$8ks@smc.vnet.net>

Hello,
I obtained the following solution from Dave Withoff, Wolfram Research,
solving a similar problem here

In[1]:= coeff = {q1^3, q1^2*q2, p1*q1^2, p2*q1^2, q1*q2^2, p1*q1*q2,
           p2*q1*q2, p1^2*q1, p1*p2*q1, p2^2*q1, q2^3, p1*q2^2,
           p2*q2^2, p1^2*q2, p1*p2*q2, p2^2*q2, p1^3, p1^2*p2,
           p1*p2^2, p2^3};

In[2]:= Unprotect[Coefficient]

Out[2]= {Coefficient}

In[3]:= Coefficient[p_Plus, q_] := Plus @@ Cases[p, z_. q -> z] /;
                      Head[q] =!= Symbol

In[4]:= Coefficient[p_, q_] := Plus @@ Cases[{p}, z_. q -> z] /;
                             Head[q] =!= Symbol

In[5]:= Protect[Coefficient]

Out[5]= {Coefficient}

In[6]:= Table[Coefficient[coeff[[i]], coeff[[i]]], {i, Length[coeff]}]

Out[6]= {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}


Maybe it helps
Alois
Sean Ross <seanross@worldnet.att.net> writes:


> vonessen@selway.umt.edu wrote:
> > 
> > The Mathematica function Coefficient seemingly does not always work as
> > it should:
> > 
> > In[1]:=Coefficient[x^2 y^2,x^2 y^2]
> > Out[1]=1
> > In[2]:=Coefficient[x1^2 x2^2,x1^2 x2^2] Out[2]=0
> > 
> > The first computation is correct, the second not.  I made this
> > computation on several computers using Mathematica 3.0 under Windows
> > 95.
> 
> No help, but some other input to the discussion:
> 
> 						   returns
> Coefficient[x^2  y^2,x^2  y^2]     			1 Coefficient[x1^2  y1^2,x1^2 
> y1^2]			1 Coefficient[x1^2  y2^2,x1^2  y2^2]			1 Coefficient[x1^2 
> x2^2,x1^2  x2^2]			0 Coefficient[(x1)^2 (x2)^2,Evaluate[(x1)^2 
> (x2)^2]]	0 Coefficient[x2^2  x3^2,x2^2  x3^2]			0 Coefficient[fred2^2 
> fred3^2,fred2^2  fred3^2]		0 Coefficient[polly2^2  fred3^2,polly2^2 
> fred3^2]	0 Coefficient[p^2  f^2,p^2  f^2]				1
> Coefficient[Evaluate[x1^2  x2^2/.{x1->x,x2->y}],
>   Evaluate[x1^2  x2^2/.{x1->x,x2->y}]]			1
> 
> It seems like it cannot correctly handle similar symbols or long symbol
> names and works best with single letters and no numbers.  This is a
> strange limitation.  I wonder if this would pass technical supports
> definition of a bug?  If it is not a bug, but a "feature", I would be
> very interested to know the explanation.
> 

-- 

___________________________________________________________________________

Alois Steindl,                  Tel.: +43 (1) 58801 / 5529        Inst.
for Mechanics II,         Fax.: +43 (1) 5875863 Vienna University of
Technology,
A-1040 Wiedner Hauptstr. 8-10   Email: Alois.Steindl+E325@tuwien.ac.at
___________________________________________________________________________



  • Prev by Date: Re: Exporting (saving) data
  • Next by Date: Re: creating packages
  • Prev by thread: Re: Exporting (saving) data
  • Next by thread: Re: problem with Coefficient