Use a time-series as parameter of ODEProblem

Since it’s an interpolation, you have to use the interpolation.

function test!(du,u,p,t)
    yield = 10
    decay = 5
    du[1] = yield*p(t) - decay*u[1]
end

p is just whatever you passed it. So when you did:

prob = ODEProblem(test!,u0,tspan,ts)
sol = solve(prob);

p is the LinearInterpolation object. So then yield*p tried to do multiplication between a scalar and a LinearInterpolation, which is what then causes the error message you see. But yield*p(t), well, that first interpolates p to get a scalar, then use that scalar, and it etc. does what you want.

From that description you can see how the other error you get is similar, with a similar solution to call the function.

1 Like