Dear Chris,
On 31.03.21 05:48, Chris Smith wrote:
Oscar posted code at issue https://github.com/sympy/sympy/issues/19164
for a interva-based Newton solver.
Thank you, that's very useful. I didn't know about interval arithmetic.
I just implemented the following, which works very well and helps to
increase my confidence that problems will be caught:
d_abs={}
d_problems={}
def MyAbs(x):
# check if this argument is already in dictionary
if x in d_abs:
return d_abs[x]
# see if there are any roots nearby
soln_list = nsolve_interval(x, 0.563, 0.583)
# nearby roots provide a warning message and get saved
if len(soln_list) > 0:
print('WARNING: ambiguous case found, argument of Abs() is', x)
d_problems[x]=soln_list
# Check sign, determine correct output
x1 = x.evalf(subs={a:0.573})
if x1 < 0.0:
out = -x
else:
out = x
# save into dictionary and return
d_abs[x] = out
return out
Cheers,
Bruce
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/ad1fc1d2-d8bf-1628-6723-de43e13f5ff3%40googlemail.com.