0

I'm trying to calculate the minimum of a function using the newton-raphson(with shift) method and I get the following error: "object arrays are not supported" (the problem occurs in solve(H, gf))

Here is my code:

import numpy as np
from sympy.abc import x, y
from sympy import ordered, Matrix, hessian
from sympy.utilities.iterables import ordered
from scipy.linalg import solve
n_iter = 50
a = 1
eq = 100*(y-x**2) + (1-x**2)**2
v = list(ordered(eq.free_symbols)); v
[x, y]
x_ = [-1.2, 1]
gradient = lambda f, v: Matrix([f]).jacobian(v)
H = hessian(eq, v)
gf = gradient(eq, v)
for _ in range(n_iter):
    H = H + a * np.identity(2)
    p = solve(H, gf)
    x = x + p
print(x)
  • 2
    What exactly is your question? What is unclear to you about the error message? – mkrieger1 Jun 05 '21 at 10:30
  • what shall i do in order to fix this? I saw a similar example for solving a system of equations and i used the same technique here but it doesn't work – ted13 Jun 05 '21 at 11:03

0 Answers0