1
$\begingroup$

I want to perform the following integration.

My function is : $r \cos(r) H_0^{(2)}(k r)$. I want to integrate from $0$ to $\pi$, and want to get the expression in terms of $k$. I used this command:

Integrate[r*cos[r]*HankelH2[0,k*r],{r,0,pi}]

The integral is not performed. Please suggest some solution. Thanks in advance

$\endgroup$
  • $\begingroup$ Hi, I edited the code to format it properly. I left cos as is. It should be Cos, but I could be sure whether it was a simple typo, or an error. Do you have a reason to think it is known how to write the integral in terms Mathematica functions? $\endgroup$ – Michael E2 Nov 1 '14 at 12:47
  • 2
    $\begingroup$ int[k_?NumericQ] := NIntegrate[r*Cos[r] HankelH2[0, k*r], {r, 0, Pi}] gives you a way to represent the function via numerical approximation. $\endgroup$ – Michael E2 Nov 1 '14 at 12:49
  • 1
    $\begingroup$ There is no closed form solution for Integrate[BesselJ[0, k r] Cos[r], r] which what causes this to fail. There is a analytical solution for k=1. k = 1; Integrate[r*Cos[r]*HankelH2[0, k*r], r] gives 1/4 (2 r^2 HypergeometricPFQ[{1/4, 3/4}, {1/2, 1/2, 2}, -r^2]- I Sqrt[2] MeijerG[{{1, 5/4, 7/4}, {1/2}}, {{1, 1}, {0, 1/2, 3/2, 3/2}}, r, 1/2]) might also be better to ask this on the math group. $\endgroup$ – Nasser Nov 1 '14 at 14:17
  • $\begingroup$ @Nasser Thank you very much for your replies. Actually i can not put the value k=1, because I want to solve the result of integral (which should be in terms of k) to find roots of equation i.e. the values of k. $\endgroup$ – Minshawi737 Nov 1 '14 at 14:37
  • $\begingroup$ @MichaelE2 Thankyou very much for your reply $\endgroup$ – Minshawi737 Nov 1 '14 at 14:38
1
$\begingroup$

To expand on my comment and to include the purpose finding roots

ClearAll[int, intjac];

int[k_?NumericQ, opts : OptionsPattern[NIntegrate]] := 
  NIntegrate[r*Cos[r] HankelH2[0, k*r], {r, 0, Pi}, opts];

intjac[k0_?NumericQ, opts : OptionsPattern[NIntegrate]] :=
  Block[{k}, {{NIntegrate[D[r*Cos[r] HankelH2[0, k*r], k] /. k -> k0, {r, 0, Pi}, opts]}}];

The Jacobian intjac is passed to FindRoot to use in Newton's method. This can sometimes help speed convergence. In this case both the function and the Jacobian are moderately expensive numerical integrations. It happens to help reduced the time by half in the test case below. Note: The Jacobian has to have a matrix value; hence the {{}} to turn the derivative into a 1 x 1 matrix.

I would suggest using a finite AccuracyGoal. The default for NIntegrate is Infinity and NIntegrate will complain (NIntegrate::slwcon and NIntegrate::ncvb) when FindRoot drives k near a root. At a root, by definition, the integral is zero, and it's impossible to achieve any PrecisionGoal in computing a value of zero. Setting a finite accuracy goal prevents NIntegrate from refining the integration further than it can at MachinePrecision. For a higher AccuracyGoal, the WorkingPrecision would have to be increased.

(sol = FindRoot[int[k, AccuracyGoal -> 15], {k, -0.01}, Jacobian -> intjac[k]]) // AbsoluteTiming
int[k, AccuracyGoal -> 15] /. sol
(*
  {0.447269, {k -> -3.19371*10^-20 - 0.520674 I}}
  2.74622*10^-20 + 8.32667*10^-17 I
*)

(sol = FindRoot[int[k, AccuracyGoal -> 15], {k, -0.01}]) // AbsoluteTiming
int[k, AccuracyGoal -> 15] /. sol
(*
  {0.821435, {k -> 1.38324*10^-18 - 0.520674 I}}
  -1.18942*10^-18 + 8.32667*10^-17 I
*)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.