Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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]

Plot of the solution

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".

share|improve this question
    
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

1 Answer 1

up vote 6 down vote accepted
(*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]}]]

Mathematica graphics

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.

share|improve this answer
    
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
1  
@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] –  belisarius Nov 3 '13 at 16:24
1  
@IvánVladimirGonzálezBustos For T < .5 the maxima found is unreliable –  belisarius Nov 3 '13 at 16:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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