express a ( x2-x1) condition in a while loop how?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Victor Seaw
el 9 de Mayo de 2015
Respondida: Walter Roberson
el 9 de Mayo de 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 comentarios
Respuesta aceptada
Walter Roberson
el 9 de Mayo de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!