'**************************************************** '* Program to demonstrate complex series evaluation * '* It is assumed that the coefficients are obtained * '* from a subroutine * '* ------------------------------------------------ * '* Reference: BASIC Scientific Subroutines, Vol. II * '* By F.R. Ruckdeschel, BYTE/McGRAWW-HILL, 1981 [1].* '* ------------------------------------------------ * '* SAMPLE RUN: * '* * '* Input the complex number as prompted: * '* * '* Real part = 1 * '* Complex part = 0 * '* * '* Results are: * '* * '* Z1 = 32 * '* Z2 = 8E-029 * '* * '**************************************************** defint i-n defdbl a-h,o-z pi = 4#*ATN(1#) 'Get coefficients gosub 1000 'input complex number cls print print " Input the complex number as prompted:" print input " Real part = ", x input " Complex part = ", y gosub 3000 print print " Results are:" print print " Z1 = "; z1 print " Z2 = "; z2 print end 'Coefficients subroutine 1000 m=5 A(0) = 1 A(1) = 5 A(2) = 10 A(3) = 10 A(4) = 5 A(5) = 1 return 'Rectangular to polar conversion 2000 u = sqr(x*x+y*y) 'Guard against ambiguous vector if y=0 then y = (.1)^30 'Guard against divide by zero if x=0 then x = (.1)^30 v = ATN(y/x) 'Check quadrant and adjust if x<0 then v = v + pi if v<0 then v = v + 2# * pi return 'Polar to rectangular conversion 2100 x = u*cos(v) y = u*sin(v) return 'Polar power 2200 u1 = u^n v1 = n * v v1 = v1 - 2#*pi * int(v1/2#/pi) return 'Rectangular complex number power 2300 gosub 2000 'Polar power gosub 2200 'Change variable for conversion u=u1 : v=v1 'Polar to rectangular conversion gosub 2100 return '******************************************************** '* Complex series evaluation subroutine * '* ---------------------------------------------------- * '* The series coefficients are A(i), assumed real, the * '* order of the polynomial is m. The subroutine uses * '* repeated calls to the nth power (Z^N) complex number * '* subroutine. Inputs to the subroutine are x, y, m and * '* the A(i). Outputs are z1 (real) and z2 (imaginary). * '******************************************************** 3000 z1 = A(0) : z2 = 0 'Store x and y a1 = x : a2 = y for n = 1 to m 'Recall original x and y x = a1 : y = a2 'Call Z^N subroutine gosub 2300 'Form partial sum z1 = z1 + A(n) * x z2 = z2 + A(n) * y next 'Restore x and y x = a1 : y = a2 return 'End of file CMPLXSER.BAS