CalculiX  2.13
A Free Software Three-Dimensional Structural Finite Element Program
cubic.f File Reference

Go to the source code of this file.

Functions/Subroutines

subroutine cubic (a0, a1, a2, solreal, solimag, n)
 

Function/Subroutine Documentation

◆ cubic()

subroutine cubic ( real*8  a0,
real*8  a1,
real*8  a2,
real*8, dimension(3)  solreal,
real*8, dimension(3)  solimag,
integer  n 
)
20 !
21 ! solves the cubic equation x**3+a2*x**2+a1*x+a0=0
22 ! (analytical solution)
23 ! there are three solutions in C (complex plane)
24 ! the real part of the solutions is stored in solreal(1..3),
25 ! the imaginary part in solimag(1..3). The real solutions have
26 ! the lower indices, their number is n
27 !
28 ! Reference: Abramowitz, M. and Stegun, I., Handbook of
29 ! Mathematical Functions (10th printing, 1972 p 17)
30 !
31  implicit none
32 !
33  integer n
34 !
35  real*8 a0,a1,a2,solreal(3),solimag(3),q,r,d,s1,s2,
36  & a,phi,s1r,s1i
37 !
38  write(30,*) 'a2,a1,a0 ',a2,a1,a0
39  q=a1/3.d0-a2*a2/9.d0
40  r=(a1*a2-3.d0*a0)/6.d0-(a2**3)/27.d0
41 !
42  d=q**3+r*r
43  write(30,*) 'q,r,d ',q,r,d
44 !
45  if(d.gt.0) then
46 !
47 ! one real solution, two complex conjugate complex
48 ! solutions
49 !
50  n=1
51  s1=(r+dsqrt(d))**(1.d0/3.d0)
52  s2=(r-dsqrt(d))
53  if(s2.gt.0.d0) then
54  s2=s2**(1.d0/3.d0)
55  else
56  s2=-(-s2)**(1.d0/3.d0)
57  endif
58  write(30,*) 'd>0 s1,s2 ',s1,s2
59 !
60  solreal(1)=(s1+s2)-a2/3.d0
61  solreal(2)=-(s1+s2)/2.d0-a2/3.d0
62  solreal(3)=solreal(2)
63 !
64  solimag(1)=0.d0
65  solimag(2)=(s1-s2)*dsqrt(3.d0)/2.d0
66  solimag(3)=-solimag(2)
67  else
68 !
69 ! three real solutions
70 !
71  n=3
72 !
73 ! amplitude and phase of s1
74 !
75  a=(r*r-d)**(1.d0/6.d0)
76  phi=(datan2(dsqrt(-d),r))/3.d0
77 c phi=(datan(dsqrt(-d)/r))/3.d0
78  write(30,*) 'd <=0 a,phi ',a,phi
79 !
80 ! real and imaginary part of s1
81 !
82  s1r=a*dcos(phi)
83  s1i=a*dsin(phi)
84  write(30,*) 'd >=0 s1r,s1i ',s1r,s1i
85 !
86  solreal(1)=2.d0*s1r-a2/3.d0
87  solreal(2)=-s1r-a2/3.d0-s1i*dsqrt(3.d0)
88  solreal(3)=-s1r-a2/3.d0+s1i*dsqrt(3.d0)
89 !
90  solimag(1)=0.d0
91  solimag(2)=0.d0
92  solimag(3)=0.d0
93  endif
94 !
95  return
Hosted by OpenAircraft.com, (Michigan UAV, LLC)