English 中文(简体)
如何解决与沙捞越的非线性等同制度?
原标题:How to solve a system of nonlinear equations with Python?

I m trying to solve this system of nonlinear equations with Python:

2y3 + y2 - y5 - x4 + 2x3 - x2 = 0
(-4x3 + 6x2 - 2x) / (5y4 - 6y2 - 2y) = 1

Here s my code:

from sympy import symbols, Eq, solve
x, y = symbols( x y )
eq1 = Eq(2*y**3 + y**2 - y**5 - x**4 + 2*x**3 - x**2, 0)
eq2 = Eq((-4*x**3 + 6*x**2 - 2*x)/(5*y**4 - 6*y**2 - 2*y), 1)
points = solve([eq1, eq2], [x,y])

I know that this system of equations have 5 solutions, however I get none with this code. Someone know how I can proceed instead?

顺便提一下,第二个公式是第一个公式的衍生结果/结果,因此,基本上Im试图在紧凑的等数1中找到所有点,其中斜体的斜坡度为1。 第一个方程式的图表是这样。

图1

我已经用Geogebra和5个答案解决这一问题。 我在试验沙尔时想看到,我是否能够利用任何沙尔图书馆来解决这个问题。

https://i.stack.imgur.com/NCQGj.png”rel=“nofollow noreferer”>。

问题回答

解决办法(在5个以下2名排雷人员中,3个)可以通过格罗伯纳办法找到(尽管我不清楚如何在基础上处理2个X-y方程式):

>>> from sympy import *

# your equations go here, then

>>> n, d = fraction((eq2.lhs-eq2.rhs).normal())
>>> sols = list(groebner((eq1,n),x,y))
>>> yy = real_roots(sols[-1])
>>> xy=list(sorted(set([(s.n(4),yi.n(4)) for e in sols[:2] for yi in yy for s in solve(e.subs(y,yi.n()))])))
>>> [d.subs(dict(zip((x,y),i))) for i in xy]
[6.697, 0, -0.1917, -0.2850, 0, -0.2850, -0.1917, 6.697]
>>> xy = [xy[i] for i in range(len(xy)) if i not in (1,4)]
>>> [i for i in xy if all(abs(v)<1e-4 for v in Tuple(eq1.lhs,n).subs(dict(zip((x,y),i))))]
[(-0.7575, 1.453), (0.2267, -0.5028), (1.106, -0.5731)]

Those are just proof-of-concept, low precision values.





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签