问题标签 [mpmath]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
286 浏览

python-3.x - mpmath : 无法创建 mpf

我想使用 mpmath.quad 来评估通过 sympy 简化的函数的积分值。

然后我使用了以下代码

但收到此错误消息

我尝试另一个简单的功能

并得到同样的错误信息

谁能知道是什么导致了这个错误消息以及如何正确使用四函数?

0 投票
1 回答
119 浏览

python - 我可以对时间数组进行拉普拉斯逆变换吗?

最近我想编写一些代码来进行拉普拉斯逆变换。

我使用 mpmath.invertlaplace 函数。

它工作得很好,但我想删除 for 循环以获得这个结果。

这是一个例子。

不幸的是,我不能将数组用于 mpmath.invertlaplace 函数。

我使用了另一个库或函数吗?

0 投票
2 回答
363 浏览

python - Relation between mpmath and scipy: Type Error

Scipy have a lot of special functions, in particular Bessel functions jn (always denoted by uppercase letter J_n(x)) and spherical Bessel functions spherical_jn (denoted by lowercase letter j_n(x)). On the other hand mpmath have quadosc, a special method for integrate rapidly oscillating functions, like jn and spherical_jn. The problem I had obtained is that seems that quadosc from mpmath not support, e.g, jn from scipy as an input to make this integral. I means, if I use quad imported from numpy, so nothing error of TypeError is obtained, but quad is not very appropriate to evaluate integrals of J_n(x) or j_n(x) when x is very large.

(***) In the site SymPy find by "Oscillatory quadrature (quadosc)", this example come from there.

But if I use J_n(x) imported from numpy:

then I got the following error (Edited: added the Traceback)

On the other hand, if I use quad then I got

So how can I use a function jn that come from scipy inside a quadosc of mpmath? How can I fix this error? Thanks for all help.

0 投票
1 回答
64 浏览

python - Python 3.8 下 mpmath 有问题,但在 2.7 下可以

以下 lttle 程序使用 Python 3.8 失败,但在 2.7 下可以:

代码看起来很奇怪,因为它是从一个相当大的程序中缩减而来的。我不能再削减它了。这可以使用https://www.python.org/shell/上的交互式 shell 轻松确认

错误报告是:

我错过了什么明显的东西吗?

0 投票
2 回答
5782 浏览

python - TypeError:无法根据规则“安全”将数组数据从 dtype('O') 转换为 dtype('float64')

我需要对 g(u)jn(u) 类型进行积分,其中 g(u) 是一个没有零的平滑函数,而贝塞尔函数中的 jn(u) 具有无穷大的零,但出现以下错误:

首先,我需要将变量 x 更改为变量 u 并在新变量 u 中进行积分,但是函数 u(x) 如何在解析上不可逆,因此我需要使用插值来进行数值求逆。

在此之后,积分为:

我使用quadoscfrommpmath而不是quadfromscipy因为quadosc更适合于对快速振荡函数进行积分,例如 Bessel 函数。但是,另一方面,这迫使我使用两个不同的包,通过插值计算,scipy计算贝塞尔函数和产品的积分,所以我怀疑两个不同包的混合会产生一些问题/冲突。所以当我做:dxdu_umpmathmp.besselj(n,U)dxdu_u(U) * mp.bessel(n,U)

我得到了错误:

有谁知道我该如何解决这个问题?谢谢

0 投票
0 回答
125 浏览

python - 用负参数矢量化不完全伽马函数

我正在使用 mpmaths 不完整的 gamma 函数,z 为负,复杂的积分范围为 a,b。请参阅文档:文档

这不能用 scipy 的不完整 gamma 函数来完成。我将标记的 mpmath 放在 Mathematica 的替补席上,得到了相同的结果。不幸的是,mpmaths 函数一次只能评估一个值,这意味着我必须遍历包含 z、a、b 值的数组。

我相信矢量化很难,因为对于负 z,必须递归地评估积分部分(参见这篇文章和相应的 wiki:python 中的不完整 gamma 函数?

有谁知道可以处理这个的模块?或者,如果它甚至可能的话,就没有这样的事情吗?

所以本质上:

我实际上已经实现了一些我认为在某种程度上有效的东西:

这是基于本文中的数值积分器

它非常快:

我不知道它有多好。所以这个问题稍微改变了我如何进行基准测试和/或改进它?此外,这似乎适用于固定范围。但是,我不知道如何实现两端无限边界的积分。

0 投票
0 回答
32 浏览

floating-point - mpmath 基本操作的实现细节

我需要在 OpenCL 中实现任意精度的浮点例程,我希望能够将结果与 mpmath 进行比较。

对于基本操作 +、-、*、/ 和基本函数 exp、log、sqrt 等:它是否遵循例如 IEEE 754?如果没有,是否遵循任何其他约定/标准/参考?

0 投票
1 回答
17 浏览

series - .series() 的问题和从 mpmath 的转换

我遇到了以下看似奇怪的行为(这是一个显示基本问题的测试用例)。

这会产生类似“TypeError:gmpy.mpq() 需要数字或字符串参数”的错误

另一方面,如果我将 1.0 更改为 1:

它给出了正确的答案。有人可以解释我为什么吗?

0 投票
1 回答
414 浏览

python - Python中的函数求和

我是 Python 编程的新手。来自 MATLAB 背景。我正在寻找类似于 Python 中 MATLAB 的 symsum 函数的东西。

我有我的阵列,

我想总结

然后在 a 和 y 之间绘制结果

我尝试了以下

y = nsum(lambda i: np.sin(2*i*a), [0,20])

我被困在这一点上。

编辑。MATLAB 等价物是

a = linspace(0,pi) syms i y=double(symsum(sin(2*i*a),i,0,20)

0 投票
0 回答
67 浏览

python-3.x - 数组的双曲正弦和余弦

我正在尝试为 eady 流函数模型定义一些函数,如下一行所示:

我注意到在使用以下消息获取数组的双曲 sin 和 cos 时出现错误:

我以前从未遇到过此错误消息,因此我不够熟悉,无法尝试找出解决此错误的方法。