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
0 answers

Differing results of integrals from scipy.integrate and mpmath.quad

I am integrating a function to implement the functions in this paper and I observe different outputs from scipy.integrate.quad and mpmath.quad as per the following: import mpmath as mp from scipy import integrate print(mp.quad(lambda x: x**58 *…
Anil
  • 1,097
  • 7
  • 20
0
votes
1 answer

Erorr:can't create mpf from an array while 3D plotting a function with incomplete gamma function

I would like to display my complex function in the complex domain, but I have a problem. I get the following error message: cannot create mpf from array The code is simple and I have tried to show where the problem is. I think that my mpmath cannot…
Ali AlCapone
  • 121
  • 7
0
votes
1 answer

Hexadecimal notation of square roots in Python - Sha-512

I am going over the description of Sha-512. It is mentioned that the initial hash value consists of the sequence of 64-bit words that are obtained by taking the fractional part of the first eight primes. I am trying to replicate these values in…
Josh
  • 131
  • 12
0
votes
1 answer

Why does numexpr.evaluate return an error when using functions from mpmath?

I've just started using numexpr's evaluate function and I've come across an annoying error. I want it to print, per se, sin(10), and it does that just perfectly, but if I do sec(10), I get "TypeError: 'VariableNode' object is not callable" Example…
Remfy
  • 61
  • 4
0
votes
1 answer

Matplotlib fails with `TypeError` when plotting with mpmath

I have 2D data which is very small (of order e-500) so I cannot use numpy which I would like to draw as a pcolormesh. For instance, import mpmath as mp import matplotlib.pyplot as plt import numpy as np from mpmath import e as e from mpmath import…
0
votes
0 answers

numpy.linalg.det of square array of mpmath.mpfs

I am having the following issue: >>> import numpy as np >>> import mpmath as mp >>> v1 = [mp.mpf(1), mp.mpf(2)] >>> v2 = [mp.mpf(3), mp.mpf(4)] >>> np.dot(v1,v2) mpf('11.0') >>> M2 = [[mp.mpf(1), mp.mpf(2)], [mp.mpf(3), mp.mpf(4)]] >>>…
zjs
  • 327
  • 1
  • 9
0
votes
1 answer

How to store the error/residue of mpmath.findroot for a particular input guess?

We have a specific set of equations whose solutions are highly dependent on the input guesses. If we use verbose given in the docs it displays a whole lot of extra information. We only want the error, or to be precise the RESIDUE. How do we obtain…
0
votes
1 answer

Describing the Reimann Xi Function in Python (Scipy, Mpmath, etc)

I am attempting to describe the Riemann Xi function in python for visualization. It is an entire function, with no holes or poles. When converting the math to some simple python code, I notice that there is an infinity*zero cancellation, and…
JayZenvia
  • 129
  • 5
0
votes
1 answer

Use a.any() or a.all() error in the code to solve Coupled ODE

Context: I am not sure if this is the right site to post this question, please let me know if it isn't. My aim is to solve the coupled differential equations given in the code for the Alpha Centauri star system. Code: #Import scipy, numpy and…
0
votes
0 answers

Mpmath findroot for multidimensional function error "cannot create mpf from matrix"

The following code gives the error: "TypeError: cannot create mpf from matrix(...)" where the matrix is the initialized vector. I don't understand why it wants to convert this matrix in the first place. To my understanding mpmath should be able to…
0
votes
1 answer

how to plot a graph with mpmath in python?

I need to simulate several models with interval arithmetic, the most viable package I found was: mpmath. However I am having problems with plotting the graphics. I did an initial test before applying it to the models. can anybody help me? Another…
0
votes
1 answer

separate real and imaginary parts of a function evaluated in mpmath python

I am evaluation a MeijerG function in mpmath, the result is a complex. i would like to separate real and imaginary parts to save them in a dataframe and subsequently plot them. I get an error TypeError: cannot create mpf from array followed by a…
datac
  • 39
  • 7
0
votes
1 answer

Error because of exponential function when using mpmath and sympy modules

I have the following code where I need to solve an expression to find the roots. The expression needs to be solved for omega. import numpy as np from sympy import Symbol,lambdify import scipy from mpmath import findroot, exp eta = 1.5 tau = 5…
Jan
  • 47
  • 7
0
votes
0 answers

"TypeError: cannot create mpf from d"', when "For" structure is executed

import sympy.printing as printing from IPython.display import display, Math, Latex from sympy import * from mpmath import * from sympy.codegen.ast import aug_assign, For init_printing() c, d, c_max, d_max, jzeros = symbols("c d c_max d_max…
Marco
  • 175
  • 2
  • 5
  • 21
0
votes
2 answers

installing packages for python 3.4

I have 2 version of python installed on my windows 10 machine. 3.7 and 3.4. I need to install some packages for my old python distribution 3.4. For some packages there was an executable file available and I could install those like matplotlib and…
Haribo
  • 2,071
  • 17
  • 37