!= tests if it's not equal to 'tol'. It's very unlikely that
you'll
get exact equality, so better to use >. Otherwise you'll get an
infinite loop. I think (?) your second condition is only evaluated if
the first is false with the && operator. So your maximum iterations
condition is only tested in the unlikely event that fx outputs tol
exactly.
The section example of r code uses the break command to get out of
the loop on the max iteration.
Jeremy
On 27 Feb 2008, at 07:05, Keith Schnakenberg wrote:
I've implemented the method of bisection using
three embedded "while"
loops. My problem is that, when I call for the function, it runs
forever even though I have specified a maximum number of iterations.
It has been running long enough that I suspect it is going to run it
an infinite number of times.
Without revealing my code for the whole problem, I'll show enough
code demonstrate how I am telling it to stop after k iterations.
while(fx(((x+y)/2)) != tol && i < iter.max){
i = i+1
while(){
while(){
}
}
}
So, my first theory was that the other two loops were running
infinitely (or a lot of times) within each iteration of the first
while loop. However, I added "&& i < iter.max" to the end of the
other while loops and this did not help. Other theories?
_______________________________________________
gov2001-l mailing list
gov2001-l at
lists.fas.harvard.edu
http://lists.fas.harvard.edu/mailman/listinfo/gov2001-l
Dr Jeremy Hodgen
Senior Lecturer in Mathematics Education
King's College London
Department of Education and Professional Studies
Franklin-Wilkins Building
Waterloo Bridge Wing
150 Stamford Street
London SE1 9NH
Tel: 020 7848 3102
Fax: 020 7848 3182
E-mail: jeremy.hodgen at kcl.ac.uk