SPEED
CUBIC.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
29
30 subroutine cubic(a,b,c,x1,x2,x3)
31
32
33 implicit none
34
35 real*8 :: a,b,c,d,x1,x2,x3,pi,prtr,prti
36 real*8 :: oot,opf,three,srth,p,q
37 real*8 :: srd,tmp,u,v, cosphi, phi, cf
38
39
40
41 !------------------------------------------------------
42 ! fdlib
43 !
44 ! copyright by c. pozrikidis, 1999
45 ! all rights reserved.
46 !
47 ! this program is to be used only under the
48 ! stipulations of the licensing agreement.
49 !-------------------------------------------------------
50
51 !-------------------------------------------------------
52 ! roots of the cubic equation:
53 !
54 ! x**3 + a*x**2 + b*x + c = 0
55 !
56 ! where a,b,c are real coefficients.
57 !
58 ! the roots are computed
59 ! using cardano's analytical formulae
60 !
61 ! See:
62 !
63 ! John W Harris and Horst Stocker,
64 ! ``Handbook of Mathematics and Computational Science''
65 ! Springer (1998).
66 !
67 ! john.harris@yale.edu
68 !
69 !-------------------------------------------------------
70
71 !Implicit Double Precision (a-h,o-z)
72
73
74 !----------
75 ! constants
76 !----------
77
78
79
80
81 pi = 3.14159265358d0
82
83 oot = 1.0d0/3.0d0
84 opf = 1.5d0
85 three = 3.0d0
86 srth = dsqrt(three)
87
88 !--------
89 ! prepare
90 !--------
91
92 p = (3.0D0*b-a**2)/3.0D0
93 q = c+2.0D0*a**3/27.0D0-a*b/3.0D0
94 D = (p/3.0D0)**3+(q/2.0D0)**2 ! discriminant
95
96 !--------------------------------------
97 ! one real, two complex conjugate roots
98 !--------------------------------------
99
100.ge. If(D0) then
101
102 srd = Dsqrt(D)
103 tmp = -0.5D0*q+srd
104 u = Dabs(tmp)**oot
105.lt. If(tmp0) u = -u
106 tmp = -0.5D0*q-srd
107 v = Dabs(tmp)**oot
108.lt. If(tmp0) v = -v
109
110 x1 = -a/3.0D0+u+v
111
112 prtr = -a/3.0D0-0.5D0*(u+v)
113 prti = srth*0.5D0*(u-v)
114
115 x2 = prtr
116 x3 = prtr
117
118
119 !-----------------
120 ! three real roots
121 !-----------------
122
123 Else
124
125 cosphi = -0.5D0*q/(Dabs(p)/3.0D0)**opf
126 phi = Dacos(cosphi)
127
128 cf = 2.0D0*sqrt(Dabs(p)/3.0D0)
129
130 x1 = -a/3.0D0 + cf*Dcos(phi/3.0D0)
131 x2 = -a/3.0D0 - cf*Dcos((phi-pi)/3.0D0)
132 x3 = -a/3.0D0 - cf*Dcos((phi+pi)/3.0D0)
133
134
135 !-----------
136
137 EndIf
138
139
140
141
142 return
143
144
145 end subroutine CUBIC
146
real *8 function phi(ng, csii, csij)
Evaluates Lengendre basis function on a specific point.
Definition PHI.f90:31