How to get more decimal places in my output?

2,250 ビュー (過去 30 日間)
PIYUSH CHOUDHARY
PIYUSH CHOUDHARY 2019 年 11 月 6 日
回答済み: ramdheeraj 2023 年 4 月 9 日
Screenshot (73).png
I am using the above line in my code, but the output neglects the second term inside the bracket (the term multiplied with 'elevation'). I want to include that too. How to do so?

採用された回答

Guillaume
Guillaume 2019 年 11 月 6 日
Nothing is ignored. Moreover, note that there is a difference between the actual value of a number and the way it is displayed.
You can use the format command to change the display of a numbers. It does not affect the actual value (which is always the full precision of a double) and therefore does not affect calculations.
>> p = pi;
>> format shortg
>> p
p =
3.1416
>> format longg
>> p
p =
3.14159265358979
>> format bank
>> p
p =
3.14
Note that despite the change of display format, the value of p never changes.
Also, 2e-5 is a much better notation than 2*(10^(-5))

その他の回答 (3 件)

John D'Errico
John D'Errico 2019 年 11 月 6 日
編集済み: John D'Errico 2019 年 11 月 6 日
In fact, it does NOT neglect that term. It is in there, just too small for you to see in only 4 decimal places.
help format
You need to learn how to change the display format in MATLAB. I often use
format long g
as a good choice.

Nimesha Niranji
Nimesha Niranji 2021 年 7 月 3 日
you can enter the function "format" like bellow.
>> x = pi;
>> format long
>> x
x =
3.141592653589793
>> format short
>> x
x =
3.1416
>> format bank
>> x
x =
3.14

ramdheeraj
ramdheeraj 2023 年 4 月 9 日
Try displaying more decimal places of the variable x using:
format long
x
You can switch back to the default display using:
format short
x

カテゴリ

Help Center および File ExchangeNumeric Types についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by