首页 > 编程知识 正文

一元三次方程求根公式推导,python解三元一次方程

时间:2023-05-05 12:14:22 阅读:175167 作者:2985

传统指甲油

cc cubic.c -lm

gcc cubic.c -lm

multiplerootdiscriminant 3360 delta1=b ^2- 3传统指甲油a传统指甲油c; delta2=b传统指甲油c-9传统指甲油a传统指甲油d; delta3=c^2-3传统指甲油b传统指甲油d

thetotaldiscriminantisdelta=delta2^2- 4传统指甲油delta1传统指甲油delta3。

When delta1=delta2=0,ShengJinformula(1) : X1=X2=X3=-b/(3) 3传统指甲油a(=-c/b=-3d/c )。

When delta=B^2-4传统指甲油a传统指甲油C0,xqdfj:

x2=(-2传统指甲油by1^(1/3) y2^ )1/3)/6传统指甲油a )3^ )1/2)传统指甲油(y1^ )1/3)-y2^ )1/3)/6

x3=(-2传统指甲油by1^(1/3) y2^ )1/3)/) 6传统指甲油a )-3^ )1/2)传统指甲油(y1^(1/3)-y2^ )1/3

When delta=B^2-4AC=0,Shengjin Formula 3:

X1=-b/a强自行车X2=X3=-K/2,K=delta2/delta1,(A0 )。

When delta=B^2-4AC0,Shengjin Formula 4:

x1=(-B-2传统指甲油sqrt(Delta1)传统指甲油cos (theta/3 ) ) ) )传统指甲油a );

x2=(-bsqrt(3(Delta1)传统指甲油(cos ) Theta/3 (sqrt )3)传统指甲油sin ) theta/3 ) ) ) 3传统指甲油a ) 3

x3=(-bsqrt(Delta1)传统指甲油(cos ) Theta/3 )-sqrt(3)3(3)传统指甲油sin ) Theta/3 ) ) ) ) 3传统指甲油

theta=arccosT,t=(2ab-3ab )/) 2a^ )3/2) )

(1) A=B=0,the equation has a三重real root。

)2) When delta=B^2-4AC0,theequationhasarealrootandapairofconjugatecomplexroots。

)3) When delta=B^2-4AC=0,the equation has three real roots,one of which has two double roots。

(4) When delta=B^2-4AC0,theequationhasthreeunequalrealroots。

#包含

#包含

enum roottype{UniReal,OneRPairComplex,TwoReal,UnequalReal};

int main ()。

const double PI=3.14159265359;

double a、b、c、d; /传统指甲油Coefficient of cubic Equation传统指甲油/

双细节1、细节2、细节3、细节3;

双精度y1、Y2、expY1、expY2;

double K,theta,t;

enum roottype rt;

打印(inputcoefficientofcubicequation : ABCD. n );

scanf (' % lf % lf % lf % lf % lf )、a、b、c和d );

delta1=b传统指甲油b-3传统指甲油a传统指甲油c;

delta2=b传统指甲油c-9传统指甲油a传统指甲油d;

delta3=c传统指甲油c-3传统指甲油b传统指甲油d;

三角洲=三角洲2传统指甲油三角洲2-4传统指甲油三角洲1传统指甲油三角洲3;

if(delta1==0delta2==0) rt=UniReal;

ELSEif(delta0) rt=OneRPairComplex;

ELSEif(delta==0) rt=TwoReal;

elseif(delta0) rt=UnequalReal;

开关(rt ) {

case UniReal:

打印(theequationhasatriplerealroot. n );

printf(x1=x2=x3=%f(n ),-c/b );

黑;

case OneRPairComplex:

printf (theequationhasarealrootandapairofconjugatecomplexroots. n ';

if(y10 ) expy1=pow ) y1,1.0/3.0; ELSEexpy1=(-1 )传统指甲油pow ) Fabs(y1 )、1.0/3.0 );

if(y20 ) expy2=pow ) y2,1.0/3.0; ELSEexpy2=(-1 )传统指甲油pow ) Fabs ) y2 )、1.0/3.0 );

printf(x1=%f(n )、(-b-expY1-expY2 )/) 3传统指甲油a );

printf(x2=%f%fi(n )、(-2传统指甲油b expY1 expY2 )/) 6传统指甲油a )、sqrt(3)3)传统指甲油(expY1-expY2 )/)

printf(x3=%f-%fi(n ),-2传统指甲油b expY1 expY2 )/) 6传统指甲油a ),sqrt(3)3)传统指甲油(expY1-expY2 )/)

黑;

case TwoReal:

printf (theequationhasthreerealroots,one of which has two double roots.n ' );

K=K2/K1;

printf(x1=x2=%f(n ),-K/2 );

printf(x3=%f(n ),-b/a强自行车);

黑;

情况真实:

打印(theequationhasthreeunequalrealroots. n );

T=(2.0传统指甲油delta1传统指甲油b-3.0传统指甲油a传统指甲油delta2)/) 2.0传统指甲油sqrt(delta1传统指甲油delta1传统指甲油

THETA=ACOS(t;

printf(x1=%f(n ),(-b-2.0传统指甲油sqrt ) Delta1(传统指甲油cos(Theta/3.0 ) ) (3.0传统指甲油a ) );

printf(x2=%f(n ),(bsqrt(3) Delta1)传统指甲油(cos ) theta/3.0 (sqrt )3)传统指甲油sin(Theta/3.0 ) ) )

printf(x3=%f(n ),(bsqrt ) Delta1)传统指甲油(cos ) theta/3.0 )-sqrt(3)3)传统指甲油sin(theta/3.0 ) )

黑;

()传统指甲油end of switch传统指甲油/

返回(0;

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。