MathGroup Archive 2011

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

Search the Archive

Re: Style Question: The Functional Way

  • To: mathgroup at smc.vnet.net
  • Subject: [mg115806] Re: Style Question: The Functional Way
  • From: Just A Stranger <forpeopleidontknow at gmail.com>
  • Date: Fri, 21 Jan 2011 04:32:03 -0500 (EST)

Of course that function would exist. Thank you for pointing that out. :)

On Thu, Jan 20, 2011 at 4:39 AM, Bob Hanlon <hanlonr at cox.net> wrote:

> DeltaList[L_] := Subtract @@@ Reverse /@ Partition[L, 2, 1]
>
> data = Array[x, 10];
>
> The simplest way is to just use Differences or ListCorrelate.
>
> DeltaList[data] ==
>  Differences[data] ==
>  ListCorrelate[{-1, 1}, data] ==
>  Most[RotateLeft[data] - data] ==
>  ({-1, 1}.# & /@ Partition[data, 2, 1])
>
> True
>
>
> Bob Hanlon
>
> ---- Just A Stranger <forpeopleidontknow at gmail.com> wrote:
>
> =============
> Hello,
>
> So I'm trying to learn how to do things the functional way. As an exercise
> I'm trying to program a simple economics related table that gives revenue,
> marginal revenue, etc given a demand schedule (2 lists of numbers
> representing quantity and price respectively). A simple task in a
> spreadsheet.
>
> The point is that I need a list of the differences in the given lists, from
> which I will be using to get marginal values (derivatives). I'll call it,
> say, DeltaList, and I was wondering if this would be a proper "functional"
> way to go about the task:
>
>
>
>
> In[0]: DeltaList[L_] := Subtract @@@ Reverse /@ Partition[L, 2, 1]
>
> (DelatList: list -> list)
>
>
> Basically, it partitions the list into ordered pairs, reverses those
> ordered
> pairs to prep them for the subsequent Subtract application.
>
> Is this the right way to think about this (painfully simple) problem in a
> functional way?
>
> Thank you. All of you have been most helpful in the past.
>
>
>


  • Prev by Date: Re: Simple n-tuple problem - with no simple solution
  • Next by Date: Re: SetOptions does not work with Grid
  • Previous by thread: Re: Style Question: The Functional Way
  • Next by thread: Re: DesignerUnits: Gallons divided by km yields an area.