Re: Compiling numerical iterations

• To: mathgroup at smc.vnet.net
• Subject: [mg129937] Re: Compiling numerical iterations
• From: Ray Koopman <koopman at sfu.ca>
• Date: Wed, 27 Feb 2013 03:05:37 -0500 (EST)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• Delivered-to: l-mathgroup@wolfram.com
• Delivered-to: mathgroup-newout@smc.vnet.net
• Delivered-to: mathgroup-newsend@smc.vnet.net
• References: <kgab2i\$c7f\$1@smc.vnet.net> <kghjis\$s3p\$1@smc.vnet.net>

```On Feb 25, 10:09 pm, firlefranz <cornelius.fr... at gmx.net> wrote:
> Thanks a lot! To be honest, some of the commands Ray is using, I've never seen before. I stopped using mathematica before version 5 came out.
>
> Coming back to Peters statement of exporting the code from Mathematica to C. How this can be done starting from my or Ray's code? There is an automated C-code-gernerator implemented in Mathematica 9, am I right?
>
> As a step forward to the first little peace of code, here is another try, which is not really optimized. The be concrete, I try to simulate the autocorrelation function of a random walk, which is doing a step at none equally distant time steps. This has to been done for a long random walk for many particles. Instead of doing an average over many random walks and calculate one autocorrelation function I want to simulate many correlation functions and make an average over them. Since the time steps are non equal, I wrote a sub-function, which creates a new time axis and taking the necessary value for the random walk from the first table.
>
> Here is what I come up with. It's running in a reasonable time for one particle, but for a real statistic ensemble, I have to do it over 1.000.000 particles for a long time. Optimizing this or (probably better) exporting it to C would hopefully help a lot. So how to export it?
>
> << code omitted >>

Before spending more time on your real problem, you might want to
work at understanding why the code I posted for your example problem
necessarily gives the same corr as your code does, and then why the
following, which is faster, is also correct, even tho its corr can
not be compared to the other two because it generates the random
walks differently.

num = 10^3;
AbsoluteTiming@Length[ tab = FoldList[Plus,0,
RandomInteger[BinomialDistribution[1000,1/2],num-1]-500] ]
AbsoluteTiming@Length[ corr = #.#[[1]]& @
Most@Partition[tab,num*9/10,1]/(num*10*9/4) ]

{0.010728, 1000}
{0.010363, 100}

There are other ways to speed things up even more,
but that will suffice for now.

```

• Prev by Date: Re: Real and Imaginary Parts of complex functions
• Next by Date: Re: Real and Imaginary Parts of complex functions
• Previous by thread: Re: Compiling numerical iterations
• Next by thread: Re: Compiling numerical iterations