user3026610 - 1 year ago 72

R Question

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.

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

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.

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**