P2820 Midterm 2 - F2014

Name:
Student number:

There are 2 questions, each worth 10 marks
Assume all quantities are given in MKS units (m, s, J, N, etc.)

Q1

A particle of mass m=1.5 moves in one dimension and is subject to an external field.  The potential energy of the particle resulting from this external field as a function of the coordinate x is:

U(x)= - 0.5 (x^2) + 0.03 (x^4)
	  
Initially, the particle is located at x = -3 has velocity v = -2

Remove["Global`*"]

a) Plot the force on the particle as a function of x:

U[x_]=-0.5*(x^2)+0.03 * (x^4)

F[x_]=-D[U[x],x]

Plot[F[x],{x,-5,5}, AxesLabel->{"x[m]","F[N]"}]

b) Determine the position at which the particle first comes to rest momentarily and the force on the particle at this position

vin=-2;
xin=-3;
m=1.5;
Kin=1/2m vin^2;
Uin=U[xin];
Ein=Kin+Uin;
xstop=x/.FindRoot[U[x]==Ein,{x,-4}]

F[xstop]

sol=NDSolve[{m*x''[t]==F[x[t]],x[0]==xin,x'[0]==vin},x[t],{t,0,200}]

X[t_]=x[t]/.sol[[1]]

Plot[X[t],{t,0,30}]

c) Solve for the position and velocity of the particle as functions of time.  To solve the ODE, use the midpoint scheme (2nd order Runge-Kutta) with a time step of 0.05 for the first 50 s.  Plot the solutin for the position of the particle

fv[y_,v_,t_]:=F[y]/m 
fy[y_,v_,t_]:=v
T=50;
Δt=0.05;
t[1]=0;
y[1]=xin;
v[1]=vin;

nmax=Round[T/Δt];
(* Midpoint scheme *)
Do[t[n+1]=n Δt+t[1];
s1v=fv[y[n],v[n],t[n]];
s1y=fy[y[n],v[n],t[n]];
vtmp=((Δt)/2)s1v+v[n];
ytmp=((Δt)/2)s1y+y[n];
s2v=fv[ytmp,vtmp,t[n]+Δt/2];
s2y=fy[ytmp,vtmp,t[n]+Δt/2];
v[n+1]=Δt s2v+v[n];
y[n+1]=Δt s2y+y[n],
{n,1,nmax}]
xM=Interpolation[Table[{t[n],y[n]},{n,1,nmax+1}]];
vM=Interpolation[Table[{t[n],v[n]},{n,1,nmax+1}]];
Plot[xM[t],{t,0,T}]

d) Plot the potential, kinetic and total energy of the particle as functions of time for the first 10s on one plot.  The total energy should be constant.

K[t_]=m * (((vM[t])^2)/2); UM[t_]=U[xM[t]]; Etot[t_]=K[t]+UM[t];
Plot[{K[t],UM[t],Etot[t]},{t,0,10}]

Q2

Remove["Global`*"]

A truck is waiting at a red light.  A cyclist trying to catch up is 3m behind the truck just as the light turns green.  The velocity of the bicylce is measured as a function of time.  The data are stored in the table below.

vcyclist={{0.,6.00513},{0.1,5.87156},{0.2,5.74513},{0.3,5.62739},{0.4,5.50192},{0.5,5.3909},{0.6,5.27931},{0.7,5.17289},{0.8,5.07015},{0.9,4.96774},{1.,4.86895},{1.1,4.77744},{1.2,4.68566},{1.3,4.59432},{1.4,4.50979},{1.5,4.4289},{1.6,4.35087},{1.7,4.27156},{1.8,4.20442},{1.9,4.12997},{2.,4.05645},{2.1,3.99069},{2.2,3.92606},{2.3,3.86422},{2.4,3.80498},{2.5,3.74004},{2.6,3.68315},{2.7,3.63422},{2.8,3.5794},{2.9,3.52807},{3.,3.47887},{3.1,3.42589},{3.2,3.38661},{3.3,3.33369},{3.4,3.29236},{3.5,3.25294},{3.6,3.21039},{3.7,3.16654},{3.8,3.13018},{3.9,3.09468},{4.,3.05571},{4.1,3.02918},{4.2,2.99032},{4.3,2.96191},{4.4,2.93131},{4.5,2.89753},{4.6,2.87235},{4.7,2.83683},{4.8,2.80847},{4.9,2.78448},{5.,2.76284}};

