"Use DSolve to analytically solve some commond second order differential equations"
dsol1=
DSolve[{u''[x]+a*u'[x]+b*u[x]==0},u[x],x];
usolNBC[xdum_]:=u[x]/.dsol1[[1]]/.{x->xdum};
"usolNBC[x] is the analaytical solution without boundary conditions"
"usolNBC[x]="
usolNBC[x]

"So, now you can define your values of a, b for the homogeneous 2nd order DE and boundary conditions and obtain the analytical solutions directly by using usolNBC[x]"

"Example 4.1, without bondary conditions"
a=5;b=6;
"usolNBC[x]="
usolNBC[x]

"Slot in two boundary condidtions which are expressed in terms of u[x00]=u0;u'[x01]=up0"
(* boundary condiditions*)
(*x00=0;u0=1;
x01=0;up0=0;
*)
dsol2:=
DSolve[{u''[x]+a*u'[x]+b*u[x]==0,u'[x01]==up0,u[x00]==u0},u[x],x];
usolBC[xdum_]:=u[x]/.dsol2[[1]]/.{x->xdum};
"usolBC[x] is the analaytical solution with boundary conditions"
"u[x00]=u0;u'[x01]=up0"
"usolBC[x]="
Simplify[usolBC[x]]

"Example 4.2, with bondary conditions"
a=6;b=9;
x00=0;u0=2;
x01=0;up0=0;
"usolBC[x]="
usolBC[x]

"We now use DSolve to obtain the analytical solution for example 4.6"
a=-1;b=-2;
n[x_]:=Sin[2x];
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]

"We now use DSolve to obtain the analytical solution for example 4.8"
a=0;b=4;
n[x_]:=2Sin[2x];
"uNHsolNBC[x]="
uNHsolNBC[x]
Simplify[uNHsolNBC[x]]