How to display all values of an iteration?
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mary Fasulo
am 30 Jan. 2020
Kommentiert: Mary Fasulo
am 30 Jan. 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!
1 Kommentar
Akzeptierte Antwort
Ridwan Alam
am 30 Jan. 2020
Bearbeitet: Ridwan Alam
am 30 Jan. 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!