Last active
June 6, 2016 07:57
-
-
Save Ansarina/ed95ece7bbdc85c0c56fc20a592d388c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PROGRAM ME | |
EXTERNAL ff,ffder | |
x0=1 | |
CALL newton(ff,ffder,x0,1e-7,1e-7,10,iflag) | |
IF(iflag>1) THEN | |
PRINT *, "there was an error occurred" | |
ENDIF | |
fx0=ff(x0) | |
PRINT *, x0,fx0 | |
READ (*,*) | |
END PROGRAM ME | |
SUBROUTINE newton(F,Fder,X0,Xtol,Ftol,Ntol,iflag) | |
PRINT *, " N x0 F(x0) der(F)" | |
iflag=0 | |
DO N=1,Ntol | |
Fx0=F(x0) | |
IF(abs(Fx0)<ftol) THEN | |
RETURN | |
ENDIF | |
derF=Fder(x0) | |
PRINT *, N,x0,Fx0,derF | |
IF(derF==0)THEN | |
PRINT *, "error, derivative=0" | |
iflag=2 | |
RETURN | |
ENDIF | |
DELTAx=Fx0/derF | |
x0=x0-DELTAx | |
IF(abs(DELTAx)<xtol)THEN | |
RETURN | |
ENDIF | |
ENDDO | |
END SUBROUTINE newton | |
FUNCTION ff(x) | |
ff=x*x*x-x-1 | |
RETURN | |
END FUNCTION | |
FUNCTION ffder(x) | |
ffder=3*x*x-1 | |
RETURN | |
END FUNCTION ffder |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment