Values Stored in Matrix not showing all decimals

33 次查看(过去 30 天)
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 个评论
Jan
Jan 2022-4-27
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 2022-4-28
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

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2022-4-28
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 个评论
SamuLibero
SamuLibero 2022-4-28
Thank you very much for your time! I solved both problems; changed the number display format and used fprintf to print.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by