186 questions
5
votes
2
answers
279
views
Why are C++ and Python giving me different answers, when given (I think) the same precision?
I have this code in C++:
#include <iostream>
#include <iomanip>
#include <limits>
#include <boost/multiprecision/mpfr.hpp>
using namespace boost::multiprecision;
template<...
0
votes
0
answers
38
views
user-defined lazy mpmath constants
Can I define my own lazy mpmath constants, just like mpmath.pi and the others documented here?
In other words, can I define a constant whose value is an mpf or mpc computed
(or retrieved from memo ...
0
votes
1
answer
84
views
Legendre function comparison between mpmath and Mathematica
I am working on a project and I would like to make sure I use Legendre function correctly. I've made a simple comparison between mpmath and Mathematica and the results are different:
For mpmath in ...
0
votes
0
answers
32
views
How to serialize mpf object to raw binary bytes or bytearray in python mpmath
I'm working on a python program that uses mpmath to implement the Chunovsky algorithm for computing pi. I want to make my program log its progress to a file on regular intervals, so that I can ...
1
vote
1
answer
68
views
Plotting lambda functions in Python and mpmath.plot
I'm using the mpmath plot function (which simply uses pyplot, as far as I understood).
Consider the following code:
from math import cos, sin
import mpmath as mp
mp.plot([sin, cos], [0, 3]) # this is ...
0
votes
0
answers
125
views
How to vectorize Jacobi elliptic function calls in python with negative arguments
I've got a differential equation which I have solved exactly in terms of Jacobi elliptic functions. Now I'd like to efficiently evaluate the (exact) solution numerically for the sake of plotting and ...
2
votes
1
answer
92
views
How to subclass mpmath's mpf?
I'd like to extend mpmath's (https://mpmath.org/) number type mpf in my own class, but it does not seem to be possible to use it as a base class in the usual way.
With
import mpmath
class A(mpmath.mpf)...
0
votes
3
answers
702
views
Strings are printed like integer with scientific notation in python
a=str(141528231211101319151414.0)
print(a)
# 1.4152823121110133e+23
This string was printed with scientific notation. I do not understand why.
I am using mpmath to deal with arithmetic operations ...
0
votes
0
answers
78
views
Numerical calculations using mpmath and numpy in python get different results?
I first did a numerical calculation with numpy and the result was correct, but due to insufficient precision, it could lead to errors. So I used mpmath for the calculation instead, but I found that ...
1
vote
1
answer
643
views
Complete integral of the third kind using scipy/python and mathematica
I recently came to an issue which requires using the complete elliptical integral of the third kind. It was written as a single fuction in the form of PI(m,n). Honestly I am not familiar with this ...
0
votes
0
answers
536
views
curve_fit and mpmath.polylog
I am trying to fit (using scipy.optimize.curve_fit) using mpmath.polylog.
For this I have defined the following function
def Vendik(x, C, T0, eps_cst, Td, xsi):
integral = (np.pi**2)/6. + (Td/x) * ...
0
votes
0
answers
127
views
Is sympy evalf() using binary or decimal arithmetic?
I'm working on a numerical evaluation using the sympy evalf() package. Consider the mpmath library's introduction to precision and accuracy https://mpmath.org/doc/current/technical.html, where on
...
1
vote
1
answer
207
views
Python Sympy and mpmath give different results
I did an evaluation of mpmath and sympy and found inconsistencies, which I cannot resolve. I believe mpmath gives correct results. Please, can somebody help in resolving this?
import sympy as sp
...
0
votes
1
answer
131
views
comparing Accurrate Dot Product with mpmath
This post is not a repost, which is related solely to mpmath. But this is mainly related to the comparison between different dot product algorithms.
I have coded an accurate dot product in python in ...
0
votes
1
answer
33
views
mpmath library magnitude of number bug?
In the documentation of mpmath library page 8 it mentioned that
There is no restriction on the magnitude of numbers
>>> print(mpf(2)**32582657 - 1)
1.24575026015369e+9808357
and I checked ...
0
votes
1
answer
156
views
How to serialise an mpmath lambdified SymPy function containing Fresnel integrals?
I am using SymPy to generate some functions requiring the evaluation of Fresnel integrals and would like to save them to disk. When I sm.lambdify the expressions using the default ["scipy", &...
-1
votes
1
answer
476
views
How to find roots of a complex function with python?
I'm working with a complex function whose coordinate is omega. I formed it as follows:
from sympy import *
def alpha(n, rho, l):
return n**2 + (2*rho + 2)*n + 2*rho + 1
def beta(n, rho, l):
...
0
votes
1
answer
73
views
Casting numpy longdouble to mpmath.mpf
How can I cast np.longdouble to mpmath.mpf?
import numpy as np
import mpmath
b = np.longdouble(1.0)
a = mpmath.mpf(b)
print (a)
1
vote
1
answer
171
views
How to combine scipy interp1d with mpmath quadosc
I have a density function (from quantum mechanics calculations) to be multiplied with the spherical Bessel function with a momentum grid (momentum q 1d array, real space distance r 1d array, so need ...
0
votes
0
answers
222
views
Why is vectorize so much slower with mpmath than just math
I'm trying to lower the error of my floating point calculation, to this end I wanted to use python mpmath to utilize the arbitrary precision of the library. But I notice that it is much slower than ...
1
vote
1
answer
234
views
Using Python to find best square approximation of Piecewise Functions?
Given a parabola, $f(x)=10(x-1)^2-1,x\in \Omega =[1,2]$, find the best approximation in the space of all linear functions. The Python code is as follows:
import sympy as sym
import numpy as np
import ...
0
votes
1
answer
94
views
cannot create mpf from array error for Elliptic Integrals
I'm working on this code that requires the use of elliptic integrals to solve an equation as a function of time. Most of the code is pretty straight forward but it runs into an error on the final ...
2
votes
1
answer
897
views
Efficient way to compute the confluent Hypergeometric function for large arrays (~ 10^8 points) with complex parameters
I am working on a project related to gravitational lensing, for which I need to evaluate the confluent hypergeometric function 1F1(a,b,z) for an array z of length ~ 10^8 complex points, a = 1+0.48j ...
0
votes
0
answers
158
views
RuntimeWarning: invalid value encountered in double_scalars and RuntimeWarning: overflow encountered in double_scalars
I am coding a newmark beta numerical dynamic equation solver but I
got this error:
d:\university\payan nameh\cssr python codes\newmarkbeta_method.py:46: RuntimeWarning: overflow encountered in ...
2
votes
1
answer
555
views
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 ...