Suppose the function

f[s2_,m_,m2_] = (s2 - m^2 + m2^2 -Sqrt[m^4 - 2m^2(s2+m2^2) + (s2-m2^2)^2])/(s2 - m^2 + m2^2 +Sqrt[m^4 - 2m^2(s2+m2^2) + (s2-m2^2)^2])

defined on the domain

$m > 0, \quad m2 > 0, \quad s2\geqslant(m+m2)^2$

This is real positive function, tending to one at $s2 = (m+m2)^2$. Mathematica's output for f[(m+m2)^2,m,m2] gives 1, as it must be. But when I try to evaluate the function for particular values of arguments, say, f[(5+0.1)^2,5,0.1], it returns complex numbers with the imaginary part not negligibly small, 1. -9.34975*10^-7i!

Will this cause any problems in numerical simulations involving the function?

  • 3
    $\begingroup$ A slight reformulation of your expression works wonders for numerical stability: f[s2_, m_, m2_] := (4 m2^2 s2)/(s2 - m^2 + m2^2 + Sqrt[(m + m2)^2 - s2] Sqrt[(m - m2)^2 - s2])^2 $\endgroup$ – J. M. will be back soon Aug 5 '17 at 9:15

looks like floating point noise/rounding off related etc... Always safer to use Exact values, in particular since your function is complicated and has powers and sqrt roots all over.

 f[(5 + 1/10)^2, 5, 1/10]

Mathematica graphics

Compare to


Mathematica graphics


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.