haskell(16)

来源:互联网 发布:mac os 安全模式 编辑:程序博客网 时间:2024/05/18 03:25

------------------equation_slove ::(RealFloat a)=>a->a->a->(Complex a,Complex a)equation_slove numa numb numc |numb^2-4*numa*numc >0 = ((((-numb) + sqrt (numb^2-4*numa*numc))/(2*numa)):+0,((-numb) - (sqrt (numb^2-4*numa*numc))/(2*numa)):+0) |numb^2-4*numa*numc ==0 =(((-numb)/(2*numa)):+0,((-numb)/(2*numa)):+0) |otherwise  =(((-numb)/(2*numa)) :+ (sqrt (4*numa*numc-numb^2)/(2*numa)), ((-numb) :+ (- (sqrt (4*numa*numc-numb^2))/(2*numa))))

除曾经讲述的类型外,haskell还定义了以下类型:

 ():空数据单元类型

String:字符串,由双引号包围

Lists:列表类型,空列表是[]

Tuples:元组

解一元二次方程组的程序为:


加载程序后运行

*Main Data.Complex> equation_slove 12 10 6

((-0.4166666666666667) :+ 0.5713045500334203,(-10.0) :+ (-0.5713045500334203))

*Main Data.Complex> equation_slove 12 12 6

((-0.5) :+ 0.5,(-12.0) :+ (-0.5))

*Main Data.Complex> equation_slove 12 16 6

((-0.6666666666666666) :+ 0.23570226039551587,(-16.0) :+ (-0.23570226039551587))

*Main Data.Complex> equation_slove 12 18 6

((-0.5) :+ 0.0,(-18.25) :+ 0.0)

*Main Data.Complex>

本博客所有内容是原创,未经书面许可,严禁任何形式的转载。

http://blog.csdn.net/u010255642