I need to replace a nested function with a class call. Here is the original code.
import numpy as np
from variables_3 import vars
def kinetics(y,t,b1,b2):
v = vars(*y)
def dydt(v):
return [
(b1 * v.n) + (b2 * v.c1),
(b1 * v.n) - (v.c1),
(b1 * v.n) - (v.c2)
]
dydt=dydt(v)
return dydt
In this code, variables3.py contains:
class vars:
def __init__(self, *args):
(self.n,
self.c1,
self.c2)= args
I would like my final code to look something like this:
import numpy as np
from variables_3 import vars
from equations_3 import eqns
def kinetics(y,t,b1,b2):
v = vars(*y)
dydt=eqns.dydt(v)
return dydt
What could the file equations_3.py possibly look like to do this?
I have tried:
from variables_3 import vars
class eqns:
def dydt(b1,b2,v):
return [
(b1 * v.n) + (b2 * v.c1),
(b1 * v.n) - (v.c1),
(b1 * v.n) - (v.c2)]
But that code does not work. Thanks in advance!
]in the last function.dydt, how do you expect it to function?