express a ( x2-x1) condition in a while loop how?

2 ビュー (過去 30 日間)
Victor Seaw
Victor Seaw 2015 年 5 月 9 日
回答済み: Walter Roberson 2015 年 5 月 9 日
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?

採用された回答

Walter Roberson
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 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by