Exercise 1. Differential equations as mathematical models

Not all problems can be solved with a built-in function!

NDSolve[{u'[t]==10u[t](1-((u[t])/5)) -((u[t]v[t])/(1+u[t])),v'[t]==((u[t]v[t])/(1+u[t]))-0.1u[t],u[0]==0.1,v[0]==0.1},{u[t],v[t]},{t,0,100}]

The logistic equation

sol01 = NDSolve[{u'[t]==10u[t](1-u[t]),u[0]==0.1},u,{t,0,1}];
sol05 = NDSolve[{u'[t]==10u[t](1-u[t]),u[0]==0.5},u,{t,0,1}];
sol1 = NDSolve[{u'[t]==10u[t](1-u[t]),u[0]==1},u,{t,0,1}];
sol15= NDSolve[{u'[t]==10u[t](1-u[t]),u[0]==1.5},u,{t,0,1}];
Plot[{
u[t]/.sol01,
u[t]/.sol05,
u[t]/.sol1,
u[t]/.sol15
},{t,0,1},PlotRange->All]

The solutions of the logistic equation, corresponding to positive initial conditions tend to the stable equilibrium (in this case, u=1) as t→∞

The spring problem

Application of Newton’s Law to modeling a spring-mass system, i.e. the resultant force is F(t) = mg - kx (gravitation and spring force with spring constant k)

m=0.06; k=14; g=9.8;
Clear[x];
spring = NDSolve[{x''[t]== g-((k x[t])/m),x[0]==0.07,x'[0]== 0},x[t],{t,0,10}];
x[t_]=x[t]/.spring;
Plot[x[t],{t,0,10},PlotRange->All,AxesLabel->{"Time t","Position x"}]

Numerical solutions are actually discrete

ListPlot[x["ValuesOnGrid"][[1]]]

Animate[
Show[ListPlot[{{0,x[t][[1]]}},PlotStyle->Red,ScalingFunctions->{Identity,"Reverse"}],AxesOrigin-> {0,0},
PlotRange->{{-0.5,0.5},{0,-0.1}},PlotLabel->t]
,{t,0,10},
AnimationRate->1,AnimationRunning->False
]

(*start from equilibrium point*)

Clear[x];
equilibrium=x/.Solve[g-((k x)/m)==0,x];
spring = DSolve[{x''[t]== g-((k x[t])/m),x[0]==equilibrium[[1]],x'[0]== 0},x,t];
x[t_]=x[t]/.spring;

Animate[
Show[ListPlot[{{0,x[t][[1]]}},PlotStyle->Red,ScalingFunctions->{Identity,"Reverse"}],AxesOrigin-> {0,0},
PlotRange->{{-0.5,0.5},{0,-0.1}},PlotLabel->t]
,{t,0,10},
AnimationRate->1,AnimationRunning->False
]

Heat conduction problem

Transient (Non-stationary) solution (Example for 1D PDE)

sol=NDSolve[{D[u[x,t],t]==D[u[x,t],{x,2}],u[x,0]==If[x≤0.5,1,0],u[0,t]==1,u[5,t]==0},u,{x,0,5},{t,0,5}]

Manipulate[
uPlot[x_]=u[x,t]/.sol;
Plot[uPlot[x],{x,0,5},PlotRange->{0,1}]
,{t,0,5,0.01}]

Stationary solution (Example for ODE with respect to a spatial variable - boundary-value problem. As t goes to infinity, the solution of the non-stationary problem above tends to the solution of the stationary problem)

sol=NDSolve[{0==D[u[x],{x,2}],u[0]==1,u[5]==0},u,{x,0,5}]

uPlot[x_]=u[x]/.sol;
Plot[uPlot[x],{x,0,5}]

2D wave equation

sol=NDSolve[{D[u[t,x,y],t,t]==D[u[t,x,y],x,x]+D[u[t,x,y],y,y]/2,u[0,x,y]==(E^(-((x^2)+(y^2)))),u[t,-5,y]==u[t,5,y]==0,u[t,x,-5]==u[t,x,5]==0,Derivative[1,0,0][u][0,x,y]==0},u,{t,0,50},{x,-5,5},{y,-5,5}]

Manipulate[
uPlot[x_,y_]=u[t,x,y]/.sol;
Plot3D[uPlot[x,y],{x,-5,5},{y,-5,5},PlotRange->{-1,1},PlotStyle->Blue],
{t,0,50,0.25}
]