Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2013

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

Search the Archive

Re: Compiling numerical iterations

  • To: mathgroup at smc.vnet.net
  • Subject: [mg129900] Re: Compiling numerical iterations
  • From: Peter Klamser <klamser at googlemail.com>
  • Date: Sat, 23 Feb 2013 23:32:40 -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: <20130223120106.68F4E68EC@smc.vnet.net>

Compiling functions with Complie[{...},...] was once ago (I think
version 5 or earlier) interesting for simple problems. Complex
algorithmen was always useless to compile.

For versions ealier then 5 it was a nice approach to write small c
programs for small modules:

http://onlinelibrary.wiley.com/doi/10.1002/piuz.19970280618/abstract

Today it only interesting exporting your results to c so it can be
integrated into a softwar, that runs outside a Mathematica workplace.

Kind regards from

Peter

2013/2/23 firlefranz <cornelius.franz at gmx.net>:
> Hi,
>
> to speed up some calculations I'd like to use this relatively new method of compiling equations or export them to C. But since I'm very new in these things, I have really problems to use this c-compiling function.
> Can someone show me on this simple part of code (calculation of a correlation function of a 1D random walk), how it should be implemented?
>
> num = 1000;
> tab = Table[0, {i, 1, num}];
> corr = Table[0, {i, 1, num/10}];
> For[l = 1, l <= 1000, l++,
>  a = 0;
>  For[i = 1, i <= num, i++,
>   tab[[i]] = tab[[i]] + a/10;
>   If[RandomReal[{-1, 1}] < 0, a = a + 1, a = a - 1];
>   ]
>  ]
> For[k = 1, k <= num/10, k++,
>  For[n = 1, n <= num/10*9, n++,
>    corr[[k]] = corr[[k]] + tab[[n]]*tab[[n + k - 1]]/num*10/9];
>  ]
> ListPlot[{corr}, Joined -> False]
>
> Best regards
> Cornelius
>



  • Prev by Date: A nonconventional ListContourPlot
  • Next by Date: Re: Mathematica and Lisp
  • Previous by thread: Compiling numerical iterations
  • Next by thread: Re: Compiling numerical iterations