我想解决以下非线性方程组。是否可以将所有变量都大于或等于零且所有参数都为正的条件设为条件?变量是(x1,x2,x3,x4,y1,y2),其他只是参数。
Maple是否比sympy更好地解决此系统?
from sympy.interactive import printing
printing.init_printing(use_latex=True)
from sympy import *
import numpy as np
import matplotlib.pyplot as plt
import sympy as sp
x1, x2, x3, x4, y1, y2 = sp.symbols('x1, x2, x3, x4, y1, y2')
N, c1, c2, c3, c4 = sp.symbols('N, c1, c2, c3, c4')
r1, r2, r3, r4 = sp.symbols('r1, r2, r3, r4')
f11, f21, f31, f41 = sp.symbols('f11, f21, f31, f41')
f12, f22, f32, f42 = sp.symbols('f12, f22, f32, f42')
eta11, eta12, eta13, eta14 = sp.symbols('eta11, eta12, eta13, eta14')
eta21, eta22, eta23, eta24 = sp.symbols('eta21, eta22, eta23, eta24')
eta31, eta32, eta33, eta34 = sp.symbols('eta31, eta32, eta33, eta34')
eta41, eta42, eta43, eta44 = sp.symbols('eta41, eta42, eta43, eta44')
epsilon1, epsilon2, K11, K22 = sp.symbols('epsilon1, epsilon2, K11, K22')
omega1, omega2, gamma12, g12 = sp.symbols('omega1, omega2, gamma12, g12')
beta11, beta21, beta31, beta41 = sp.symbols('beta11, beta21, beta31, beta41')
beta12, beta22, beta32, beta42 = sp.symbols('beta12, beta22, beta32, beta42')
F2 = x1 * (r1 * (1 - (eta11 * x1 + eta12 * x2 + eta13 * x3 + eta14 * x4) / N) - \
f11 * y1 - f12 * y2)
F3 = x2 * (r2 * (1 - (eta21 * x1 + eta22 * x2 + eta23 * x3 + eta24 * x4) / N) - \
f21 * y1 - f22 * y2)
F4 = x3 * (r3 * (1 - (eta31 * x1 + eta32 * x2 + eta33 * x3 + eta34 * x4) / N) - \
f31 * y1 - f32 * y2)
F5 = x4 * (r4 * (1 - (eta41 * x1 + eta42 * x2 + eta43 * x3 + eta44 * x4) / N) - \
f41 * y1 - f42 * y2)
F6 = y1 * (-epsilon1 * (1 + (y1 + omega2 * y2) / K22) - g12 * y2 + beta11 * f11 * x1 + \
beta21 * f21 * x2 + beta31 * f31 * x3 + beta41 * f41 * x4)
F7 = y2 * (-epsilon2 * (1 + (omega1 * y1 + y2) / K11) +gamma12 * g12 * y1 + \
beta12 * f12 * x1 + beta22 * f22 * x2 + beta32 * f32 * x3 + beta42 * f42 * x4)
equ = (F2, F3, F4, F5, F6, F7)
sol = nonlinsolve(equ, x1, x2, x3, x4, y1, y2)
print(sol)
答案 0 :(得分:1)
您可以在符号中添加假设。关于哪些求解器遵循这些假设,文档对我有些困惑,但是从the docs看来nonlinsolve
确实遵循了这些假设:
x1,x2,x3,x4,y1,y2=sp.symbols('x1,x2,x3,x4,y1,y2', nonnegative=True)
N,c1,c2,c3,c4=sp.symbols('N,c1,c2,c3,c4', positive=True)
答案 1 :(得分:1)
这是一个多项式系统,我们可以将其转换为标准格式
In [2]: equ = [eq.as_numer_denom()[0].expand() for eq in equ]
In [3]: for eq in equ: pprint(eq)
2
-N⋅f₁₁⋅x₁⋅y₁ - N⋅f₁₂⋅x₁⋅y₂ + N⋅r₁⋅x₁ - η₁₁⋅r₁⋅x₁ - η₁₂⋅r₁⋅x₁⋅x₂ - η₁₃⋅r₁⋅x₁⋅x₃ - η₁₄⋅r₁⋅x₁⋅x₄
2
-N⋅f₂₁⋅x₂⋅y₁ - N⋅f₂₂⋅x₂⋅y₂ + N⋅r₂⋅x₂ - η₂₁⋅r₂⋅x₁⋅x₂ - η₂₂⋅r₂⋅x₂ - η₂₃⋅r₂⋅x₂⋅x₃ - η₂₄⋅r₂⋅x₂⋅x₄
2
-N⋅f₃₁⋅x₃⋅y₁ - N⋅f₃₂⋅x₃⋅y₂ + N⋅r₃⋅x₃ - η₃₁⋅r₃⋅x₁⋅x₃ - η₃₂⋅r₃⋅x₂⋅x₃ - η₃₃⋅r₃⋅x₃ - η₃₄⋅r₃⋅x₃⋅x₄
2
-N⋅f₄₁⋅x₄⋅y₁ - N⋅f₄₂⋅x₄⋅y₂ + N⋅r₄⋅x₄ - η₄₁⋅r₄⋅x₁⋅x₄ - η₄₂⋅r₄⋅x₂⋅x₄ - η₄₃⋅r₄⋅x₃⋅x₄ - η₄₄⋅r₄⋅x₄
2
K₂₂⋅β₁₁⋅f₁₁⋅x₁⋅y₁ + K₂₂⋅β₂₁⋅f₂₁⋅x₂⋅y₁ + K₂₂⋅β₃₁⋅f₃₁⋅x₃⋅y₁ + K₂₂⋅β₄₁⋅f₄₁⋅x₄⋅y₁ - K₂₂⋅ε₁⋅y₁ - K₂₂⋅g₁₂⋅y₁⋅y₂ - ε₁⋅ω₂⋅y₁⋅y₂ - ε₁⋅y₁
2
K₁₁⋅β₁₂⋅f₁₂⋅x₁⋅y₂ + K₁₁⋅β₂₂⋅f₂₂⋅x₂⋅y₂ + K₁₁⋅β₃₂⋅f₃₂⋅x₃⋅y₂ + K₁₁⋅β₄₂⋅f₄₂⋅x₄⋅y₂ - K₁₁⋅ε₂⋅y₂ - K₁₁⋅g₁₂⋅γ₁₂⋅y₁⋅y₂ - ε₂⋅ω₁⋅y₁⋅y₂ - ε₂⋅y₂
SymPy将尝试使用Groebner基础解决此问题,但计算该过程将花费很长时间:
In [4]: groebner(equ, [x1,x2,x3,x4,y1,y2]) # Not sure how long this takes
我希望即使完成了结果也不会接受解析解,因为求解可能会导致多项式大于4阶。
如果您用具体的有理数替换所有参数,则有可能找到一个解决方案,但否则就任意符号(r3
等)而言,我不希望采用封闭形式的解决方案存在-如果是真的,那么您使用Maple还是SymPy还是其他都没关系。
编辑:我现在看到您的系统是什么。每个方程都是x1 * (a*x1 + b*x2 + ...)
形式,因此它是一个线性方程乘以未知数之一。这意味着存在两种可能性:x1 = 0
或线性方程式均满足。因此,一种解决方案是x1 = x2 = ... = 0
,然后是另一种解决方案,其中都不为零。有6个未知数,有64种可能的解决方案,除了一些可能不满足非负性假设的情况。您可以使用
from sympy.interactive import printing
printing.init_printing(use_latex=True)
from sympy import *
import numpy as np
import matplotlib.pyplot as plt
import sympy as sp
x1, x2, x3, x4, y1, y2 = sp.symbols('x1, x2, x3, x4, y1, y2', nonnegative=True)
N, c1, c2, c3, c4 = sp.symbols('N, c1, c2, c3, c4', positive=True)
r1, r2, r3, r4 = sp.symbols('r1, r2, r3, r4', positive=True)
f11, f21, f31, f41 = sp.symbols('f11, f21, f31, f41', positive=True)
f12, f22, f32, f42 = sp.symbols('f12, f22, f32, f42', positive=True)
eta11, eta12, eta13, eta14 = sp.symbols('eta11, eta12, eta13, eta14', positive=True)
eta21, eta22, eta23, eta24 = sp.symbols('eta21, eta22, eta23, eta24', positive=True)
eta31, eta32, eta33, eta34 = sp.symbols('eta31, eta32, eta33, eta34', positive=True)
eta41, eta42, eta43, eta44 = sp.symbols('eta41, eta42, eta43, eta44', positive=True)
epsilon1, epsilon2, K11, K22 = sp.symbols('epsilon1, epsilon2, K11, K22', positive=True)
omega1, omega2, gamma12, g12 = sp.symbols('omega1, omega2, gamma12, g12', positive=True)
beta11, beta21, beta31, beta41 = sp.symbols('beta11, beta21, beta31, beta41', positive=True)
beta12, beta22, beta32, beta42 = sp.symbols('beta12, beta22, beta32, beta42', positive=True)
F2 = (r1 * (1 - (eta11 * x1 + eta12 * x2 + eta13 * x3 + eta14 * x4) / N) - \
f11 * y1 - f12 * y2)
F3 = (r2 * (1 - (eta21 * x1 + eta22 * x2 + eta23 * x3 + eta24 * x4) / N) - \
f21 * y1 - f22 * y2)
F4 = (r3 * (1 - (eta31 * x1 + eta32 * x2 + eta33 * x3 + eta34 * x4) / N) - \
f31 * y1 - f32 * y2)
F5 = (r4 * (1 - (eta41 * x1 + eta42 * x2 + eta43 * x3 + eta44 * x4) / N) - \
f41 * y1 - f42 * y2)
F6 = (-epsilon1 * (1 + (y1 + omega2 * y2) / K22) - g12 * y2 + beta11 * f11 * x1 + \
beta21 * f21 * x2 + beta31 * f31 * x3 + beta41 * f41 * x4)
F7 = (-epsilon2 * (1 + (omega1 * y1 + y2) / K11) - gamma12 * g12 * y1 + \
beta12 * f12 * x1 + beta22 * f22 * x2 + beta32 * f32 * x3 + beta42 * f42 * x4)
equ = ((x1, F2), (x2, F3), (x3, F4), (x4, F5), (y1, F6), (y2, F7))
from itertools import product
for eqs in product(*equ):
sol = solve(eqs, [x1, x2, x3, x4, y1, y2])
pprint(sol)
给出:
$ python t.py
{x₁: 0, x₂: 0, x₃: 0, x₄: 0, y₁: 0, y₂: 0}
[]
[]
⎧ ε₂⋅(K₁₁⋅(K₂₂⋅g₁₂ + ε₁⋅ω₂) - K₂₂⋅ε₁) ε₁⋅(-K₁₁⋅ε₂ + K₂₂⋅(K₁₁⋅g₁₂⋅γ₁₂ + ε₂⋅ω₁
⎨x₁: 0, x₂: 0, x₃: 0, x₄: 0, y₁: ───────────────────────────────────────────────, y₂: ──────────────────────────────────────────
⎩ ε₁⋅ε₂ - (K₂₂⋅g₁₂ + ε₁⋅ω₂)⋅(K₁₁⋅g₁₂⋅γ₁₂ + ε₂⋅ω₁) ε₁⋅ε₂ - (K₂₂⋅g₁₂ + ε₁⋅ω₂)⋅(K₁₁⋅g₁₂⋅γ₁₂ + ε
)) ⎫
─────⎬
₂⋅ω₁)⎭
⎧ N ⎫
⎨x₁: 0, x₂: 0, x₃: 0, x₄: ───, y₁: 0, y₂: 0⎬
⎩ η₄₄ ⎭
⎧ N⋅ε₂⋅(K₁₁⋅f₄₂ + r₄) K₁₁⋅r₄⋅(N⋅β₄₂⋅f₄₂ - ε₂⋅η₄₄)⎫
⎪x₁: 0, x₂: 0, x₃: 0, x₄: ──────────────────────────, y₁: 0, y₂: ───────────────────────────⎪
⎨ 2 2 ⎬
⎪ K₁₁⋅N⋅β₄₂⋅f₄₂ + ε₂⋅η₄₄⋅r₄ K₁₁⋅N⋅β₄₂⋅f₄₂ + ε₂⋅η₄₄⋅r₄⎪
⎩ ⎭
⎧ N⋅ε₁⋅(K₂₂⋅f₄₁ + r₄) K₂₂⋅r₄⋅(N⋅β₄₁⋅f₄₁ - ε₁⋅η₄₄) ⎫
⎪x₁: 0, x₂: 0, x₃: 0, x₄: ──────────────────────────, y₁: ───────────────────────────, y₂: 0⎪
⎨ 2 2 ⎬
⎪ K₂₂⋅N⋅β₄₁⋅f₄₁ + ε₁⋅η₄₄⋅r₄ K₂₂⋅N⋅β₄₁⋅f₄₁ + ε₁⋅η₄₄⋅r₄ ⎪
⎩ ⎭
... (continues)
空解[]
对应于已知不满足非负性要求的情况。