"Use DSolve to analytically solve some commont first order differential equations encountered in elementary physics"

"DSolve without imposing boundary conditions"
sol0=DSolve[vy'[t]==-g,vy[t],t]
(*extract the expression of the solution from sol in the form of vysol[t_]:= *)
vysol[tdum_]:=vy[t]/.sol0[[1]]/.{t->tdum}
vysol[t]

"Include boundary condition into the solution"
sol1=DSolve[{vy'[t]==-g,vy[0]==0},vy[t],t]
(*extract the expression of the solution from sol in the form of a function of t *)
vysol[tdum_]:=vy[t]/.sol1[[1]]/.{t->tdum}
vysol[t]

sol2=DSolve[{y'[t]==vysol[t],y[0]==0},y[t],t]
ysol[tdum_]:=y[t]/.sol2[[1]]/.{t->tdum}
ysol[t]

g=9.981;
Plot[ysol[t],{t,0,1},PlotLabel->"y(t) vs. t"]
Plot[vysol[t],{t,0,1},PlotLabel->"vy(t) vs. t"]

"Solving a free fall motion with drag force"
sol3=DSolve[{m*vy'[t]==-m*g-eta*vy[t],vy[0]==0},vy[t],t]
vydsol[tdum_]:=vy[t]/.sol3[[1]]/.{t->tdum}
Simplify[vydsol[t]]
 
g=9.981;m=10;eta=1.0;
Plot[vydsol[t],{t,0,50},PlotLabel->"vy(t) vs. t",PlotRange->All]

"Solving beta particle penetrating a slab "
sol4=DSolve[{n'[x]==-lambda*n[x],n[0]==n0},n[x],x]
nsol[xdum_]:=n[x]/.sol4[[1]]/.{x->xdum}
Simplify[nsol[x]]
 
lambda=1.0;n0=10^6;
Plot[nsol[x],{x,0,10lambda},PlotLabel->"n(x) vs. x",PlotRange->All]

"Solving radioactity remains in a sample as a function of time"
sol5=DSolve[{n'[t]==-n[t]/tau,n[0]==n0},n[t],t]
(*extract the expression of the solution from sol in the form of a function of t*)
nsol[tdum_]:=n[t]/.sol5[[1]]/.{t->tdum}
Simplify[nsol[t]]
 
tau=10^6;n0=10^6;
Plot[nsol[t],{t,0,5tau},PlotLabel->"n(t) vs. t",PlotRange->All]

"Solving the relation between speed and displacement in a SHM"
sol6=DSolve[{m*v'[x]==-k x,v[x0]==v0},v[x],x]
(*extract the expression of the solution from sol in the form of a function in x *)
vsol[xdum_]:=v[x]/.sol6[[1]]/.{x->xdum}
Simplify[vsol[x]]
 
m=1.0;k=1.0;v0:=0.0;x0=1.0;
Plot[vsol[x],{x,-x0,x0},PlotLabel->"v(x) vs. x",PlotRange->All]