
Erratic behavior with complex arithmetic, e.g., sin(z) returns NaN

jp.long
My code is producing unexpected results when taking the sine of a complex number. I wrote the following test function to research the problem.
Function testsine() variable /c a a=cmplx(0,1) print "a= ", a print "sin(a)= ", sin(a) print "sin(sqrt(-1))= ", sin(sqrt(-1)) end [Click and drag to move]
The results printed in the Command Window are pasted here:
•testsine()
a= (0,1)
sin(a)= 0
sin(sqrt(-1))= NaN
The built-in sine function is not handling complex numbers as the manual leads me to believe, i.e., sin(x+iy)=sin(x)cosh(y)+ i cos(x)sinh(y). Shouldn't this have produced the result (0, 1.1752) in both cases above, i.e., the sin(a) and sin(sqrt(-1))?
This is rather a 'problem' of the print command not expecting a complex number unless explicitly getting handed one. Try this:
Will give:
June 5, 2021 at 07:15 pm - Permalink
Wow, who knew?
Well, chozo did! Thanks!
June 6, 2021 at 05:33 am - Permalink
print/C also solves the problem easily
with result
June 6, 2021 at 06:16 am - Permalink
Oh, yes. I always forget that print has more flags than just /D. :-)
June 6, 2021 at 06:20 am - Permalink