SPEED
FIND_ROOT_POL.f90
Go to the documentation of this file.
1! Copyright (C) 2012 The SPEED FOUNDATION
2! Author: Ilario Mazzieri
3!
4! This file is part of SPEED.
5!
6! SPEED is free software; you can redistribute it and/or modify it
7! under the terms of the GNU Affero General Public License as
8! published by the Free Software Foundation, either version 3 of the
9! License, or (at your option) any later version.
10!
11! SPEED is distributed in the hope that it will be useful, but
12! WITHOUT ANY WARRANTY; without even the implied warranty of
13! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14! Affero General Public License for more details.
15!
16! You should have received a copy of the GNU Affero General Public License
17! along with SPEED. If not, see <http://www.gnu.org/licenses/>.
18
28
29
30 real*8 function find_root_pol(x1,x2,xacc,n)
31
33
34 implicit real*8(a-h,o-z)
35
36 parameter(jmax=1000)
37
38 call get_legendre_value(p2,fmid,p1,p1der,n,x2)
39 call get_legendre_value(p2,f,p1,p1der,n,x1)
40
41 if (f*fmid .ge. 0.d0) then
42 write(*,*) 'root non-bracketed !'
43 call exit(exit_root)
44 endif
45
46 if (f .lt. 0.d0) then
47 find_root_pol = x1
48 dx = x2 - x1
49 else
50 find_root_pol = x2
51 dx = x1 - x2
52 endif
53
54 do j = 1,jmax
55 dx = 0.5d0*dx
56 xmid = find_root_pol + dx
57 call get_legendre_value(p2,fmid,p1,p1der,n,xmid)
58 if (fmid .le. 0.d0) find_root_pol = xmid
59
60 if (dabs(dx) .lt. xacc .and. dabs(fmid) .le. xacc) then
61 find_root_pol = xmid
62 return
63 endif
64
65 enddo
66
67 end function find_root_pol
68
69
real *8 function find_root_pol(x1, x2, xacc, n)
Find a root of a polynomial of degree n.
subroutine get_legendre_value(p2, p2der, p1, p1der, n, x)
Computes Legendre polynomial and its derivative on a given point x.
SPEED exit codes.
Definition MODULES.f90:25
integer, parameter exit_root
Definition MODULES.f90:39