Closed RebetezG closed 4 years ago
That's an interesting question. I haven't tried this but I believe the following should work:
from symfit import Piecewise, D, parameters, variables
A, t = variables('A, t')
k1, k2 = parameters('k1, k2')
t0 = 5.0
model_dict = {
D(A, t): Piecewise((- k1 * A, t > t0), (- k2 * A, t <= t0))
}
where Piecewise
is a sympy
object which can just be imported from symfit
like everything else.
It is also possible to make t0
into a Parameter as well if that's what you need.
Good luck modeling corona virus outbreaks or whatever it is you're trying to do, and let me know if it works!
It works like a charm! Thanks for the quick response and this great package!
Excellent! Happy to hear that it worked and that you enjoy the package!
I was wondering if there was an easy way to implement ODEmodel in a piecewise manner like:
If t>to: D(A,t) = -k1 A
else: D(A,t) = -k2 A