1
$\begingroup$

When I try to integrate the following,

Integrate[-GegenbauerC[22,-1/2,x]/(1+k*x),{x,-1,1}] 

where -1<k<1 and k!=0, Mathematica gives different results if I specify k before hand or after integrating the expression. Why does this happen ? Somehow, the result is also different, if I multiply and divide the expression by (say) 100. I feel like this must be some issue with accuracy or data size, but can someone please explain what I can do to overcome this issue ?

$\endgroup$
2
  • $\begingroup$ Can you share your results and a minimum reproducible example? $\endgroup$ Commented Mar 6, 2021 at 18:18
  • $\begingroup$ I just ran the aforementioned line with k=0.2 before and after integrating and got 262144. and 458752. respectively (I think both are wrong as the result should be close to 0) $\endgroup$ Commented Mar 6, 2021 at 20:21

2 Answers 2

2
$\begingroup$
Clear["Global`*"] int[k_] = Assuming[-1 < k < 1 && k != 0, Integrate[-GegenbauerC[22, -1/2, x]/(1 + k*x), {x, -1, 1}]]; 

To test equality of assigning values to k before and after the integration

test[k_] := int[k] == Integrate[-GegenbauerC[22, -1/2, x]/(1 + k*x), {x, -1, 1}] test2[k_] := int[k] - Integrate[-GegenbauerC[22, -1/2, x]/(1 + k*x), {x, -1, 1}] test /@ Range[-9/10, 9/10, 1/5] (* {True, True, True, True, True, True, True, True, True, True} *) Block[{$MaxExtraPrecision = 200}, test2 /@ Range[-9/10, 9/10, 1/5] // N[#, 10] &] 

enter image description here

Using machine precision can cause problems

test[0.1] (* False *) test2[0.1] (* 3.43597*10^10 *) 

However, for the same value even with relatively low arbitrary - precision

test[0.1`10] (* True *) test2[0.1`10] (* 0.*10^22 *) 

Consequently, don't use machine precision.

Plot[int[k], {k, -1, 1}] 

enter image description here

Plot[int[k], {k, -1, 1}, WorkingPrecision -> 10] 

enter image description here

The integral is small but non-zero in the interval

Block[{$MaxExtraPrecision = 200}, int /@ Range[-9/10, 9/10, 1/5] // N[#, 100] & // N] // Quiet (* {-8.7837*10^-7, -1.61377*10^-10, -3.40942*10^-14, -4.85371*10^-19, \ -9.0857*10^-29, -9.0857*10^-29, -4.85371*10^-19, -3.40942*10^-14, \ -1.61377*10^-10, -8.7837*10^-7} *) LogPlot[Abs[int[k]], {k, -1, 1}, WorkingPrecision -> 100] 

enter image description here

$\endgroup$
1
$\begingroup$

I think it is a matter of precision. You are looking at high order polynomials. I don't see the issue connected with fixing k before or after integration:

t1 = Integrate[-GegenbauerC[22, -1/2, x]/(1 + k*x), {x, -1, 1}]; k = 1/2; t2 =Integrate[-GegenbauerC[22, -1/2, x]/(1 + k*x), {x, -1, 1}]; k =.;N[(t1 /. k -> 1/2) - t2, 20] (* 0.*10^-59*) 

When you evaluate the integral t1 you should use increased WorkingPrecision. Compare

Plot[t1, {k, -1., 1.}, PlotRange -> {-.0001, 0}] 

with

Plot[t1, {k, -1., 1.}, WorkingPrecision -> 20,PlotRange -> {-.0001, 0}] 
$\endgroup$
2
  • $\begingroup$ Thanks! Ill try it out. It seems like the value is 0 throughout the domain. This sounds right. When i try to analytically integrate, i get a conditional expression. Is there any way to get that to evaluate to 0 using some precision arguement as well ? (i dont think we can specify working precision for Integrate, and Nintegrate does not converge even with precision of 20) $\endgroup$ Commented Mar 6, 2021 at 20:34
  • $\begingroup$ @daveSmith the integral is not zero, as you can see Plot[t1, {k, .8, 1}, WorkingPrecision -> 20] $\endgroup$ Commented Mar 6, 2021 at 22:02

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.