what is wrong with this code

clc; clear variables;
x(1)=0;
tic
for i=1:500
x(i+1)=(x(i).^2)*0.5+4;
if abs((x(i+1)-x(i)))<=0.00000001
break
else
x(i)=x(i+1);
end
end
toc

 Respuesta aceptada

Hiro Yoshino
Hiro Yoshino el 16 de En. de 2020

0 votos

if abs((x(i+1)-x(i)))<=0.00000001
This condition is less likely to be met ... I think.

1 comentario

DEV
DEV el 16 de En. de 2020
thank you
I applied
max(abs(x(i+1)-x(i)))<=0.000001
Now it is working

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

DEV
el 16 de En. de 2020

Comentada:

DEV
el 16 de En. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by