sympref('FloatingPointOutput',false)

%was the solution! Must have changed it sometime

67 views (last 30 days)

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

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

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.

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

Start Hunting!
## 1 Comment

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/716098-precision-decimal-digits-are-very-low-and-digits-32-does-not-help#comment_1261893

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/716098-precision-decimal-digits-are-very-low-and-digits-32-does-not-help#comment_1261893

Sign in to comment.