It's a physics promblem, I want to confirm an integration without analytic solution to have the form of f[x]=k/x^2. The data set come from a NIntegration:
{xmin, xmax, xstep} = {2, 5000000, 100000};
ydata = Table[NIntegrate[((1 - x*Cos[a])*(x - Cos[a]))/((x^2 - 2*x*Cos[a] + 1)^(3/2)) - (x - Cos[a])/((x^2 - 2*x*Cos[a] + 1)^(3/2)) + (2*(x^2)*(Sin[a])^2*(x - Cos[a]))/((x^2 - 2*x*Cos[a] + 1)^(5/2)), {a, 0, 2*Pi}, WorkingPrecision -> 100], {x, xmin, xmax, xstep}];
xdata = Table[x, {x, xmin, xmax, xstep}];
data = Partition[Riffle[xdata, ydata], 2];
fit = NonlinearModelFit[data, k/(x^2), k, x]
data sample look like this:
[![enter image description here][1]][1]
when xmin=2, no matter how large xmax is, the best estimate of coefficient k is the same -0.28, but when change the starting point to say 3 million, every time I change xmin or xmax it returns a different result, and usually it's apparently a bad regression like this:
[![enter image description here][2]][2]
Can anyone help me figure out what's happening? lots of thanks.
Update
@JimBaldwin As suggested I remove the NIntegration and use the new code for generating data:
xdata = Table[Exp[Log[2] + (Log[5000000] - Log[2]) (i - 1)/100], {i, 101}];
integrand = ((1 - x*Cos[a])*(x - Cos[a]))/((x^2 - 2*x*Cos[a] + 1)^(3/
2)) - (x - Cos[a])/((x^2 - 2*x*Cos[a] + 1)^(3/2)) + (2*(x^2)*(Sin[a])^2*(x - Cos[a]))/((x^2 - 2*x*Cos[a] + 1)^(5/2));
y = FullSimplify[Integrate[integrand, {a, 0, \[Pi]}, Assumptions -> x > 2] + Integrate[integrand, {a, \[Pi], 2 \[Pi]}, Assumptions -> x > 2]];
ydata = SetPrecision[Table[y, {x, xdata}], 100];
data = Transpose[{xdata, -ydata}];
fit = NonlinearModelFit[Log[data], k - 2 logx, k, logx]
Show[ListLogLogPlot[data],
LogLogPlot[Exp[fit[Log[x]]], {x, 2, 5000000}, PlotStyle -> Red]]
But it still returns the same(need 10 reputation to post the image, it is the same with the first image in the answer)
don't know whether I take the suggested method wrong or there is nothing improved by breaking the integration apart.


