Borrar filtros
Borrar filtros

round off in matlab

1 visualización (últimos 30 días)
dav
dav el 5 de Abr. de 2013
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 comentario
Roger Stafford
Roger Stafford el 6 de Abr. de 2013
Editada: Roger Stafford el 6 de Abr. de 2013
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.

Iniciar sesión para comentar.

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 5 de Abr. de 2013
  2 comentarios
dav
dav el 5 de Abr. de 2013
Editada: dav el 5 de Abr. de 2013
thanks
should you put a ";" after this command?
And is there a way to specify the number of decimal places?
Azzi Abdelmalek
Azzi Abdelmalek el 5 de Abr. de 2013
a=0.1234567891011
sprintf('%.10f',a)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Oil, Gas & Petrochemical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by