Values Stored in Matrix not showing all decimals
30 次查看(过去 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
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.
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!