How to display all values of an iteration?

16 次查看(过去 30 天)
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 个评论
KSSV
KSSV 2020-1-30
编辑:KSSV 2020-1-30
Attach your code..not an image snippet. Tell us what value you want to store?

请先登录,再进行评论。

采纳的回答

Ridwan Alam
Ridwan Alam 2020-1-30
编辑:Ridwan Alam 2020-1-30
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by