# Find a numerical solution for an ODE with an initial condition which is not at the beginning

This may sound really weird...

Consider the following Cauchy problem:

Find $$y(t)$$ for all $$t \geq 0$$ such that: $$\begin{cases} \dot{y} & = f(t, y)\\ y(T) &= Y \end{cases},$$ for some $$T > 0$$.

I know that, under suitable conditions, this Cauchy problem has exactly one solution.

Anyway, all numerical tools that I know are meant (or I believe so!) to solve problems like:

Find $$y(t)$$ for all $$t \geq 0$$ such that: $$\begin{cases} \dot{y} & = f(t, y)\\ y(0) &= Y \end{cases},$$

How can I solve the first problem?

You can follow the suggestion by @LutzLehmann or you can just perform a change of variables, $$\tau = T - t$$ and get something like $$\begin{cases}y'(\tau) = - f(\tau, y(\tau)) \\[0.7em] y(0)= Y \end{cases}.$$

Ancient trade secret: You can apply the numerical methods also with a negative step size.

Most numerical tools also support this, the sequence of evaluation points, if given, just has to be monotonous. This makes two calls to the ODE solver routine, one for the interval $$[0,T]$$ and one for $$[T,T_{end}]$$

Test of concept: Plot solutions of $$y'(x)=\frac{x-y}{x+y}$$ with value $$y(2)$$ around $$2$$ for $$x\in[-1,5]$$.

f=lambda y,x: (x-y)/(x+y)
x1 = np.linspace(2,-1,150)
x2 = np.linspace(2,5,150)
for y0 in 2+np.linspace(-0.5,0.5,6):
y1,y2 = (odeint(f,y0,x) for x in (x1,x2))
l, = plt.plot(x1,y1)
c = l.get_color()
plt.plot(x2,y2,c=c,label=f"y(2)={y0}")
plt.grid(); plt.legend()
plt.show()