Exercise 1

Problem 1

Clear[r];
r[t_]={t Cos[t],t Sin[t],t};
Manipulate[Quiet[
Show[ParametricPlot3D[r[t],{t,0,50}],
Graphics3D[Arrow[{{0,0,0},r[t]}]],
Graphics3D[Arrow[{r[t],r'[t]+r[t]}]],
Graphics3D[Arrow[{r[t],r'[t]/Norm[r'[t]]+r[t]}]]]],
{t,0,50,1}
]

Problem 2

CubicBezier[t_,Points_]:= (1-t)^3 Points[[1]]+3(1-t)^2 t Points[[2]]+3 (1-t)t^2 Points[[3]]+t^3 Points[[4]];

(Subscript[P, 0])={1,1};(Subscript[P, 1])={2,2}; (Subscript[P, 2])={3,2};  (Subscript[P, 3])={4,1};
Show[ListLinePlot[{(Subscript[P, 0]),(Subscript[P, 1]),(Subscript[P, 2]),(Subscript[P, 3])}],ParametricPlot[CubicBezier[t,{(Subscript[P, 0]),(Subscript[P, 1]),(Subscript[P, 2]),(Subscript[P, 3])}],{t,0,1},PlotStyle->Red],PlotRange-> All,AspectRatio-> 1/2]

(Subscript[P, 0])={1.5,10}; (Subscript[P, 1])={0.5,10};  (Subscript[P, 2])={0,0}; (Subscript[P, 3])={1.5,0};
Show[ListPlot[{(Subscript[P, 0]),(Subscript[P, 1]),(Subscript[P, 2]),(Subscript[P, 3])}],ParametricPlot[CubicBezier[t,{(Subscript[P, 0]),(Subscript[P, 1]),(Subscript[P, 2]),(Subscript[P, 3])}],{t,0,1}]]

(Subscript[P, 0])={5,30}; (Subscript[P, 1])={2,28};(Subscript[P, 2])={0,0}; (Subscript[P, 3])={3,0};
(Subscript[P, 4])={6,0};(Subscript[P, 5])={5,-30}; (Subscript[P, 6])={1,-30};
Show[ListPlot[{(Subscript[P, 0]),(Subscript[P, 1]),(Subscript[P, 2]),(Subscript[P, 3])}],ParametricPlot[CubicBezier[t,{(Subscript[P, 0]),(Subscript[P, 1]),(Subscript[P, 2]),(Subscript[P, 3])}],{t,0,1}],ParametricPlot[CubicBezier[t,{(Subscript[P, 3]),(Subscript[P, 4]),(Subscript[P, 5]),(Subscript[P, 6])}],{t,0,1},PlotStyle->Red],ListPlot[{(Subscript[P, 3]),(Subscript[P, 4]),(Subscript[P, 5]),(Subscript[P, 6])},PlotStyle->Red],PlotRange-> All]

Problem 3

Clear[r,z,θ];
c=100/130;
(Subscript[ϵ, g])=-1;
B=2.4;
result=NDSolve[{r'[t]== Cos[θ[t]],z'[t]== Sin[θ[t]],θ'[t]== If[r[t]==0,c,2 c- Sin[θ[t]]/r[t]+(Subscript[ϵ, g]) B z[t]],r[0]== 0,z[0]==0,θ[0]==0 },{r,z,θ},{t,0,2.5}][[1]];
r[t_]=r[t]/.result;
z[t_]=z[t]/.result;
θ[t_]=θ[t]/.result;
tmax=0;
While[r[tmax]≤1,
tmax=tmax+10^(-3);
];

Show[ParametricPlot[{r[t],z[t]},{t,0,tmax}],ParametricPlot[{-r[t],z[t]},{t,0,tmax}],AxesLabel->{"r","z"},AxesOrigin-> {0,0},PlotRange-> All,AspectRatio-> 2]

Problem 4

r=1;K=3;b=1;a=3;λ=1;c=2;P0=3;X0=5;
Clear[P,X];
result=NDSolve[{X'[t] == r  X[t](1-X[t]/K)-P[t]a X[t]/(b+X[t]),P'[t]==-P[t] c + P[t] λ a X[t] /(b+X[t]),X[0]==X0,P[0]==P0},{X,P},{t,0,500}];
X[t_]=X[t]/. result;
P[t_]=P[t]/. result;
GraphicsRow[{Plot[X[t],{t,0,200},PlotRange->All,AxesLabel->{"Time t","Prey N"}],Plot[P[t],{t,0,200},PlotRange->All,AxesLabel->{"Time t","Predator P"}]},ImageSize->Large]

u[t_]={X[t],P[t]};
ParametricPlot[u[t],{t,0,200},PlotRange->All,AxesLabel->{"N","P"}]

K=10;
Clear[P,X];
result=NDSolve[{X'[t] == r  X[t](1-X[t]/K)-P[t]a X[t]/(b+X[t]),P'[t]==-P[t] c + P[t] λ a X[t] /(b+X[t]),X[0]==X0,P[0]==P0},{X,P},{t,0,500}];
X[t_]=X[t]/. result;
P[t_]=P[t]/. result;
GraphicsRow[{Plot[X[t],{t,0,200},PlotRange->All,AxesLabel->{"Time t","Prey N"}],Plot[P[t],{t,0,200},PlotRange->All,AxesLabel->{"Time t","Predator P"}]},ImageSize->Large]

u[t_]={X[t],P[t]};
ParametricPlot[u[t],{t,0,500},PlotRange->All,AxesLabel->{"Prey N","Predator P"}]