SUEWS API Site
Documentation of SUEWS source code
Functions/Subroutines
mod_solver Module Reference

Functions/Subroutines

real(kind(1d0)) function newtonpolynomial (x0, Pcoeff, conv, maxiter)
 

Function/Subroutine Documentation

◆ newtonpolynomial()

real(kind(1d0)) function mod_solver::newtonpolynomial ( real(kind(1d0))  x0,
real(kind(1d0)), dimension(:)  Pcoeff,
real(kind(1d0))  conv,
integer  maxiter 
)

Definition at line 207 of file suews_phys_estm.f95.

Referenced by estm_module::estm().

207  !Solves Newton's Method for a polynomial of the form
208  !f(x)=Pcoeff(1)*x^n+Pcoeff(2)*x^n-1+...+Pcoeff(n+1)
209  ! f(x(i))
210  ! x(i+1) = x(i)- -------
211  ! f'(x(i))
212  !
213  !conv is the level required for convergence
214  !maxiter is the maximum allowed iterations
215  !----------------------------------------------------
216  REAL(KIND(1d0)) ::x0, x, conv
217  REAL(KIND(1d0)) ::pcoeff(:)
218  REAL(KIND(1d0)) ::e, xprev
219  REAL(KIND(1D0))::f, fp
220  INTEGER ::maxiter
221  INTEGER ::niter
222  LOGICAL ::converged = .false.
223  INTEGER ::n, i, j
224 
225  e = huge(1.)
226  n = SIZE(pcoeff)
227  x = x0
228  DO i = 1, maxiter
229  IF (abs(e) < conv) THEN
230  converged = .true.
231  EXIT
232  ENDIF
233  f = 0; fp = 0
234  DO j = 1, n - 1
235  f = f + pcoeff(j)*x**(n - j)
236  fp = fp + pcoeff(j)*(n - j)*x**(n - j - 1) !!FO!! derivative
237  ENDDO
238 
239  f = f + pcoeff(n)
240  xprev = x
241  IF (fp == 0.) fp = tiny(1.)
242  x = xprev - f/fp
243  e = x - xprev
244  ENDDO
245  niter = i - 1
246  IF (.NOT. converged) THEN
247  print *, "Solution did not converge. Niter=", niter, " Error=", e
248  x = x0
249  ENDIF
integer, parameter maxiter
real(kind(1d0)), parameter conv
real(kind(1d0)), dimension(5) pcoeff
Here is the caller graph for this function: