'***************************************************** '* Program to demonstrate the complex * '* root counting subroutine * '* ------------------------------------------------- * '* Reference: BASIC Scientific Subroutines, Vol. II * '* By F.R. Ruckdeschel, BYTE/McGRAWW-HILL, 1981 [1]. * '* * '* ------------------------------------------------- * '* Example: Find the number of complex roots of * '* F(z) = z^2 + 1 * '* * '* SAMPLE RUN: * '* Where is the center of the search circle (x0,y0): * '* * '* X0 = 0 * '* Y0 = 0 * '* * '* What is the radius of this circle: 4 * '* How many evaluation points per quadrant: 4 * '* * '* Number of complete cycles found: 2 * '* Residual: 0 * '***************************************************** defint i-n defdbl a-h,o-z cls print print " Where is the center of the search circle (x0,y0): " print input " X0 = ",x0 input " Y0 = ",y0 print input " What is the radius of this circle: ", w print input " How many evaluation points per quadrant: ", m print dim N(4*m) 'Table of integers gosub 2000 'Call RootNum subroutine print print " Number of complete cycles found: "; nn print print " Residual: "; a print end '******************************************* 1000 ' Complex function(x,y) subroutine u=x*x-y*y+1# v=2#*x*y return '******************************************* '************************************************* '* Complex root counting subroutine * '* --------------------------------------------- * '* This routine calculates the number of complex * '* roots within a circle of radius w centered on * '* (x0,y0) by counting (u,v) transitions around * '* the circumference. The input parameters are: * '* w radius of the circle * '* x0,y0 center of the circle * '* m evaluation points per quadrant * '* The routine returns nn, the number of roots * '* found, and a, where a<>0 indicates a failure. * '************************************************* 2000 a=3.1415926#/(2#*m) 'Establish the N(i) array for i=1 to 4*m x=w*COS(a*(i-1))+x0 y=w*SIN(a*(i-1))+y0 gosub 1000 'Call complex function subroutine if u>=0 then if v>=0 then N(i)=1 if u< 0 then if v>=0 then N(i)=2 if u< 0 then if v< 0 then N(i)=3 if u>=0 then if v< 0 then N(i)=4 next i 'Count complete cycles counterclockwise nn=N(1) : a=0 for i=2 to 4*m if nn=N(i) then goto 2100 if nn<>4 then if nn=N(i)+1 then a=a-1 if nn= 1 then if N(i)=4 then a=a-1 if nn=4 then if N(i)=1 then a=a+1 if nn+1=N(i) then a=a+1 nn=N(i) 2100 next i 'Complete circle if nn<>4 then if nn=N(1)+1 then a=a-1 if nn= 1 then if N(1)=4 then a=a-1 if nn=4 then if N(1)=1 then a=a+1 if nn+1=N(1) then a=a+1 a=ABS(a) : nn=INT(a/4) a=a-4#*INT(a/4) return 'End of file Rootnum.bas