是否有用于集成复杂函数的Haskell库?

编程入门 行业动态 更新时间:2024-10-11 09:26:13
本文介绍了是否有用于集成复杂函数的Haskell库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

  • 如何在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 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) pre>

    因此,我们表示从 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 to b of function f on point x. i, x, a, b are all of Complex Double or better Num 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 define realIntegrate 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 to b as a function on the real interval from 0 to 1 by linear interpolation, take the value of f 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库?

    本文发布于:2023-11-22 01:36:48,感谢您对本站的认可!
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:函数   Haskell

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!