how to solve $x''=f(x)$ numerically?

I know how to solve when $f(x)$ is linear, but how to solve the equation $x''=f(x)$ with $f$ a unknown nonlinear function using numerical methods?

Any references would be helpful. Thanks!

Update: Sorry that I am not clear about it, what I mean is the exact form of $f$ is unknown, but you can think it as a black box and you can get values at any points from $f$.

• If $f$ is truly unknown, you're somewhat dead in the water with respect to numerical methods. You can do $(x')^2/2=\int f(x)\,x'\,dt=\int f(x)\,dx,$ for a single formal integration, but that's about as far as you can get. – Adrian Keister Aug 27 '18 at 18:36
• Perhaps instead of saying an "unknown" function, one may ask about a "black box" function $f$, i.e. the internal details are unknown but we can evaluate it at any point. – hardmath Aug 27 '18 at 18:55
• I think you need to clarify what you mean by "unknown". As written, this is like asking "How can you solve an equation when you don't know what is on the right-hand side?" The obvious answer is you can't. – mweiss Aug 27 '18 at 19:07
• I think that, with high probability, Sherry really means "a general nonlinear function" rather than "a unknown nonlinear function." Indeed Sherry is contrasting to the "linear function" case, for which "general nonlinear function" seems to be the most appropriate opposite case. So, the answer that was (unfortunately) deleted was likely the answer being sought by the asker. – Michael Aug 27 '18 at 19:46

Generally you convert the second order ODE in the first order: $$\begin{pmatrix} v'\\ x' \end{pmatrix} = \begin{pmatrix} f(x)\\ v \end{pmatrix}$$

Here I used a notation common in mathematical physics where generally the new variable $v$ is the velocity, i.e. the first derivate.

Now you use a double step:

• first you solve $v' = f(x)$
• after you solve $x' = v$

Until this point there is no difference between the linear and the non linear case.

The difference is the choice of the numerical method. For the non linear case an implicit method involve to solve non linear equation, this can be a delicate passage where you must determine how and which solution to consider. For example think the case that come from a dynamic problem where $f$ is quadratic with the velocity and try to use the most simple implicit method as Eulero implicit.

So in general you use IMEX methods where you use an explicit discretization for the non linear terms and implicit for the linear terms. In your problem you do not know the form of $f$ and you can not split the operator, so you can use an explicit numerical scheme for the first equation and an implicit scheme for the second. As explicit scheme you can choice, for example, a scheme as Adam-Bashord

For some equation is possible to solve it without the reduction to the first order, see Numerov's method