Springs3

Here is the damped oscillator and its generic solution:

de1 = x''[t]+ 2 γ x'[t] + ω0^2 x[t] == 0
DSolve[de1,x[t],t]
s1 = %[[1]] (* take the first and only solution, i.e. remove some {}'s *)

A typical problem might involve determining C[1] and C[2] from some initial value data,
in which case we write and solve a pair of linear equations given the position and velocity at time t=0:

x[t]/. s1/. t->0
D[x[t]/. s1,t]/.t->0
Solve[{%==v0,%%==x0},{C[1],C[2]}]

If we specify the boundary conditions, DSolve will determine the constants for us:

DSolve[{de1,x[0]==x0,x'[0]==v0},x[t],t]//FullSimplify

Note the expression in terms of Sinh and Cosh, which are a convenient way
of writing sums of exponentials.  For the underdamped case we find our 
sinusoids using  Cosh[I t] = Cos[t] and Sinh[I t] = I Sin[t].
If we specify numerical values for the parameters, DSolve will give the appropriate expressions:

p1= {ω0->1,γ->1/10,x0->1,v0->0}
DSolve[{de1,x[0]==x0,x'[0]==v0}/.p1,x[t],t]
x1[t_] = x[t]/.%[[1]]

Observe how the result is plainly real, as it should be when starting from real boundary conditions.
Express the period in terms of givens, and plot some number of cycles

T = 2 π / Sqrt[ω0^2-γ^2]/.p1
Plot[x1[t],{t,0,2T}]

Note the zero crossing comes “late” (i.e. later than π/2 in the 2π cycle):

FindRoot[x1[t],{t,1}]
(t/.%)/(π/2)

Here is the energy and a LogPlot as a function of time.

e[t_] = (1/2) (x1'[t])^2 + (1/2)(ω0/.p1)^2 x1[t]^2//Simplify
LogPlot[e[t],{t,0,2T}]

And here is an animation tool.

osc[x_,a_:2,b_:8]:= {ParametricPlot[{(a)+t*(x+b-a),Sin[2 Pi 6 t]},{t,0,1},PlotStyle->Red,Axes->False][[1]],{Brown,Disk[{a,0},.2]},
{Black,Rectangle[{x+b-1/4,-1/4},{x+b+1/4,1/4}]}}
Animate[Graphics[osc[x1[t]],PlotRange->{{0,12},{-1,1}}],{t,0,4T}]

Now add a driving force and ask for the generic solution

de2 = x''[t]+ 2 γ x'[t] + ω0^2 x[t] == Cos[ω t]
s2=DSolve[de2,x[t],t]//Simplify

Let’s pick out that long time non-decaying piece and then find the amplitude of oscillations in the straightforward way:

x2[t_] = x[t]/. s2[[1]] /. {C[1]->0,C[2]->0}
peaktime=Solve[x2'[t]==0,t];
x2[t]/.peaktime[[2]]//FullSimplify[#,Assumptions->{γ>0,ω>0,ω0>0,C[1]==0}]&
amp[ω_,ω0_,γ_] = %;

p2= {ω0->1,γ->1/4,ω->.1}
Animate[Graphics[{osc[x2[t]/.p2,3+Cos[(ω/.p2) t]],{Green,Dashed,Line[{{3,-1},{3,1}}],Line[{{8,-1},{8,1}}]}},PlotRange->{{0,12},{-1,1}}],{t,0,20π}]

Here is the phenomenon of resonance, i.e. a peak in the amplitude when driving at the natural frequency:

Manipulate[LogPlot[amp[ω,ω0,γ],{ω,0,3}],{{ω0,1},0,2},{{γ,1/10},0,1}]