如何在Julia中进行两个变量数值积分? [英] How to do two variable numeric integration in Julia?

查看:212
本文介绍了如何在Julia中进行两个变量数值积分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用quadgk在Julia中进行单变量数字积分.一些简单的例子:

I can do single variable numeric integration in Julia using quadgk. Some simple examples:

julia> f(x) = cos(x)
f (generic function with 1 method)

julia> quadgk(f, 0, pi)
(8.326672684688674e-17,0.0)

julia> quadgk(f, 0, pi/2)
(1.0,1.1102230246251565e-16)

julia> g(x) = cos(x)^2
g (generic function with 1 method)

julia> quadgk(g, 0, pi/2)
(0.7853981633974483,0.0)

julia> pi/4
0.7853981633974483

有关Quadgk的文档似乎并不意味着支持多维集成,如果尝试将其用于2D积分,我肯定会得到一个错误:

The documentation for quadgk doesn't seem to imply an support for multidimensional integration, and sure enough I get an error if I attempt to misuse it for a 2D integral:

julia> quadgk( h, 0, pi/2, 0, pi/2)
ERROR: `h` has no method matching h(::Float64)

文档确实建议有一些用于集成的外部软件包,但未命名.我猜一个这样的包可以做二维积分.这种任务最好的软件包是什么?

The documentation does suggest there are some external packages for integration, but doesn't name them. I'm guessing that one such package can do two dimensional integrals. What's the best such package for this task?

推荐答案

我想您想检查一下Cubature软件包:

I think you'll want to check out the Cubature package:

https://github.com/stevengj/Cubature.jl

可以说,应该将quadgk从标准库中删除,因为它有局限性,并且会误导人们不要寻找要进行集成的软件包.

Arguably, quadgk should simply be removed from the standard library because it's limited and just misleads people into not looking for a package to do integration.

这篇关于如何在Julia中进行两个变量数值积分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