Solving system of nonlinear equations with python

前端 未结 3 1895
面向向阳花
面向向阳花 2021-01-12 06:54

Can I solve a system of nonlinear equations in terms of parameters in python? Is there a example or tutorial? I can do this easily in maple, but the expressions for my parti

3条回答
  •  青春惊慌失措
    2021-01-12 07:22

    Reiterating @Russ's answer, this can be easily accomplished in sympy. For example:

    In [1]: import sympy as sp
    In [2]: x, y, z = sp.symbols('x, y, z')
    In [3]: rho, sigma, beta = sp.symbols('rho, sigma, beta')
    In [4]: f1 = sigma * (y - x)
    In [5]: f2 = x * (rho - z) - y
    In [6]: f3 = x * y - beta * z
    In [7]: sp.solvers.solve((f1, f2, f3), (x, y, z))
    Out[7]: 
    [(0, 0, 0),
     (-sqrt(beta*rho - beta), -sqrt(beta*(rho - 1)), rho - 1),
     (sqrt(beta*rho - beta), sqrt(beta*(rho - 1)), rho - 1)]
    

    where the output format is 3 possible tuples of the possible values for (x, y, z).

提交回复
热议问题