0

I have set up a differential equation using the deSolve package and ode-function in R. I have the values for y(1), however I need to find y(0). Is there any function in R that allows me to calculate backwards and find y(0) values - the actual initial state? I am only finding forward calculations examples online.

Any help is useful! Thank you

Phil
  • 7,287
  • 3
  • 36
  • 66
Mandy94
  • 37
  • 4
  • 1
    Interesting question. Can you just negate the value of your derivative(s) (i.e., the value(s) returned by the `func` function in `lsoda()`)? Alternatively, will `lsoda` and similar accept negative values for the `times` vector? I have never tried it. – sashahafner Mar 11 '22 at 18:55
  • 1
    See https://stackoverflow.com/questions/40580485/how-to-specify-final-value, the desolve package should be sophisticated enough to handle a sample time array that is falling. Some other example in python https://math.stackexchange.com/questions/3930911/find-a-numerical-solution, note that underlying both is the ODEPACK Fortran library. – Lutz Lehmann Mar 11 '22 at 19:09
  • 1
    Here I have to admit that, as far as I remember, the solvers of deSolve cannot integrate backwards. The underlying ODEPACK solvers can, but the extensions cannot. But, there was a workaround posted some time ago in the r-sig-dynamic-models mailing list. And, another package can possible do. – tpetzoldt Mar 12 '22 at 07:15
  • Here the link to the beforementioned post from Karline, the package author: https://stat.ethz.ch/pipermail/r-sig-dynamic-models/2011q3/000086.html – tpetzoldt Mar 13 '22 at 10:50
  • Thank you all for your input! Informative link tpetzoldt, thank you! I tried negating the values as sashahafner mentioned, and also the steps @LutzLehmann (from the other question) by simply changing the time steps from c(1, 0) and parameters when necessary. So now I have an estimation of y(0) - but whether the differential equation is actually valid when time steps are reversed is a different question. – Mandy94 Mar 14 '22 at 16:08
  • @tpetzoldt : The linked post does however not say that it is impossible by implementation to run the integration backwards, but that backwards integration of this specific SIR example runs into dynamical instabilities forcing the step size to effective zero. This is not really astonishing as SIR backwards is as unstable diverging from as SIR forwards is stable converging towards the equilibrium. A more simple model of that would be `y'=-y^2`. – Lutz Lehmann Mar 14 '22 at 16:53

0 Answers0