-
Notifications
You must be signed in to change notification settings - Fork 2
/
newtna.for
54 lines (54 loc) · 1.51 KB
/
newtna.for
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
C
C**************************** ABSTRACT *******************************
C
C THIS SUBROUTINE EMPLOYES NEWTON'S METHOD IN ORDER TO SOLVE A
C SET OF N NONLINEAR EQUATIONS CONTAINING N UNKNOWNS.
C THIS SUBROUTINE IS CALLED BY THE MAIN PROGRAM AND IS SUPPLIED
C THE VALUES OF THE INITIAL GUESS FOR X(I)'S AS WELL AS THE VALUE OF
C N. THIS SUBROUTINE USES THE VALUES OF THE FUNCTION FROM FUNC AND
C THE VALUES OF THE PARTIAL DERIVATIVES OF THE FUNCTION IN ORDER TO
C DETERMINE THE SOLUTION. THIS METHOD USES THE LIBRARY ROUTINE LINPAC
C TO SOLVE THE SYSTEM OF LINEAR EQUATION USED BY NEWTON'S METHOD.
C
C************************************************************************
C
C
SUBROUTINE NEWTNA(FUNC,DER,N,X,FX,ERLIM,A,B,XX,IPVT)
IMPLICIT REAL*8(A-H,O-Z)
DIMENSION A(N,1),B(1),XX(1),IPVT(1),X(1),FX(1)
EXTERNAL FUNC,DER
1 CONTINUE
ITEST=0
C
C MAKE FUNCTION EVALUATIONS
C
CALL FUNC(N,X,FX)
DO 3 I=1,N
3 B(I)=-FX(I)
C
C EVALUATE JACOBIAN MATRIX
C
CALL DER(N,X,A)
C
C CALL LINEAR EQUATION SOLVER
C
CALL LINPAC(N,A,B,XX,IPVT)
C
C MAKE AN IMPROVED VALUE FOR X(I)
C
ITEST=0
DO 5 I=1,N
C ANTICIPATE ZERO ROOTS
TS=DABS(X(I))
IF(TS.LT.1.D-10)GO TO 5
RAT=XX(I)/X(I)
IF(DABS(RAT).GT.ERLIM)ITEST=ITEST+1
IF(DABS(XX(I)/X(I)).GT..5)XX(I)=.5*X(I)*DABS(XX(I))/XX(I)
X(I)=X(I)+XX(I)
5 CONTINUE
C
C CHECK FOR CONVERGENCE
C
IF(ITEST.NE.0)GO TO 1
RETURN
END