`
tangtong
  • 浏览: 62524 次
  • 来自: ...
社区版块
存档分类
最新评论

Section 1.1

阅读更多

1.1 略

1.2 略

1.3

sumSLT :: (Num a,Ord a) => a -> a -> a -> a
sumSLT a b c
    | (a<b && a<c) = b*b + c*c
    | (b<a && b<c) = a*a + c*c
    | otherwise  = a*a + b*b
 

1.4 略

1.5 略

1.6 略

1.7

newSqrt :: (Num a,Fractional a,Ord a) => a -> a
newSqrt x = sqrt_iter 1.0 x
    where sqrt_iter guess x = if (good_enough guess x) then guess
                              else sqrt_iter (improve guess x) x
          good_enough guess x = (guess*guess/x < 1.001) && (guess*guess/x > 0.999)
          improve guess x = (guess + (x/guess))/2

 1.8

improve guess x = (x/(guess*guess)+2*guess)/3

good_enough guess x = abs (guess*guess*guess - x) < 0.0001

cubet_iter guess x = if (good_enough guess x) 
                    then guess 
                    else (cubet_iter (improve guess x) x)
                    
cubet x = cubet_iter 1.0 x
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics