【发布时间】:2014-09-19 13:20:20
【问题描述】:
我尝试在不使用cosh 函数的情况下计算 ch 值。
ch :: Double -> Int -> Double
ch' :: Double -> Int -> Integer -> Double -> Double
fac :: Integer -> Integer
fac 0 = 1
fac k | k > 0 = k * fac (k-1)
taylor :: Double -> Int -> Double
taylor x n = ((x^2*n))/ (2*(fac n))
ch x iter = ch' x iter 0 1
ch' x iter n sum | iter == fromIntegral n = sum
| iter /= fromIntegral n = ch' x iter (n+1) (sum + (taylor x n))
但我有错误:
Couldn't match expected type `Double` with actual type `Integer`
In the second argument of `(*)`, namely `n`
In the first argument of `(/)`, namely `((x ^ 2 * n))`
和
Couldn't match expected type `Double` with actual type `Integer`
In the second argument of `(*)`, namely `fac n`
In the first argument of `(/)`, namely `(2 *(fac n))`
我想我试图除以 Double,但我得到了 Integer。我该如何解决这个问题?
非常感谢!
【问题讨论】:
标签: haskell math haskell-platform