# Find maximum from NDSolve output

Here is my code:

rawdata = http://pastebin.com/fgeZrSCp (* I hope pastebin is OK *)

f[x_] := Interpolation[rawdata, InterpolationOrder->1][(x + 1)*10]
(* just creating a function with the data *)
d = 0.05;
T = 0.8;
wn = 2 Pi/T;
wd = wn*Sqrt[1 - d^2];

sol =
NDSolve[{xx''[t] + 2 d wn*xx'[t] + wn^2 xx[t] == -f[t], xx[0] == 0, xx'[0] == 0}, xx,
{t, 0, 65}, MaxSteps -> 500000];
Plot[Evaluate[xx[t] /. sol], {t, 0, 65}, PlotRange -> All]


My goal is to get the maximum value of Abs[xx[t]]. How can I do this in an efficient way?

Note that d and T can change. In this particular example the maximum should be around 0.052.

Context: Structural Dynamics, I'm trying to find a "response spectrum".

-
Well, you can't use NDSolve if you do not have a numerical value for d and T. So, once these are set, and you get your solution xx[t] from NDSolve, then you can use many of Mathematica maximum related functions, may be NMaxValue migth do it. "gives the maximum value of f with respect to x." reference.wolfram.com/mathematica/ref/NMaxValue.html – Nasser Nov 3 '13 at 5:21

(*just creating a function with the data*)
d = 0.05;
T = 0.8;
wn = 2 Pi/T;
wd = wn*Sqrt[1 - d^2];
f[x_] := Interpolation[rawdata, InterpolationOrder -> 1][(x + 1)*10] ;
sol = NDSolve[{xx''[t] + 2 d wn*xx'[t] + wn^2 xx[t] == -f[t], xx[0] == 0,
xx'[0] == 0}, xx, {t, 0, 65}, MaxSteps -> 500000];
Show[Plot[Abs[xx[t]] /. sol, {t, 0, 65}, PlotRange -> All],
Graphics[{Red, PointSize[Large],
Point@{t /. #[[2]], #[[1]]} &@ NMaximize[{Abs[xx[t]] /. sol[[1]], 1 < t < 65}, t]}]]


NMaximize always attempts to find a global maximum of f subject to the constraints given.

If f and cons are linear, NMaximize can always find global maxima, over both real and integer values.

Otherwise, NMaximize may sometimes find only a local maximum.

-
Thank you so much! Now I have to iterate through T to plot a curve of the maxima found and it's taking a year. Would it be possible to make my code run faster? (Should I open a new question for that?) – Ivan Nov 3 '13 at 15:59
@IvánVladimirGonzálezBustos sol = ParametricNDSolve[{xx''[t] + 2 d 2 Pi /T xx'[t] + (2 Pi/T)^2 xx[t] == -f[t], xx[0] == 0, xx'[0] == 0}, xx, {t, 0, 65}, {T}, MaxSteps -> 500000]; ss = Table[ NMaxValue[{Abs[xx[T][t]] /. sol[[1]], 1 < t < 65}, t], {T, .55, 3, .125}] ListPlot[ss, Joined -> True] – Dr. belisarius Nov 3 '13 at 16:24
@IvánVladimirGonzálezBustos For T < .5 the maxima found is unreliable – Dr. belisarius Nov 3 '13 at 16:25