MathGroup Archive 2004

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

Search the Archive

Please, can someone explain this small function?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg50715] Please, can someone explain this small function?
  • From: Cole Turner <REMOVEcole.turner at liwest.at>
  • Date: Sat, 18 Sep 2004 05:48:02 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

input: two polynomials as lists
output: the GCD

methinks, this is the Euclidean Algorithm, what I don't get is how the
"mon" is constructed here and what exactly the "MapIndexed" function
does here - the MATHEMATICA help wasn't too helpful!
thanks a lot in advance!!!!

Cole ***



In[1]:=
myGCD[p1_List,p2_List]:=
    Module[{mon,x,pol1,pol2,num},
      mon[a_,{b_}]:=a*x^(b-1);
      pol1=Factor[Plus@@MapIndexed[mon,p1]];
      pol2=Factor[Plus@@MapIndexed[mon,p2]];
      num=Numerator[pol1/pol2];
      CoefficientList[pol1/num,x]
      ];
In[2]:=
myGCD[{1,1,-2,-2,1,1},{-2,-3,1,3,1}]
Out[2]=
{-1,-1,1,1}


-- 
Johnny: [plugging back in the runway lights] 
          "Just kidding."
                   ('Airplane!', 1980)


  • Prev by Date: Re: How to simplify to a result that is real
  • Next by Date: Re: Outline view?
  • Previous by thread: Please, can someone explain this small function?
  • Next by thread: Re: Please, can someone explain this small function?