Home > Mobile >  I am trying to define the following vector function, but keep getting an error
I am trying to define the following vector function, but keep getting an error

Time:09-20

Where am I going wrong? The function:

enter image description here

The code I have written is as follows! Note the second def function is an attempt to integrate it using solve_ivp! please let me know if there are any issues there as well:

def fun(s, rho_0, rho_1):
return lambda t, s:np.dot(np.array([0.775416, 0,0, 0.308968]).reshape(2,2), s)   np.array([rho_0,rho_1]).reshape(2,1)

def fun2(t, rho_0, rho_1):
    res = solve_ivp(fun, [0, 5], y0 = [0, 0], t_eval=np.arange(0,5), args = (rho_0, rho_1), vectorized = True)
    return res.y[1]

fun2(t = 0, rho_0 = 0.0099532, rho_1 = 0.001699)

The error I get:

TypeError: fun() takes 3 positional arguments but 4 were given

CodePudding user response:

From the documentation, fun should take t and y as it's first two arguments. Thus, you need to define fun as follows:

fun(t, y, rho1, rho2)

That's why you're facing this error, it is passing t, y, and then the arguments specified in args (you've provided 2 arguments, so you end up with 4 in total including t and y).

  • Related