Re: Help on Function
- To: mathgroup at smc.vnet.net
- Subject: [mg3849] Re: Help on Function
- From: ianc (Ian Collier)
- Date: Mon, 29 Apr 1996 00:33:34 -0400
- Organization: Wolfram Research, Inc.
- Sender: owner-wri-mathgroup at wolfram.com
In article <4lesps$e4m at dragonfly.wolfram.com>, Roberto Diego
<roberto at medusa.es> wrote:
> 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
You can use Partition (with an offset of 1 specified as the third argument)
to divide your list up and then Map a suitable function across the list of
pairs.
The following should do what you want:
In[16]:=
ls = {a1, a2, a3, a4, a5, a6}
Out[16]=
{a1, a2, a3, a4, a5, a6}
In[17]:=
f[ list_ ] := Map[ #[[2]]/#[[1]] &, Partition[ list, 2, 1 ]]
In[18]:=
f[ls]
Out[18]=
a2 a3 a4 a5 a6
{--, --, --, --, --}
a1 a2 a3 a4 a5
I hope this helps.
--Ian
-----------------------------------------------------------
Ian Collier
Wolfram Research, Inc.
-----------------------------------------------------------
tel:(217) 398-0700 fax:(217) 398-0747 ianc at wolfram.com
Wolfram Research Home Page: http://www.wolfram.com/
-----------------------------------------------------------
==== [MESSAGE SEPARATOR] ====