When I try to fit an exponential damped sine, it acts as if it cannot reach the amplitude at all. What do I change?

link to data: datafile

Getting data:

dane = ReadList[
dane2", Real];
dlugosc = Length[dane]/2;
czas = dane[[1 ;; dlugosc]];
napiecie = dane[[dlugosc + 1 ;; 2 dlugosc]];

dane2 = Transpose[{czas, napiecie}];


fit = NonlinearModelFit[dane2, 
   a *Exp[-b*x]*Sin[c*x + d], {a, b, c, d}, x, Method -> Automatic];

Show[{ListPlot[dane2, PlotRange -> All], 
  Plot[fit[x], {x, 0, 600}, PlotStyle -> Red, 
   PlotLabel -> "Automatyczne dopasowanie wielomianu", 
   AxesLabel -> {"x", "y"}]}]

Plot: enter image description here

  • $\begingroup$ Try Method -> "NMinimize"! $\endgroup$ Commented Feb 9 at 11:59
  • $\begingroup$ @UlrichNeumann I've tried it before, nothing changes $\endgroup$
    – hubvoy
    Commented Feb 11 at 7:51
  • $\begingroup$ Please provide a minimal working example including some data . I won't/can't download from your google link $\endgroup$ Commented Feb 11 at 9:36
  • $\begingroup$ Just as @UlrichNeumann have mension, fit = NonlinearModelFit[dane2, a*Exp[-b*x]*Sin[c*x + d], {a, b, c, d}, x, Method -> "NMinimize"]; Show[{ListPlot[dane2, PlotRange -> All], Plot[fit[x], {x, 0, 600}, PlotStyle -> Red, PlotRange -> All, PlotLabel -> "Automatyczne dopasowanie wielomianu", AxesLabel -> {"x", "y"}]}] $\endgroup$
    – cvgmt
    Commented Feb 12 at 4:42

2 Answers 2


NonlinearModelFit requires parameter estimates in most cases - just provide acceptable guesses for the values. I downloaded your file, added a .dat extension, so I could Import[ ] it:

dane2 = Transpose[ Import["dane2.dat"] ]

fit = NonlinearModelFit[dane2, a*Exp[-b*x]*Sin[c*x + d], {{a, 50}, {b, 0.01}, {c, 0.03}, {d, 0}}, x]

Show[ Plot[fit[x], {x, 0, 600}, PlotRange -> All], ListPlot[dane2]]

fitted function and input data


The usual methods of non-linear regression are iterative and require "guessed" or "estimated" values of the parameters to start the process. This is often a cause of difficulty when the "guessed" values are too far from the correct unknown values.

In some cases it is possible to fit the model function thanks to a different method which isn't iterative and doesn't require initial "guessed" values. The general principle is explained with several examples of application in : Regressions-et-equations-integrales

Instead of directly fitting the non-linear model equation one fit a linear integral equation to which the model equation is solution.

In case of model equation involving sine functions the accuracy of the period is critical. If the range of the data covers only a few periods the calculs is generally simple. If the number of periods is large a more accurate numerical calculs is necessary but more complicated.

The case of Damped Sine function is treated pp.54-70. For a rough approximate of the solution a simplified version is used below (called "Short way" in the referenced paper).

In the present experimental case the number of given points is 400 covering a large number of periods with among them many with very low signifiance. In order to use the simplified version only a few periods are sufficient. For example the first n=200 points are taken in account in the calculus below. Even with 100points the result would be quite the same.

enter image description here

In order to get even more accurate result the approximate values of the parameters obtained above could be used as very good initial values for performing non-linear regression thanks to any convenient available software.


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.