53 votes
Accepted

Why does Mathematica results differ from C++ results within machine precision?

Something important to keep in mind is that Mathematica parses x / y as Times[x, Power[y, -1]] For actual floating point ...
ilian's user avatar
  • 25.5k
40 votes

Is manual adjustment of AccuracyGoal and PrecisionGoal useless?

Introduction The first section below can be found in standard numerical analysis textbooks. Most current textbooks seem to assume a working environment such as MATLAB or a programming language such C,...
Michael E2's user avatar
  • 236k
26 votes
Accepted

Why am I getting that $0.999999999999988 \geq 1.0$ is True?

You can lower the value of Internal`$EqualTolerance: Block[{Internal`$EqualTolerance = 0}, 0.999999999999988 >= 1.0 ] <...
Greg Hurst's user avatar
  • 35.9k
22 votes
Accepted

What explains the inaccuracies in machine-precision 'integers' with trigonometry or powers?

The result given by python is completely wrong, as are the results given by Mathematica for machine numbers. To get a correct result, you need to use extended precision numbers: ...
Carl Woll's user avatar
  • 131k
19 votes

How to deal with loss of significance in the case $f(x) = \sqrt{x+2} -\sqrt{x}$?

Your expression can be written in a more numerically stable form: Sqrt[x + 2] - Sqrt[x] == 2/(Sqrt[x + 2] + Sqrt[x]) // FullSimplify (* True *) This evaluates ...
mikado's user avatar
  • 16.7k
18 votes
Accepted

Why is Mathematica destroying this graph?

There are several important things about the way computer systems represent real numbers, which most of the time can be blithely ignored, just like the safety of bridges in the United States. One ...
Michael E2's user avatar
  • 236k
17 votes
Accepted

Why does 1 - Exp[-10.0^12] cause an out-of-memory error?

Actually this is not a duplicate. The prior question is about underflows that require massive bignums to represent at machine precision, and that much is present here as well. So what @J.M notes is ...
Daniel Lichtblau's user avatar
16 votes

Why does Mathematica results differ from C++ results within machine precision?

Without code and your actual results, this question cannot be answered. Here is one thing that might help: We have a compiler that can compile to C it can show you the code it creates. So why don't ...
halirutan's user avatar
  • 113k
15 votes
Accepted

Can Mathematica provide a reliable estimate of the numerical error from NDSolve?

We can adapt the MonitorMethod: ...
Michael E2's user avatar
  • 236k
14 votes

Funny behaviour when plotting a polynomial of high degree and large coefficients

Surprisingly enough, converting the polynomial to the Bernstein basis yields a result that Plot[] can stably deal with: ...
J. M.'s missing motivation's user avatar
14 votes
Accepted

Really understanding precision

Here are my thoughts: Q1 Machine numbers: For machine numbers, what you describe is correct. I would just add that you can use InputForm or FullForm to see all the digits if desired: ...
Carl Woll's user avatar
  • 131k
14 votes

How to display very small numbers in Mathematica?

Can also use exact numbers. f[x_] = Cos[x] - E^(-27 x/10); f[17 10^-26]//N[#,50]& (*4.5899999999999999999999988020950000000000000000002*10^-25*) Another ...
Bill Watts's user avatar
  • 8,217
14 votes

Where is the numerical solving breaking down?

Some experimentation shows that the NDSolve problem is associated exclusively with z with no feedback to ...
bbgodfrey's user avatar
  • 61.4k
13 votes
Accepted

How to calculate accurate answer in Mathematica?

Numerics in Mathematica can be as precise as you like. However, precision comes at price; you pay for it in computation time and in additional coding effort. In Mathematica there are several ...
m_goldberg's user avatar
  • 108k
13 votes

Keep Round-Off errors for educational purpose

You can do 5.291`4/0.003`4 (* 1764. *) Precision[%] (* 3.69897 *) But as you noted, the precision of the result is lower than 4 due to precision tracking. ...
Szabolcs's user avatar
  • 235k
12 votes
Accepted

How are Accuracy and Precision related Mathematica for a given operation?

