Sig figs on the rand function
3 ビュー (過去 30 日間)
古いコメントを表示
Just another general question here, is there a reason the rand function has 6 sig figs? i.e. 12.3456
Is there a way to change this so there are more or less post decimal? Or is this just how MATLAB handles this function, generally.
Thank you in advance!
0 件のコメント
採用された回答
Chunru
2024 年 3 月 20 日
==> Just another general question here, is there a reason the rand function has 6 sig figs? i.e. 12.3456
rand function (by defaut) has "double" type, which means it is represented internally by 64bits, precision of up to 15 digits.
MATLAB has a default display format, which is "short" and has 4 digits after decimal point (Note: this is only for display, internal computations are based on double).
==>Is there a way to change this so there are more or less post decimal? Or is this just how MATLAB handles this function, generally.
Use format long to display data with more digits after decimal point (doc format for more details)
a = rand(); % internally stored as double
a % default (4 digits after dp)
format long % (15 digits after dp)
a
3 件のコメント
Chunru
2024 年 3 月 20 日
% format long?
format long
grade=rand(1,49)*(100-20)+20; % could also do randi([20 100],1,49);
% format long?
grade_avg=mean(grade);
grade_avg
% Use fprintf for more control of the format
%fprintf('The average grade is %1.0f \n',grade_avg)
fprintf('The average grade is %0.10f \n',grade_avg) % 10 digits after dp
if grade_avg>=60
disp('passing average')
else
disp('failing average')
end
format default % revert to default
grade_avg
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!