Tag Info

36

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

20

The default value of $NumberMarks Automatic means that  should by default be used in arbitrary-precision but not machine-precision numbers. Arbitrary-precision numbers can contain an arbitrary number of digits e.g. : Sqrt[321] == 1.73205080756887729353 Machine numbers contain the same number of digits and maintain no information on their ... 17 The backtick is a short-hand to mark the precision of your output. If it is not followed by any number, it denotes machine precision. You can denote arbitrary precision by including a number, as for example, 0.320. By default, these are not displayed in InputForm, which is why you see them only when copying. You can show them with NumberMarks -> True. ... 16 If you calculate Log[2,Log[2,$MaxNumber]], you'll get 29.999999828017338886225739 which is remarkably close to 30. Therefore I conclude that Mathematica calculates with a 31-bit exponent (1 bit for the exponent's sign). Which means that if Mathematica uses the same ordering as IEEE floats (i.e. first sign bit, then exponent, then mantissa), the first 32 ...

15

I wonder whether I have understood your question correctly because I know you'll be aware of Clip data = Clip[#, {-$MaxMachineNumber,$MaxMachineNumber}] & /@ {0, Exp[1000.]} (* ==> {0, 1.797693135*10^308} *) Precision /@ data (* ==> {\[Infinity], MachinePrecision} *) data = RandomReal[10, {10, 2}]~Join~{{0, Exp[1000.]}}; ...

15

