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

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

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 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 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 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] ... 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 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 /@ ... 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 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 = ... 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}, ... 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 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.9856743 394.99 Please note Accuracy is a different concept from Precision. 3 Use the$PrePrint global parameter: $PrePrint = If[MatchQ[#, _?NumericQ], NumberForm[#, {4, 2}], #] &; Note: if you dont want the way rationals will be represented after setting the global variable (e.g.$3.00/4.00$) then use this instead$PrePrint = If[MatchQ[#, Except[_Rational,_?NumericQ]], NumberForm[#, {4, 2}], #] &; Update: if you ...

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

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

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

3

This is not an answer, just too long for a comment. To start of with your NIntegrate call looks peculiar, the f(r) part is not a function call but is interpreted as f*r a function call looks like f[r] (* Obtained by doing ToExpression[...I pasted latex stuff here..., TeXForm] and replaced e with E ( /.e->E) *) g[r_] := -((3^(1/3) (E^(-2 ...

3

While ubpdqn has ansered the first of your questions already here a solution to your second question: robksTable[rstart_, rend_, dstart_, dend_] := TableForm[ Table[PaddedForm[a[r, 30, d], {3, 2}], {r, rstart, rend, .01}, {d, dstart, dend, 5}], TableHeadings -> {(ToString[#] <> "%") & /@ IntegerPart[100 Range[rstart, rend, 0.01]], ...

3

I think your reasoning about the numbers you want to plot is flawed. Let's make a simple example 15 (* 1.0000 *) If you specify the accuracy like that, you say that you are uncertain of the digits that could possibly follow after 1.0000. Therefore, if you have an Accuracy of 5 and there are some digits after the zeroes, they are not taken into account ...

2

Next time it would be really nice of you to give actual Mathematica code for your function definitions. Well, for now, thanks to @ssch and ToExpression we have the following definition of g[r]: g[r_]=-((3^(1/3) (E^(-2 r))^(1/3))/\[Pi]^(2/3))- (2 \[Pi])^(1/3)/(5 (E^(-2 r))^(1/3) (1+(3 \[Pi]^(1/3) ArcSinh[(2 (2 \[Pi])^(1/3))/(E^(-2 r))^(1/3)])/(5 2^(2/3) ...

2

This isn't an answer (yet) but it was too long for a comment. Here is an extended example where the quoted precision does not appear to be true: f1 = Derivative[0, 6][StieltjesGamma][0, #] &; f2 = {Accuracy@#, Precision@#, InputForm@#} &; f1 @ 115 f2 @ % N[f1 @ 1, 10] f2 @ % 725.59 {2.29961, 5.1603, ...

2

You must set the option PrintPrecision to a higher value (The default is 6 digits). This can be done with the Option Inspector very easily. This can also be done programmatically : SetOptions[SelectedNotebook[], PrintPrecision -> 16] It works too with Style[]: Style[N[\[Pi]], PrintPrecision -> 10] --> 3.141592654 (instead of default 6 digits ...

2

The following is a place to start: Use StringToStream to convert the string data to an input stream: num = "-5.100686209408900133332e+02 -1.294005398404007344443e+01 -2.59376479781563728887e+02 -1.3043629998334040122222e+02" Now str = StringToStream[num]; Use ReadList to read the InputStream data = ReadList[str, Table[Record, {4}], RecordSeparators ...

2

You can modify options : a[r_, n_, d_] := (((1 + r)^n) - 1)/(1 - (1 + r)^-d) TableForm[ Table[PaddedForm[ a[r, 30, d], {3, 2}], {r, .000000000001, .15, .01}, {d, 15, 40, 5}], TableHeadings -> {Style[#, Bold, FontFamily -> "Calibri"] & /@ {"0%", "1%", "2%", "3%", "4%", "5%", "6%", "7%", "8%", "9%", "10%", "11%", "12%", ...

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