# Tag Info

## Hot answers tagged precision

42

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

15

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

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

11

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

11

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

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

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. ... 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 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, ... 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 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 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 ... 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 ... 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 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 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 /@ ... 4 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 ...

4

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

4

You can use Accounting to do this. It has the options available. a[r_, n_, d_] := (((1 + r)^n) - 1)/(1 - (1 + r)^-d) padIt[v_?(Element[#, Reals] &), f_List] := AccountingForm[v, f, NumberSigns -> {"-", "+"}, NumberPadding -> {"0", "0"}, SignPadding -> True]; TableForm[ Table[padIt[a[r, 30, d], {3, 2}], {r, .000000000001, .15, .01}, ...

4

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

4

In some ways this is an extension of my answer here. To understand how Precision, works it helps to understand how floating point numbers work and how error is propagated. I don't wish to give a full explanation of the subject. It can be sought out elsewhere, such as in a book on numerical analysis. But I will show how one can calculate the precision of ...

4

Changing the parameters in NIntegrate as the OP does can show there are difficulties with the numerics. Checking the numerics First let int1 be the OP's integrand and int3 be a simplified version to be discussed later. int1 = (1/(108 π)) E^(-((2 Pq^2)/9) - 1/18 (53 - 16 Pq + 2 Pq^2)^2) (12 + E^(1/18 (53 - 16 Pq + 2 Pq^2)^2) Sqrt[2 π] (9 - 4 Pq^2) ...

3

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

3

The reason for the fragmented plot is that the function evaluates to Indeterminate for most of the input values in the plot range, when using machine precision arithmetic. (Specifically, the argument to ArcTanh is equal to 1.0 with machine precision, and ArcTanh[1.0] is Indeterminate). Even if we didn't have this problem with ArcTanh, there is another ...

3

This is not a full answer but may be a start. Note that 2.5 and 3.5 are MachinePrecison numbers and are treated as inherently inaccurate. If you specify the precisions explicitly you will get a consistent result: Round[{2.54, 3.54}] {2, 4} NumberForm[{2.54, 3.54}, 1] {2., 4.} But why NumberForm and Round treat MachinePrecision 2.5 ...

3

Arbitrary precision can be a tricky thing, particularly when you start to mix numbers at various levels of precision. As the was pointed out in the comments, if you mix quantities Mathematica will coerce the results to be of the lower precision. For example: {Sin[Pi/4], Sin[0.25 Pi]} (* Out: {1/Sqrt[2], 0.707107} *) Note that Sin[Pi/4] returns the ...

3

Is SetAccuracy what you want? a = N[10/3, {∞, 3}] 3.33 b = 33 3.00 a + 1 4.33 b + 1 4.00 394.985674`3 394.99 Please note Accuracy is a different concept from Precision.

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