'***************************************************** '* Program to demonstrate NextRoot subroutine * '* ------------------------------------------------- * '* Reference: BASIC Scientific Subroutines, Vol. II * '* By F.R. Ruckdeschel, BYTE/McGRAWW-HILL, 1981 [1]. * '* * '***************************************************** defint i-n defdbl a-h,o-z dim A(10) cls print input " How many roots have been determined: ",l print print " Input the roots as prompted:" print for i=1 to l print " A(";i;") = "; : input A(i) next print print " Input the initial guess:" print input " X0 = ",x0 print input " Convergence criterion: ",e print input " Maximum number of iterations: ",m gosub 2000 'Call NextRoot subroutine print : print print " The calculated zero is X = "; x print print " The associated Y value is Y = "; y print print " The number of steps was: "; n print end '************************************* 1000 ' Function subroutine y = SIN(x/2) 'derivative y1 = 0.5*COS(x/2) return '************************************* '************************************************ '* NextRoot subroutine * '* -------------------------------------------- * '* This routine determines additional roots of * '* a function Y(x), given a set of already * '* established roots. Method applied is Newton- * '* Raphson iteration. The l established roots * '* are in A(i). The routine requires an initial * '* guess, x0, and an accuracy criteria, e. It * '* also requires a maximum number of iterations.* '************************************************ 2000 n=0 'Given x0, find Y/Y' 2100 x=x0 : gosub 1000 b=y1/y for i=1 to l b=b-1#/(x0-A(i)) next i 'Newton-Raphson iteration x1=x0-1#/b n=n+1 'Test for convergence if n>=m then goto 2200 if ABS(x1-x0)