I am struggling with a function that supposedly has a numerical error. I checked for consistency which seems to be fine but I couldn't find the stability error nor attempt to correct it.
where c = 1-r^(-d) and d =[1:100]
The function is struggling with small values of r and I should, therefore, find a way to redefine it but after two days of trial and error I couldn't come up with a solution.

Use $$1-\cos\theta=2\sin^2\frac\theta2.$$