Questions tagged [numerical-integration]

Questions on the use of numerical functions NIntegrate and NDSolve.

Questions on the use of numerical functions NIntegrate and NDSolve.

Useful links

Example questions

3496 questions
46
votes
2 answers

Nested NIntegrate

Suppose that we have the given simple integral expression $$ \int_{-5}^{5} x \int_{-\infty}^{x} e^{\int_{0}^{z} -y dy} dz dx $$ Writing this out in Mathematica we obtain: Integrate[x Integrate[Exp[Integrate[-y, {y, 0, z}]], {z, -∞, x}], {x, -5.,…
jmlopez
  • 6,470
  • 4
  • 28
  • 48
38
votes
2 answers

Determining which rule NIntegrate selects automatically

I need to numerically integrate a highly oscillatory function over the semi-infinite domain $(0,\infty)$: $$\int_0^\infty \frac{\sin^2(x) \sin^2(1000 x)}{x^{5/2}}\mathrm dx$$ Since the Levin rule (which was recently added to Mathematica, starting in…
user7885
  • 381
  • 4
  • 3
16
votes
1 answer

Obtaining an NIntegrate error estimate

Is there a way to extract the error that Mathematica estimates when calculating a numerical integral using NIntegrate? Internally Mathematica must keep track of this error, because it is used to determine if the PrecisionGoal has been met. The…
TimRias
  • 3,160
  • 13
  • 17
16
votes
5 answers

This integral is divergent. How to use NIntegrate to see how it grows?

I am trying to get information on the following integral: $$ \int_{\pi-0.3}^{\pi-\epsilon} \frac{1}{(3+\cos{x})\sqrt{(3+\cos{x})^2-4}} $$ The lower limit is somewhat arbitrary; the point is that this integral is known to be divergent if the…
12
votes
1 answer

Boosting the performance of expensive NIntegrate by feeding in a cheap approximation of the integrand

I need to integrate an expensive likelihood L[x] over its n-dimensional domain. I know that L[x] is decently approximated by a gaussian likelihood G[x], which is very cheap to evaluate. In particular, L and G share the same maximum. The…
Valerio
  • 1,982
  • 13
  • 23
12
votes
2 answers

Efficient evaluation of functions defined by NIntegrate

I have a complicated function $f$ and I want to plot the function $F(x)$ defined by the definite integral of $f$ from $0$ to $x$: $$ F(x) = \int_0^x f(y)\mathrm dy. $$ Apparently $f$ cannot be integrated in closed-form, and I use NIntegrate[]…
Kakashi Hatake
  • 123
  • 1
  • 5
10
votes
1 answer

NDSolve break condition

I'm solving a differential equation numerically by NDSolve[{p'[r] == -function[r,p[r]], p[0] == pcenter}, p,{r, 0, rmax}] with function>0. At some r, p[r] becomes negative. I want NDSolve to stop as soon as this happens and save the value of r. Any…
dan-ros
  • 415
  • 3
  • 8
10
votes
4 answers

NIntegrate doesn't evaluate

The integral Integrate[(t^4 x^3)/Sqrt[-t + x], {x, 0, 1}, {t, 0, x}] (* 512/5355 *) can be solved analytically. Trying to apply NIntegrate NIntegrate[(t^4 x^3)/Sqrt[-t + x], {x, 0, 1}, {t, 0, x}] fails (although with Method ->…
Ulrich Neumann
  • 53,729
  • 2
  • 23
  • 55
10
votes
2 answers

NIntegrate appears to give incorrect results

I am trying to specify a bivariate probability density function in Mathematica. As a check, I would like to confirm that it integrates to one. Here is the function: f[x1_, x2_, u1_, u2_, v11_, v22_, v12_] := Det[2*Pi*{{v11, v12}, {v12,…
Miguel
  • 201
  • 1
  • 5
9
votes
2 answers

Unify the sampling of NIntegrate[ {f, g, h} w ]

I'm trying to numerically integrate a function which has a vector-valued slow part and a much faster component which is shared by all the components, i.e. an integral of the form $$ \int_a^b\begin{pmatrix}f(x)\\ g(x) \\ h(x)\end{pmatrix}w(x)\,\text…
Emilio Pisanty
  • 10,255
  • 1
  • 36
  • 69
9
votes
3 answers

NIntegrate does not converge for this integrand but Simpson's Rule does

I am trying to numerically integrate a function that flips sign at a certain location. In the vicinity of this location the function is approximately asymmetric so there are large negative and positive contributions to the integral which presumably…
kotozna
  • 319
  • 1
  • 6
8
votes
3 answers

highly oscillatory integral

Hi am trying to compute the following integral in Mathematica: NIntegrate[(Sign[Cos[q]] Sqrt[Abs[Cos[q]]])/(q+100),{q,0,Infinity}] But when I run that command I get the following error: NIntegrate::ncvb: NIntegrate failed to converge to…
Andrea
  • 521
  • 2
  • 10
8
votes
3 answers

Certain integral over torus

Let $F(t_1,s_1,t_2,s_2)=$ $$\big((2+\cos t_1)\cos s_1 - (2+\cos t_2)\cos s_2\big)^2 + \big((2+\cos t_1)\sin s_1-(2+\cos t_2)\sin s_2\big)^2 + (\sin t_1 -\sin t_2 )^2.$$ I am interested in computing the following…
BigM
  • 257
  • 3
  • 10
7
votes
1 answer

Strange Behaviour of NIntegrate

I found some of the values remained unevaluated using the following code Table[NIntegrate[Sin[i x]/((2^x + 1) (Sin[x])), {x, -Pi/2, Pi/2}], {i,70, 90}] Pick them out, the unevaluated ones remain unevaluated. For example, NIntegrate[Sin[81 x]/((2^x…
vapor
  • 7,911
  • 2
  • 22
  • 55
7
votes
4 answers

Conditional numerical integration boundaries

I have a multidimensional integration of the form: somefunc[t] = NIntegrate[ otherfunc[x, y, z, t ], {z, z1[t], z2[t]}, {y, y1[t, z], y2[t, z]}, {x, x1[t, z, y], x2[t, z, y]}]; This needs to be evaluated only when $z2 > z1$, $y2 > y1$ and $x2 >…
Hsn
  • 413
  • 2
  • 6
1
2 3
33 34