How to display all values of an iteration?

16 visualizaciones (últimos 30 días)
Mary Fasulo
Mary Fasulo el 30 de En. de 2020
Comentada: Mary Fasulo el 30 de En. de 2020
hi so this is my code, currently it only displays the root and the number of bisections, but I need it to also display the value of each iteration, I'm not sure how to do this. Any help would be much appreciated!Capture.JPG
  1 comentario
KSSV
KSSV el 30 de En. de 2020
Editada: KSSV el 30 de En. de 2020
Attach your code..not an image snippet. Tell us what value you want to store?

Iniciar sesión para comentar.

Respuesta aceptada

Ridwan Alam
Ridwan Alam el 30 de En. de 2020
Editada: Ridwan Alam el 30 de En. de 2020
for i = 1:100
xc = (x1 + x2)/2;
if f(x1)*f(xc)<0
x2 = xc;
else
x1 = xc;
end
disp(['x1 = ',num2str(x1),',' ' x2 = ',num2str(x2)])
if abs(f(x1))<1e-6
break
end
end
you can also use fprintf() instead of disp().
hope this helps.
  1 comentario
Mary Fasulo
Mary Fasulo el 30 de En. de 2020
This works, thank you very much for your help!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by