Alright I have some data I want to fit using a function I know.
data={7783.52,7763.52,7804.15,7782.85,7606.1,7529.88,7541.92,7498.92,7544.81,7594.85,7469.69,7222.08,6958.88,6879.17,6889.06,6891.73,6805.94,6700.71,6478.79,6286.9,6025.6,5812.06,5700.92,5617.63,5562.48,5581.15,5482.96,5446.83,5248.6,5118.35,5030.38,4911.35,4717.25,4638.33,4450.75,4244.48,4109.38,4095.5,3989.44,4023.46,3960.42,3937.88,3890.94,3739.92,3556.4,3417.06,3282.96,3178.1,3129.85,2998.65,2943.69,2852.4,2824,2827.29,2862.67,2784.71,2658.15,2571.81,2490.88,2426.5,2405.88,2411.5,2476.65,2460.15,2391.88,2395.1,2335.58,2287.94,2287.44,2258.25,2213.81,2145.44,2083.92,2016.02,2007.75,2086.63,2128.38,2023.54,2008.46,2018.67,2066.35,2072.35,2080.73,2001.58,1898.58,1881.21,1930.35,1982.42,1933.96,1962.83,1970.31,1962.83,1933.96,1982.42,1930.35,1881.21,1898.58,2001.58,2080.73,2072.35,2066.35,2018.67,2008.46,2023.54,2128.38,2086.63,2007.75,2016.02,2083.92,2145.44,2213.81,2258.25,2287.44,2287.94,2335.58,2395.1,2391.88,2460.15,2476.65,2411.5,2405.88,2426.5,2490.88,2571.81,2658.15,2784.71,2862.67,2827.29,2824,2852.4,2943.69,2998.65,3129.85,3178.1,3282.96,3417.06,3556.4,3739.92,3890.94,3937.88,3960.42,4023.46,3989.44,4095.5,4109.38,4244.48,4450.75,4638.33,4717.25,4911.35,5030.38,5118.35,5248.6,5446.83,5482.96,5581.15,5562.48,5617.63,5700.92,5812.06,6025.6,6286.9,6478.79,6700.71,6805.94,6891.73,6889.06,6879.17,6958.88,7222.08,7469.69,7594.85,7544.81,7498.92,7541.92,7529.88,7606.1,7782.85,7804.15,7763.52,7783.52} This is a dataset of Z values as function of degree, so I make a table for the fit.
datatofit=Transpose[{Table[n*Pi/180, {n, 0, 180}], data}] Now I define the function I want to fit with.
orbital00[t_]:= 1+i*LegendreP[2,Cos[t]] orbital22[t_]:= 1+j*LegendreP[2,Cos[t]] orbital02[t_]:= 1+k*LegendreP[2,Cos[t]] intensity[t_]:=a*((1-c^2)*orbital00[t]+c^2*orbital22[t]*WignerD[{2, 0, 0}, t]^2 +2*c*Sqrt[1-c^2]*orbital02[t]*WignerD[{2, 0, 0}, t]) Alright let's try to fit. And I'm helping with coefficients very close to what I am looking for.
NonlinearModelFit[datatofit,intensity[t], {{a, 3600}, {c, .45}, {i, -.3}, {j, 1}, {k, .4}}, t] I get an error
The function value (some list) is not a list of real numbers with dimensions {181} at {a,c,i,j,k} = {-215905.,-53.542,151.348,302.937,136.279} Now, I insists, these coefficients are actually very close to the ones I am looking for, as if the function intensity[t] is plotted while replacing variables by the values provided, it is extremely close.
When trying to fit the data with a function A+B*Cos[t], it works (but that's not the function I am looking for).
I don't understand the error I have, and why I have it. I understand the function is complex but I am giving good starting parameters.
Origin 8 manages to do it quite easily.
