Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

There are many possible variants of Assumptions here, including

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, n ∈ Reals}]]
(* {4.00979075897103, ConditionalExpression[
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2], 
    n < 1 && l + n > -1]} *)

or

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, -1 - l < n < 1}]]
(* {11.002235487576527, 
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2]} *)

or

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, (n | l) ∈ Integers}]]
(* {4.107987620241559, ConditionalExpression[
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2], 
    n <= 0 && l + n >= 0]} *)

All works sometimes and not others. The latter two seem faster and more reliable, however.

Addendum

A work-around is to run the same Integrate two or three times in succession. I have posted a questionquestion about this strange behavior, in the hope of gaining more insight.

Solution

From comments made on the question referenced above, it has become apparent that Integrate times out after 60 seconds when attempting to do many of the integrals above when called the first time. The solution is to give it more time. For instance,

TimeConstrained[
    Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
        Assumptions -> {l > 0, R > 0, n ∈ Integers}], 120] // AbsoluteTiming

returns with the correct answer after about 70 seconds.

There are many possible variants of Assumptions here, including

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, n ∈ Reals}]]
(* {4.00979075897103, ConditionalExpression[
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2], 
    n < 1 && l + n > -1]} *)

or

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, -1 - l < n < 1}]]
(* {11.002235487576527, 
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2]} *)

or

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, (n | l) ∈ Integers}]]
(* {4.107987620241559, ConditionalExpression[
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2], 
    n <= 0 && l + n >= 0]} *)

All works sometimes and not others. The latter two seem faster and more reliable, however.

Addendum

A work-around is to run the same Integrate two or three times in succession. I have posted a question about this strange behavior, in the hope of gaining more insight.

Solution

From comments made on the question referenced above, it has become apparent that Integrate times out after 60 seconds when attempting to do many of the integrals above when called the first time. The solution is to give it more time. For instance,

TimeConstrained[
    Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
        Assumptions -> {l > 0, R > 0, n ∈ Integers}], 120] // AbsoluteTiming

returns with the correct answer after about 70 seconds.

There are many possible variants of Assumptions here, including

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, n ∈ Reals}]]
(* {4.00979075897103, ConditionalExpression[
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2], 
    n < 1 && l + n > -1]} *)

or

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, -1 - l < n < 1}]]
(* {11.002235487576527, 
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2]} *)

or

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, (n | l) ∈ Integers}]]
(* {4.107987620241559, ConditionalExpression[
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2], 
    n <= 0 && l + n >= 0]} *)

All works sometimes and not others. The latter two seem faster and more reliable, however.

Addendum

A work-around is to run the same Integrate two or three times in succession. I have posted a question about this strange behavior, in the hope of gaining more insight.

Solution

From comments made on the question referenced above, it has become apparent that Integrate times out after 60 seconds when attempting to do many of the integrals above when called the first time. The solution is to give it more time. For instance,

TimeConstrained[
    Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
        Assumptions -> {l > 0, R > 0, n ∈ Integers}], 120] // AbsoluteTiming

returns with the correct answer after about 70 seconds.

added "solution"
Source Link
bbgodfrey
  • 62.1k
  • 18
  • 92
  • 160

There are many possible variants of Assumptions here, including

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, n ∈ Reals}]]
(* {4.00979075897103, ConditionalExpression[
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2], 
    n < 1 && l + n > -1]} *)

or

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, -1 - l < n < 1}]]
(* {11.002235487576527, 
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2]} *)

or

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, (n | l) ∈ Integers}]]
(* {4.107987620241559, ConditionalExpression[
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2], 
    n <= 0 && l + n >= 0]} *)

All works sometimes and not others. The latter two seem faster and more reliable, however.

AddendumAddendum

A work-around is to run the same Integrate two or three times in succession. I have posted a question about this strange behavior, in the hope of gaining more insight.

Solution

From comments made on the question referenced above, it has become apparent that Integrate times out after 60 seconds when attempting to do many of the integrals above when called the first time. The solution is to give it more time. For instance,

TimeConstrained[
    Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
        Assumptions -> {l > 0, R > 0, n ∈ Integers}], 120] // AbsoluteTiming

returns with the correct answer after about 70 seconds.

There are many possible variants of Assumptions here, including

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, n ∈ Reals}]]
(* {4.00979075897103, ConditionalExpression[
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2], 
    n < 1 && l + n > -1]} *)

