I have an ordinary differential equation:
$\quad$ $\frac{dP}{dx}$ = $f(x,P,Q)$
which I need to integrate from $x$ = $0$ to $X$, where $P$=$P_0$ at $x$=$0$.
For the moment let's assume I am using simple Euler to solve it:
$\quad$ $P_{i+1}$ = $P_i$ + $h*f(x_i,P_i,Q)$
From the solution to this I get the values of $P_i$ at each $x_i$, and in particular $P_n$ at $x$=$X$. All this works fine where $Q$ is a constant.
I now need to deal with the case where $Q$ is variable and in particular I need to find $\frac{\partial P_n}{\partial Q}$. Obviously I can do it numerically by perturbing $Q$ by a small amount $q$, rerunning the Euler solution to get $P_n'$ to give $\frac{\partial P_n}{\partial Q}$ $\approx$ $\frac{P_n'-P_n}{q}$, however this will take two Euler passes.
So I wish to do it analytically using the first Euler solution. $f$ is an analytic function and so I have all the required derivatives $\frac{\partial f}{\partial x}$, $\frac{\partial f}{\partial P}$, $\frac{\partial f}{\partial Q}$
I also need $\frac{\partial P_n}{\partial P_0}$ although I guess the solution methodology is the same as for $\frac{\partial P_n}{\partial Q}$
Any help doing this would be appreciated.
PS. I am actually using Runge Kutta for this, but am choosing Euler in this question for simplification as the solution technique is all that is important here.
Using $$ \frac{d}{dx}\frac{d}{dQ}P(x,Q)=\frac{d}{dQ}f(x,P(x,Q),Q)=\frac{∂f}{∂P}(x,P,Q)·\frac{dP}{dQ}+\frac{∂f}{∂Q}(x,P,Q) $$ you get for $V=\frac{dP}{dQ}(x,Q)$ the augmented ODE system \begin{align} P'&=f(x,P,Q)\\ V'&=f_P·V+f_Q \end{align} which you can solve like any other ODE system. It also works if $P_0$ is a compontent of $Q$.