0

I have a system of ODEs which assume the form

enter image description here

In essence, I have the solutions B_1(t) and B_2(t) for t=5 and I am interested in finding the unknown parameters rho_1 and rho_2. The approach I took entailed: 1) define the function corresponding to the system above; 2) integrate using solve_ivp and deduct the result from the true values of B_1(t) and B_2(t); 3) finally use fsolve to find the appropriate values of rho_1 and rho_2, such that the difference between the true parameters B_1(t) and B_2(t) and the ones obtained using the tuned parameters of rho_1 and rho_2 is a zero vector. The code I have implemented for this purpose is the following:

t_eval = np.arange(0, 5)

def fun(t, s, rho_1, rho_2):
    return np.dot(np.array([0.775416, 0,0, 0.308968]).reshape(2,2), s) + np.array([rho_1, rho_2]).reshape(2,1)
    
def fun2(t, rho_1, rho_2):
    res = solve_ivp(fun, [0, 5], y0 = [0, 0], t_eval=t_eval, args = (rho_1, rho_2), vectorized = True)
    sol = res.y[:,4]-np.array([0.01306365, 0.00589119])
    return sol

root = fsolve(fun2, [0, 0])

However, I am not sure whether fsolve is not appropriate for this purpose tor there is something wrong with my code, as I get the following error:

fun2() missing 2 required positional arguments: 'rho_1' and 'rho_2'
Carl
  • 301
  • 2
  • 10
  • In terms of getting it to run, you only need to add the `args` parameter with the `rho` values `fsolve(fun2, [-1,1], args=(0,0))`. It seems to give back the initial guess, which could mean a couple of things, which you can read about [`here`](https://stackoverflow.com/questions/8562080/fsolve-always-returning-the-guess-estimate). You should be able to plug the solution back into `fun2` and get something close to zero- otherwise the root finder is failing (e.g. unstable equation behavior, ill defined search conditions, etc) – t.o. Sep 22 '22 at 04:33

0 Answers0