round off in matlab

Hi,
I am running a large simulation in matlab. I have noticed that matlab rounds off after 4 decimal places and this affects my results.
Is there a way to give a command at the beginning of the program so that matlab does the round off after about 10 decimal places?
Thanks.

댓글 수: 1

Roger Stafford
Roger Stafford 2013년 4월 6일
편집: Roger Stafford 2013년 4월 6일
Matlab's 'double' does not round off after four decimals as far as the actual computations are concerned. It is always accurate to about 16 significant decimal digits. It's only the display of its results that is given to four digits if you are using format short. It is important to understand the difference.
Try this experiment.
format short
x = pi^2
fprintf('x = %19.16f\n',x)
The second display is accurate to 16 places which means that this was the accuracy of the original computation. The 'short' format only displayed four of the significant digits.

댓글을 달려면 로그인하십시오.

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 4월 5일

1 개 추천

format long

댓글 수: 2

dav
dav 2013년 4월 5일
편집: dav 2013년 4월 5일
thanks
should you put a ";" after this command?
And is there a way to specify the number of decimal places?
a=0.1234567891011
sprintf('%.10f',a)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by