一元三次方程求根程序
七夕签名-安徽省教育招生考试院
一元三次方程求根程序
算法如下:
算法来源:
http:#0$$f
703738da9773912a5584298f8198
618377ae2c9
C程序如下:
#include
#include
main()
{
doublea,b,c,d;
doubleA,B,C,L,K,T,rad;
double
GS1,GS2,Y1,Y2,P1,P2;
double X1,X2,X3;
--
--------------------------------------------------
-----------------
printf(请输入a,b,c,d:
scanf(
printf(
printf(
A=b*b-3*a*c;
B=b*c-9*a*d;
C=c*c-3*b*d;
printf(
L=B*B-4*A*C;
判别式
printf(
-------------------------------
--------------------------------------
if(A==0
&&B==0)
{
X1=X2=X3=-b(3*a);
printf(
}
-------------------------------
--------------------------------------
else
{
if(L>0)
{
Y1=A*b+(3*a*(-B+sqrt(L)))2;
Y2=A*b+(3*a*(-B-sqrt(L)))2;
printf(
if(Y1>0)
GS1=pow(Y1,1.03);
GS1为三次根号Y1
else
GS1=-pow(fabs(Y1),1.03);
if(Y2>0)
GS2=pow(Y2,(1.03)); GS2为三次根号Y2
else
GS2=-pow(fabs(Y2),(1.03));
P1=(-2*b+GS1+GS2)(6*a);
P2=sqrt(3)*(GS1-GS2)(6*a);
X1=(-b-GS1-GS2)(3*a);
printf(
printf(
printf(
}
-------------------------------
--------------------------------------
else
if(L==0)
{
K=BA;
X1=-ba+K;
X2=X3=-K2;
printf(
printf(
}
------------------------------
---------------------------------------
else
{
T=(2*A*b-3*a*B)(2*pow(A,1.5));
A>0
rad=acos(T);
X1=(-b-2*sqrt(A)*cos(rad3))(3*a);
X2=(-b
+sqrt(A)*(cos(rad3)+sqrt(3)*sin(rad3)))(3*a);
X3=(-b+sqrt(A)*(cos(rad3)-sqrt(3)*sin(rad3)))(3*a)
;
printf(
printf(
printf(
}
}
}