MathGroup Archive 2007

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

Search the Archive

check inside a loop?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg80736] check inside a loop?
  • From: "Jeremy Price" <cfgauss at u.washington.edu>
  • Date: Thu, 30 Aug 2007 23:41:07 -0400 (EDT)
  • Organization: University of Washington

I have a large loop that is ndsolving/nintegrating a bunch of things, and a 
lot of the results give me various errors due to the equations not being 
very nice.  I'd like to have a way to check what values of my paramaters are 
causing the errors, but I can't find a way to do that inside a loop.

For example, if I have something like,
f[x_] = 1/Sin[2 pi x]

For[ i=1, i < 1000, i++,
f[i]
]

I'm going to get a lot of "Power::infy: Infinite expression 1/0 
encountered." errors.  I'd like to see what values of i these occur at.

I've tried something like

For[ i=1, i<1000, i++,
Check[ f[i] , i]
]

But this just returns "Power::infy: Infinite expression 1/0 encountered." 
errors without the i vaule, which is different than I get by evaluating 
something like
Check[ f[0],0]
Which returns:
Power::infy: Infinite expression 1/0 encountered.
0

Is there any way I can get it to return the index that the error occured at 
for every error that occurs inside of the loop? 



  • Prev by Date: Re: Re: Questions on AstronomicalData
  • Next by Date: Re: Special characters in the axis label?
  • Previous by thread: Rotated Text with Full AspectRatio and ImageSize
  • Next by thread: Rule-based programming: declare variables to be a number