是否有用于集成复杂函数的Haskell库? [英] Are there any Haskell libraries for integrating complex functions?
问题描述
- 如何在Haskell中以数值方式集成复杂的复值函数?
- 是否有任何现有的库? 数字工具仅适用于reals。
我知道在复杂的平面上只有线积分,所以我感兴趣的界面如下所示:
i =整合fxab精度
计算沿直线的积分从 a
到 b
函数 f
on point X
。
i
, x
, a
, b
都是复合双倍
或更好 Num a =>复杂的a 类型。
请......:)
你可以自己做这样的事情。假设你有一个函数 realIntegrate
类型为(Double - > Double) - > (Double,Double) - > Double
,接受一个函数和一个包含下限和上限的元组,并将结果返回一定的精度。例如,您可以使用数字工具定义 realIntegrate f(lo,hi)= quadRomberg defQuad(lo,hi)f
。
然后,我们可以按照如下方式创建你想要的函数 - 我现在忽略了精度(而且我不明白你的 x
参数是用于什么的! ):
integrate ::(Complex Double - > Complex Double) - >复合双 - >复合双 - > Complex Double
pre>
integrate fab = r:+ i其中
r = realIntegrate realF(0,1)
i = realIntegrate imagF(0,1)
realF t = realPart(f t)) - 或realF = realPart。 F 。插值
imagF t = imagPart(f(interpolate t))
interpolate t = a +(t:+ 0)*(b - a)
因此,我们表示从
a
到b
作为通过线性插值从0到1的实际区间的函数,沿着该路径取值f
,分别对实部和虚部进行积分(我不虽然),并将它们重新组合成最终答案。
我没有测试过这段代码,因为我没有numeric-工具安装,但至少它typechecks: - )
- How to numerically integrate complex, complex-valued functions in Haskell?
- Are there any existing libraries for it? numeric-tools operates only on reals.
I am aware that on complex plane there's only line integrals, so the interface I am interested in is something like this:
i = integrate f x a b precision
to calculate integral along straight line from
a
tob
of functionf
on pointx
.i
,x
,a
,b
are all ofComplex Double
or betterNum a => Complex a
type.Please... :)
解决方案You can make something like this yourself. Suppose you have a function
realIntegrate
of type(Double -> Double) -> (Double,Double) -> Double
, taking a function and a tuple containing the lower and upper bounds, returning the result to some fixed precision. You could definerealIntegrate f (lo,hi) = quadRomberg defQuad (lo,hi) f
using numeric-tools, for example.Then we can make your desired function as follows - I'm ignoring the precision for now (and I don't understand what your
x
parameter is for!):integrate :: (Complex Double -> Complex Double) -> Complex Double -> Complex Double -> Complex Double integrate f a b = r :+ i where r = realIntegrate realF (0,1) i = realIntegrate imagF (0,1) realF t = realPart (f (interpolate t)) -- or realF = realPart . f . interpolate imagF t = imagPart (f (interpolate t)) interpolate t = a + (t :+ 0) * (b - a)
So we express the path from
a
tob
as a function on the real interval from 0 to 1 by linear interpolation, take the value off
along that path, integrate the real and imaginary parts separately (I don't know if this can give numerically badly behaving results, though) and reassemble them into the final answer.I haven't tested this code as I don't have numeric-tools installed, but at least it typechecks :-)
这篇关于是否有用于集成复杂函数的Haskell库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!