My question has been asked before by other members, however, I didn't find the answer to their question helpful in my case. I'm doing a simple numerical integral with real numbers in mathematica, but I get a complex number as a result. This is my integral:

NIntegrate[f1[x], {x, b1, b2}]

, where

f1[x_] := 0.0472245 (4.2312 - x)^3.53272 (-1.19737 + x)^0.630549;

and b1 = 4.2312 and b2 = 8.46239.

The result is 2.40249 - 23.2898i. This is a complex number which I don't expect. Does someone know why I get this result? and, is there any way to avoid getting it?

Thanks in advance

  • 3
    $\begingroup$ The expression (4.2312 - x)^3.53272 is complex when x > 4.2312. As to how to avoid it: Well, it's correct for the function you've written. If you think the answer should be real, then you set up the function or interval wrong. Maybe you want (x - 4.2312)^3.53272 $\endgroup$
    – Michael E2
    Commented Mar 24, 2019 at 17:37
  • $\begingroup$ If a and b are real numbers and a > 0, then (-a)^b is equivalent to Exp[b (I \[Pi] + Log[a])], in case you're wondering why it should be complex. $\endgroup$
    – Michael E2
    Commented Mar 24, 2019 at 17:42

1 Answer 1


When plotting the real and imaginary part of your function

  Evaluate@ReIm[f1[x]], {x, 1, 5},
  PlotRange -> All, 
  PlotLegends -> {"Re[f[x]]", "Im[f[x]]"}, 
  GridLines -> {List @@ Reduce[f1[x] == 0, x, Reals][[All, 2]], None}

Plot of real and imaginary part of f1[x].

you can see, that only in the range $1.19737 < x < 4.2312$ the function evaluates to purely real values. Like Michael already commented, a fractional power of a negative value will produce complex values outside of that range. Hope that helps to understand the result you got!


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