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

查看:21
本文介绍了如何在 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天全站免登陆