~ubuntu-branches/ubuntu/karmic/python-scipy/karmic

« back to all changes in this revision

Viewing changes to Lib/optimize/minpack/lmdif1.f

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T. Chen (new)
  • Date: 2005-03-16 02:15:29 UTC
  • Revision ID: james.westby@ubuntu.com-20050316021529-xrjlowsejs0cijig
Tags: upstream-0.3.2
ImportĀ upstreamĀ versionĀ 0.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
      subroutine lmdif1(fcn,m,n,x,fvec,tol,info,iwa,wa,lwa)
 
2
      integer m,n,info,lwa
 
3
      integer iwa(n)
 
4
      double precision tol
 
5
      double precision x(n),fvec(m),wa(lwa)
 
6
      external fcn
 
7
c     **********
 
8
c
 
9
c     subroutine lmdif1
 
10
c
 
11
c     the purpose of lmdif1 is to minimize the sum of the squares of
 
12
c     m nonlinear functions in n variables by a modification of the
 
13
c     levenberg-marquardt algorithm. this is done by using the more
 
14
c     general least-squares solver lmdif. the user must provide a
 
15
c     subroutine which calculates the functions. the jacobian is
 
16
c     then calculated by a forward-difference approximation.
 
17
c
 
18
c     the subroutine statement is
 
19
c
 
20
c       subroutine lmdif1(fcn,m,n,x,fvec,tol,info,iwa,wa,lwa)
 
21
c
 
22
c     where
 
23
c
 
24
c       fcn is the name of the user-supplied subroutine which
 
25
c         calculates the functions. fcn must be declared
 
26
c         in an external statement in the user calling
 
27
c         program, and should be written as follows.
 
28
c
 
29
c         subroutine fcn(m,n,x,fvec,iflag)
 
30
c         integer m,n,iflag
 
31
c         double precision x(n),fvec(m)
 
32
c         ----------
 
33
c         calculate the functions at x and
 
34
c         return this vector in fvec.
 
35
c         ----------
 
36
c         return
 
37
c         end
 
38
c
 
39
c         the value of iflag should not be changed by fcn unless
 
40
c         the user wants to terminate execution of lmdif1.
 
41
c         in this case set iflag to a negative integer.
 
42
c
 
43
c       m is a positive integer input variable set to the number
 
44
c         of functions.
 
45
c
 
46
c       n is a positive integer input variable set to the number
 
47
c         of variables. n must not exceed m.
 
48
c
 
49
c       x is an array of length n. on input x must contain
 
50
c         an initial estimate of the solution vector. on output x
 
51
c         contains the final estimate of the solution vector.
 
52
c
 
53
c       fvec is an output array of length m which contains
 
54
c         the functions evaluated at the output x.
 
55
c
 
56
c       tol is a nonnegative input variable. termination occurs
 
57
c         when the algorithm estimates either that the relative
 
58
c         error in the sum of squares is at most tol or that
 
59
c         the relative error between x and the solution is at
 
60
c         most tol.
 
61
c
 
62
c       info is an integer output variable. if the user has
 
63
c         terminated execution, info is set to the (negative)
 
64
c         value of iflag. see description of fcn. otherwise,
 
65
c         info is set as follows.
 
66
c
 
67
c         info = 0  improper input parameters.
 
68
c
 
69
c         info = 1  algorithm estimates that the relative error
 
70
c                   in the sum of squares is at most tol.
 
71
c
 
72
c         info = 2  algorithm estimates that the relative error
 
73
c                   between x and the solution is at most tol.
 
74
c
 
75
c         info = 3  conditions for info = 1 and info = 2 both hold.
 
76
c
 
77
c         info = 4  fvec is orthogonal to the columns of the
 
78
c                   jacobian to machine precision.
 
79
c
 
80
c         info = 5  number of calls to fcn has reached or
 
81
c                   exceeded 200*(n+1).
 
82
c
 
83
c         info = 6  tol is too small. no further reduction in
 
84
c                   the sum of squares is possible.
 
85
c
 
86
c         info = 7  tol is too small. no further improvement in
 
87
c                   the approximate solution x is possible.
 
88
c
 
89
c       iwa is an integer work array of length n.
 
90
c
 
91
c       wa is a work array of length lwa.
 
92
c
 
93
c       lwa is a positive integer input variable not less than
 
94
c         m*n+5*n+m.
 
95
c
 
96
c     subprograms called
 
97
c
 
98
c       user-supplied ...... fcn
 
99
c
 
100
c       minpack-supplied ... lmdif
 
101
c
 
102
c     argonne national laboratory. minpack project. march 1980.
 
103
c     burton s. garbow, kenneth e. hillstrom, jorge j. more
 
104
c
 
105
c     **********
 
106
      integer maxfev,mode,mp5n,nfev,nprint
 
107
      double precision epsfcn,factor,ftol,gtol,xtol,zero
 
108
      data factor,zero /1.0d2,0.0d0/
 
109
      info = 0
 
110
c
 
111
c     check the input parameters for errors.
 
112
c
 
113
      if (n .le. 0 .or. m .lt. n .or. tol .lt. zero
 
114
     *    .or. lwa .lt. m*n + 5*n + m) go to 10
 
115
c
 
116
c     call lmdif.
 
117
c
 
118
      maxfev = 200*(n + 1)
 
119
      ftol = tol
 
120
      xtol = tol
 
121
      gtol = zero
 
122
      epsfcn = zero
 
123
      mode = 1
 
124
      nprint = 0
 
125
      mp5n = m + 5*n
 
126
      call lmdif(fcn,m,n,x,fvec,ftol,xtol,gtol,maxfev,epsfcn,wa(1),
 
127
     *           mode,factor,nprint,info,nfev,wa(mp5n+1),m,iwa,
 
128
     *           wa(n+1),wa(2*n+1),wa(3*n+1),wa(4*n+1),wa(5*n+1))
 
129
      if (info .eq. 8) info = 4
 
130
   10 continue
 
131
      return
 
132
c
 
133
c     last card of subroutine lmdif1.
 
134
c
 
135
      end