I am trying to fit sinusoids to my experimental data of the form: $y= a+b sin(\theta)+csin(2\theta)+dsin(4\theta)$ and I am using the non-linear fit model. However I feel the data fitting is not good, how can I iteratively improve my fit? Here is my code
Position50K ={2.29398, 16.4984, 31.471, 45.8031, 57.4666, 69.7218, 81.0981, \
92.5701, 106.796, 121.909, 136.564, 149.898, 160.087, 172.138, \
185.383, 196.216, 209.591, 221.267, 231.311, 244.509, 258.118, \
273.437, 287.129, 298.899, 310.201, 323.688, 335.386, 348.173, \
361.205, 365.005};
Torque50K ={6.19*10^-8, 5.46*10^-8, 5.24*10^-8, 4.69*10^-8, 4.49*10^-8,
4.37*10^-8, 4.41*10^-8, 4.52*10^-8, 4.76*10^-8, 5.08*10^-8,
5.37*10^-8, 5.78*10^-8, 6.24*10^-8, 6.55*10^-8, 7.04*10^-8,
7.32*10^-8, 7.59*10^-8, 7.76*10^-8, 7.94*10^-8, 8.13*10^-8,
8.32*10^-8, 8.13*10^-8, 8.16*10^-8, 8.06*10^-8, 7.89*10^-8,
7.63*10^-8, 7.4*10^-8, 7.04*10^-8, 6.66*10^-8, 6.76*10^-8};
Torquedata50K = Transpose@{Position50K, Torque50K};
nlm = NonlinearModelFit[Torquedata50K,
a + b*Sin[x*\[Pi]/180] + c*Sin[x*\[Pi]/90] +
d*Sin[4 x*\[Pi]/180], {a, b, c, d}, x] (*x is in degrees*)
nlm["BestFitParameters"];
Show[ListPlot[Torquedata50K, PlotStyle -> Black],
Plot[nlm[x], {x, 0, 365}, PlotStyle -> Red]]
Now basically, I want to subtract the constant term and $sin(\theta)$ term from my raw data so that I can get the $sin(2\theta)$ and $sin(4\theta)$ variation. So I did this in code
BaseTorque[x_] :=
6.495726466567145`*^-8 - 1.9304374060084893`*^-8 Sin[(\[Pi] x)/180]; (*what I obtained from fitting*)
Torque50Knew = Torque50K - BaseTorque /@ Position50K;
Torque50KnewData = Transpose@{Position50K, Torque50Knew};
Show[ListPlot[Torque50KnewData, PlotStyle -> Black],
Plot[test[x], {x, 0, 365}, PlotStyle -> Red]]
You can clearly see neither my subtracted data, nor the fits look good. What can I do to improve my fitting?
p1
,p2
, andp3
as innlm = NonlinearModelFit[Torquedata50K, a + b*Sin[x*\[Pi]/180 + p1] + c*Sin[x*\[Pi]/90 + p2] + d*Sin[4 x*\[Pi]/180 + p3], {a, b, c, d, {p1, 0}, {p2, 0}, {p3, 0}}, x]
. $\endgroup$ – JimB Oct 10 '19 at 23:44Fourier
orFourierDST
? $\endgroup$ – Silvia Nov 16 '19 at 6:30