express a ( x2-x1) condition in a while loop how?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2015-5-9
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!