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

조회 수: 1 (최근 30일)
MalteMan
MalteMan 2021년 1월 13일
답변: MalteMan 2021년 1월 14일
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