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

2 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Walter Roberson
Walter Roberson il 9 Mag 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

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by