Crossposted at SciComp SE
I'm very new to finite difference method and I am just introduced to methods of solving differential equation using finite difference method via sparse matrix method.
I find that the main idea is to approximate the differentials by central differences and writing the differential equation at different points in domain and making sparse matrices out of them.
For example, take the following 1-D boundary value problem: $$ \begin{cases} \dfrac{d^2 f(x)}{dx^2} = f(x)\\ f(0)=1,\\ f(2) = e^2. \end{cases} $$
At different points in domain with $h= 0.25$ (minimum step size), $$ \begin{cases} f(0) = 1\\ \\ \dfrac{f(0) - 2f(0.25) + f(0.5)}{h^2} - f(0.25) = 0 \\ \dfrac{f(0.25) - 2f(0.5) + f(0.75)}{h^2} - f(0.5) = 0\\ \dfrac{f(0.5) - 2f(0.75) + f(1)}{h^2} - f(0.75) = 0\\ \qquad\vdots \\ \\ f(2) = e^2 \end{cases} $$ Rewriting the above set of equations in sparse matrices, i.e. as the linear equation $A\cdot f = b$, $$ \begin{pmatrix} 1 & 0 & 0 & 0 & \cdots & 0\\ 1/h^2 & (-2/h^2 -1) & 1/h^2 & 0 & \cdots & 0\\ 0 & 1/h^2 & (-2/h^2 -1) & 1/h^2 & \cdots & \vdots\\ 0 & 0 & 1/h^2 & (-2/h^2 -1) & \cdots &\\ \vdots & \vdots & \vdots & \vdots &\ddots & 1/h^2\\ 0 &0 &\cdots & \cdots & 1/h^2 & 1\\ \end{pmatrix} \cdot \begin{pmatrix} f(0)\\ f(0.25)\\ f(0.5)\\ \vdots\\ f(2)\\ \end{pmatrix} = \begin{pmatrix} 1\\ 0\\ 0\\ \vdots\\ e^2\\ \end{pmatrix}\,, $$ then the solution becomes $f = A^{-1} \cdot b $.
Even for nonlinear differential equations, the method takes the similar footing and these sparse matrices are to be built first before going through iteration methods for solving nonlinear systems.
Now, the question that I have now is, what about differential equations that involves sin and cos of the unknown function?
For example:
$$
\frac{d^2 f(x)}{dx^2} + \sin( f(x) ) = 0
$$
or system that involves inverse, for example
$$
\frac{d^2 f(x)}{dx^2} + \frac{1}{1+f(x)} f(x) = 0 \; ?
$$
How do we tackle problems like these using finite difference sparse matrix methods?