The second approach works with one minor change. The value of the delayed variable has to be passed as an argument to the function directly.
eqns = { 'x' : 'f(x, x(t - tau))'}
mycode = """
double f(double x, double x_tau) {
if (x > 1.0){
return 0.25 * x_tau / (1.0 + pow(x_tau, 10.0)) -0.1*x;
}
else{
return 0.45 * x;
}
}
"""
Although this does run, note that it cannot give a very accurate solution. This is due to the discontinuity at x=1
. More advanced solvers can explicitly handle such discontinuities (see e.g. http://www.radford.edu/~thompson/ffddes/).
If you want to stick with the pydelay solver for convenience or just to get an overview, you can try to set the maximum step size dtmax
small enough to reduce the error.