Questions tagged [mpmath]

Mpmath is a Python library for arbitrary-precision floating-point arithmetic.

Mpmath is a pure-Python library for multiprecision floating-point arithmetic. It provides an extensive set of transcendental functions, unlimited exponent sizes, complex numbers, interval arithmetic, numerical integration and differentiation, root-finding, linear algebra, and much more. Almost any calculation can be performed just as well at 10-digit or 1000-digit precision, and in many cases mpmath implements asymptotically fast algorithms that scale well for extremely high precision work. Mpmath internally uses Python's builtin long integers by default, but automatically switches to GMP/MPIR for much faster high-precision arithmetic if gmpy is installed or if mpmath is imported from within Sage.

Mpmath is free (BSD license) and easy to install or include in other software due to being written entirely in Python with no additional required dependencies. It runs on Python 2.5 or higher, including Python 3.x. It can be used as a library, interactively via the Python interpreter, or via SymPy which uses it for numerical evaluation of symbolic expressions. Mpmath is also a standard component of Sage which uses it for special function evaluation.

If matplotlib is available, mpmath also provides a convenient plotting interface.

169 questions
0
votes
1 answer

Acess the SDPA-GMP solver from mpmath

I do have code in mpmath that does the main part of what i do, except soling a semidefinite programming in arbitrary precision. For that, i might be able to use SDPA-GMP, a C++ piece of software that solves a SDP in arbitrary precision using GMP as…
lrnv
  • 1,038
  • 8
  • 19
0
votes
1 answer

Why am I getting 'float() argument must be a string or a number, not 'mpc'' when trying to plot mpmath.pcfd?

I'm trying to use mpmath for parabolic cylinder functions as I need to be able to use complex variable inputs, which scipy.special.pbdv doesn't allow, but I keep getting the following error when plotting: Traceback (most recent call last): File…
PewtDmD
  • 3
  • 1
0
votes
0 answers

NumPy exponential of MPC's arrays

I'm trying to define the exponential of the wave equation which is e^(ik(x-ct)). This is new for me, so I'm trying to understand MPC's arrays with real and imaginary numbers, and what do they mean. I'm trying to rewrite a code originally in Matlab…
0
votes
0 answers

Hyperbolic sin and cos of an array

I'm trying to define some function for an eady stream function model as shown in the next line: # Geometry of the wave / domain / mean state: Lx = 3800 # Zonal Wavelength in km H = 10000 # tropopause…
0
votes
1 answer

Summation of a function in Python

I'm new to Python programming. Coming from a MATLAB background. I'm looking something similar to symsum function from MATLAB in Python. I have my array, a = np.linspace([0,3.14]) I want to sum sin(2*i*a) where i ranges from 1 to 20 and then plot…
Venus8588
  • 15
  • 6
0
votes
1 answer

issues with .series() and conversion from mpmath

I came across the following seemingly bizarre behavior (this is a test case showing the basic issue). from sympy import * dz = symbols('dz') f = 1/(dz - (1.0+I)) f1.series(dz,0,1) this gives an error like "TypeError: gmpy.mpq() expects numeric or…
woody
  • 3
  • 2
0
votes
0 answers

mpmath implementation details for basic operations

I need to implement arbitrary precision floating point routines in OpenCL and I'd like to be able to compare results with mpmath. For basic operations +,-,*,/ and basic functions exp, log, sqrt etc: does it follow eg IEEE 754 ? And if not is there…
Jim
  • 135
  • 4
0
votes
2 answers

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…
Diogo
  • 64
  • 2
  • 7
0
votes
1 answer

Can I make inverse laplace transformation on time array?

Recently I want to make some code to make inverse Laplace transformation. I use mpmath.invertlaplace function. It works quite well, but I want to remove for loop to get this result. Here is an example. import mpmath as mp def func = lambda s: 1 /…
0
votes
1 answer

mpmath : cannot create mpf

I want to use mpmath.quad to evaluate an integral value of a function simplified by sympy. Then I used the following code from sympy import * import mpmath as mp r = symbols("r") f = 4**(-r)*r*(0.115391565000863*2**r +…
TingYu
  • 3
  • 2
0
votes
1 answer

How can I do a numerical inverse Laplace transform of a data array?

I would like to perform a numerical inverse Laplace transform on an array of data using Python. I found an algorithm in mpmath called invertlaplace, however it accepts only lambda functions.
Imaginary
  • 135
  • 1
  • 7
0
votes
2 answers

Is there any alternative to lambda in mpmath.nsum()?

I was using mpmath's nsum() function for summation operation from 1 to inf. like this but lambda is one line function and my equations are so long like ∑_(n=1)^∞▒e^(〖-n〗^2 )/(n^2+ 4〖(a-b)〗 for simple one line summation equations it works but for…
0
votes
2 answers

mpmath and precision issue

The precision of mpmath.sqrt(2) is not what I expected. What am I doing wrong? import mpmath as mp mp.prec = 20 mp.nprint(mp.sqrt(2), 20) result: 1.4142135623730951455 expected: 1.4142135623730950488 (according to this reference)
0
votes
1 answer

How to fix TypeError when using mpmath.nsum() and scipy.special.gamma()?

I am implementing some mathematical formulas in Python and I get the following error when I use mpmath.nsum() TypeError: ufunc 'gamma' not supported for the input types, and the inputs could not be safely coerced to any supported types according to…
Watermelon
  • 72
  • 1
  • 6
0
votes
0 answers

Numpy with mpmath uses single thread for matrix multiplication

I'm working on a numpy matrix adj which represent the adjacency matrix of some networkx graph. When I construct adj as follows: adj = sparse.csr_matrix(nx.adjacency_matrix(graph), dtype='longdouble').todense() and later run adj = adj ** 2, then I…
A.Budziak
  • 27
  • 6