# Tag Info

48

Control the Precision and Accuracy of Numerical Results This is an excellent question. Of course everyone could claim highest accuracy for her product. To deal with this situation there exist benchmarks to test for accuracy. One such benchmark is from NIST. This specific benchmark deals with the accuracy of statistical software for instance. The NIST ...

19

What is wrong: a) you're using exact arithmetic. b) You keep iterating even if the point seems to be escaping. Try this ClearAll@prodOrb; prodOrb[c_, maxIters_: 100, escapeRadius_: 1] := NestWhileList[#^2 + c &, 0., Abs[#] < escapeRadius &, 1, maxIters ] prodOrb[0. + 10. I] prodOrb[0. + .1 I] (if you don't need the entire list but ...

15

Just a bit of fun with @acl's code: ArrayPlot[Table[ NestWhile[#^2 - (0. - 1 I) & , r + i I, Abs[#] < 2.0 &, 1, 10], {r, -2, 2, 0.005}, {i, -2, 2, 0.005}]]

13

N does not round numbers or truncate them. The internal forms of N[Pi, 1] // FullForm N[Pi, 2] // FullForm are respectively (* 3.14159265358979323846264338327950288421. 3.14159265358979323846264338327950288422. *) Note that the numerical values are identical although the precisions differ. Their difference is zero and all significant digits ...

12

This is how you manually invoke "LevinRule" when you know part of the integrand is a rapidly oscillatory function satisfying a linear ODE: First, a rapidly oscillatory function: In[25]:= osc = y /. NDSolve[{y''[x] - (x^2 - 3 x) y'[x] + 10000 y[x] == 0, y[0] == 3, y'[0] == 1}, y, {x, 0, 5}] // First Out[25]= ...

12

The documentation states: N does not raise the precision of approximate numbers in its input 163.0 (or 163., or 163) is a machine precision number, and Mathematica will not fake a higher precision when a certain number of digits are requested with N. See this answer and this tutorial for more. These questions may also be of interest: Converting to ...

9

Mathematica does not, by default, act like most calculators that will spew out digits in a result whether or not they are "valid" or "real" digits. In most modes of usage, Mathematica keeps track of the precision of inputs, intermediate calculations, etc. and attempts to return results where the digits are correct, accurate, and "justified", that is, given ...

9

