MathGroup Archive 2000

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

Search the Archive

Re: Unusual speedup of Table


on 10/11/00 3:50 AM, SATether at satether at aol.com wrote:

> Timing[Table[Switch[j, _, a[[j + 1]] - 2 a[[j]] + a[[j - 1]]], {j, 2, n -
> 1}];]


I think the problem is you are thinking procedurally and you have an example
of two procedures where one is more efficient than another.  An even faster
way is to let Mathematica figure it out with something like

Take[ Append[Append[a, 0], 0] - 2Append[Prepend[a, 0], 0] +
        Prepend[Prepend[a, 0], 0], -n];

which appears to be more than twice as quick (my timing runs) as your fast
alternative.  The reason is I am using canned functions and they don't have
to interpret Mathematica code in some looping construct to do the job.

I'm sure my way won't be the fastest -- there are some smart programmers who
read this list.  I suspect the winner will use something like listconvolve


Regards,

Richard Palmer



  • Prev by Date: Re: integral of Bessel function, bug in Mathematica 4.0
  • Next by Date: Re: Unusual speedup of Table
  • Previous by thread: Re: Unusual speedup of Table
  • Next by thread: Re: Unusual speedup of Table