with t measured from the moment the light turns green in s. The truck accelerates at a rate measured as a function of time which is stored  in the table:

atruck={{0., 2.00393}, {0.1, 1.99445}, {0.2, 1.98669}, {0.3, 1.97999}, {0.4, 1.96132}, {0.5, 1.95445}, {0.6, 1.94448}, {0.7, 1.93546}, {0.8, 1.92399}, {0.9, 1.91884}, {1., 1.90322}, {1.1, 1.89236}, {1.2, 1.88944}, {1.3, 1.87752}, {1.4, 1.86386}, {1.5, 1.85843}, {1.6, 1.84158}, {1.7, 1.83898}, {1.8, 1.82884}, {1.9, 1.81934}, {2., 1.80971}, {2.1, 1.7981}, {2.2, 1.78548}, {2.3, 1.772}, {2.4, 1.76577}, {2.5, 1.75365}, {2.6, 1.74879}, {2.7, 1.73202}, {2.8, 1.72445}, {2.9, 1.7192}, {3., 1.7043}, {3.1, 1.69656}, {3.2, 1.68047}, {3.3, 1.67035}, {3.4, 1.66109}, {3.5, 1.6542}, {3.6, 1.64103}, {3.7, 1.63284}, {3.8, 1.62723}, {3.9, 1.61577}, {4., 1.60945}, {4.1, 1.59386}, {4.2, 1.58838}, {4.3, 1.57643}, {4.4, 1.56974}, {4.5, 1.55577}, {4.6, 1.54291}, {4.7, 1.53443}, {4.8, 1.52397}, {4.9, 1.51212}, {5., 1.50412}};

(a) Using the backwards difference approximation for the first derivative, determine and plot the acceleration of the cyclist as a function of time.  (Do not interpolate, but rather operate on the discretet data directly.)

cd[d_,i_]:=((d[[i,2]]-d[[i-1,2]])/(d[[i,1]]-d[[i-1,1]]));
acyclist=Table[{vcyclist[[i,1]],cd[vcyclist,i]},{i,2,Length[vcyclist]}];
ListPlot[acyclist]

(b) Now use the Trapezoid rule to determine the position of cyclist as a function of time.  Plot your result.

DNITrap[list_,j_]:=(Δx=list[[2,1]]-list[[1,1]];((Δx)/2)(list[[1,2]]+list[[j,2]]+2(∑_(i=2)^(j-1))list[[i,2]]));
xcyclist=Table[{vcyclist[[i,1]],DNITrap[vcyclist,i]-3},{i,2,Length[vcyclist]}];
ListPlot[xcyclist,AxesLabel->{"t[s]","x cyclist[m]"}]

(c) use the Trapezoid rule to determine the truck velocity as a function of time

vtruck=Table[{atruck[[i,1]],DNITrap[atruck,i]},{i,2,Length[atruck]}];

(d)  use the Trapezoid rule to determine the truck position as a function of time. 
               Plot your result.

xtruck=Table[{vtruck[[i,1]],DNITrap[vtruck,i]},{i,2,Length[vtruck]}];
ListPlot[xtruck,AxesLabel->{"t[s]","x truck[m]"}]

(e) Interpolate the solutions for the positions of the truck and cyclist and find when does the truck overtake the bicycle:

xb=Interpolation [xcyclist];
xt=Interpolation [xtruck];
Plot[{xb[t],xt[t]},{t,0.2,4.8},AxesLabel->{"t[s]","x[m]"}]

t2=t/.FindRoot[xb[t]==xt[t],{t,3.6}]