0
votes

I would like to solve a differential equation in R (with deSolve?) for which I do not have the initial condition, but only the final condition of the state variable. How can this be done?

The typical code is: ode(times, y, parameters, function ...) where y is the initial condition and function defines the differential equation.

2

2 Answers

2
votes

Are your equations time reversible, that is, can you change your differential equations so they run backward in time? Most typically this will just mean reversing the sign of the gradient. For example, for a simple exponential growth model with rate r (gradient of x = r*x) then flipping the sign makes the gradient -r*x and generates exponential decay rather than exponential growth.

If so, all you have to do is use your final condition(s) as your initial condition(s), change the signs of the gradients, and you're done.

I initially misread your question as stating that you knew both the initial and final conditions. This type of problem is called a boundary value problem and requires a separate class of numerical algorithms from standard (more elementary) initial-value problems.

library(sos)
findFn("{boundary value problem}")

tells us that there are several R packages on CRAN (bvpSolve looks the most promising) for solving these kinds of problems.

0
votes

Given a differential equation

y'(t)=F(t,y(t))

over the interval [t0,tf] where y(tf)=yf is given as initial condition, one can transform this into the standard form by considering

x(s) = y(tf - s)  
==>  x'(s) = - y'(tf-s) = - F( tf-s, y(tf-s) )
     x'(s) = - F( tf-s, x(s) )

now with

x(0) = x0 = yf.

This should be easy to code using wrapper functions and in the end some list reversal to get from x to y.


Some ODE solvers also allow negative step sizes, so that one can simply give the times for the construction of y in the descending order tf to t0 without using some intermediary x.