【问题标题】:Finding the roots of a system of non-linear equations that has multiple roots with python fsolve使用 python fsolve 查找具有多个根的非线性方程组的根
【发布时间】:2022-08-04 14:10:32
【问题描述】:

我有以下非线性方程组,我想找到它的根源:

  • x - exp(a x + b y) = 0
  • y - exp(c x + d y) = 0 我用来查找其根源的代码是:
equations = lambda x, kernel: np.array([x[0] - np.exp(kernel[0] * x[0] + kernel[2] * x[1]), x[1] - np.exp(kernel[1] * x[1] + kernel[3] * x[0])])

kernels = np.array([kernel0, kernel1, kernel2, kernel3])
x_init = np.array([x_init0, x_init1])
x_sol = fsolve(two_equations, x_init, args=(kernels))

从方程中我知道,在某些情况下,这个系统对每个变量都有两个答案:(x_sol1, x_sol2) 和 (y_sol1, y_sol2)。

有没有一种干净的方法可以将多个初始猜测传递给这个 fsolve 函数以获得每个变量的两个根? (而不是使用 for 循环) 我只知道如何为一个方程组做这件事,但我不能在这种情况下使用那种方法。

  • 因此,我遇到了类似的问题,并找到了适合我的情况的解决方案。在规避for 循环方面-如果您找到方法,请发布它,因为这也会优化我的代码。查看解决方案here。它在答案的第二部分

标签: python scipy numerical-methods


【解决方案1】:

您可以通过消除y 将系统简化为单个单变量方程。

y = (ln(x) - a x) / b

以便

(ln(x) - a x) / b - exp(c x + d (ln(x) - a x) / b) = 0

【讨论】:

    猜你喜欢
    • 2012-10-14
    • 2022-10-18
    • 2016-02-10
    • 1970-01-01
    • 1970-01-01
    • 2014-03-17
    • 2017-04-22
    • 2018-09-23
    • 1970-01-01
    相关资源
    最近更新 更多