I used Plot[NIntegrate[...]...]
to plot a function of 5 different variables. It took really long. Right now I need to integrate this function one more time over the 5th variable and plot the result. Can someone tell me if there is an option to Nintegrate
the plot to speed things up? Maybe there's a way to convert the plot to a list of $x$ and $y$ and then take a sum over $(y2-y1)\,(x2-x1)$ and list plot it or something similar?
I guess it's not gonna work for me. I have the following function:
f[ρ_, ϕ_, ζ_, ξ_, r_] := 2.*100.*20.*0.02*0.2*ρ*Cos[ϕ]*Sech[20*(ρ - 1.)]^2.*ζ*Exp[-ζ]*
BesselJ[0, 100.*ζ*Sqrt[r^2. + ρ^2. - 2.*r*ρ*Cos[ϕ]]]*(Sqrt[ζ^2. + 0.02^2.]*
Cosh[10.*Sqrt[ζ^2. + 0.02^2.]*(ξ + 1.)] + ζ*Sinh[10.*Sqrt[ζ^2. + 0.02^2.]
*(ξ + 1.)])/((2.*ζ^2. + 0.02^2.)*Sinh[10.*Sqrt[ζ^2. + 0.02^2.]] +
2.*ζ*Sqrt[ζ^2. + 0.02^2.]*Cosh[10.*Sqrt[ζ^2. + 0.02^2.]])
Here the function $f$ have 5 variables: $\rho,\ \phi,\ \zeta,\ \xi,\ r.$. First, I need to integrate over $\rho,\ \phi,\ \zeta,\ \xi.$ and plot $f=f(r).$ It takes about 1 hour. I use as I said before
Plot[NIntegrate[f, {ξ, -1., 0.}, {ζ, 0., ∞}, {ϕ, -3.1415, +3.1415}, {ρ, 0., ∞}], {r, 0, 10}]
The next step is I need to integrate one more time over $r$, {r,0,r1}
and plot it over {r1,0,7}
. I tried what you've said, but I failed. Is your method with NDsolve going to work with this kind of function?
r
and the integration w.r.tr
? Is your motivation performance? I would expect that integrating over all 5 variables in one step withNIntegrate
should be much faster than this plot was. You can also speed up plotting by limiting the number of plot points. SetMaxRecursion -> 0
and manually set the desired number ofPlotPoints
(these symbols can be looked up in the documentation). $\endgroup$Plot
but build aTable
of the values, which you can store for later, and theListPlot
them. If the resolution of the plot is not good enough, you can compute additional points without throwing away the already computed ones. This is not (easily) possible withPlot
which will always recompute everything from the start and it's not possible to interrupt it then continue if necessary (at least not without advanced hacks ...) $\endgroup$