Tag Info

New answers tagged

4

A nice trick to force Mathematica to use a given precision is to use Block and make $MinPrecision equal to $MaxPrecision. So you can write your result1 as: Block[{$MinPrecision = 10, $MaxPrecision = 10}, FixedPointList[N[1/2 Sqrt[10 - #^3] &, 10], 1.5`10]] {1.500000000, 1.286953768, 1.402540804, 1.345458374, 1.375170253, 1.360094193, ...


2

Mathematical operations on numbers of a given precision cannot guarantee the output to maintain the precision of the input numbers. In general precision will decrease. The amount of decrease depends on the operations and some operations will cause precision to decrease significantly. If you want a specific precision on the final result then the working ...


2

I think your problem can be illustrated as simple as this: res = {}; For[t = 0.1, t <= 1, t += 0.1, AppendTo[res, t]]; res // InputForm and Mathematica is just doing what it is asked for: This is the most simple example of the ubiquitous problems with machine precision numbers (you might want to learn at least the very basics of doing numeric analysis ...


2

If you want better approximations, then do the integration with exact quantities and put off the numerical approximations as long as possible. SfereDure = {}; For[t = 1/10, t <= 1, t += 1/10, x = Integrate[Sqrt[(1 + 8/10*y)/(y^2*(1 - y))], {y, 1, t}]; SfereDure = Prepend[SfereDure, {x/2, t} // N]; SfereDure = Prepend[SfereDure, {-x/2, t} // N]] ...


4

Your integral simply changes very rapidly near 1. Plot[ Evaluate[ Integrate[Sqrt[(1 + 2 .4*y)/(y^2*(1 - y))], {y, t, 1}, Assumptions -> {0 < t && t < 1}] ] , {t, .5, 1}] Your real issue I suppose is assuming your For loop ends at one. It does not due to numerical roundoff, the last value is ~ 1-10^-16 If you insist ...


3

Why, exactly, are you doing this? The integral can be evaluated in closed form: Integrate[Sqrt[(1 + a y)/(y^2 (1 - y))], y] Gives: $$ \frac{\sqrt{y-1} y \sqrt{\frac{a y+1}{y^2-y^3}} \left(\sqrt{a} \log \left(2 a y+2 \sqrt{a} \sqrt{y-1} \sqrt{a y+1}-a+1\right)-\tan ^{-1}\left(\frac{(a-1) y+2}{2 \sqrt{y-1} \sqrt{a y+1}}\right)\right)}{\sqrt{a y+1}} $$ ...


5

[Not exactly an answer but possibly of interest and definitely too large for the margins..] Another way to do this is to reverse the order of summation. That is to say, there is an implicit sum over integer digits with an outer sum over integers. One could, in a sense, sum over the integers in the inner loop, and over digits in the outer. Well, sort of. ...


6

If you wish to compute the correct values using the method you have chosen you could specify Method -> "Procedural" for Sum: CumDigitSum[x_, b_] := Sum[DigitSum[n, b], {n, 1, x}, Method -> "Procedural"] CumDigitSum[1000001, 10] 27000003 However, the problem comes form the fact that Sum attempts to speed the calculation by finding a symbolic ...


2

Second answer -- OK, the first answer was hogwash (the curious can inspect the edit history). It pays sometimes to write out the equation and think about it first. The code for this one looks so complicated, but the equations basically have the form (here d = 80000) rc'[t] == 2.05594*10^-10/rc[t] - 8189.14 rc[t] + 80000. rm[t], rm'[t] == -80000. rc[t] + ...


3

If I understand your question correct, you actually want to have an Accuracy of 50 and not a Precision of 50. If you use Export["oscillatorwf_n0.dat", N[oswf0, {Infinity, 51}]] the exported numbers will have a precision of 50 or less. (Less, if they end with zeros.) 2.79918439290959673893721788332716676696872559e-6 ...


3

If I understand what you want, the trouble is that final zeros are truncated. Using NumberForm can fix that. oswf0 = {1/(E^(25/2) π^(1/4)), 1/(E^(81/8) π^(1/4)), 1/(E^8 π^(1/4)), 1/(E^(49/8) π^(1/4)), 1/(E^(9/2) π^(1/4))} ExportString[ NumberForm[#, Round@Precision[#], NumberFormat -> (Row[{#1, If[#3 == "", "", "e"], #3}] &)] & /@ ...


1

It is best to do this sort of thing within a Block, so $MinPrecision is not changed globally, but only inside the scope of Block. I recommend Block[{$MinPrecision = 30}, Off[N::precsm]; ListPlot[{{1, 2}}]] but Block[{$MinPrecision = 30}, Quiet @ ListPlot[{{1, 2}}]] will work as well.


0

Below I give some code for cvt that converts a number string to a number with the same accuracy as the string. Example: datastring = "8.2457409790900005e+08\n8.2457409810599995e+08"; StringCases[datastring, s : floatpat :> cvt[StringSplit[s, "e" | "E"]]] (* {8.2457409790900005*10^8, 8.2457409810599995*10^8} *) Some slight variations: ...


0

Note that the trick of adding a zero only works for numbers in scientific notation: This is a convoluted approach that works with arbitrary floats: toarbprecision[string_] := Module[{dp, ep, firstnonzero, mend, pow, dig}, dp = StringPosition[string, "."][[1, 1]]; ep = StringPosition[string, "e" | "E"]; firstnonzero = ...


3

You need to have sufficient precision in your input file to trigger an arbitrary precision representation automatically. In your example, you just need one more digit as, I believe, one digit past machine doesn't typically do it. ImportString[ "8.24574097909000040e+08,8.2457409790900004e+08", "CSV"] (* Out: {{8.2457409790900004*10^8, 8.24574*10^8}} *) ...


7

Update: I think this is a numeric precision problem rather than a matter of the behavior of Re. I don't know if I should leave my original answer below for reference or remove it. Consider: expr = MathieuC[MathieuCharacteristicA[-(19999999999/10000000000), -2], -2, 5]; N[expr] N[expr, 15] SetPrecision[expr, 15] -9.85323*10^-16 + 3.39211*10^-8 I ...


6

I think your problems are made by order of appling Re and N. Re@Bloch is not yet a state before the computation. So you have to apply the computation by Re@Norder. Block[{$MaxExtraPrecision = 500, ϵ = 10^-10}, Re@N@BlochΚ[-2 + ϵ, -1, -10]] Block[{$MaxExtraPrecision = 1000, ϵ = 10^-20}, Re@N@BlochΚ[-2 + ϵ, -1, -10]] Block[{$MaxExtraPrecision = 500, ϵ = ...


3

If we compare N on the exact values with the MachinePrecision values, we see that the second two graphs (of the first quartet) look correct and the first two are wrong. Block[{z = 0}, Table[With[{V0 = -1, κ = 2 - ϵ}, Re@MathieuC[MathieuCharacteristicA[κ, V0], V0, z]], {ϵ, {15/10*10^-8, 18/10*10^-8}}] ] N[%, 6] (* ...



Top 50 recent answers are included