Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

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

Search the Archive

Re: how decrease computation time?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg18643] Re: how decrease computation time?
  • From: Paul Abbott <paul at physics.uwa.edu.au>
  • Date: Thu, 15 Jul 1999 01:45:39 -0400
  • Organization: University of Western Australia
  • References: <37610ED6.C47372B7@diamant.ensg.u-nancy.fr> <7m1850$5i0$6@dragonfly.wolfram.com>
  • Sender: owner-wri-mathgroup at wolfram.com

Arnold.Blaisonneau wrote:

> Hi, I' m a new user of Mathematica and I try to translate C program in
> Mathematica language;
> When I do a calculation with Mathematica it takes too many time
> compared with C program (6.4 second versus 0.1second);
> Please excuse me for the lentgh of my message but I really don't know
> what to do for increase the speed;
> (Note that separately each function doesn't take many)
> If any one could help me....
> Thanks

Consider just the first function:

> \!\(\(BessIn[z1_, z2_, n_] :=
>       Module[{i},
>         i = n; \n\t\tz2[0] =
>           Re[BesselI[i, z1[0]\ Exp[I\ z1[1]]]]; \n\t\tz2[1] =
>           Im[BesselI[i, z1[0]\ Exp[I\ z1[1]]]];];\)\n\t\t\n

I see that you have done a very direct translation of the C code. Before
you can call this routine you have to assign (array) values to z1[0] and
z1[1] and you are then writing the output to a second array. Writing
things this way is poor Mathematica style and is likely to slow things
down.

Here is a more Mathematica-like way of writing this function:

BessIn[{z11_, z12_}, n_] := 
  With[{w = BesselI[n, z11*Exp[I*z12]]}, {Re[w], Im[w]}]

If you pass BessIn a list of two values and the parameter n it will
return a list consisting of the real and imaginary parts.  

There are many other things which could be done to speed up your code
and, as others have pointed out, unless you take advantage of
Mathematica's symbolic capabilities, you should expect direct numerical
computation of C-like Mathematica code to be much slower than C.

Cheers,
	Paul

____________________________________________________________________ 
Paul Abbott                                   Phone: +61-8-9380-2734
Department of Physics                           Fax: +61-8-9380-1014
The University of Western Australia           
Nedlands WA  6907                     mailto:paul at physics.uwa.edu.au 
AUSTRALIA                            http://physics.uwa.edu.au/~paul

            God IS a weakly left-handed dice player
____________________________________________________________________


  • Prev by Date: Re: "At long last, Sir, have you no shame?"
  • Next by Date: Re: Need a means to get arguments of a function
  • Previous by thread: Re: how decrease computation time?
  • Next by thread: trouble with printing