-
Notifications
You must be signed in to change notification settings - Fork 205
Closed
Description
from mpmath import *
y = lambda x: pi*(7.92e-24*x*(1 - exp(2.47376311844078e-6/x)) + 3.91844077961019e-30*exp(2.47376311844078e-6/x))/(x**7*(1 - exp(2.47376311844078e-6/x))**2)I'm trying to find the root that is visible in the plot above close to 0.5e-6. However, findroot finds a different root:
>>> mp.dps = 15
>>> findroot(y, 0.5e-6, verbose=True)
x: 0.2500005
error: 0.25
mpf('0.2500005')
So, instead, I specify an interval, but I get an error:
>>> mp.dps = 15
>>> findroot(y, (0.4e-6, 0.6e-6))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/finefoot/.local/lib/python3.9/site-packages/mpmath/calculus/optimization.py", line 985, in findroot
raise ValueError('Could not find root within given tolerance. '
ValueError: Could not find root within given tolerance. (1.21186214334073616909e-17 > 2.16840434497100886801e-19)
Try another starting point or tweak arguments.
However, I am successful with both a lower as well as a higher value for mp.dps:
>>> mp.dps = 10
>>> findroot(y, (0.4e-6, 0.6e-6))
mpf('4.982288428783e-7')
>>> mp.dps = 20
>>> findroot(y, (0.4e-6, 0.6e-6))
mpf('4.9822884287834956804705e-7')
How can this be explained? Unfortunately, the docs on root-finding and optimization https://www.mpmath.org/doc/current/calculus/optimization.html don't mention mp.dps at all.
Furthermore, if I enable verbose=True for the previous call with mp.dps = 15, it looks like the root was indeed found - despite what the error says:
>>> findroot(y, (0.4e-6, 0.6e-6), verbose=True)
x: 5.3578149929971142579e-7
error: 1.9999999999999999095e-7
x: 4.72164087189809447005e-7
error: 6.42185007002885470587e-8
x: 5.02383012597846992377e-7
error: 6.36174121099019787856e-8
x: 4.98641817056914280534e-7
error: 3.02189254080375453729e-8
x: 4.98221655157573724369e-7
error: 3.74119554093271184333e-9
x: 4.98228855137876342545e-7
error: 4.20161899340556164784e-10
x: 4.98228842878712985304e-7
error: 7.1999803026181755294e-12
x: 4.98228842878349568029e-7
error: 1.22591633572409451659e-14
x: 4.98228842878349568047e-7
error: 3.63417275350997737668e-19
x: 4.98228842878349568047e-7
error: 1.847827784389698053e-26
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/finefoot/.local/lib/python3.9/site-packages/mpmath/calculus/optimization.py", line 985, in findroot
raise ValueError('Could not find root within given tolerance. '
ValueError: Could not find root within given tolerance. (1.21186214334073616909e-17 > 2.16840434497100886801e-19)
Try another starting point or tweak arguments.
Reactions are currently unavailable
