Precision (decimal digits) are very low and digits(32) does not help.

1 次查看(过去 30 天)
Hi everyone,
I searched everywhere but cant find a solution. The problem seems so simple! I am using the code below. See that my numbers have many digits (are precise).
The following code returns m4m5 = 1.010 while I know from my calculator / wolframalpha that the solution is closer to 1.0095....
How can I achieve a higher level of precision?
  • Changing to solve instead of vpasolve did not help.
  • Changing line one to syms m4m5 'double' did not help.
I also have this problem when multiplying later: a is very precise and then for b I cannot see more digits (I need them.)
syms m4m5
Breguet1 = 1852*1500 == (230.1330/(1.466*10^-4))*(18.4)*log(m4m5);
solvem4m5 = vpasolve(Breguet1, m4m5);
m4m5 = solvem4m5(1,1)
a = 62826.3402201552
b = a * m4m5
  1 个评论
MalteMan
MalteMan 2021-1-13
My current code, which still does not reveal more digits:
clear
clc
format longG
digits 50
syms m4m5
Breguet1 = 1852*1500 == (230.1330/(1.466*10^-4))*(18.4)*log(m4m5);
solvem4m5 = vpasolve(Breguet1, m4m5);
m4m5 = solvem4m5(1,1)
a = sym(62826.3402201552)
b = a * m4m5
The result is:
m4m5 =
1.1010
a =
6.2826e+04
b =
6.9169e+04

请先登录,再进行评论。

采纳的回答

MalteMan
MalteMan 2021-1-14
sympref('FloatingPointOutput',false)
%was the solution! Must have changed it sometime

更多回答(2 个)

James Tursa
James Tursa 2021-1-13
编辑:James Tursa 2021-1-13
This is likely just a display issue and you don't need the Symbolic Toolbox. MATLAB does regular calculations in full double precision, but only displays four digits beyond the decimal point using the default format, so what you see displayed is a rounded version of the actual number stored. Try this
format longG
and then run your code as a regular expression and examine the result again.
E.g.,
>> m4m5 = exp(1852*1500/((230.1330/(1.466*10^-4))*(18.4)))
m4m5 =
1.1010 <-- The rounded version of the number for display purposes only
>> format longG
>> m4m5
m4m5 =
1.10095349222101 <-- the longer decimal version of the actual number stored
  7 个评论
MalteMan
MalteMan 2021-1-13
I am using
R2020b Update 3 (9.9.0.1538559)
64-bit (maci64)
Nov 23, 2020
on Mac OS Catalina
MalteMan
MalteMan 2021-1-13
编辑:MalteMan 2021-1-13
I added my "latest" code as a direct comment to my question above, still does not help!
This is so strange. Thanks so much for your time and suggestions already...

请先登录,再进行评论。


John D'Errico
John D'Errico 2021-1-13
Of course, asking for 32 or more digits of precision is a bit on the side of the ridiculous, when the numbers going into the computation are themselves only accurate to 4 significant digits. Even worse, numbers like this:
230.1330
are not exactly the numbers you want them to be when converted to symbolic form.
vpa(sym(230.1330),32)
ans =
230.13300000000000977706804405898
vpa(sym(1.466*10^-4),32)
ans =
0.00014660000000000001263607274371026
That is, each of these numbers are stored as a double precision number, then converted into symbolic form. And that ratio is FIRST computed as a double precision number.
So you don't have exactly the numbers you think you have. Then asking for more digits is asking MATLAB to generate what are virtually garbage results.

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by