首页 > 解决方案 > Newton_Raphson 换档

问题描述

我正在尝试使用 newton-raphson(with shift) 方法计算函数的最小值,但出现以下错误:“不支持对象数组”(问题出现在求解(H,gf)中)

这是我的代码:

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)

标签: pythonnewtons-method

解决方案


推荐阅读