MathGroup Archive 2001

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

Search the Archive

Stuck in a For Loop

  • To: mathgroup at smc.vnet.net
  • Subject: [mg30948] Stuck in a For Loop
  • From: Moranresearch at aol.com
  • Date: Fri, 28 Sep 2001 03:54:56 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

I am trying to iterate from c0 -.1 to c0+.1 in steps of 0.001 and from K=-2 
to k= 2 insteps of 0.01

The code below hangs up. Any suggestions appreciated. Thank you. 

de = {0.221`, 0.45225`, 0.6602777777777777`, 0.8903611111111112`, 
      1.0920277777777778`, 1.3204166666666668`, 1.5235833333333335`, 
      1.7480833333333334`};
ce = {6.1280277777777785`, 6.129388888888888`, 6.129833333333334`, 
      6.130222222222223`, 6.1306111111111115`, 6.130916666666667`, 
      6.131055555555555`, 6.130972222222223`};
c0 = ce[[1]];
MAXERR = 100000; K = 10;
minErr = MAXERR;
bestK = STARTK;
numConvergence = 0;
For[c0 = c0 - 0.1, c0 <= c0 + 0.1, c0 += 0.001, 
    For[K = -2.0, K <= 2.0, K += 0.01, sum = 0.0; num = 0;
        c02 = c0*c0;
        For[j = 0, j < 7, j++, 
          If[(c0 > 0), r = de[j]; c = ce[j]; 
            sum += Abs[(Sqrt(c02 - K*r*r) - c)]; num++;]];
        If[(num <= 0), Continue];
        err = sum/num;
        If[(err < minErr), bestc0 = c0; bestK = K; minErr = err; 
          numConvergence++;];];];
If[(numConvergence == 1), STARTK, bestK]



  • Prev by Date: Re: checking for a particular value in a matrix
  • Next by Date: Re: checking for a particular value in a matrix
  • Previous by thread: Re: Re: Factorising operators??
  • Next by thread: Strange syntax errors when writing functions ?