# Plotting Integral equation

I want to plot the following indefinite integral :

$C_l^{CC}=\int k^2\mathrm{d}k\: [e^{-2k^{2}}P_{Cl}^2(k\eta)|\dot{h}(\eta)|^2]$

with k from 0 to some large value (considered to be $\infty$), where:

$P_{Cl}(k\eta) = \frac{2(l+2)}{(2l+1)}j_{l-1}(k\eta) - \frac{2(l-1)}{2l+1} j_{l+1}(k\eta)$

$\dot{h}(\eta) = r^{1/2} [A_1j_2(k\eta)+A_2y_2(k\eta)]$

where

$A_1=\frac{3k-k\cos{2k}+2\sin{2k}}{2k^2}$

$A_2 = \frac{2-2\cos{2k}-k-2k^2}{2k^2}$

$j_l$ are the spherical Bessel functions and $y_l$ are spherical Neumann functions. $\eta$ may be set to $0.0195$. I would like to do a LogLogPlot of the above integral with $l$ on the x axis and maybe even manipulate over the values $r=0.01,0.1,0.3$. However NIntegrate took an exceedingly long time to evaluate the integral and returned nothing after several minutes of waiting. What approach should i take now for plotting ?

Edit : New error for the moment with the codes i tried

p[l_, k_] := (2 (l + 2))/(2 l + 1) SphericalBesselJ[l - 1, k] - (2 (l - 1))/(2 l + 1) SphericalBesselJ[l + 1, k]
d[k_] := (1/2)(E^(-2 k^2))
a[k_] := (3 k - k Cos[2 k] + 2 Sin[2 k])/(2 k^2)
b[k_] := (2 - 2 Cos[2 k] - k Sin[2 k] - 2 k^2)/(2 k^2)
h[k_] := k(a[k] SphericalBesselJ[2, k] + b[k] SphericalBesselY[2, k])
NIntegrate[k^2 (d[k])^2 (p[l, k])^2 (h[k])^2 /. l -> 1, {k, 0.1, 10}]


$\eta$ is set to $1$ for simplicity. And yeah i haven't even plotted yet. Just tried to integrate.

Edit #2 : Thanks to @Koen for pointing errors in code. After successful NIntegrate I tried to plot the results

ListLogLinearPlot[Table[NIntegrate[k^2 (d[k])^2 (p[l, k])^2 (h[k])^2, {k, 10, 100}],{l, 0.1, 50}], Joined -> True, AxesLabel -> Automatic,Frame -> True, Axes -> False] But I was expecting something like this (according to textbooks) Where could I have gone wrong ?

• It would help if you wrote your inputs in Mathematica syntax. Oct 29, 2014 at 9:27
• Sorry i was late. Codes added now. Oct 29, 2014 at 13:04
• Can't test the code now, but is it the same if you defined f[k_] = k^2 (d[k])^2 (p[l, k])^2 h[k] /. l -> 1 // FullSimplify, and then NIntegrated f[k]? Oct 29, 2014 at 13:36
• @Peltio I tried your solution but still gives ...non-numerical values for all sampling points.... error Oct 29, 2014 at 14:11

The problem with your code is that MMA uses [ and ] exclusively for functions. If you instead use ( and ) as parentheses, your problem is solved.

Specifically, clearing the functions d[k_] and h[k_] and changing their definitions to

ClearAll[d, h]
d[k_] := (1/2)(E^(-2 k^2))
h[k_] := k(a[k] SphericalBesselJ[2, k] + b[k] SphericalBesselY[2, k])


resolves the error message. Now the command

NIntegrate[k^2 (d[k])^2 (p[l, k])^2 h[k] /. l -> 1, {k, 0.1, 10}]


gives the outcome:

0.00532152

Note that the outcome is the same (up to 12 digits) when you change the upper limit of integration from 10 to Infinity, but that the MMA takes a lot longer to compute. That the outcome is more or less the same is because of the factor $e^{-2k}$, which decays rather rapidly, as do most of your other functions. Note, however, that SphericalBesselJ[l,k] is a bit tricky in this respect, since its decay rate (in k) depends on l. It seems to me that SphericalBesselY[l,k] is less affected by this, but you may want to check that. Either way, it seems to me that your required upper limit of integration (depending on the accuracy that you are looking for) is only very weakly dependent on l.

Edit #2

There are a few strange things in your code. First of all, you currently integrate from 10 to 100 in your code, instead of from 0 to 10. Second, the definition of $A_2$ in your post does not match the definition of b[k] in your code. Third, your definition of h[k] has a factor k intead of r^[1/2]. Fourth, d[k] contains an additional factor 1/2. However, all of this does not seem to fix the problem.

Furthermore, your notation of the original problem is a bit sloppy. For instance, $\dot{h}(\eta)$ does not just depend on $\eta$, but also on $k$. Do $A_1$ and $A_2$ only depend on $k$, or also on the special combination $k \eta$?

At this point, I would suggest you to carefully investigate the original problem. For instance, you could ask the following question: if the textbook says that the integral increases for small values of l, can I explain this by considering the dependence of the spherical Bessel functions on l? What is the influence of $\eta$ on the integral? Is it an overall scale factor, or does it have a different role?

• Post edited after you pointed the mistake :) Oct 30, 2014 at 6:28