Re: For loop problem in mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg90197] Re: [mg90163] For loop problem in mathematica
- From: "W_Craig Carter" <ccarter at mit.edu>
- Date: Wed, 2 Jul 2008 05:28:59 -0400 (EDT)
- References: <200807011059.GAA14895@smc.vnet.net>
Hello PhysNova, There are a couple reasons why your computation is not behaving well for timing. 1) You can use one of Mathematica's list constructs to eliminate the For loop 2) You are computing an exact representation that you evaluate to a number. To see this, compare: Timing[Sqrt[6 Total[Table[1/i^2, {i, 1, 1000}]]]] and Timing[Sqrt[6 Total[Table[1/i^2, {i, 1., 1000.}]]]] Timing[Sqrt[6 Total[Table[1/i^2, {i, 1., 10^8}]]]] (*returns*) {23.1435, 3.14159} on my laptop WCC On Tue, Jul 1, 2008 at 6:59 AM, PhysNova <skhoshbinfar at gmail.com> wrote: > > > x=0;For[i = 1, i < 10,000,000, i++, x = x + 1/(i^2)];N[Sqrt(6*x),25]// > Timing > > the result was catastrophe! it take few minuates. but i first expect > to do this very simple job in few > >
- References:
- For loop problem in mathematica
- From: PhysNova <skhoshbinfar@gmail.com>
- For loop problem in mathematica