# I've some problems with modelization of differential equations

Hi ! I've a project in mathematics and I'm supposed to modelize 5 functions according to various parameters that vary (hence the use of sliders). But I can't because it is highly developed functions and I had no lessons on this program. I give you the code which gives me this error:

  File "<ipython-input-1-943112df05f1>", line 30
T.ode_solve( y_0=[lambda,Integer(0),Integer(1)-lambda,Integer(0)] , t_span=[Integer(0),Integer(150)] , params=[nu,d,B,v,c,p,beta] , num_points=Integer(1000))
^
SyntaxError: invalid syntax


Code

# y = X : – B - nuX - (lambda)cX
# y = Y : (lambda)cX - (v + nu)Y
# y = Z : (1 - p)vY - nuZ
# y = A : pvY - (d + nu)A
# y = lambda : ((beta)Y / (X + Y + Z))
# params = nu : natural death rate == 0.03125
# params = d : AIDS death rate == 1
# params = B : immigration rate of people likely == 13333.3
# params = v : conversion rate HIV-> AIDS == 0.2
# params = c : number of sexual partners == 4
# params = p : infectious HIV-positive proportion == 0.3
# params = beta : probability of transmission == 0.014
# t : temps

@interact
def interactive_function(nu = slider(0.01, 0.1, 0.005, default=0.03125),
d = slider(0, 1, 0.05, default=1),
B = slider(500, 30000, 250, default=13333),
v = slider(0, 1, 0.05, default=0.2),
c = slider(0, 50, 1, default=4),
p = slider(0, 1, 0.05, default=0.3),
beta = slider(0, 1, 0.002, default=0.014),):

def f_1(t,y,params) :
return [ -params-params*y-y*params*y , y*params*y-(params+params)*y, (1-params)*params*y-params*y, params*params*y-(params+params)*y, (params*y)/(y+y+y) ]

T = ode_solver()
T.function = f_1
T.algorithm="rk8pd"
T.ode_solve( y_0=[lambda,0,1-lambda,0] , t_span=[0,150] , params=[nu,d,B,v,c,p,beta] , num_points=1000 )

f = T.solution
X = [(x,x) for x in f]
Y = [(x,x) for x in f]
Z = [(x,x) for x in f]
A = [(x,x) for x in f]
lambda = [(x,x) for x in f]

P1 = line(X, rgbcolor='green')
P2 = line(Y, rgbcolor='pink')
P3 = line(Z, rgbcolor='red')
P4 = line(A, rgbcolor='brown')
P5 = line(lambda, rgbcolor='green')
show(P1+P2+P3+P4+P5)


Cordially, LordHorus.

PS = Sorry if my english can be wrong, I'm french :p

edit retag close merge delete

2

lambda is a reserved word in Python, so you can't use it as a variable name: pick another one.

You're trying to use lambda in the initial conditions for the system of differential equations, but then define it in terms of the solution. That's circular logic.

Oh true, sorry x) But then I got them errors :/

http://www.noelshack.com/2016-43-1477344904-sans-titre.png (http://www.noelshack.com/2016-43-1477...)

@LordHorus, to display blocks of code, either indent them with 4 spaces, or select the corresponding lines and click the "code" button (the icon with '101 010').

Can you edit your question to do that?

It's ok, paulmasson helped me on another post, thanks anyways ! :)

Okay, I'll do it for you. Please click the "edit" button to see the difference.

You can then do the same to properly display code in future questions.