python - 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)
解决方案
推荐阅读
- netbeans - Netbeans.conf:用户主页的变量是什么?
- javascript - 用户选择:没有在 Safari 中表现不同
- r - 如何使用带有复选框事件 Shiny 的 observeEvent
- javascript - 当我在 html 和 css 中向下滚动时,如何使图像位于菜单栏后面?
- reactjs - 为 React+Firebase 项目分离测试/生产环境的最佳方法
- javascript - 如何在 Enzyme React 中模拟按钮单击?
- chef-infra - inspec 将单个控件作为 sudo 运行
- c - 在 C (Linux) 中查找虚拟网络接口
- oracle - 如何更改 Oracle Client 12c 第 2 版的语言
- powershell - 如何将注册表编辑器设置为根键