MathGroup Archive 1996

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

Search the Archive

Re: Help on Function

  • To: mathgroup at
  • Subject: [mg3858] Re: [mg3799] Help on Function
  • From: brucec (Bruce Carpenter)
  • Date: Sat, 4 May 1996 02:12:52 -0400
  • Sender: owner-wri-mathgroup at

>Hi people,
>Could you please help me? I4m trying to write a function (not procedure
>if possible) that works on a list such as {a1, a2, a3, a4, ...} and
>returns a list {a2/a1, a3/a2, a4/a3, ...}. I know it should be an easy
>task but I4m a newbe...
>Thanks a lot

Hi Roberto,

Here are a couple of ways to do it:

myfunction1[vec_?VectorQ] := Partition[vec,2,1] /.{a_,b_}->b/a
mylist = {a1,a2,a3,a4,a5,a6};

{a2/a1, a3/a2, a4/a3, a5/a4, a6/a5}

myfunction2[vec_?VectorQ] := Rest[mylist]/Drop[mylist,-1]

{a2/a1, a3/a2, a4/a3, a5/a4, a6/a5}

myfunction1 has the virtue of handling the empty list more gracefully,
while myfunction2 is faster.

Bruce Carpenter

Bruce Carpenter
Courseware Coordinator         phone: (217) 398-0700
Wolfram Research, Inc.           fax: (217) 398-0747
100 Trade Centre Drive         email: brucec at
Champaign, IL  61820             web:


  • Prev by Date: Tick marks and labels
  • Next by Date: Re: Function
  • Previous by thread: Re: Help on Function
  • Next by thread: Re: Help on Function