(*NDSolve for solution of differential equations:
((dh(t))/dt) = -n.h(t)
h(0) = 20
n = 1
*)
eqs={D[h[t],t]==-n*h[t]}
inits={h[0]==20}
vars={h[t]}

params={n->1}
(*this defines the system*)

(*what does applying params to eqs do?*)
eqs/.params

(*consult the help documentation for NDSolve*)
arg1=Join[eqs/.params,inits]
arg2=vars
sol=NDSolve[arg1,arg2,{t,0,10}]

(*extract solution value at a specific timepoint*)
h[t]/.sol/.t->10

(*Plot solution over a time range, add a frame and labels*)
Plot[h[t]/.sol,{t,0,10},PlotRange->All,Frame->True,FrameLabel->{"t","h(t)"}]

(*EXERCISE*)
(*Solve the coupled differential equations that describe a predator-prey system: 
((dx(t))/dt) = x(t)*(k - l*y(t)) and dy(t)/dt = -y(t)*(m - n*x(t)) 
with initial conditions x(0)=10, y(0)=1 
and parameter values k=0.04, l=0.02, m=0.08, n=0.04 
for 0 ≤ t ≤ 1000*)
(*Plot x(t) and y(t) and show them om the same axis. *)
eqs={D[x[t],t]==x[t]*(k - l*y[t]),D[y[t],t]==-y[t]*(m - n*x[t])};
inits={x[0]==10,y[0]==1};
params={ k->0.04, l->0.02, m->0.08, n->0.04 };
arg1=Join[eqs,inits]/.params;
vars={x[t],y[t]};
sol=NDSolve[arg1,vars,{t,0,1000}]

Plot[{x[t]/.sol,y[t]/.sol},{t,0,1000},PlotRange->{{0,1000},{0,20}},PlotLegends->{"prey","predator"},Frame->True]

(*Now plot y(t) against x(t), give the plot a name and export it to a file*)

p1=ParametricPlot[{x[t],y[t]}/.sol,{t,0,1000},PlotRange->All,Frame->True,FrameLabel->{"prey","predator"},AspectRatio->1,BaseStyle->{FontSize->14,FontFamily->"Helvetica"},ImageSize->300,PlotStyle->{Thickness[0.0075],Red}]

Export["p1.pdf",p1,ImageResolution->300];