简体   繁体   中英

Error while trying to solve a system of long coupled differential equations [on hold]

I know that this question is repeated but I just cant find the error!!

Here are my equations and I don't have lists but used vectors to collect my parameters because I have many of them. when I try to run the code I got the following error message.

--------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-234b5ee352cc> in <module>
     51               +gamma42*(a[4,2]*x4)/(y2+a[4,2]*h[4,2]*x4))    
     52     return [dx1dt,dx2dt,dx3dt,dx4dt,dy1dt,dy2dt]
---> 53 print( dynamical_model_bacteria([10,2,3,4,5,8],0))

<ipython-input-3-234b5ee352cc> in dynamical_model_bacteria(x, t)
     29     gamma42=4
     30     dx1dt=x1*(r1*(1-(sigma[1,1]*x1+sigma[1,2]*x2+sigma[1,3]*x3+sigma[1,4]*x4)/K)\
---> 31     -(a[1,1]*y1)/(y1+a[1,1]*h[1,1]*x1)-(a[1,2]*y2)/(y2+a[1,2]*h[1,2]*x1))+s[1]
     32 
     33     dx2dt=x2*(r2*(1-(sigma[2,2]*x2+sigma[2,1]*x1+sigma[2,3]*x3+sigma[2,4]*x4)/K)\

TypeError: can't multiply sequence by non-int of type 'numpy.float64'

also why it is not possible to multiply a list with a float? My code:

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
import scipy as scp
from scipy.integrate import solve_ivp
def dynamical_model_bacteria(x,t):
    x1=x[0]
    x2=x[1]
    x3=[2] 
    x4=x[3]
    y1=x[4]
    y2=x[5]
    K=500
    sigma=np.ones((4,4))
    a=np.array((4,2))
    h=np.array((4,2))
    h_p=2
    s=0*np.ones((4,1))
    r=np.array([5,1,2,3,4])
    r1=r[0]
    r2=r[1]
    r2=r[2]
    r3=r[3]
    epsilon=np.array([2,5])
    omega12=2
    omega21=4
    K11=500
    K22=1000
    b12=2
    beta=np.ones((4,1))
    gamma12=1
    gamma22=2
    gamma32=3
    gamma42=4
    dx1dt=x1*(r1*(1-(sigma[1,1]*x1+sigma[1,2]*x2+sigma[1,3]*x3+sigma[1,4]*x4)/K)\
    -(a[1,1]*y1)/(y1+a[1,1]*h[1,1]*x1)-(a[1,2]*y2)/(y2+a[1,2]*h[1,2]*x1))+s[1]

    dx2dt=x2*(r2*(1-(sigma[2,2]*x2+sigma[2,1]*x1+sigma[2,3]*x3+sigma[2,4]*x4)/K)\
    -(a[2,1]*y1)/(y1+a[2,1]*h[2,1]*x2)-(a[2,2]*y2)/(y2+a[2,2]*h[2,2]*x2))+s[2]

    dx3dt=x3*(r3*(1-(sigma[3,3]*x3+sigma[3,1]*x1+sigma[3,2]*x2+sigma[3,4]*x4)/K)\
    -(a[3,1]*y1)/(y1+a[3,1]*h[3,1]*x3)-(a[3,2]*y2)/(y2+a[3,2]*h[3,2]*x3))+s[3]

    dx4dt=x2*(r4*(1-(sigma[4,4]*x4+sigma[4,1]*x1+sigma[4,2]*x2+sigma[4,3]*x3)/K)\
    -(a[4,1]*y1)/(y1+a[4,1]*h[4,1]*x4)-(a[4,2]*y2)/(y2+a[4,2]*h[4,2]*x4))+s[4]

    dy1dt=y1*(-epsilon[0]*(1+(y2+omega21*y1)/K22)-eta12*(b12*y1)/(y2+b12*h_p*y1)\
              +beta[1,1]*(a[1,1]*x1)/(y1+a[1,1]*h[1,1]*x1)\
              +beta[2,1]*(a[2,1]*x2)/(y1+a[2,1]*h[2,1]*x2)\
              +beta[3,1]*(a[3,1]*x3)/(y1+a[3,1]*h[3,1]*x3)\
              +beta[4,1]*(a[4,1]*x4)/(y1+a[4,1]*h[4,1]*x4))
    dy2dt=y2*(-epsilon[1]*(1+(y1+omega12*y2)/K11)-(b12*y2)/(y2+b12*h_p*y1)\
              +gamma12*(a[1,2]*x1)/(y2+a[1,2]*h[1,2]*x1)\
              +gamma22*(a[2,2]*x2)/(y2+a[2,2]*h[2,2]*x2)\
              +gamma32*(a[3,2]*x3)/(y2+a[3,2]*h[3,2]*x3)\
              +gamma42*(a[4,2]*x4)/(y2+a[4,2]*h[4,2]*x4))    
    return [dx1dt,dx2dt,dx3dt,dx4dt,dy1dt,dy2dt]
print( dynamical_model_bacteria([10,2,3,4,5,8],0))

There is a typo error: x3=[2]

Should be: x3=x[2]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM