I need help with using a while loop
Show older comments
My problem I think is quite simple. But I just cannot get my brain around it.
I'm trying to use a while loop to iterate my code until m = 1.000e-5. But when I execute the code what I get is an infinite loop.
Here is the code:
c1 = 0.1;
v1 = 0.1;
v2 = 1;
p = 0;
m = 0;
while m ~= 1.000e-5
c1 = c1*v1/v2
m = c1*0.1
p = p+1
end
Accepted Answer
More Answers (1)
David Hill
on 19 Apr 2021
c1 = 0.1;
v1 = 0.1;
v2 = 1;
p = 0;
m = 1;
while m > 1.000e-5%floating point errors, use >
c1 = c1*v1/v2
m = c1*0.1
p = p+1
end
1 Comment
Ikmal Rosli
on 19 Apr 2021
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!