How to display all values of an iteration?

15 ビュー (過去 30 日間)
Mary Fasulo
Mary Fasulo 2020 年 1 月 30 日
コメント済み: Mary Fasulo 2020 年 1 月 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.
  1 件のコメント
Mary Fasulo
Mary Fasulo 2020 年 1 月 30 日
This works, thank you very much for your help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by