Ask Your Question

Revision history [back]

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[0] = X : – B - nuX - (lambda)cX

y[1] = Y : (lambda)cX - (v + nu)Y

y[2] = Z : (1 - p)vY - nuZ

y[3] = A : pvY - (d + nu)A

y[4] = lambda : ((beta)Y / (X + Y + Z))

params[0] = nu : natural death rate == 0.03125

params[1] = d : AIDS death rate == 1

params[2] = B : immigration rate of people likely == 13333.3

params[3] = v : conversion rate HIV-> AIDS == 0.2

params[4] = c : number of sexual partners == 4

params[5] = p : infectious HIV-positive proportion == 0.3

params[6] = 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[2]-params[0]*y[0]-y[4]*params[4]*y[0] , y[4]*params[4]*y[0]-(params[3]+params[0])*y[1], (1-params[5])*params[3]*y[1]-params[0]*y[2], params[5]*params[3]*y[1]-(params[1]+params[0])*y[3], (params[6]*y[1])/(y[0]+y[1]+y[2]) ]

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[0],x[1][0]) for x in f]
Y = [(x[0],x[1][1]) for x in f]
Z = [(x[0],x[1][2]) for x in f]
A = [(x[0],x[1][3]) for x in f]
lambda = [(x[0],x[1][4]) 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)

Thanks for the help you can bring to me !

Cordially, LordHorus.

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

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

syntax

Code

# y[0] = X : – B - nuX - (lambda)cX

(lambda)cX # y[1] = Y : (lambda)cX - (v + nu)Y

nu)Y # y[2] = Z : (1 - p)vY - nuZ

nuZ # y[3] = A : pvY - (d + nu)A

nu)A # y[4] = lambda : ((beta)Y / (X + Y + Z))

Z)) # params[0] = nu : natural death rate == 0.03125

0.03125 # params[1] = d : AIDS death rate == 1

1 # params[2] = B : immigration rate of people likely == 13333.3

13333.3 # params[3] = v : conversion rate HIV-> AIDS == 0.2

0.2 # params[4] = c : number of sexual partners == 4

4 # params[5] = p : infectious HIV-positive proportion == 0.3

0.3 # params[6] = beta : probability of transmission == 0.014

0.014 # t : temps

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),):

default=0.014),):

    def f_1(t,y,params) :
     return [ -params[2]-params[0]*y[0]-y[4]*params[4]*y[0] , y[4]*params[4]*y[0]-(params[3]+params[0])*y[1], (1-params[5])*params[3]*y[1]-params[0]*y[2], params[5]*params[3]*y[1]-(params[1]+params[0])*y[3], (params[6]*y[1])/(y[0]+y[1]+y[2]) ]

 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[0],x[1][0]) for x in f]
 Y = [(x[0],x[1][1]) for x in f]
 Z = [(x[0],x[1][2]) for x in f]
 A = [(x[0],x[1][3]) for x in f]
 lambda = [(x[0],x[1][4]) 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)

Thanks for the help you can bring to me !

Cordially, LordHorus.

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