I want to get the numerical result of the integration below:
Integrate[Exp[I* s*1000.0]*1/(1 + (10)^2*s^2), {s, 0, Infinity}]
(*5.8434816785318*10^-45 - 5.204153095728048*10^26 I*)
The result is wrong in my opinion because when the Exp[I*...] have a high frequency this tends to make the integral zero or finite, this is called wave rotating approximation in physics.
I tried:
NIntegrate[Exp[I* s*1000.0]*1/(1 + (10)^2*s^2), {s, 0, Infinity},
MaxRecursion -> 1000]
(* lots of erros ...........
-0.000021305291177576493 + 0.0010002002551860643 I*)
Because the function 1/(1 + (10)^2*s^2) decays fast enough I think it isn't necessary to integrate up to infinity so I change it to a numerical number like 10^3, using bigger upper limits almost has no effect on the result so it's a good approximation and I consider this as the right answer:
NIntegrate[Exp[I* s*1000.0]*1/(1 + (10)^2*s^2), {s, 0, 10^3},
MaxRecursion -> 1000]
(*1.1026966286690337*10^-14 + 0.0010002002470217504 I*)
Questions:
Why does MMA give the wrong result in the first example by using Integrate?
I really couldn't get the errors in the second example and I am not familiar with either Integrate's options or that of NIntegrate. Is it possible to get the correct result when the upper bound of Integration is infinity?
1000in the exponential function to something else likexand define a function out of it, and then put x then the result is wrong. I think MMA solves the integrate wrong when we useIntegrate. I don't know in this case how the precision matters. – MOON Jan 07 '15 at 13:42However, int[1000] returns: 5.843481678531469*10^-45 + 0.001000200240724069 I
– MOON Jan 07 '15 at 14:291000is a number with infinity precision, while1000.0is a number withMachinePrecison. There're many posts about this issue in this site, have a search :) – xzczd Jan 07 '15 at 14:35Limit[int[x], x -> 1000.0]returns 5.843481678531469*10^-45, it omits the imaginary part. – MOON Jan 07 '15 at 15:24MiejerGeval breaks down dramatically if you do not request extended precision:N[MeijerG[{{1/2}, {}}, {{1/2, 1/2}, {0}}, 2500],16]-> 0.01128...N[MeijerG[{{1/2}, {}}, {{1/2, 1/2}, {0}}, 2500]]-> -3.7376*10^27obviously an implementation bug, er.. limitation. – george2079 Jan 07 '15 at 18:41Exp[I*s*1000]*Apart[1/(1 + (10)^2*s^2) /. s -> u/I] /. u -> I s. Expand and integrate each part. Use exact coefficients as @xzczd recommends above. Numerically it is better behaved. As forN[expr]vsN[expr, prec]: The first does machine precision quickly without precision tracking, and the second tracks the precision and ensures an accurate result. The first way, depending on the algorithm, can accumulate a lot of error. – Michael E2 Jan 07 '15 at 23:53N[expr]should differ (in this case wildly) fromN[expr,$MachinePrecision]– george2079 Jan 08 '15 at 21:51tutorial/MachinePrecisionNumbers; see alsotutorial/ArbitraryPrecisionNumbers. Try timingNonexpr = Sin[Range[10^5]]; the$MachinePrecisioncalculation takes about 25 times longer. Also compare the number of digits inFullFormandByteCountofN[Sin[1]]with those ofN[Sin[1], $MachinePrecision]. – Michael E2 Jan 08 '15 at 23:33