How to change the number of digits that matlab displays using fprintf

28 ビュー (過去 30 日間)
Elin Howells
Elin Howells 2018 年 11 月 5 日
コメント済み: madhan ravi 2018 年 11 月 5 日
For my code I'm required to have an absolute error below 1*10^-6 when I get MATLAB to display the error it's so small that it just shows up as 0.000000. I want to make it display more numbers after the decimal point but I don't know where exactly I need to be typing the commands. Any help would be appreciated :)
i
root=(w_left+w_right)/2;
absoluteerror=(w_right-w_left)/2;
fprintf('The estimated root is %f \n',root)
fprintf('The absolute error is %f \n',absoluteerror)
if absoluteerror > (1*(10^-6))
disp ("Absolute Error is too large! Try increasing number of bisections to be used")
else
disp ("Absolute Error is sufficiantly small")
end

採用された回答

madhan ravi
madhan ravi 2018 年 11 月 5 日
編集済み: madhan ravi 2018 年 11 月 5 日
fprintf('%.16e',pi)
values = sprintf('%.16e %.2g %f %.2f', pi*50*ones(1,4))
  3 件のコメント
Elin Howells
Elin Howells 2018 年 11 月 5 日
Brilliant thank you
madhan ravi
madhan ravi 2018 年 11 月 5 日
Anytime :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by