A nice trick to force Mathematica to use a given precision is to use Block and make $MinPrecision equal to$MaxPrecision. So you can write your result1 as: Block[{$MinPrecision = 10,$MaxPrecision = 10}, FixedPointList[N[1/2 Sqrt[10 - #^3] &, 10], 1.510]] {1.500000000, 1.286953768, 1.402540804, 1.345458374, 1.375170253, 1.360094193, ...

8

The problem is that the precision of a and b are set by the form of their input. a = 1234567891234567889998.5; b = 1234567891234567889999.5; Precision[a] 22.0915 And 0.5 by default has MachinePrecision, these days typically Log10[2^53] or just under 16 digits. Precision[0.5] MachinePrecision Neither setting the precision of 0.5 to 200 or ...

8

With a compiled version you get it so fast, that you can manipulate it in real time. fc = Compile[{{in, _Complex, 0}, {c, _Complex, 0}}, Module[{iter = 0, max = 10, z = in}, While[iter++ < max, If[Abs[z = z^2 + c] > 2.0, Break[] ] ]; {Abs[z], iter} ], CompilationTarget -> "C", Parallelization -> True, ...

8

According to Precision, the precision of a number x with absolute uncertainty dx is p -> -Log10[dx / x]. Conversely the uncertainty is given by dx -> x * 10^-p. For a calculation f[x, y, ...], the precision is estimated by Dt[f[x, y, ...] / f[x, y, ...], where Dt[x] represents the uncertainty of x and so on for any other variables. I'll show that ...

8

In V10 there has been added some symbolic processing of integrands containing an InterpolatingFunction. In particular if the interpolation grid divides the domain of integration into a number of subintervals, the number being at most the value of the option "MaxSubregions", the integrand will automatically be integrated over each subinterval. In V9, this is ...

8

I'll mimic the precision/accuracy handling for FindRoot as indicated in its documentation: The default settings for AccuracyGoal and PrecisionGoal are WorkingPrecision/2. The setting for AccuracyGoal specifies the number of digits of accuracy to seek in both the value of the position of the root, and the value of the function at the root. The ...

7

NumberForm can be used to control the number of decimal places. Plot[0, {x, 8.5, 9.3}, PlotRange -> {{7.9, 11}, {0, 0}}, Axes -> {True, False}, Ticks -> {({#, NumberForm[N@#, {Infinity, 1}]} & /@ Range[0, 11, 1/5]), {}}, PlotStyle -> {Red, Thickness[0.02]}]

7

This question probably will not receive a "real" answer because it is based on a misconception about what $MachineEpsilon actually is. But, since the question is upvoted, I suppose there is more than one person who is not yet clear on how this is defined. Therefore, here is a comment to try to clarify the definition and tie up the loose ends of the thread. ... 7 Mathematica arrives at the particular precision that it does using significance arithmetic and associated propagation of precision. This answer describes how to double check that. Oleksandr's answer makes a good case for the assertion that significance arithmetic is insufficient for this problem as it fails to account for the correlation in error between ... 7 Update: I think this is a numeric precision problem rather than a matter of the behavior of Re. I don't know if I should leave my original answer below for reference or remove it. Consider: expr = MathieuC[MathieuCharacteristicA[-(19999999999/10000000000), -2], -2, 5]; N[expr] N[expr, 15] SetPrecision[expr, 15] -9.85323*10^-16 + 3.39211*10^-8 I ... 7 If you wish to compute the correct values using the method you have chosen you could specify Method -> "Procedural" for Sum: CumDigitSum[x_, b_] := Sum[DigitSum[n, b], {n, 1, x}, Method -> "Procedural"] CumDigitSum[1000001, 10] 27000003 However, the problem comes form the fact that Sum attempts to speed the calculation by finding a symbolic ... 7 You can disable error tracking as below (effectively working in fixed precision). range = N[Range[0, 2 Pi - 0.0000001, 2 Pi/8192],20]; FFT[f_, wf_, range_] := Mean[Exp[I*(f - 1)*range]*(wf /@ range)]; Block[{$MinPrecision = 20, $MaxPrecision = 20}, FFT[#, wf, range] & /@ {257, 513} ] (* Out[360]= {-5.7615176179584663593*10^-40 + ... 7$MachinePrecision is different from MachinePrecision. The former calls for an arbitrary precision calcluation, done at the same precision as the machine-precision one. The main reason one would want to use this is to enable precision tracking, which is absent for a true machine-precision calculation using MachinePrecision. And, there is your answer. ...

6

You are going to get clobbered by an ugly blend of cancellation and roundoff error here. Those fixed points are on the order of epsilon away from one. If you work at machine precision then at epsilon around 10^(-8) you can expect: 8 digits at the front lost to cancellation Some number lost at the back to roundoff error. With default settings of NIntegrate ...

6

One might consider using the simple-minded strategy of splitting the known oscillatory part over its roots (or extrema), evaluating the integral over the intervals determined by the roots, and summing all those integrals to arrive at the actual integral you need. Now, finding the roots of an oscillatory function that is only known through its differential ...

6

As @acl mentioned in chat, your question really indicates that you should read some fundamental sources. Two that I'd recommend are: A First Course in Chaotic Dynamical Systems by Bob Devaney for a good overview of the mathematical theory. Mathematica in Action by Stan Wagon, specifically Chapter 11, for a more condensed overview but with specific ...

6

To make the result of NSum more precise you can use also the NSumTerms option (15 by default, see e.g. Numerical Evaluation of Sums and Products) appropriately increased. Let's try e.g. : a1 = NSum[ HarmonicNumber[2 m]/m^3, {m, 1, Infinity}, WorkingPrecision -> 140, PrecisionGoal -> 70, NSumTerms -> 2000] ...

6

This question feels familiar but I could not find a true duplicate. You can use the string replacement that Oleksandr proposed here and then use ToExpression to convert the numbers: string = "-5.100686209408900133332e+02 -1.294005398404007344443e+01 \ -2.59376479781563728887e-02 -1.3043629998334040122222e+02" ToExpression /@ ...

6

I'll go over the examples in your comment, and urge you to re-read the content & documentation links in the referenced answer. Bottom line, Mathematica tries to not give answers with false precision (digits that appear significant, but are not), and in general it "tracks" the precision of inputs, intermediate results, calculations, etc. to ensure this. ...

6

This is not an answer, but more of a comment to help motivate the question. Apparently the phrasing of the question, as it currently is, is not convincing for many people. However, this is not really related to Quantity. Perhaps it can be an "answer" in the sense that it provides an alternative to relying on the built-in methods. Definitions The values ...

6

You can see the very same effect already without Quantity: a = 1.07 (* ==> 1.000000 *) b = 1.014 (* ==> 1.0000000000000 *) a/Sqrt[a]-Sqrt[a]+b (* 1.000000 *) You might argue that there should be more precision here because a cancels out completely. But the point is that as soon as a is evaluated, all Mathematica has is a value of 1.07, and ...

6

Answering my own question from a while ago. Turns out the easiest method is using MMA’s built-in Computer Arithmetic package << ComputerArithmetic (*Set Math Parameters*) SetArithmetic[6, 10, ExponentRange -> {-20, 20}]; fpConvert[x_, integerbits_, fractionbits_] := ComputerNumber[IntegerPart[x] + Round[FractionalPart[x], 2^-fractionbits]]; ...

6

I think your problems are made by order of appling Re and N. Re@Bloch is not yet a state before the computation. So you have to apply the computation by Re@Norder. Block[{$MaxExtraPrecision = 500, ϵ = 10^-10}, Re@N@BlochΚ[-2 + ϵ, -1, -10]] Block[{$MaxExtraPrecision = 1000, ϵ = 10^-20}, Re@N@BlochΚ[-2 + ϵ, -1, -10]] Block[{\$MaxExtraPrecision = 500, ϵ = ...

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