complex result in numerical integral I'm in a contradiction that I open the topic is here because it is also related to programming. I try to calculate definite integral using Simpson's Rule. However, after some tries, I have encountered a problem referred as nan meaning not a number. How can I know ? I checked some equations. I get that my program shows nan when result of the equation is complex number. The interesting point is that I discussed the result with my lecturer, he said if you find complex number from numerical integral calculation I will give you two prizes(no pun intended). At the first glance, I acknowledged him to be right. However, I found complex number. How is it possible? For example, when I try to calculate $$ \sin^{t}(2t) + \cos^{t}(\frac{t}{9})  = pow(sin(2*t), t ) + pow( cos(t / 9), t ) $$

.
.
29)  1.066912
30)  pow(sin(2*1.525000), 1.525000 ) + pow( cos(1.525000 / 9), 1.525000 )
30)  1.004298
31)  pow(sin(2*1.575000), 1.575000 ) + pow( cos(1.575000 / 9), 1.575000 )
31)  nan
32)  pow(sin(2*1.625000), 1.625000 ) + pow( cos(1.625000 / 9), 1.625000 )
32)  nan
.
.
.
This is not an anwer but an enlargement.

I was at first incredulous. 

I tried a routine calculation with Mathematica, which is known to be rigorous in its treatment of real vs. complex numbers, and I was very surprised to find a similar (even slightly worse) situation.

Mathematica (an old version), at the request : 

Cos[2.629]^2.629 gives the result : -0.27461 + 0.640097 I  !

Sin[2*(2.477)]^(2.477)  gives 0.06711 + 0.92716*I ...

and the same result if you separate the computation into 2 steps...

a=Sin[2*(2.477)] ; a^(2.477)

Of course, we know that the trigonometric functions can take complex values, but for complex arguments ! Why this behaviour ? It's valuable to ask it in a numerical analysis forum...
This is not an anwer but an enlargement.

I was at first incredulous. 

I tried a routine calculation with Mathematica, which is known to be rigorous in its treatment of real vs. complex numbers, and I was very surprised to find a similar (even slightly worse) situation.

Mathematica (an old version), at the request : 

Cos[2.629]^2.629 gives the result : -0.27461 + 0.640097 I  !

Sin[2*(2.477)]^(2.477)  gives 0.06711 + 0.92716*I ...

and the same result if you separate the computation into 2 steps...

a=Sin[2*(2.477)] ; a^(2.477)

Of course, we know that the trigonometric functions can take complex values, but for complex arguments ! Why this behaviour ? It's valuable to ask it in a numerical analysis forum...