Suppose I have a differential equation
$\frac{d}{dt}y(t,\lambda) = f(y(t,\lambda),\lambda)$
where $\lambda$ is some parameter of the system. The initial value $y(0,\lambda)$ is specified.
I am looking for a good way to estimate $\frac{d}{d\lambda}y(t,\lambda)$ at finite $t$.
Using the RK4 method I can approximate $y$ (over small steps $h$) at time $t=(n+1)h$ as follows
$y(t,\lambda) \simeq y_{n+1} = y_n + \frac{h}{6}\left( k_1 + 2k_2 + 2k_3 + k_4 \right)$
where $y_0 = y(0,\lambda)$ and
$k_1=f(y_n,\lambda)$
$k_2=f(y_n + \frac{h}{2}k_1,\lambda)$
$k_3=f(y_n + \frac{h}{2}k_2,\lambda)$
$k_4=f(y_n + hk_3,\lambda)$
So far, so good.
Of course, I can then evaluate the derivative numerically; i.e. plug in a slightly larger value $\lambda+\epsilon$, iterate RK4 $(n+1)$ times from the initial condition to evaluate the approximation to $y(t,\lambda+\epsilon)$ and then evaluate $\frac{y(t,\lambda+\epsilon) - y(t,\lambda)}{\epsilon}$.
Is there a systematic improvement on this? I started trying to compute the derivatives of $k_1$, $k_2$ etc. by making the substitution $\lambda \to \lambda+\epsilon$ but they got messy quickly and seemed to indicate that I'd need higher-order derivatives to get correct results (which doesn't seem very much in the spirit of RK4). Also, it'll be even more complicated if I start doing multiple RK4 steps (though for the system I'm interested in, $f$ varies slowly enough that one Runge-Kutta step might potentially be sufficient; not sure).
Anyway, this seems like an obvious enough problem that I'm probably reinventing the wheel...
Update (4/25 4:24pm): corrected RHS of ODE from $f(t,\lambda)$ to $f(y(t,\lambda),\lambda)$.