mpmath

How to mpf an array?

时光毁灭记忆、已成空白 提交于 2019-12-18 02:50:56
问题 I have: import numpy as np from mpmath import * mpf(np.array(range(0,600))) But it won't let me do it: TypeError: cannot create mpf from array So what should I be doing? Essentially I'm going to have use this array and multiply element-wise with an incredibly large or incredible small number depending on circumstance (eg 1.35626567e1084 or 6.2345252e-2732 ) hence the need for mpf. More specifically I'll be using the besseli and besselk function which create the incredible large and incredible

Convert from mpf to Sympy Float without losing precision

元气小坏坏 提交于 2019-12-12 15:26:39
问题 Is there any way to do this? For example in the code below I lose precision: >>> from sympy import * >>> from sympy.mpmath import * >>> mp.dps = 50 >>> a = mpf('1.0')/mpf('3.0') >>> a mpf('0.33333333333333333333333333333333333333333333333333311') >>> b = Float(a,50) >>> b 0.33333333333333331482961625624739099293947219848633 回答1: Converting to a string first seems to do the trick: >>> from sympy import * >>> from sympy.mpmath import * >>> mp.dps = 50 >>> a = mpf('1.0')/mpf('3.0') >>> a mpf('0

Precision loss numpy - mpmath

你。 提交于 2019-12-11 04:00:00
问题 I use numpy and mpmath in my Python programm. I use numpy, because it allows an easy access to many linear algebra operations. But because numpy's solver for linear equations is not that exact, i use mpmath for more precision operations. After i compute the solution of a System: solution = mpmath.lu_solve(A,b) i want the solution as an array. So i use array = np.zeros(m) and then do a loop for setting the values: for i in range(m): array[i] = solution[i] or for i in range(m): array.put([i]

Cannot create mpf from a complex number when calling qr_solve

萝らか妹 提交于 2019-12-10 22:58:28
问题 I make the following imports: from sympy.matrices import Matrix as sy_matrix import sympy.mpmath as sy_mp Create my matrices like this: sysMat = sy_matrix([[0.0]*sz1]*sz2) resVec = sy_matrix([[0.0]]*sz2) .Populate then with python complex numbers (eg 1.0+1.0j) and then call: coeffVec = sy_mp.qr_solve(sysMat, resVec) However I get the following exception: File "..\RatSMat.py", line 69, in solve self.coeffVec = sy_mp.qr_solve(self.sysMat, self.resVec) File "C:\Python27\lib\site-packages\sympy

Python mpmath not arbitrary precision?

别来无恙 提交于 2019-12-08 17:50:30
I'm trying to continue on my previous question in which I'm trying to calculate Fibonacci numbers using Benet's algorithm. To work with arbitrary precision I found mpmath . However the implementation seems to fail above certain value. For instance the 99th value gives: 218922995834555891712 This should be ( ref ): 218922995834555169026 Here is my code: from mpmath import * def Phi(): return (1 + sqrt(5)) / 2 def phi(): return (1 - sqrt(5)) / 2 def F(n): return (power(Phi(), n) - power(phi(), n)) / sqrt(5) start = 99 end = 100 for x in range(start, end): print(x, int(F(x))) mpmath provides

Python mpmath not arbitrary precision?

霸气de小男生 提交于 2019-12-08 03:24:06
问题 I'm trying to continue on my previous question in which I'm trying to calculate Fibonacci numbers using Benet's algorithm. To work with arbitrary precision I found mpmath . However the implementation seems to fail above certain value. For instance the 99th value gives: 218922995834555891712 This should be (ref): 218922995834555169026 Here is my code: from mpmath import * def Phi(): return (1 + sqrt(5)) / 2 def phi(): return (1 - sqrt(5)) / 2 def F(n): return (power(Phi(), n) - power(phi(), n)

Create mpf from array

余生长醉 提交于 2019-12-04 06:01:54
问题 I'm trying to use fsolve in combination with the mpmath package. However, I get the error cannot create mpf from array([mpf('1.0')], dtype=object) . Here is a minimal example reproducing the error. For this example, I technically do not need the mpmath package, but my actual function contains hyperconfluent functions that do. from scipy.optimize import fsolve #from mpmath import hyp1f1 as hyp1f1mp #from mpmath import gamma as gammamp import mpmath as mp #import numpy as np mp.dps = 250; mp

Create mpf from array

橙三吉。 提交于 2019-12-02 09:32:51
I'm trying to use fsolve in combination with the mpmath package. However, I get the error cannot create mpf from array([mpf('1.0')], dtype=object) . Here is a minimal example reproducing the error. For this example, I technically do not need the mpmath package, but my actual function contains hyperconfluent functions that do. from scipy.optimize import fsolve #from mpmath import hyp1f1 as hyp1f1mp #from mpmath import gamma as gammamp import mpmath as mp #import numpy as np mp.dps = 250; mp.pretty = True def cosFunc(p): vn = p output = mp.sin(vn) return output estimate = mp.mpf(1) value =

sympy and mpmath give “TypeError: cannot create mpf” when using the erf() function within solveset()

一曲冷凌霜 提交于 2019-12-02 07:27:47
I have 4 input variables (floats): Xmax Xmin percentage mode and I want to solve the following (rather long) equation for s: > (1/2+1/2*erf((log(Xmax)-(log(mode)+s**2))/(sqrt(2)*s))-(1/2+1/2*erf((log(Xmin)-(log(mode)+s**2))/(sqrt(2)*s))) - percentage == 0 I want to use mpmath and sympy to solve the equation, but it gives me the following error message: TypeError: cannot create mpf from 0.707106781186547*(-s**2 - 0.287682072451781)/s My code is as follows: from mpmath import erf, log, sqrt from sympy import Symbol, solveset, S percentage = 0.95 mode = 2 Xmin = 1. Xmax = 1.5 s = Symbol('s') eqn

sympy and mpmath give “TypeError: cannot create mpf” when using the erf() function within solveset()

梦想与她 提交于 2019-12-02 07:07:03
问题 I have 4 input variables (floats): Xmax Xmin percentage mode and I want to solve the following (rather long) equation for s: > (1/2+1/2*erf((log(Xmax)-(log(mode)+s**2))/(sqrt(2)*s))-(1/2+1/2*erf((log(Xmin)-(log(mode)+s**2))/(sqrt(2)*s))) - percentage == 0 I want to use mpmath and sympy to solve the equation, but it gives me the following error message: TypeError: cannot create mpf from 0.707106781186547*(-s**2 - 0.287682072451781)/s My code is as follows: from mpmath import erf, log, sqrt