Module Shengjin_mod
Implicit None
容器
函数cubic _ equation (co )结果(x ) x
! 盛金公式求解一元三次方程
! 默认浮点数为8个字节,保证精度
Integer,parameter :3360 p=selected _ real _ kind (12 ) )
real(kind=p ),Parameter : Eps=1.0_P
real(kind=p ),intent(in ) :3360co )4) ) ) ) ) ) ) ) ) ) ) )。
real(kind=p ) : A、b、c、d、A0、B0、C0、D0、Y1、cqdYC/pcomplex ) kind=p ) 33603360x(3) ) )
a=co(1)
B=二氧化碳
c=二氧化碳(3)
d=co(4)
x=huge(a )/100.0_P
! 非三次方程
if(ABS ) Eps ) Return
B0=B*C - 9.0_P*A*D
D0=B0ldwl - 4.0_P*A0*C0
if(ABS(A0 ) Eps.and.ABS ) B0 ) EPS ) Then
! 三重实根
x(1:3(=-b/) 3.0_p*a ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )。
Else
if(D0.0_p ) Then
if(y1.0_p ) Then
Else
End If
if(y20.0_p ) Then
Else
End If
! 一个实根,一对共轭复根
x(1)=--(byydyb )/(3.0_P*A ) ) )。
x(2)=cmplx(-2.0_p*byydyb,sqrt ) 3.0_p ) ) (*(Y1-Y2 ) )/(6.0_P*A ) ) ) ) )。
x(3)=conjg ) x ) )2) ) ) ) ) x ) x ) x ) x ) x ) x )2) ) x ) x ) x ) x ) x ) x )
ELSEif(D0.0_p ) Then
! 三个不同的实根
x(1)=(-B-2.0_p*sqrt ) A0 ) cos ) Y2 ) )/)/(3.0_P*A ) ) ) ) ) ) ) )。)
x(2)=(-bsqrt(a0 ) ) cos ) y2 ) sqrt ) 3.0_p ) sin ) y2 ) ) )/(3.0_P*A ) ) )。
x(3)=(-bsqrt(a0 ) ) cos ) y2 )-sqrt ) 3.0_p ) sin ) y2 ) )/)/(3.0_P*A ) ) ) )。
Else
! 三个果实的根,其中两个相等
x(1)=B0/A0 - B/A
x ) 2:3 (=-0.5 _ pl dwl/wrd zdj/pendif
End If
End Function Cubic_equation
End Module Shengjin_mod
Program www_fcode_cn
Use Shengjin_mod
Implicit None
real(kind=8) :3360a(4),Emax
complex(kind=8) :3360x(3),e (3) ) ) )。
a=()/3568.d0,458.d0,47.d0,-20.D0 /) ) ) ) ) )。
x=cubic_equation(a )
e=a(1) x*x*xa )2) x*xa )3) xa )4) ) ) ) ) )。
emax=MaxVal(ABS(e ) )
write(*,) ) 6f15.7 ) ) real(x )、aimag (x )、real(x )、aimag (x )、real(x ) )、3 )、) )。
! 0.1250000.00000-0.12668160.1696904-0.12666816-0.1696904
Write (* ()、()、最大误差)、Emax
! 4.733964436118326E-008
读(*,* )。
End Program www_fcode_cn