MathGroup Archive 2004

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

Search the Archive

Re: Please, can someone explain this small function?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg50718] Re: [mg50703] Please, can someone explain this small function?
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Sat, 18 Sep 2004 05:48:05 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

>-----Original Message-----
>From: Cole Turner [mailto:REMOVEcole.turner at liwest.at]
To: mathgroup at smc.vnet.net
>Sent: Friday, September 17, 2004 7:17 AM
>To: mathgroup at smc.vnet.net
>Subject: [mg50718] [mg50703] Please, can someone explain this small function?
>
>
>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)
>
>

Cole, 

did you try?

In[1]:= mon[a_,{b_}]:=a*x^(b-1)

In[2]:= MapIndexed[mon,{1,1,-2,-2,1,1}]

Out[2]= {1, x, -2*x^2, -2*x^3, x^4, x^5}


In[4]:= MapIndexed[f, {a,b,c}]
Out[4]= {f[a, {1}], f[b, {2}], f[c, {3}]}


--
Hartmut


  • Prev by Date: Re: more than 1 function with Plot3D
  • Next by Date: Re: Plot Question
  • Previous by thread: Re: Please, can someone explain this small function?
  • Next by thread: Re: Please, can someone explain this small function?