	PROGRAM D9R8

C	Driver for routine RTNEWT

	EXTERNAL FUNCD,FNCT

	PARAMETER(N=100,NBMAX=20)

	DIMENSION XB1(NBMAX),XB2(NBMAX)

	WRITE(*,*)'X1=? X2=? NB=?'

	READ(*,*)X1,X2,NB

	CALL ZBRAK(FNCT,X1,X2,N,XB1,XB2,NB)

	WRITE(*,20)

20	FORMAT(/1X,'Roots of F(X):')

	WRITE(*,30)

30	FORMAT(/1X,T19,'x',T31,'F(x)'/)

	DO 11 I=1,NB

		XACC=(1.0E-6)*(XB1(I)+XB2(I))/2.0

		ROOT=RTNEWT(FUNCD,XB1(I),XB2(I),XACC)

	  WRITE(*,40) I,ROOT,FNCT(ROOT)

40	FORMAT(1X,'root',I2,2X,F12.6,E16.4)

11	CONTINUE

	END

C

	SUBROUTINE FUNCD(X,FN,DF)

	FN=EXP(X)-3.*X

	DF=EXP(X)-3.

	RETURN

	END

C

	FUNCTION FNCT(X)

	FNCT=EXP(X)-3.*X

	RETURN

	END

      FUNCTION RTNEWT(FUNCD,X1,X2,XACC)

      PARAMETER (JMAX=20)

      RTNEWT=.5*(X1+X2)

      DO 11 J=1,JMAX

	CALL FUNCD(RTNEWT,F,DF)

	DX=F/DF

	RTNEWT=RTNEWT-DX

	IF((X1-RTNEWT)*(RTNEWT-X2).LT.0.)PAUSE 'jumped out of brackets'

	IF(ABS(DX).LT.XACC) RETURN

11    CONTINUE

      PAUSE 'RTNEWT exceeding maximum iterations'

      END

      SUBROUTINE ZBRAK(FX,X1,X2,N,XB1,XB2,NB)

      PARAMETER(NBMAX=20)

      DIMENSION XB1(NBMAX),XB2(NBMAX)

      NBB=NB

      NB=0

      X=X1

      DX=(X2-X1)/N

      FP=FX(X)

      DO 11 I=1,N

	X=X+DX

	FC=FX(X)

	IF(FC*FP.LT.0.) THEN

	  NB=NB+1

	  XB1(NB)=X-DX

	  XB2(NB)=X

	ENDIF

	FP=FC

	IF(NBB.EQ.NB)RETURN

11    CONTINUE

      RETURN

      END

