I have a nonlinear differential equation as follows
\begin{align} \ddot{x}(t) = f(\theta(t),k), \end{align}
where $f$ is a function of the time variable $t \in \mathbb{R}^{+}$, $k \in \mathbb{R}$ is the designed parameter, and $\theta(t)$ is a known function of time. The function $\theta(t)$ only depends on time and it is a quite complicated so I cannot integrate to find $x(t)$ and $\dot{x}(t)$ analytically.
My task is: compute the parameter $k$ such that following initial/terminal conditions should be met as good as possible:
\begin{align} x(0) = 0, \quad \dot{x}(0) = 0, \quad x(t_{f}) = \bar{x}, \end{align}
where the terminal time $t_{f}$ and the value of $\bar{x}$ are both known.
My question is: is there any elegant way to solve such problem?
My current idea: I will formulate an optimization problem as below:
\begin{align} &\min \quad J = x^{2}(0) + \dot{x}^{2}(0) + [x(t_{f}) - \bar{x}]^2 \\ & \quad {k} \end{align}
Then I will use a nonlinear programmer to solve. But I think it is a bit brute to solve in that way.
I appreciate any suggestion. Thank you!