# Tag Info

## New answers tagged numerics

5

It looks like you have to program it yourself. At a boundary x == 2.^n, the distance to the next machine real is either x * $MachineEpsilon or x *$MachineEpsilon / 2. The documentation for MantissaExponent ambiguously states that the mantissa will be "between 1/b and 1". It seems be the case that 1 / b <= mantissa < 1. nextafter[0., y_] := Sign[y] ...

0

Specifying initial conditions (as per gwr) resolves matters: sol = ParametricNDSolve[{2*I*a'[t] == -0.1*w* b[t]*(Exp[I*(0.1*w)*t] + Exp[-I*(2.1*w)*t]), 2*I*b'[t] == -0.1*w*a[t]*(Exp[-I*(0.1*w)*t] + Exp[I*(2.1*w)*t]), a[0] == b[0] == 1}, {a, b}, {t, 0, 1000}, w]; f[w_] := a[w] /. sol Manipulate[Plot[Evaluate[Abs[f[w][t]]]^2, {t, 0, 1000}], ...

1

Here is a short sketch of how I would do it. Since I am not a physicist this is more or less simply a how to get a function plot advice. ;-) parSol = ParametricNDSolve[ { 2 I a'[t] == -0.1 w b[t] (Exp[ I (0.1 w) t] + Exp[-I (2.1 w) t]), 2 I b'[t] == -0.1 w a[t] (Exp[-I (0.1 w) t] + Exp[ I (2.1 w) t]), (* initial conditions *) a[0] == b[0] ...

1

f1, f2, and f3 are not equations themselves, but from what you show I think that you want to find roots to those expressions. In that case, FindRoot can do that VERY fast (I am using your definitions of f1, f2, f3): solutions = FindRoot[{f1 == 0, f2 == 0, f3 == 0}, {{x, 1*^60}, {y, 1*^60}, {z, 1*^60}}, MaxIterations -> 1000] (* Out: {x -> ...

0

I believe that all you need to do is select the following method option in NDSolve Method->{"PDEDiscretization"->{"MethodOfLines",{"SpatialDiscretization"->"FiniteElement"}}}

2

The solution to this problem was a simple one: BC1 was defined at [t,0], and BC2 was also defined at [t,0]. Change the location of BC2 to [t,2*L] and the problem is solved. I.e. both boundary conditions were defined for the same point.

5

For large $x$, the value of $\operatorname{erf}(x)$ approaches $1$, so even if you were able to evaluate it you would encounter a catastrophic loss of precision when you subtracted $1$ from it. For this reason, implementations typically also provide the complementary function $$\operatorname{erfc}(x)=1-\operatorname{erf}(x)$$ designed to provide better ...

3

Look at LK4[{a, b, c, d}, I, 0, 0, 0, 0] What has happened is that the a in the argument {a, b, c, d} has been replaced by {1, 2, 3, 4} in the Sum[..., {a, 1, 4}] code in the definition of LK4. If you change the definition of LK4 to use a different iterator, you get consistent results: LK4[coeff_, tau_, xi1_, xi2_, x_, y_] := ...

8

To complement the existing answers I would like to point out that these digits can be efficiently produced directly by RealDigits without the use of N etc.: RealDigits[Pi, 10, 10, 9 - 1*^6] {{5, 7, 7, 9, 4, 5, 8, 1, 5, 1}, -999990} Regarding the updated question I believe you are still confused by the different index between the different methods. ...

6

It happens because Compile cannot infer the types returned by the subsidiary functions enn and fF. In the second approach, you partially solved this by specifying it manually for enn. In principle you could have done that in the first approach as well if you had specified it for fF too, but in practice getting the type inference to work out correctly is not ...

6

While I'm not sure why the error you see is generated, you can fix your sumT function by taking the fF call out of the Map form: sumT = Compile[ {{tab, _Real, 2}}, Total[fF /@ Map[enn[#[[1]], #[[2]]] &, tab]], CompilationTarget -> "C"]; This worked fine for me in version 10.1 of Mathematica: sumT[tab] // AbsoluteTiming (* ==> {0.000667, ...

13

That N[Pi, 1000005] is simply showing guard digits as well as the certified digits. You can get some idea of this from the checks below. npi = N[Pi, 10^6 + 5]; digits = RealDigits[npi]; digits[[1, -5 ;; -1]] str = ToString[npi, InputForm]; StringLength[str] Characters[str][[-(StringLength[str] - 10^6 - 1) ;; -1]] (* Out[426]= {1, 3, 0, 9, 2} Out[428]= ...

30

You have selected the wrong digit. Mathematica gets the digit in the million-th decimal place right if the calculation is performed correctly. q = N[Pi, 1000010]; RealDigits[q][[1, 1000001]] 1 I take the 1000001-th digit because RealDigits includes the integer part, 3. Update It is really important to use RealDigits to decide this question. ...

3

NIntegrate does each integral separately This has been observed before: NIntegrate piecewise vector function, Nested NIntegrate of vector function. It is also clear from the following BenchmarkPlot: int[n_] := Block[{shaxis}, shaxis = Table[1.0*i, {i, 1, n}]; NIntegrate[shaxis/(x^3 + 10), {x, 0, Infinity}, Method -> {"GlobalAdaptive", Method ...

0

Two small issues in your code. You have incorrect syntax in your Nest statement that assigns a value to S. sqrt is not defined. I think you want Sqrt and will have to change your brackets as well. Use SetDelayed (:=) for assignment of w to have it re-evaluated each time in the Nest statement. Hope this helps.

6

Instead of doing the integration yourself, why not have Mathematica do it for you? g = 6.674*^-11; dt = 0.001; tStop = 2000; soln = First@NDSolve[{ x1''[t] == g (m2/Norm[x2[t] - x1[t]]^3 (x2[t] - x1[t]) + m3/Norm[x3[t] - x1[t]]^3 (x3[t] - x1[t])), x2''[t] == g (m3/Norm[x3[t] - x2[t]]^3 (x3[t] - x2[t]) + m1/Norm[x1[t] ...

0

RandomVariate[NormalDistribution[0,1]] If you want 10 such numbers: RandomVariate[NormalDistribution[0, 1], 10] Answering the question below: RandomVariate[TruncatedDistribution[{0, 1}, NormalDistribution[0, 1]], 12]

Top 50 recent answers are included