Values Stored in Matrix not showing all decimals

30 visualizaciones (últimos 30 días)
SamuLibero
SamuLibero el 27 de Abr. de 2022
Comentada: SamuLibero el 28 de Abr. de 2022
Hi Everyone,
I'm having truble working with matrices, I'm doing a calculation which gives me results with a lot of d decimal places.
I want to store all the results in a matrix. Everything is working except that the values are somehow rounded up when stored in the matrix.
How do I change this?
Here is the example, it may be helpfull.
%DATA INPUT
format long;
syms D d C1 w Re C2 mnorm;
D = 0.11;
d = 0.04192;
C1 = 1;
rho = 997.8;
dpw = 99000;
mu = 9.972E-4;
C = [];
beta = d / D;
Ad = d^2*pi/4;
AD = D^2*pi/4;
mnorm = C1/sqrt(1-beta^4)*Ad*sqrt(2*dpw*rho);
w = mnorm/(AD*rho);
Re = (rho * w * D)/(mu);
C2 = 0.99 - 0.2262*beta^4.1-(0.00175*beta^2-0.0033*beta^4.15)*(10^6/Re)^1.15;
for i = 1:4
i;
mnorm1 = double(subs(mnorm,C1,C2));
w1 = double(subs(w,mnorm,mnorm1));
Re1 = double(subs(Re,w,w1));
C3 = double(subs(C2,Re,Re1));
B = [mnorm1, w1, Re1, C3];
C(i,:) = B;
end
Thanks a lot!
  2 comentarios
Jan
Jan el 27 de Abr. de 2022
Which matrix do you mean? C? Of course the values are rounded by the double() command. The format of doubles contains about 16 digits.
What does "with a lot of decimals" mean? Of course the calculations produce results with an infinite number of decimals. It is clear, that they cannot be displayed, because this would require infinite resources.
SamuLibero
SamuLibero el 28 de Abr. de 2022
You are completely right, my question was not really exaustive.
The matrix I am talking about ist the C matrix indeed.
Nevermind I just got to the problem. When I visualize the matrix C numbers are rounded up, but by clicking on the single cell, or printing C in command window i get all the decimals I need.
Thank you Jan

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 28 de Abr. de 2022
There are a few different possible meanings here.
If you are using the Variable Browser, then the display format for each item is controlled by the "Number Display Format" control in the View tab of the Variable Browser. There is a preference that controls the default format to use.
If you are using disp() then the display format for each item is controlled by the current "format" command. There is a preference (different from the one above) that controls what the default is for MATLAB sessions.
None of formats supported for the above two cases show all of the decimal places for double precision values. None of them show enough significant digits to be able to unambiguously distinguish between a number and its nearest representable neighbour.
In order to be able to see enough significant digits to be able to unambiguously tell a number from its nearest represetnable neighbour, use fprintf() with a %.16e format (I would have to research whether there are cases where %.17e is needed.) If you want to see the full decimal places, try %.999g .
Note: on MS Windows, historically digits after about the 15th were just arbitrarily 0. If you are using Windows, I recommend you get the File Exchange contribution num2strexact()
Note: on Linux, historically more digits were available, but there was still a limit before 0 would arbitrarily appear.
Note: on MacOS, at least as far back as I have tested, all digits of double precision have been available.
  1 comentario
SamuLibero
SamuLibero el 28 de Abr. de 2022
Thank you very much for your time! I solved both problems; changed the number display format and used fprintf to print.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by