I am trying to fit dataset with a function, but with little success, as illustrated below. The blue line is the data I wish to fit, and the red line is my attempt.

Below is the function I used:
$$ g(x) = -A\sin\left(f \frac{\pi}{2}\cos(x)\right)^2 + D $$
where $A$, $f$, and $D$ are parameters. In Python,
-A*np.sin(f*(np.pi/2)*np.cos(x))**2+D
Any help would be greatly appreciated!


Half the frequency of your function (replace
xwithx / 2), and then square the entire result. The resulting function should be proportional to a rough approximation of the function you are trying to approximate, so you can just scale it down until you are happy with the result. Eyeballing it from your image, I would guess that an added factor of $0.2$ would do the trick ($10^2\div20=5$, $1\div5=0.2$). (Bear in mind that you would be multiplying your entire function by $0.5$, not dividing by $0.5$.)