Problem with SYMPY

54 views
Skip to first unread message

mkaj...@gmail.com

unread,
Mar 15, 2018, 7:24:39 PM3/15/18
to sympy
Hello.
I need your assistant.
I have my Model.
I am intrested to solve for the equilibria.

I wrote as pasted bellow, It is not giving me results

Your inputs will highly be appreciated


import sympy as sm
# define the system in this way (asuming a predator-prey-system with no negative values)
# to avoid interference x = r (for resource) and y = c (for consumer)
p,q,z,s = sm.symbols('p, q, z, s', negative=False)
a = 0.00431
b = 1.02
c = 3.41
k1 =  2
eta2 = 0.015
l1 = 20.0
e1 = 0.0412
l2 = 20.0
e2 = 0.0412
l3 = 1.36
e3 = 0.9
P = a*p*(1-b*p)-c*z*p-c*p*q+(eta2*p*q)/(l1+p)
Q = -k1*p*q+(eta2*p*q)/(l1+p)-e1*q
Z = -k1*z*p+(eta2*z*p)/(l2+p)-e2*z
S = l3-e3*s

PEqual = sm.Eq(P, 0)
QEqual = sm.Eq(Q, 0)
ZEqual = sm.Eq(Z, 0)
SEqual = sm.Eq(S, 0)
# compute fixed points
equilibria = sm.solve( (PEqual, QEqual, ZEqual, SEqual), p, q, z, s )
print(equilibria)



 

Leonid Kovalev

unread,
Mar 15, 2018, 8:03:00 PM3/15/18
to sympy
I ran your code exactly as it's posted here and got

[{s: 1.51111111111111, q: 0.0, z: 0.0, p: 0.0}, {s: 1.51111111111111, q: 0.0, z: 0.0, p: 0.980392156862745}]

I'm using SymPy 1.1.1. Perhaps your version of SymPy is old? 

By the way, it's better to use the assumption 

sm.symbols('p, q, z, s', nonnegative=True)

although this doesn't change the result. 

There is a difference: negative=False just says it cannot be negative, but it might be a complex number like 2+3*I. While nonnegative=True means it's a real number >=0.
It's rare that setting an property to False is needed, with exception of commutative=False (and that is because commutative is True by default.)  


Reply all
Reply to author
Forward
0 new messages