"We will use the generic code of DSolve for analytically solving a second order non-homegeneos differential equation to solve the equations of motions of pendulum"

"Simple pendulum. No drag force. No external force"
a=0;b=g/l;
n[x_]:=0;
dsol4:=
DSolve[{u''[x]+a*u'[x]+b*u[x]==n[x]},u[x],x];
uNHsolNBC[xdum_]:=u[x]/.dsol4[[1]]/.{x->xdum};
"uNHsolNBC[x] is the analaytical solution without boundary conditions with a non-zero non-homegeneous term"
"uNHsolNBC[x]="
uNHsolNBC[x]

"Pendulum with drag force. No external force"
a=q;b=g/l;
n[x_]:=0;
dsol4:=
DSolve[{u''[x]+a*u'[x]+b*u[x]==n[x]},u[x],x];
uNHsolNBC[xdum_]:=u[x]/.dsol4[[1]]/.{x->xdum};
"uNHsolNBC[x] is the analaytical solution without boundary conditions with a non-zero non-homegeneous term"
"uNHsolNBC[x]="
uNHsolNBC[x]

"Pendulum with drag force. No external force"
"whether a pendulum is under-, over- or critically damped is dependent on the relative magnitude of Omega = Sqrt[g/l] and (1/4)*(k/m), where (k/m) = q "

"Let's test three casses: Omega << q/4; Omega >> q/4 and Omega = q/4"

g:=9.81;l:=1;a:=q;b:=g/l;
Omega:=Sqrt[g/l];
T:=2Pi*Sqrt[l/g];
n[x_]:=0;
x00:=0;(*initial time*)
x01:=0;(*initial time*)
u0:=0.2;(*initial displacement*)
up0:=0;(*initial angular speed at t=0*)

dsol4:=
DSolve[{u''[x]+a*u'[x]+b*u[x]==n[x],u[x00]==u0,u'[x01]==up0},u[x],x];
uNHsolBC[xdum_]:=u[x]/.dsol4[[1]]/.{x->xdum};

"First case, overdamped: Set Omega << q/4 
=> q >> 4 Omega = 4 Sqrt[g/l]"

q=5*(4Omega);

"uNHsolNBC[x] is the analaytical solution for a non-homegeneous second order DE with specified boundary conditions"
"uNHsolBC[x]="
uNHsolBC[x]
plt1=Plot[uNHsolBC[t],{t,0,5T},PlotLabel->{"q,4Omega=",{q,4Omega}},PlotRange->All,PlotStyle->Red];
plt1

"Second case, underdamped: Set Omega >> q/4 
=> q << 4 Omega = 4 Sqrt[g/l]"
q:=0.1*(4Omega);
"uNHsolNBC[x] is the analaytical solution for a non-homegeneous second order DE with specified boundary conditions"
"uNHsolBC[x]="
uNHsolBC[x]
plt2=Plot[uNHsolBC[t],{t,0,5T},PlotLabel->{"q,4Omega=",{q,4Omega}},PlotRange->All,PlotStyle->Blue];
plt2

"Thid case case, critically damped: Set Omega = q/4 
=> q = 4 Omega = 4 Sqrt[g/l]"
q:=4Omega;
"uNHsolNBC[x] is the analaytical solution for a non-homegeneous second order DE with specified boundary conditions"
"uNHsolNBC[x]="
uNHsolBC[x]
plt3=Plot[uNHsolBC[t],{t,0,5T},PlotLabel->{"q,4Omega=",{q,4Omega}},PlotRange->All,PlotStyle->Black];
plt3

Show[plt1,plt2,plt3]

"Analytical solution for forced, underdamped pendulum"
q:=0.1*(4Omega);
FD:=1;m:=q*l;
OmegaD=1.75*Omega;
n[x_]:=FD*Sin[OmegaD*x];

"uNHsolBC[x] is the analaytical solution with boundary conditions with a non-zero non-homegeneous term"
"uNHsolBC[x]="
uNHsolBC[x]
plt4=Plot[Re[uNHsolBC[t]],{t,0,5T},PlotLabel->{"q,4Omega=",{q,4Omega}},PlotRange->All,PlotStyle->Black];
plt4

"Analytical solution for forced, undamped pendulum"
a:=0;b:=g/l;
FD:=1;m:=1;l:=1;
OmegaD:=0.99Omega;
n[x_]:=FD*Sin[OmegaD*x]/(m*l);

"uNHsolBC[x] is the analaytical solution with boundary conditions with a non-zero non-homegeneous term"
"uNHsolBC[x]="
uNHsolBC[x]
plt4=Plot[uNHsolBC[t],{t,0,20T},PlotLabel->{"q,4Omega=",{q,4Omega}},PlotRange->All,PlotStyle->Black];
plt4

OmegaD:=1.99Omega;
plt4:=Plot[uNHsolBC[t],{t,0,20T},PlotLabel->{"q,4Omega=",{q,4Omega}},PlotRange->All,PlotStyle->Black];
plt4