30 subroutine cubic(a,b,c,x1,x2,x3)
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
41 !------------------------------------------------------
44 ! copyright by c. pozrikidis, 1999
45 ! all rights reserved.
47 ! this
program is to be used only under the
48 ! stipulations of the licensing agreement.
49 !-------------------------------------------------------
51 !-------------------------------------------------------
52 ! roots of the cubic equation:
54 ! x**3 + a*x**2 + b*x + c = 0
56 !
where a,b,c are real coefficients.
58 ! the roots are computed
59 ! using cardano
's analytical formulae
63 ! John W Harris and Horst Stocker,
64 ! ``Handbook of Mathematics and Computational Science''
67 ! john.harris@yale.edu
69 !-------------------------------------------------------
71 !Implicit Double Precision (a-h,o-z)
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
96 !--------------------------------------
97 ! one real, two complex conjugate roots
98 !--------------------------------------
112 prtr = -a/3.0D0-0.5D0*(u+v)
113 prti = srth*0.5D0*(u-v)
125 cosphi = -0.5D0*q/(Dabs(p)/3.0D0)**opf
128 cf = 2.0D0*sqrt(Dabs(p)/3.0D0)
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)
real *8 function phi(ng, csii, csij)
Evaluates Lengendre basis function on a specific point.