How to numerically set up to solve this differential equation? I have a 1-d differential equation:
$$\frac{\mathrm{d}f}{\mathrm{d}\theta} = c(\mathrm{max}(\sin\theta,0)-f^4)~.$$
I am given periodic boundary condition, i.e. $f(\theta) = f(2\pi+\theta)$. How would I set up a discretised form of this equation to solve for $f(\theta)$?
 A: This problem is harder than a traditional finite-differencing problem. Traditional "time"-stepping methods will not work because your boundary conditions are not in the form of an initial-value problem. 
The way you should think about this is setting up a nonlinear equation then performing Newton's method. From your periodicity requirement, you only need to consider points in $[0,2\pi)$. Generate an equispaced grid with $N+1$ points $\theta_i, \ i=0,\dots,N$ and $N$ unknowns $f_i, \ i=0,\dots,N$. Let $f$ be the vector of unknowns and let $h$ be the step size between the grid points. We can then write our problem as $$G(f) = 0,$$
where $$G(f)_i= \frac{f_{i+1}-f_{i-1}}{2h}-c(\max\{\sin\theta_i,0\}-f_i^4).$$
In your implementation, make sure that the equations for $i=0$ and $i=N$ are properly adjusted to account for the periodic conditions. Applying Newton's method with a forward difference Jacobian-vector product and a Krylov solver of your choice should do the trick for $N$ in the thousands or so.
This is all assuming that a solution exists and that your initial guess is close enough. It is also not obvious that the continuous problem has a solution, so it is possible that as you take $h\to0$, things stop making sense since you are trying to find an answer that isn't there. 
