Say I have the following ODE: $\frac{d^2x}{dt^2} = k \cdot f(x,t)$ where $k$ is an unknown constant and I'm trying to solve for $k$ knowing that at $x = x_f \rightarrow \frac{dx}{dt} = v_f$. Also the initial conditions are: $t = 0 \rightarrow x = 0 \,\, \& \,\, \frac{dx}{dt} = 0$.
Furthermore, I'm attempting to solve this numerically rather than analytically.
So far I've come up with the following:
Let $\frac{d^2x}{dt^2} = \frac{dv}{dt}$ therefore we can now apply Euler's method (bear in mind that $\frac{dx}{dt} = v$):
$v_{n+1} = v_n + k \cdot f(x,y) \cdot \Delta t$
$x_{n+1} = x_n + v_n \cdot \Delta t$
$t_{n+1} = t_n + \Delta t$
where $\Delta t \approx 0$
The initial conditions have already been stated in the first paragraph. Having defined the recurrence relationship we can now iterate and plot a graph of $x(t)$. If I look at the value of $v$ at $x = x_f$ I clearly get a different result depending on the value of $k$. So the point is to find that value for $k$ such that when $x = x_f \rightarrow v = v_f$.
The "simple" solution would be trial and error, i.e, to try different values for $k$. If you exceed $v_f$ decrease $k$, otherwise, increase it and keep doing so until you're satisfied with a good enough number.
This method is the one I'm trying to avoid and I'm seeking for something a lot quicker and smarter. Any ideas?
Thanks