from pymrm import NumJac, newton
import scipy.optimize as optim
import numpy as np
# Define the objective function and its Jacobian
numjac = NumJac((2,))
def fun(x, a, b):
return np.array([a * x[0] ** 2 + b * x[1] ** 2 - 1, x[0] - x[1]])
# Initial guess
x0 = np.array([0.5, 0.5])
args = (2,3)
# Solve the system
def wrapper_fun(x, *args):
g, Jac = numjac(lambda x: fun(x, *args), x)
return g, Jac.toarray()
sol = optim.root(wrapper_fun, x0, args=args, jac=True)
print(f"Solution SciPy root:\n {sol}\n")
sol2 = newton(lambda x: numjac(lambda x: fun(x, *args), x), x0)
print(f"Solution pymrm newton:\n {sol2}\n")