Tag Info

Hot answers tagged

11

You can see how accurate a number is represented using the Accuracy[] function. For the OPs example: a = N[Sqrt[2], 20]; {Accuracy[a], Accuracy[a^2], Accuracy[N[a^2,100]]} {19.8495, 19.3979, 19.3979} Hence, when printing out N[a^2,100], only the first 20 (or so) digits are significant and are printed. This is also true in general, for example: b = ...


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

If you look at the documentation for Precision, it says that if x is the value and dx the "absolute uncertainty", Precision[x] is -Log[10,dx/x]. This, whenever the estimated error is larger than the value, Mathematica will give a negative precision. Thus, for an estimated error $dx$ and a value $x$ such that $dx/x<1$ here is how the precision as defined ...


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


4

Numerical integration in Mma is a big topic. I suggest reading at least this. The following gives the correct answer: NExpectation[(-(x*y) + z^2) Boole[x*y - z^2 <= 0], {x, z, y} \[Distributed] MultinormalDistribution[{0, 0, 0}, {{3/8, 0, 1/8}, {0, 1/8, 0}, {1/8, 0, 3/8}}], Method -> {"NIntegrate", {Exclusions -> True}}]


4

If you Rationalize all your finite precision numbers and add WorkingPrecision -> 50 to FindRoot the messages go away. For example: /. {Mn -> Rationalize[0.08], cn -> Rationalize[0.25]} and: Table[Vnuc[x, y, 0] + Vdisk[x, y, 0] + Vbar[1, Rationalize[0.1], 7, Rationalize[1.5], Rationalize[0.6], x, y, 0], {x, -10, 10, 1/2}, {y, -10, 10, ...


4

Is the following a better result? (I'm not an expert.) Block[{$MaxExtraPrecision = 100}, N[-PolyLog[5/2, -E^500], 20] ] (* Out: 1.6821298518320559359*10^6 + 0.*10^-14 I *)


4

Thanks for the report, @rasher. This was a bug and it is already fixed in the development version. In[1]:= Table[intleg = tleg/2; sa = SparseArray[{{i_, i_} :> 1 - (intleg - i + 1)/tleg, {i_, j_} /; j == i + 1 :> (1 - i + intleg)/tleg}, {intleg + 1, intleg + 1}]; saN = N[sa, 50]; mp = DiscreteMarkovProcess[1, sa]; mpN = ...


3

Simply increase PlotPoints: Plot[Cos[.3 x] Exp[-0.01 x], {x, 0, 1000}, PlotRange -> {{300, 500}, {-0.05, 0.05}}, ImageSize -> 600, PlotPoints -> 2000] Increasing PlotPoints would also draw a smooth ellipse in your orbit example


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

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


2

Initially I forgot to specifically address Manipulate. In addition to this post see also: Manipulating an arbitrary-precision ContourPlot This question may qualify as a duplicate (I'll let the community votes decide) but it has been asked in a different way so I'll answer it anew. There are two issues that may be confounded here: input syntax and ...


2

Clearly, you can factor out the tiny portion of your constant, so: NSum[1/Pochhammer[m^2 + 1, 2 m], {m, 1, ∞}, WorkingPrecision -> 50] 1*^-26 1.6726218229590580987863882056891582636342622102204*10^-27 OTOH, ...products of all the numbers between consecutive squares. Product[j, {j, (k - 1)^2, k^2}] Pochhammer[(-1 + k)^2, 2 k] This doesn't ...


2

The comments by image_doctor led me to the answer I was looking for: StandardForm@NumberForm[1.2, {20, 4}, ExponentFunction -> (Null &)] (* 1.2000 *) StandardForm@NumberForm[1., {20, 4}, ExponentFunction -> (Null &)] (* 1.0000 *) StandardForm@NumberForm[0.2, {20, 4}, ExponentFunction -> (Null &)] (* 0.2000 *) StandardForm@NumberForm[0., ...


2

Might want to have a look at the InputForm of these. SetAccuracy[0., 5] // InputForm (*Out[38]//InputForm = 0``5.*) SetAccuracy[1.2, 5] // InputForm (*Out[39]//InputForm=1.19999999999999995559107901499373838305`5.079181246047625*) I doubt either gives the behavior you are after. As was suggested in a comment, maybe NumberForm or PaddedForm will meet ...


2

The problem has to do with the sample points used to contruct the plot, and not with NDSolve. Mathematica automatically subdivides segments when the angle is greater than some limit, but it will do so only MaxRecursion times. One can increase PlotPoints to increase the number of initial sample points and increase MaxRecursion to let Mathematica subdivide ...


2

First, you have t in the slot for δ -- that may be a mistake. Be that as it may, the the question about the warning FindRoot::lstol has an explanation. Second, you're getting complex solutions because the function evaluates to complex numbers: fumfa[2.0, 1.0, Ωs, 2.0, 3.5, t, 4] /. {t -> 0.1, Ωs -> 4.0} (* 1.02171 + 0. I *) Finally, the ...


2

(root = x /. FindRoot[x*Tan[x] - Cos[x] == 0, {x, 3}]) // InputForm 2.8170396080933187 root // Precision MachinePrecision Your machine precision is seen with $MachinePrecision $MachinePrecision 15.9546 root2 = x /. FindRoot[x*Tan[x] - Cos[x] == 0, {x, 3}, WorkingPrecision -> 20] 2.8170396080933199925 root2 // Precision ...


2

The expression I get for the angle angle increment $d$ is (d^2 + 2d (Pi + t) + 2(Pi + t)^2 - 2(Pi + t)(d + Pi + t) Cos[d])/(4 Pi^2) = c^2 For your problem, $c=1$ and $t$ is the start angle of Pi/2. Solve the transcendental equation for d using FindRoot[(d^2 + 2d (Pi + t) + 2(Pi + t)^2 - 2(Pi + t)(d + Pi + t) Cos[d])/(4 Pi^2) == 1 /. ...


1

Well, as @Öskå wrote, adding Exclusions -> None to Plot is all that was needed.


1

It seems to be because of numerical errors. There are A LOT of operations so there is plenty of opportunity for errors to grow. To get around this you can use exact arithmetic which Mathematica does if it is given exact numbers, for instance a=3.9 is stored as a floating point number which is inexact causing all computation done to be inexact too. a=39/10 ...


1

Of course, one should also remember that the Method options of NSum[] accept sub-options as well. For instance, NSum[HarmonicNumber[2 m]/m^3, {m, 1, Infinity}, Method -> {"EulerMaclaurin", "ExtraTerms" -> 50, Method -> {NIntegrate, Method -> "DoubleExponential"}}, NSumTerms -> 50, PrecisionGoal -> 90, ...


1

An example that allows you to accomplish your goal of exporting to a file without needing SetAccuracy is as follows: Export["test.txt", ToString@NumberForm[#, {5, 4}] & /@ {RandomReal[], 0.0}]] FilePrint["test.txt"] Out[40]= "test.txt" 0.6538 0.0000



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