I have to fit a Cos^2 function to data I measured. The function is $a \cos^2(\frac{bx\pi}{180}+c)+d $ and I tried the FindFit and Linear Model Function. I have 4 datasets which I have to fit, the first one worked. The other three only yielded not usable fits. I am pretty new to Mathematica so I hope its just a newbie mistake which is easy to fix.
Here's a minimal example:
data45 = Import["data45.txt", "table"]
{{0, 132}, {20, 279.5}, {40, 289}, {60, 312}, {80, 307}, {100,
173}, {120, 92}, {140, 25}, {160, 44.5}, {180, 109.5}, {200,
230.5}, {220, 305}, {240, 339}, {260, 246.5}, {280, 181.5}, {300,
92.5}, {320, 32}, {340, 43}}
FindFit[data45, a Cos[(b x Pi)/180 + c]^2 + d, {a, b, c, d}, x]
{a -> 45.2733, b -> 0.886263, c -> 39.01, d -> 157.974}
This yields the following fit of the data:
Which is not usable.
I would really appreciate some help!
Greetings
a Cos[(b x 𝜋)/180 + c]^2 + d == a/2 Cos[(b x 𝜋)/90 + 2 c] + (d + a/2)
you may be better off (in terms of numerics) to fit a cosine instead of a squared cosine, and then re-interpret the fitting parameters. A further advantage of this would be that you can get an initial guess of the fitting parameters from looking at the peak of the Fourier transform. $\endgroup$