Precision is the principal representation of numerical error Except for numbers that are equal to zero, error in arbitrary-precision numbers is stored internally as its precision. For numbers equal ...
Michael E2's user avatar
  • 236k
12 votes
Accepted

How does Mathematica determine when to use scientific notation?

Mathematica uses 2 criteria to determine whether to show a number in scientific notation or not. For both arbitrary precision and machine precision numbers, use scientific notation if the exponent is ...
Carl Woll's user avatar
  • 131k
12 votes
Accepted

How to deal with loss of significance in the case $f(x) = \sqrt{x+2} -\sqrt{x}$?

By using arbitrary precision numbers instead of machine numbers: x = 3.2`100 10^30; Sqrt[x + 2] - Sqrt[x] 5....
Henrik Schumacher's user avatar
12 votes
Accepted

How to force Mathematica to do infinite-precision calculations?

Mathematica will perform exact arithmetic only so long as all quantities are expressed as exact numbers. 90.12 is an inexact number with machine precision (i.e. ...
WReach's user avatar
  • 68.9k
11 votes
Accepted

Improve Accuracy of FindRoot

This has remained unanswered for a while, perhaps because the main fixes are hinted at in the comments and because it takes so long for FindRoot to finish. I can ...
Michael E2's user avatar
  • 236k
11 votes

Machine-Precision and Arbitrary Precision

This is not an answer. But I don't believe we should close this question as "easily found in the documentation". Numerics in Mathematica is an extremely complicated and mostly undocumented subject, ...
11 votes
Accepted

How to round half down in Mathematica?

ClearAll[roundDown] roundDown = Ceiling[# - 1/2] &; (* thanks: @MichaelE2 *) roundDown @ {7.4999, 7.5, 7.51} (* or roundDown[{7.4999, 7.5, 7.51}] *) {7, 7, ...
kglr's user avatar
  • 395k
11 votes

How to display very small numbers in Mathematica?

First convert the expression to trigonometric form: y = Cos[x] - Exp[-2.7*x] // ExpToTrig Cos[x] - Cosh[2.7 x] + Sinh[2.7 x] ...
Vixillator's user avatar
11 votes
Accepted

Why is Mathematica's default precision only 16 digits?

To give a simple answer to the question in the title: There is dedicated hardware in your CPU for machine precision computations. In contrast, arbitrary precision computations have to be emulated in ...
Henrik Schumacher's user avatar
11 votes

Can Mathematica provide a reliable estimate of the numerical error from NDSolve?

I'll add more details when I have my copy of Wagon's "Mathematica in Action" again, but as I mentioned in a comment, one possible way to check your solution would be to "integrate backwards", with ...
J. M.'s missing motivation's user avatar
11 votes
Accepted

Computing separatrix orbit

The precision of Mathematica numbers can be defined automatically. In this case number 1/2 is exact, while 0.5 has machine precision. If we evaluate ...
Alex Trounev's user avatar
  • 44.5k
11 votes

Why am I getting that $0.999999999999988 \geq 1.0$ is True?

From the help. Equal (==): Approximate numbers with machine precision or higher are considered equal if they differ in at most their last seven binary digits (roughly their last two decimal digits). ...
Daniel Huber's user avatar
  • 51.6k
11 votes

NIntegrate fails to converge to desired accuracy

My usual answer for the numerical calculation of high-dimensional integrals is: try to do as many dimensions as possible analytically, and then use numerical integration for the remaining dimensions. ...
Roman's user avatar
  • 47.5k
11 votes
Accepted

IntegerPart - is this a known bug?

[H]ow do I fix it once and for all for the entire Notebook? I suppose it depends on how you want to treat results that contain round-off error. You cannot really get rid of the problem, only shift ...
Michael E2's user avatar
  • 236k
10 votes

Why do I get number with Precision larger than error estimate?

Consider any numerical integration method $I^*(f,a,b)$ that approximates the exact integral $I$ of a function $f$ over an interval $[a,b]$. It will be implemented by a computation represented by, say, ...
Michael E2's user avatar
  • 236k

Only top scored, non community-wiki answers of a minimum length are eligible