python - 如何在 Python 中求解非线性方程组?

标签 python numpy scipy

我有一个方程组:

for i [1, N]:

        |A_i x (X - B_i)|
y_i = ------------------------
           |A_i|
the goal: find X such that it minimizes the target function:
sum_{i in [1, N]} (y_i)^2 -> min

其中 A_i, X, B_i3x1 向量,* 是标量乘法,|v|v 的欧几里得范数,x 是叉乘。

如何使用 Python(scipy.optimize?)来求解这个方程组?我之前只使用 numpy.linalg.solve 解决了 Ax = b,所以我有点困惑。

我想我应该使用Nelder-Mead simplex algorithm ,听起来正确吗?

最佳答案

基本上我最终使用了 SciPy documentation 中的代码:

import numpy as np
from scipy.optimize import minimize

# Target function
def rosen(x):
    """The Rosenbrock function"""
    return sum(100.0*(x[1:]-x[:-1]**2.0)**2.0 + (1-x[:-1])**2.0)

x0 = np.array([1.3, 0.7, 0.8, 1.9, 1.2])
res = minimize(rosen, x0, method='nelder-mead',
               options={'xtol': 1e-8, 'disp': True})

print(res.x)

关于python - 如何在 Python 中求解非线性方程组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55827156/

相关文章:

python - 从json中深度获取项目,并在python中使用默认值

python - 能够排除 python 中的某些变量

numpy - Python 中 cor.test 的 R 等价物

python - scipy splrep 的行为

python - 描述化学方程的 Scipy ODE 错误

python - 正在恢复wald分布的参数: from numpy to scipy

python - 用于在 python 中搜索视频的 Youtube API 中的 Unicode

python - Tensorflow 1.10 TFRecordDataset - 恢复 TFRecord

python - 如何在图像处理中减小图像尺寸(scipy/numpy/python)

python - 使用 numpy 中的 ctypeslib 返回错误