# Tag Info

## Hot answers tagged precision

44

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}]]

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 ...

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]= ...

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

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

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

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 ...

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 ... 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 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 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 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, ϵ = ...

6

[Not exactly an answer but possibly of interest and definitely too large for the margins..] Another way to do this is to reverse the order of summation. That is to say, there is an implicit sum over integer digits with an outer sum over integers. One could, in a sense, sum over the integers in the inner loop, and over digits in the outer. Well, sort of. ...

5

Mathematica produces this Message during evaluation of Abs[1/4 (-1 - Sqrt[5]) + 1/4 (1 + Sqrt[5])]. It seemingly tries to calculate approximate value of this expression using N although the user does not ask for this. Note that Simplify[Unevaluated@Abs[1/4 (-1 - Sqrt[5]) + 1/4 (1 + Sqrt[5])]] produces no error messages and gives correct result (0). ...

5

Try using Record and one of the options of ReadList data = ReadList["filename", Table[Record, {7}], RecordSeparators -> {"\t", "\n"}] Then use ToExpression to convert the elements (since they have Head String) to Reals. ToExpression[data] Or combine both into one line data = ToExpression @ ReadList["filename", Table[Record, {7}], ...

5

I think your problem arises because the value of $MinPrecision is not distributed correctly (If I remember correctly none of the variables in the System context are distributed automatically). So we have to do this by hand ParallelEvaluate[$MinPrecision = 40] Parallelize[{dGenBessE[1/10, 0], dGenBessE[1/10, 1]}] // AbsoluteTiming Should now work without ...

5

Can do as follows. First generate the matrix of machine numbers. size = 100; min = 10*^7; max = 10*^8; ltm = Table[ If[j <= i, RandomReal[{min, max}], 0], {i, size}, {j, size}]; matrix = ltm.Transpose[ltm]; Now set the precision, invert, check the product. use the higher prec matrices throughout. mat2 = SetPrecision[matrix, 30]; inv2 = ...

5

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 ...

5

The problem lies with your 15.5 which has a small precision. Mathematica won't try to add digits beyond machine precision for this. Mathematica by default only displays 6 digits of precision unless otherwise specified. To view all the digits, wrap the output in InputForm. To specify your precision, try this: N[f1[15.515],15] Or even this: ...

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