Tag Info

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

22

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 ... 18 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 StandardForm, which is why you see them only when copying, at which point it gets converted to ... 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

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

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

13

I have figured out why you are getting the structure you are getting. The reason has to do with your initial choice of the angle, which you set at $0$ in the Nest[] statement. The actual image is generated by choosing the mean result of iterating the map for many initial values chosen uniformly at random in $[0,1]$. With $n = 50$ iterations and $m = 20$ ...

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

9

This question looks as a duplicate of these questions: How to create internally optimized expression for computing with high WorkingPrecision? How to work with ExperimentalNumericalFunction? An internally optimized version of the original function can be created as follows: n = 500; f = ExperimentalCreateNumericalFunction[{a, b}, Unevaluated[Nest[# ...

9

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

8

As it seems to depend on more than machine bits I'm curious what $MaxNumber various Mathematica installs have. If your setup is different please fill in system information and Log2 @ Log2 @$MaxNumber // Round in the table below: $$\begin{array}{r|c|c|l|c} \text{OS} & \text{Bits} & \text{Version} & \text{\MaxNumber} & \log_2\log_2\\ ... 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 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 ...

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

yes, it will work anyway. Mathematica will practically always give you exact results when working with rational numbers. Consider this identity: In[1]:= 10000! == 9999!*10000 Out[1]= True 10000! is 35660 digits long - no problem for Mathematica.

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

How do I tell mathematica that all numbers e.g. 1.5 are actually 20 Digits precision? SetPrecision on all numbers or add the 20 everywhere? You could force this with $PreRead. This naive definition is likely inefficient and probably breaks a number of corner cases I have not considered, but here is a rough demonstration:$PreRead = (# /. ...

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

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

Here is my implementation of quadric spline arbitrary precision interpolation which is defined exactly as in Interpolation with options Method->"Spline", InterpolationOrder->2. Theoretical background Quadric spline interpolation for n datapoints is defined as a Piecewise function which consists of n-2 parabolas which are spliced together in the ...

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

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

Ditch the decimal point after the 16 (this makes it a machine precision number): 1/Sqrt[1 - (150^2 10^(-4))/(9 10^16)] - 1 yeilds: -1 + 200000000/Sqrt[39999999999999999]

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

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.0`200*Exp[y]] z[SetAccuracy[20., 200], SetAccuracy[20., 200]] // Accuracy 190.0318717

4

How about something like z[x_, y_] := Exp[Sin[60*x]] + Sin[50*Exp[y]] z[SetAccuracy[20., 200], SetAccuracy[20., 200]] // Accuracy does this not do what you need?

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