# How to Find minimum and maximum using FindMaximum[] and FindMinimum[]

this is the data that i use to plot. data_damped_osccilation

this is my code so far, however it still give me error

datadamped = Import["Datadamped.txt", "Data"]
i[c_, d_, e_, t_, h_] := c *Exp[(-d*e*t) Sin[(Sqrt[1 - d^2]) e*t + h]]
datadx = NonlinearModelFit[datadamped, i[c, d, t, e, h], {c, d, e, h},
t]
NonLdataFit["BestFitParameters"];


How to find maximum and minimum? secondly how can i find first minimum and the vaues of t where this occur? thirdly how to know the exact coordinates of the second maximum at t=1.0 ?

all help is appreciated. thank you.

• Your fitting model does not seem to reproduce the behavior of your data at least for some values of the parameters. Consider for instance: Plot[i[1, 0.01, 6, t, 1], {t, 0, 5}, PlotRange -> All], which returns this: image. Commented Apr 5, 2016 at 16:15
• Do you really need a fit or you just need the maximums/minimums? Commented Apr 5, 2016 at 16:32

datadamped =
Import["http://comsics.usm.my/tlyoon/teaching/ZCE111_1516SEM2/data/\
data_A6Q2.dat", "Data"];



This gives you list of maximums and minimums. If you need a fit you probably want to simplify the fitting space and optimize for different fit parameters:

g = NonlinearModelFit[datadamped,
A Exp[-b x] Sin[c x + h], {A, b, c, h}, x]
PlotStyle -> {Blue, Red, Green}],
Plot[g[x], {x, 0, 5}, PlotStyle -> {{Dashed, Orange}}]]


Your data doesn't look real, since the fit was too good to be true :) For real data you probably want to play with parameters for FindPeaks. If you trust your fit better than your data, you can find peaks from fitted function now:

minfit = {x, g[x]} /.
Solve[g'[x] == 0 && g''[x] > 0 && x > 0 && x < 5, x]
maxfit = {x, g[x]} /.
Solve[g'[x] == 0 && g''[x] < 0 && x > 0 && x < 5, x]


And finally you can use FindMinimum if you really want to use this function:

FindMinimum[g[x], {x, 0}]


And it gives the same answer as minfit[[1]]

Now you probably want to find out your original parameters set $d,e$

params = g["BestFitParameters"]
Solve[-d e == b && Sqrt[1 - d^2] e == c /. params, {d, e}]


{A -> -0.5, b -> 0.628319, c -> -6.25169, h -> 4.71239}

{{d -> 0.1, e -> -6.28319}}

And $e$ really looks suspiciously close to $2\pi$

• FindPeaks is a useful command. thank you. @Blackow Commented Apr 6, 2016 at 3:02
• @Nabil FindPeaks is useful, but don't use it blindly. When you have real data, you almost always need to deal with noise. FindPeaks can add smoothing to your data, see more here Commented Apr 6, 2016 at 14:28