For x1, I am using a different formula f = @(t) K / (1 + (K / x0 - 1) * exp(-1*r*t)). If you try to input index like f(1), f(2), it outputs a number perfectly well and it should not be 0. I think there is a problem of how this formula is defined.
‘I think there is a problem of how this formula is defined.’
I agree. However since your coding for it is all that I have to work with, this is the best that I can do with it. Check to be certain that ‘r’ and ‘K’ have the correct values.