0
$\begingroup$

I have a set of data:

data = {{-2., 0.979167}, {0., 1.}, {2., 0.959184}, {4., 0.917526}, {6., 
  0.852632}, {8., 0.833333}, {10., 0.770833}, {12., 0.717172}, {14., 
  0.621053}, {16., 0.536842}, {18., 0.452632}, {20., 0.354167}, {22., 
  0.290323}, {24., 0.252747}, {26., 0.195652}, {28., 0.16129}, {30., 
  0.204301}, {32., 0.16129}, {34., 0.2}, {36., 0.217391}, {38., 
  0.217391}, {40., 0.218391}, {42., 0.164835}, {44., 0.140187}, {46., 
  0.146667}, {48., 0.127753}, {50., 0.145455}, {52., 0.208696}, {54., 
  0.330233}, {56., 0.378995}, {58., 0.400881}, {60., 0.502439}, {62., 
  0.663462}, {64., 0.641509}, {66., 3/4}, {68., 0.82266}, {70., 
  0.888325}, {72., 0.900498}, {74., 0.837975}, {76., 0.845411}, {78., 
  0.833333}, {80., 0.817259}, {82., 0.734694}, {84., 0.659794}, {86., 
  0.557789}, {88., 0.507853}, {90., 0.412371}, {92., 0.262136}, {94., 
  0.28}, {96., 0.179245}, {98., 0.187817}, {100., 0.135922}, {102., 
  0.114286}, {104., 0.157895}, {106., 0.144385}, {108., 0.117647}}

And I wanted to fit series to find coefficients but I don't know how:

enter image description here

I know that to the series should be fitted two COMPLEX NUMBERS coefficients. "n" must be equal 3, there shouldn't be "b" coefficient. The value $9.77333 \times 10^{20}$ might be different.

The Mathematica command:

nlm = NonlinearModelFit[data, 1/n*Abs[\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(m = \(-\((n - 1)\)\)/
        2\), \(\((n - 1)\)/2\)]\(
\*SubscriptBox[\(a\), \(m\)]*Exp[
\*FractionBox[\(I*m*1.55898*
\*SuperscriptBox[\(10\), \(8\)]*x\), \(2*\[Pi]*3*
\*SuperscriptBox[\(10\), \(8\)]\)]]*b*Exp[\(-
\*FractionBox[\(5.02545*
\*SuperscriptBox[\(10\), \(6\)]*Abs[x]\), \(2*\[Pi]*3*
\*SuperscriptBox[\(10\), \(8\)]\)]\)]*Exp[\(-I\) 
\*FractionBox[\(2*\[Pi]*9.77333*
\*SuperscriptBox[\(10\), \(20\)]*x\), \(3*
\*SuperscriptBox[\(10\), \(8\)]\)]]\)\)], {Subscript[a, m]}, x, 
  MaxIterations -> 10000]
$\endgroup$
9
  • $\begingroup$ Please post actual code rather than an image. You'll get better help that way. Also, is n a known constant? Is it $a_n$ or $a_m$? $\endgroup$
    – JimB
    Apr 20, 2022 at 23:18
  • $\begingroup$ I added image to show the command which I used. It's $a_{m}$ coefficients which are complex numbers. $\endgroup$ Apr 20, 2022 at 23:20
  • $\begingroup$ I understand and that is fine. But you're expecting help but want everyone to attempt to type in the code from the image when you could just supply it? $\endgroup$
    – JimB
    Apr 20, 2022 at 23:23
  • $\begingroup$ I don't know how to paste Mathematica code here to be readable. $\endgroup$ Apr 20, 2022 at 23:24
  • $\begingroup$ Thanks! It's true that it isn't very readable here but one can easily paste in the commands and obtain readable code. $\endgroup$
    – JimB
    Apr 20, 2022 at 23:27

1 Answer 1

5
$\begingroup$

Here is one approach:

n = 5;
Array[a, n, {-1, 1} (n - 1)/2]
nlm = NonlinearModelFit[data, (1/n)*Abs[Sum[a[m]*
  E^((0. + 0.08270645772713434*I)*(-2.4749233673632412*^14 + m)*
  x - 0.0026660840292038845*Abs[x]), {m, -(n - 1)/2, (n - 1)/2}]],
  Table[a[i], {i, -(n - 1)/2, (n - 1)/2}], x];
nlm["BestFitParameters"]
(* {a[-2] -> 2.03091, a[-1] -> 1.86209, a[0] -> 1.05792, a[1] -> 0.128069, a[2] -> 0.0179921} *)

Show[Plot[nlm[x], {x, Min[data[[All, 1]]], Max[data[[All, 1]]]}, 
  WorkingPrecision -> 50], ListPlot[data, PlotStyle -> Red]]

Data and fit

I've removed the parameter $b$ because the product $b a_m$ is estimable but the individual parameters $b$ and $a_m$ are not.

If you want to determine which value of $n$ is best, then you should consider using AICc. That results in $n=13$ is the best fit (of the models considered).

n =.;
nMax = 19;
Array[a, nMax, {-1, 1} (nMax - 1)/2]
aic = Table[{n, NonlinearModelFit[data, (1/n)*Abs[Sum[a[m]*
  E^((0. + 0.08270645772713434*I)*(-2.4749233673632412*^14 + m)*x -
  0.0026660840292038845*Abs[x]), {m, -(n - 1)/2, (n - 1)/2}]], 
  Table[a[i], {i, -(n - 1)/2, (n - 1)/2}], x]["AICc"]}, {n, 1, nMax, 2}];
ListPlot[aic, PlotRange -> All, Frame -> True, 
 FrameLabel -> (Style[#, Bold, 18, Black] &) /@ {"n", 
    "\!\(\*SubscriptBox[\(AIC\), \(c\)]\)"}]

n vs AICc

$\endgroup$
3
  • 1
    $\begingroup$ I wonder about that (-2.47492*10^14 + m)....If I change it to m, I get a better looking fit: i.stack.imgur.com/j5kei.png (less error from range reduction in compute E^(I * (<bignum> + m)x) perhaps). $\endgroup$
    – Michael E2
    Apr 21, 2022 at 0:23
  • $\begingroup$ $n$ must be equal to 3. $\endgroup$ Apr 21, 2022 at 12:12
  • $\begingroup$ I don't know the subject matter so I can't justify selecting other values of $n$. However, even if there is some subject matter consideration that requires $n=3$, if other values of $n$ give lower $AIC_c$ values, then that suggests more examination of the data collection method. $\endgroup$
    – JimB
    Apr 21, 2022 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.