python迭代法求解非线性方程,用python求解非线性方程组

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 particular system are pretty big and copying them over is quite hard.

Example:

sigma*(y-x) = 0

x*(rho-z)-y = 0

x*y-beta*z = 0

You should get the solutions:

[[x = 0, y = 0, z = 0], [x = sqrt(beta*rho-beta), y = sqrt(beta*rho-beta), z = rho-1],

[x = -sqrt(beta*rho-beta), y = -sqrt(beta*rho-beta), z = rho-1]]

The reason I ask: I have a large system of nonlinear ODEs. I want to solve for the fixed points (this is doable, it's been done in maple, but they are large and ugly). I want to create further expressions from the fixed points and then use optimisation package in scipy. I'd rather do it all in python than translate things back and forth since it is very inefficient and mistakes can be made.

解决方案

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).

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值