I have the following discrete data (6001 data points) stored in the external file called analysis: the format of data set as:
-0.32026 -0.00185
-0.32016 0.00488
-0.32005 0.01161
-0.31994 0.01834
-0.31983 0.02507
-0.31973 0.0318
-0.31962 0.03853
-0.31951 0.04526
-0.31941 0.05199
what I want is to fit the data by Fourier series, and get fitting parameters $C_n$ (n>20)
$\qquad y=\sum_n c_n \cos(nk)$,
code likes the following:
list = Import["C:\Users\mxguan\Desktop\analysis.txt", "Table"]
bothfit = Fit[list, Flatten[Table[{Cos[n*x], Sin[n*x]}, {n, 0, end}]], x];
Grid[
Table[
bothfit =
Fit[list, Flatten[Table[{Cos[n*x], Sin[n*x]}, {n, 0, end}]], x];
{
Show[{
ListPlot[list, PlotRange -> All, Joined -> True,
PlotStyle -> Directive[Red, Thickness[0.015]]],
Plot[bothfit, {x, list[[1, 1]], list[[-1, 1]]},
PlotRange -> All,PlotStyle -> Black]}, PlotRange -> {-10, 10},
ImageSize -> 350, PlotLabel ->
"Both Fit: n = " <> "0.." <> ToString[end]]
}
, {end, {70}}]
]
however,during the calculation,there are some error raiesd:
Table::iterb: Iterator {n,0,end} does not have appropriate bounds.
General::stop: Further output of Table::iterb will be suppressed during this calculation.
Fit::fitm: Unable to solve for the fit parameters; the design matrix is nonrectangular, non-numerical, or could not be inverted.
The result is that only fitting curve are plot, but I can not find the fitting parameter,is there any fault in a input?

endsupposed to be? – J. M.'s missing motivation Oct 25 '17 at 07:22endis the maximum value of series numbern. – mxguan Oct 25 '17 at 07:34end, you're getting these errors. – J. M.'s missing motivation Oct 25 '17 at 08:04end = 70;line before the one forbothfit. On another note: the function seems to be odd, so why are you fitting with cosine instead of sine? – J. M.'s missing motivation Oct 25 '17 at 09:17Table::iterb: Iterator {n,0,end} does not have appropriate bounds.is appearing precisely becauseendhas not been defined. That's the reason (the main one) you can't get the fitting parameters. – aardvark2012 Oct 25 '17 at 10:13