I am considering the following function called funAl:

1/2 (1 + (Sqrt[3] Sqrt[868 - 1700 xi + 825 xi^2])/Sqrt[4 - 25 xi^2])

This function occurs as a boundary in one of my integrals which i am integrating with Vegas numerically. For all considered values of xi funAl should be real and less than 1. But for some values of xi (values which are allowed), i get something like:

funAl //. xi -> 0.973991669410735`
0.942244 + 0. I

Vegas stopes integrating because of non-real values, but as you see the imaginary part is just 0. NIntegrate for example works perfectly fine. Any ideas why the funtions funAl containing only square roots gives back such values?

The integral is of the following form:

contr42 = 
 Vegas[Sqrt[xi^2*u0Max2^2 - mu^2]*u0Max2*1/(2*(2*Pi)^3)*g*
   J2[xi *u0Max2], {xi, 14/15, 1}, {alpha, funAl, 
   1}, {eta, 0, 1}, {rho, 0, 1}, {beta, 0, 1}, MaxPoints -> 10^6]

So values of xi are inserted into funAl and return the kind of numbers given above and due to the imaginary part i get an error.

  • $\begingroup$ Add //Chop should be OK $\endgroup$ – Nasser Aug 3 at 13:13
  • $\begingroup$ Both square roots are imaginary at that value of xi. The imaginary parts just happen to cancel each other out. But they're there in the intermediate calculations, which means that the expression is type-casted into Complex, thus the (float-vanishing) imaginary part. You should use Chop to remove this small number (or, say, Limit instead of ReplaceRepeated; and, FWIW, you should probably using ReplaceAll in the first place anyway). $\endgroup$ – AccidentalFourierTransform Aug 3 at 13:22
  • $\begingroup$ both Chop and Limit work for the example above, but the actual problem is the integration error in the integral exression which i added to my question. How can i use Chop or Limit there to get rid of the imaginary part? $\endgroup$ – RealDestructor Aug 3 at 13:38
  • $\begingroup$ If you are integrating numerically use arbitrary-precision rather than machine precision, i.e., specify a WorkingPrecision. We cannot verify that it will work since you have not provided a definition for Vegas, J2, ... $\endgroup$ – Bob Hanlon Aug 3 at 17:13
  • $\begingroup$ Does it work if you merge the roots, as in funAl = 1/2 (1 + Sqrt[3 (868 - 1700 xi + 825 xi^2)/(4 - 25 xi^2)])? $\endgroup$ – Roman Aug 3 at 19:10

Your Answer

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

Browse other questions tagged or ask your own question.