"Or" is written || instead of &&.
J
On Wed, Feb 27, 2008 at 2:54 AM, Keith Schnakenberg <
keith.schnakenberg at gmail.com> wrote:
Thanks for the quick replies. R and I are still
learning how to
communicate to each other, and we appreciate the counseling.
After looking at the worksheet, I got rid of "&& i < iter.max" in
the
while loops and did it the way you had it in the example with the if
statements. Everything seems to be in order now.
I left "tol" in the copy and paste on accident, but pretend those are
zeros instead of "tol."
So for future reference, when I put "x(((x+y)/2)) != 0 && i <
iter.max,"
did it want to run it until *both *of those conditions were met? I was
going for an "or" rather than an "and," so maybe that was my issue.
On Feb 26, 2008, at 11:39 PM, Jenn Larson wrote:
Hi Keith,
First glance suggests that one place you should look is in the argument to
while(). You're saying the while loop should continue so long as two
conditons are met: that the midpoint of your function fx is not equal to the
tolerance level you specified in the call to your function, and that i is
less than the maximum number of iterations you presumably also specified
elsewhere.
Usually tolerance is the maximum difference between the output of
subsequent iterations you will tolerate to be content with a solution. That
is, if your first six iterations produce a sequence like .25, 1, .75, .79,
.80, .80, ..., and if you set a tolerance of .01, you're saying that in this
case you'll be content with the first five draws: .79 and .80 are
sufficiently similar that something around .80 will be your solution.
Hence, the point is not to run the algorithm until the midpoint of your
function *equals* the tolerance level. The point is to run the algorithm
until two subsequent estimates of a function's zero are within the tolerance
level of eachother.
Finally, check to be sure 'i' is defined: if all this takes place in a
forloop iterating through different values of something you call 'i',
you're
fine. But the while loops do not automatically label each iteration 'i'.
Hope this helps,
Jenn
On Wed, Feb 27, 2008 at 2:05 AM, Keith Schnakenberg <
keith.schnakenberg at gmail.com> 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
_______________________________________________
gov2001-l mailing list
gov2001-l at
lists.fas.harvard.edu
http://lists.fas.harvard.edu/mailman/listinfo/gov2001-l
_______________________________________________
gov2001-l mailing list
gov2001-l at
lists.fas.harvard.edu
http://lists.fas.harvard.edu/mailman/listinfo/gov2001-l