'******************************************************* '* Program to demonstrate the Newton root subroutine * '* in the complex domain * '* --------------------------------------------------- * '* Reference: BASIC Scientific Subroutines, Vol. II * '* By F.R. Ruckdeschel, BYTE/McGRAWW-HILL, 1981 [1]. * '* * '* --------------------------------------------------- * '* SAMPLE RUN: * '* * '* (Example: find a complex root of z^2 + 1 = 0) * '* * '* What is the initial guess: * '* * '* X0 = .2 * '* Y0 = 1.2 * '* * '* Convergence criterion: 1e-8 * '* Maximum number of iterations: 10 * '* * '* The root estimate is: * '* * '* X0 = -0.000000 * '* Y0 = 1.000000 * '* * '* The number of iterations performed was: 5 * '* * '******************************************************* defint i-n defdbl a-h,o-z cls print print " What is the initial guess: " print input " X0 = ", x0 input " Y0 = ", y0 print input " Convergence criterion: ", e input " Maximum number of iterations: ", n print gosub 2000 'Call ZNewton subroutine print print " The root estimate is:" print print using " X0 = ##.######"; x print using " Y0 = ##.######"; y print print " The number of iterations performed was: "; k print end '**************************** 1000 ' Functions subroutine u=x*x-y*y+1# : v=2#*x*y u1=2#*x : u2=-2#*y v1=2#*y : v2=2#*x return '**************************** '************************************************* '* Complex root seeking using Newton's method * '* --------------------------------------------- * '* This routine uses the complex domain form of * '* Newton's method for iteratively searching * '* for roots. The complex function and its first * '* partial derivatives must be available in the * '* form: F(Z) = U(X,Y) + I V(X,Y). The required * '* derivatives are DU/DX and DU/DY. * '* --------------------------------------------- * '* INPUTS: initial guess, x0 and y0, convergence * '* criteria, e, maximum number of iterations, n. * '* OUTPUTS: approximation to the root, x and y, * '* number of performed iterations, k. * '************************************************* 2000 k=0 2100 k=k+1 'Get u,v and the derivatives x=x0 : y=y0 : gosub 1000 a=u1*u1+u2*u2 x=x0+(v*u2-u*u1)/a y=y0-(v*u1+u*u2)/a 'Check for convergence in euclidean space if (x0-x)*(x0-x)+(y0-y)*(y0-y)<=e*e then return if k>=n then return x0=x : y0=y goto 2100 return 'End of file Znewton.bas