Given an initial guess for an array of values x
, I am trying to find the root of a system that is closest to x
. If you are familiar with finding roots of a system, you will understand that finding a root for a system of equations f
satisfies:
0 = f_1(x)
0 = f_2(x)
....
0 = f_n(x)
Where f_i
is one particular function within f
There is a package within scipy
that will do this exactly: scipy.optimize.newton_krylov
. For example:
import scipy.optimize as sp
def f(x):
f0 = (x[0]**2) + (3*(x[1]**3)) - 2
f1 = x[0] * (x[1]**2)
return [f0, f1]
# Nearest root is [sqrt(2), 0]
print sp.newton_krylov(f, [2, .01], iter=100, f_tol=Dc('1e-15'))
>>> [ 1.41421356e+00 3.49544535e-10] # Close enough!
However, I am using the decimal
package within python because I am doing extremely precise work. decimal
offers more than normal decimal precision. scipy.optimize.newton_krylov
returns float-precision values. Is there a way to get my answer at an arbitrarily precise decimal precision?