a=5; (*defining a variable by giving it a value*)

a^2 (*performing an operation on a variable*)

(*comments*)

Clear[a] (*clearing the value of a variable*)

a

thisIsMySymbol (*camel case*)

func[x_,y_]:=x*y (*defining a function that takes arguments*)

func[3,2] (*evaluating a function by giving it arguments*)

func[x,4]

Plot[Sin[x],{x,0,2Pi},PlotStyle-> Directive[Red,Thickness[0.05]],Axes->False,Frame->True,FrameLabel->{"xlabel","ylabel"},PlotRange->{{0,3},All}]

Clear[x,y]

h=Sin[x]+Cos[y]

h

rule={x-> 3,y->2} (*defining a rule associates a value with a variable withou replacing the symbol*)

h

h/.rule (*applying a rule to a symbol, replaces occurences of all variables by their associated values*)

h

Plot3D[h,{x,0,2Pi},{y,0,2Pi},AxesLabel->{"x","y","z"}]

listA={5,27,1,6,7}

2*listA

listA[[2]]*listA[[1]]

Head[listA[[1]]]

Length[listA]

listB={a,b,c,d}

Join[listA,listB]

ListPlot[listA]

list2D={{3,2},{6,3},{1,4}}

dataPlot=ListPlot[list2D,PlotStyle->Red]

linePlot=ListLinePlot[list2D]

Show[dataPlot,linePlot]

list2D//TableForm

tab=Table[
j=i^2;
{i,j^2},
{i,1,100,0.5}
]

ListLinePlot[tab]

ftab=Interpolation[tab]

D[ftab[x],x]

Plot[ftab[x],{x,1,10}]

D[Sin[x],x]

Integrate[Cos[x],x]

Integrate[Cos[x],{x,0,Pi}]

f=x^2;

Solve[f-4==0,x]

FindRoot[f-4==0,{x,3}]

Manipulate[
Plot[x^a,{x,0,4},PlotRange->{{0,4},{0,4}}],{a,1,5}]

odes={
D[a[t],t]==-Vm*a[t]/(Ka+a[t]),
D[b[t],t]==Vm*a[t]/(Ka+a[t])}

parameters={Vm->10,Ka->0.2}

initialValues={a[0]==5,b[0]==0}

odes/.parameters

Join[odes,initialValues]/.parameters

sol=NDSolve[Join[odes,initialValues]/.parameters,{a[t],b[t]},{t,0,1}]

Plot[{a[t]/.sol,b[t]/.sol},{t,0,1},PlotLegends->{"a[t]","b[t]"}]

(*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];