Why is my while loop stopping after one loop?
1 view (last 30 days)
Show older comments
I'm trying to find the root of a polynomial that's closest to my guess. My guess is supposed to keep running through the loop until it is within 6 decimals of accuracy of the actual root. But it stops after 1 loop. Please help!!
Here's part of my script:
dpolyvec=polyder(polyvec);
x=guess;
actual=roots(polyvec);
count=0;
notDone=1;
while notDone
if dpolyvec==0
notDone=0
end
x=x-(polyval(polyvec,x)./polyval(dpolyvec,x));
if x<(actual-10^(-6))
notDone=0;
end
if x<(actual+10^(-6))
notDone=0;
end
count=count+1;
if count>500
notDone=0;
end
end
0 Comments
Accepted Answer
Image Analyst
on 22 Feb 2014
Try this: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/ and you'll see that evidently you're stepping into one of the blocks that sets notDone = 0.
0 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!