express a ( x2-x1) condition in a while loop how?
2 views (last 30 days)
Show older comments
Victor Seaw
on 9 May 2015
Answered: Walter Roberson
on 9 May 2015
for my while loop how do i express my condition to be (x2-x1)<0.01?
x=3;
z=0;
while z<0.01
x=3;
n=x+1
i = randfunction(func,a,b,n)
x=x+2;
end
randfunction is my created function while a and b is my input as for lower and upper limit and n is my number of points between this limits how do i express in a way if my randfunction = 4 when n=3 and when n=4 my randfunction = 5, these two subtract and if their value isn't lesser than 0.01 the loop continue till their subtracted value get a value of <0.01?
0 Comments
Accepted Answer
Walter Roberson
on 9 May 2015
while true
x = 3;
n = x + 1;
i = randfunction(func,a,b,n);
x = x + 2;
if (n - i) < 0.01
break
end
end
I cannot tell whether you would want (n-i)<0.01 or (i-n)<0.01 as your ending condition. If you are trying to determine whether they are within 0.01 of each other, then
if abs(n-i) < 0.01
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!