
'im' as a global variable used for computing a complex wave

yaohualiu
<br /> <br /> Function test()<br /> <br /> make /c /o /N=2 cm1, cm2, cm3, cm4, cm5<br /> <br /> variable a1= 1, b1=1, c1=0<br /> <br /> Nvar im = root:im<br /> Nvar im1 = root:im1<br /> <br /> cm1={a1, b1}<br /> cm2= {a1, b1*im}<br /> cm3= {a1, b1*im1}<br /> <br /> cm4[0]= a1; cm4[1]= b1*im<br /> cm5[0]=cmplx(a1, 0)<br /> cm5[1]=cmplx(b1*im, 0)<br /> <br /> <br /> print "im=", im,"\r"<br /> print "im1=", im1, "\r"<br /> printf, "a1= %3.1f, b1=%3.1f, b1*im=%3.1f\r",a1, b1, b1*im<br /> <br /> <br /> print cm1, cm2, cm3, cm4, cm5<br /> <br /> end<br />
We would expect that cm2 = cm3 = cm4 = cm5. However, they are not. Here are the results,
•test()
im= 0
im1= 0
a1= 1.0, b1=1.0, b1*im=0.0
cm1[0]= {cmplx(1,0),cmplx(1,0)}
cm2[0]= {cmplx(1,0),cmplx(0,1)}
cm3[0]= {cmplx(1,0),cmplx(0,0)}
cm4[0]= {cmplx(1,0),cmplx(0,1)}
cm5[0]= {cmplx(1,0),cmplx(0,0)}
Here is what was printed:
May 5, 2014 at 09:38 am - Permalink
It was my mistake. I noticed that the problem happened if 'im' was originally defined as a complex number, but was referred a real number in the function. It only prints out the real part of the number. However, it is still treated as a complex number during the computation.
variable /G /c im
im= cmplx(0, 1)
May 5, 2014 at 12:37 pm - Permalink
May 5, 2014 at 01:32 pm - Permalink