As the comments indicate, there is no completely hardware-based solution - but that doesn't mean you can't do some tweaking. The trick is always: stick with machine precision as long as you can, then switch to arbitrary precision only to refine your results. Instead of making up an example (which is hard because Mathematica implements the above principle ...

12

David Goldberg ("What every computer scientist should know about floating-point arithmetic", ACM Computing Surveys, Vol 23, No 1, March 1991, p 12, Th 4) gives pseudocode that is equivalent to log1p[x_Real] := With[{w = 1 + x}, If[w-1 == 0, x, x*Log@w/(w-1)]] EDIT - Following Mark Adler's comments, I checked the binary representation of the results (using ...

8

As others have mentioned, the wrong result is given by N[expr] and the errors are due to cancellation. Let's discuss a bit why N[expr, 3] is able to give a good result. Mathematica can do computations with inexact ( = floating point) numbers in two ways: Using the computers native floating point arithmetic, which is very fast, but has no precision ...

8

The exact equality comparison returns unevaluated. Root[1 + 6 #1 - 12 #1^2 - 32 #1^3 + 16 #1^4 + 32 #1^5 &, 5] == root[1] (* Out[900]= Root[1 + 6 #1 - 12 #1^2 - 32 #1^3 + 16 #1^4 + 32 #1^5 &, 5] == Cos[(2 \[Pi])/11] *) The numerical values agree to all significant digits. N[Root[1 + 6 #1 - 12 #1^2 - 32 #1^3 + 16 #1^4 + 32 #1^5 &, 5], 20] ...

7

Your function isn't evaluating correctly when given inexact input: In[16]:= Table[f2b[N[E^-k]], {k, 0, 50, 10}] Out[16]= {-0.01730248257001, -0.01784636881283, -0.01785014954397, -0.01785017502377, -0.01785017519545, -0.01785017519660} If we force f2b to be evaluated with exact inputs (delaying the numericization of the result) we get the ...

7

The determinant of the matrix A in this case is about 10^282 The determinant isn't very useful, but the condition number is: You can use SingularValuesList to get the largest and the smallest singular value. If the ratio between the two is too large, the matrix is ill-conditioned. Solving an ill-conditioned linear system will still give "exact" results ...

7

I don't think Mathematica has that function. Seems like it should. (Same for expm1().) You should not need to resort to non-machine arithmetic to get the right answer. Here is something that will do the trick using only machine arithmetic, if the input is a machine number: log1p[x_] := If[MachineNumberQ[x], If[x < 0.5, If[# - 1 == 0, x, x ...

6

My guess is that the wrong answer is the one given by N[expr] and not N[expr,3]. My mind is simple and I cannot manage big numbers, so, let's give 'em names: aN = 95881665812878; bN = 120000000000000; cN = 121576521638975; dN = 321097753837557; eN = Log[1/3 (1 + (19 - 3 Sqrt[33])^(1/3) + (19 + 3 Sqrt[33])^(1/3))]; fN = 321097753837557; gN = Log[(-1 + 1/3 ...

6

Before people get any ideas: although we have the identity: $${}_2 F_1\left({{1,1}\atop{m}}\mid -1\right)=\frac{m-1}{2}\Phi\left(\frac12,1,m-1\right)$$ where $\Phi(z,s,a)$ is the Lerch transcendent; or, in Mathematica notation: Hypergeometric2F1[1, 1, m, -1] == (m - 1) HurwitzLerchPhi[1/2, 1, m - 1]/2 the computation becomes even more unstable with that ...

5

Using @Sjoerd idea of Clipping, maybe you could use too Rescale. Something simple could be a wrapper to rescale every point inside a Graphics: rescale[things_] := Module[{points = Cases[things, {_?NumericQ, _?NumericQ}, \[Infinity]], minmax, rescaled}, minmax = Transpose[{Min /@ #, Max /@ #} &@Transpose[points]]; rescaled = Clip[minmax, ...

5

WorkingPrecision is really more meant for setting the internal number precision while calculating your result. If you want a random number with one floating point digit you're probably better off with Round[#, 0.1] & /@ RandomVariate[UniformDistribution[], 1000] or 1/10 RandomInteger[{0, 10}, 1000] // N or you can also set the precision or accuracy ...

5

Straight from the Mathematica documentation of SetPrecision bit = Log[10., 2.]; f[x_] := Module[{p = Precision[x], lx}, lx = Block[{$MaxPrecision = p,$MinPrecision = p},4*x*(1 - x)]; SetPrecision[lx, p - bit]] then testing x0 = N[1/3, 20]; fl = NestList[f, x0, 20] As mentioned in the comment of your question, those related questions has got tons of ...

5

New method I found that using a step value that is arbitrary precision also works: Manipulate[plottricrit[ω], {ω, 0.21760, 0.2254560, 160*^-6}] Old method For reference this was my original answer, which also works but is less clean: plottricrit[ω0_] := With[{ω = SetPrecision[ω0, 100]}, ContourPlot[D[minimizeme[ω][β][ϵ], ϵ] == 0, {β, 0.5, 1.}, ...

5

The following is a shameful plug of Ｊ. Ｍ. 's answer you already linked to show how to get the parametrization by using BSplineBasis[] with arbitrary precision and packed into a function: splineInterp[data_, order_, prec_] := Module[{parametrizeCurve, tvals, bas, ctrlpts, knots}, parametrizeCurve[pts_ /; MatrixQ[pts, NumericQ], a : (_?NumericQ) : 1/2] := ...

4

If you use inexact constant in your equation it helps if you increase their accuracy as well. You can do that easily using the backtick notation: z[x_, y_] := Exp[Sin[60.0200*x]] + Sin[50.0200*Exp[y]] z[SetAccuracy[20., 200], SetAccuracy[20., 200]] // Accuracy 190.0318717

4

Keeping exact values until the last moment yields this: f2b[b_] := Exp[-1000 - 2 Sqrt[1000*b] - b]*(Erfi[Sqrt[1000]] - Erfi[Sqrt[1000] + Sqrt[b]]); ticks = Transpose[{Range[8]*10 - 9, Table[x, {x, -50, 20, 10}]}]; Show[ListLinePlot[Table[N[f2b[E^x]], {x, -50, 20}], Frame -> True, FrameTicks -> {{All, All}, {ticks, ticks}}], ...

4

For the sake of alternatives, here's another way. You can specify a precision with a backtick. This is called an "arbitrary-precision" number. Such numbers are treated differently than machine precision numbers. Examples of 3 and 5 digits of precision: 16.3 16.0 16.5 16.000 Machine precision depends on the machine, but it's often ...

4

Perhaps SetAttributes[log1p, NumericFunction]; N[log1p[x_?MachineNumberQ], _] := N@log1p[SetPrecision[x, $MachinePrecision]]; N[log1p[x_?NumericQ], {MachinePrecision, MachinePrecision}] := N@N[log1p[x],$MachinePrecision]; N[log1p[x_?NumericQ], a_] := N[Log[1 + x], a] EDIT This probably makes more sense ClearAll[log1p] log1p[x_?MachineNumberQ] := ...

3

As Szabolcs suggests, cranking up WorkingPrecision (or for that matter, just forcing Plot[] to use arbitrary precision) helps a lot. In this answer, I've taken the liberty to slightly simplify your barycentric interpolant as well: f[x_] := Sin[x] Ni3[n_Integer, x_] := (x - n) Binomial[x, n] Sum[(-1)^(n - k) Binomial[n, k] f[k]/(x - k), {k, 0, n}, ...

3

Here's a simpler example of a similar phenomenon where it might be easier to see what is happening. Consider: 10^100 - (10^100 - 1) 1 10.^100 - (10.^100 - 1.) 0. The first of these operates on exact numbers and hence gives the answer as an exact number. The second (because of the 10.) operates in floating point numbers which have limited accuracy (in ...

3

The crash is because you set WorkingPrecision too low. Simply making WorkingPrecision higher solved the problem. (no crash) but notice that some roots print saying no significant digits available to display (pink boxes). I found this when I increased the WorkingPrecision to 5000 from 50, and then saw the message NSolve::precw: The precision of the ...

3

Yes, it is possible to do this with adaptive precision. Unfortunately, Mathematica doesn't support anything less than double precision, so you can't make many gains at the beginning of the process unless you want to defer to a LibraryLink program and do it all in C instead. But, if you're interested in a high-precision result, the approach can definitely be ...

3

Regarding your last question: in the docs for FindRoot it says that FindRoot continues until either of the goals specified by AccuracyGoal or PrecisionGoal is achieved. The same thing is mentioned in the docs for NMinimize. On the other hand, the docs for NDSolve say AccuracyGoal effectively specifies the absolute local error allowed at each ...

3

Another alternative is to set WorkingPrecision to Infinity: f2b[b_?NumericQ]:=Exp[-1000-2 Sqrt[1000*b]-b]*(Erfi[Sqrt[1000]]-Erfi[Sqrt[1000]+Sqrt[b]]) Plot[{f2b[E^b],0},{b,-50,0},PlotStyle->{{Blue,Thick},{Red,Thick}},WorkingPrecision->Infinity] The above works but it is quite strange that setting WorkingPrecision to a value more than 150 results in ...

3

I believe your problem is the result of the numbers' internal binary representation. Consider this: Tuples[{0, 1}, 3] FromDigits[{#, -1}, 2] & /@ % SetPrecision[%, 1] {{0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {0, 1, 1}, {1, 0, 0}, {1, 0, 1}, {1, 1, 0}, {1, 1, 1}} {0, 1/16, 1/8, 3/16, 1/4, 5/16, 3/8, 7/16} {0, 0.06, 0.1, 0.2, 0.3, 0.3, 0.4, 0.4}

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