or

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, -1 - l < n < 1}]]
(* {11.002235487576527, 
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2]} *)

or

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, (n | l) ∈ Integers}]]
(* {4.107987620241559, ConditionalExpression[
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2], 
    n <= 0 && l + n >= 0]} *)

All works sometimes and not others. The latter two seem faster and more reliable, however.

Addendum

A work-around is to run the same Integrate two or three times in succession. I have posted a question about this strange behavior, in the hope of gaining more insight.

There are many possible variants of Assumptions here, including

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, n ∈ Reals}]]
(* {4.00979075897103, ConditionalExpression[
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2], 
    n < 1 && l + n > -1]} *)

or

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, -1 - l < n < 1}]]
(* {11.002235487576527, 
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2]} *)

or

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, (n | l) ∈ Integers}]]
(* {4.107987620241559, ConditionalExpression[
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2], 
    n <= 0 && l + n >= 0]} *)

All works sometimes and not others. The latter two seem faster and more reliable, however.

Addendum

A work-around is to run the same Integrate two or three times in succession. I have posted a question about this strange behavior, in the hope of gaining more insight.

Solution

From comments made on the question referenced above, it has become apparent that Integrate times out after 60 seconds when attempting to do many of the integrals above when called the first time. The solution is to give it more time. For instance,

TimeConstrained[
    Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
        Assumptions -> {l > 0, R > 0, n ∈ Integers}], 120] // AbsoluteTiming

returns with the correct answer after about 70 seconds.

edited original answer to express unreliability of the computations.
Source Link
bbgodfrey
  • 62.1k
  • 18
  • 92
  • 160

Integrate seems unhappy only with There are many possible variants of n ∈ IntegersAssumptions. It works well with here, including

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, n ∈ Reals}]]
(* {4.00979075897103, ConditionalExpression[
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2], 
    n < 1 && l + n > -1]} *)

and also withor

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, -1 - l < n < 1}]]
(* {11.002235487576527, 
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2]} *)

Perhaps, the condition l + n > -1 is the source of the problem, if n is assumed an integer and l a real. In any case, the following eliminates the problem and, indeed, runs faster.or

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, (n | l) ∈ Integers}]]
(* {4.107987620241559, ConditionalExpression[
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2], 
    n <= 0 && l + n >= 0]} *)

All works sometimes and not others. The latter two seem faster and more reliable, however.

Addendum

A work-around is to run the same Integrate two or three times in succession. I have posted a question about this strange behavior, in the hope of gaining more insight.

Integrate seems unhappy only with n ∈ Integers. It works well with

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, n ∈ Reals}]]
(* {4.00979075897103, ConditionalExpression[
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2], 
    n < 1 && l + n > -1]} *)

and also with

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, -1 - l < n < 1}]]
(* {11.002235487576527, 
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2]} *)

Perhaps, the condition l + n > -1 is the source of the problem, if n is assumed an integer and l a real. In any case, the following eliminates the problem and, indeed, runs faster.

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, (n | l) ∈ Integers}]]
(* {4.107987620241559, ConditionalExpression[
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2], 
    n <= 0 && l + n >= 0]} *)

Addendum

A work-around is to run the same Integrate two or three times in succession. I have posted a question about this strange behavior, in the hope of gaining more insight.

There are many possible variants of Assumptions here, including

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, n ∈ Reals}]]
(* {4.00979075897103, ConditionalExpression[
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2], 
    n < 1 && l + n > -1]} *)

or

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, -1 - l < n < 1}]]
(* {11.002235487576527, 
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2]} *)

or

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞}, 
    Assumptions -> {l > 0, R > 0, (n | l) ∈ Integers}]]
(* {4.107987620241559, ConditionalExpression[
    (2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2], 
    n <= 0 && l + n >= 0]} *)

All works sometimes and not others. The latter two seem faster and more reliable, however.

Addendum

A work-around is to run the same Integrate two or three times in succession. I have posted a question about this strange behavior, in the hope of gaining more insight.

added addendum
Source Link
bbgodfrey
  • 62.1k
  • 18
  • 92
  • 160
Loading
added third block of code
Source Link
bbgodfrey
  • 62.1k
  • 18
  • 92
  • 160
Loading
Source Link
bbgodfrey
  • 62.1k
  • 18
  • 92
  • 160
Loading