Precision (decimal digits) are very low and digits(32) does not help.
Show older comments
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 Comment
MalteMan
on 13 Jan 2021
Accepted Answer
More Answers (2)
James Tursa
on 13 Jan 2021
Edited: James Tursa
on 13 Jan 2021
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 Comments
MalteMan
on 13 Jan 2021
James Tursa
on 13 Jan 2021
Edited: James Tursa
on 13 Jan 2021
What doesn't work for you? I just showed you code that displays the full digits and should agree pretty well with your calculator etc. If you have an m4m5 that is symbolic then you can do this:
m4m5 = double(m4m5)
E.g.,
>> syms m4m5
>> Breguet1 = 1852*1500 == (230.1330/(1.466*10^-4))*(18.4)*log(m4m5);
>> solvem4m5 = vpasolve(Breguet1, m4m5);
>> m4m5 = solvem4m5(1,1)
m4m5 =
1.100953492221007152713645627688375978171968089947806639541560572250312809929508272188194937733533164
>> m4m5 = double(m4m5)
m4m5 =
1.1010
>> format longG
>> m4m5
m4m5 =
1.10095349222101
James Tursa
on 13 Jan 2021
Edited: James Tursa
on 13 Jan 2021
What version of MATLAB are you using?
And setting the digits prior to your symbolic stuff doesn't help? E.g.,
digits 50
syms m4m5
:
etc.
MalteMan
on 13 Jan 2021
MalteMan
on 13 Jan 2021
John D'Errico
on 13 Jan 2021
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.
Categories
Find more on Number Theory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!