Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading