Midterm 2 P2820 Fall 2015  [25 marks total]

Name:
Student number:

Q1. [15 marks]

The potential energy (in J) due to an external field as a function of a particle’s coordinate is given by
uf[x_]:=2Exp[((-(((x-3))^2))/2)]+1.5 Exp[((-(((x+4))^2))/2)]+Exp[((-(((x+0.1))^2))/2)]+(10^(-5)) (x^6)

Remove["Global`*"]

(a) 1 marks

Plot the potential energy for x changing from -10 to 10

uf[x_]:=2Exp[((-(((x-3))^2))/2)]+1.5 Exp[((-(((x+4))^2))/2)]+Exp[((-(((x+0.1))^2))/2)]+(10^(-5)) (x^6);
Plot[uf[x],{x,-10,10}]

(b) 2 mark

What is the force due to this external field on a particle at position x? What is the value of the force at x=0.3?

F[x_]=-D[uf[x],x];
F[0.3]

(c) 5 marks

Solve for the trajectory of a particle with mass m1=1kg, initial position x1[0]=0 and velocity x1’[0]=-3 m/s.  Plot the particle trajectory (position x1[t] versus time) for the first 30s.

m1=1;T=30;sol=NDSolve[ {x1''[t]==F[x1[t]]/m1, x1[0]==0,x1'[0]==-3},x1[t],{t,1,T}];
X1[t_]=x1[t]/.sol[[1]];
Plot[X1[t],{t,0,29}]

(d) 2 marks

Now a second particle with mass m2=2kg, inital position x2[0]=2 and intial velocity x2’[0]=3m/s is connected to m1 by a spring and particle 2 is always to the right of particle 1.  The spring potential energy is
 
us[r_]:= 3 (((r-4))^2)

What is the spring force on particle 2 if the particle coordinates are given by x1[t] and x2[t]   (Inspect your answer qualitatively to make sure that the direction of the force is correct.)

us[r_]:= 3 (((r-4))^2);
r:=(x2[t]-x1[t]);
F1=-D[us[r],x1[t]];
F2=-D[us[r],x2[t]]

(e) 5 marks

Solve for the trajectories of the two particles.  Plot their trajectories (position versus time) for the first 5s.

m1=1;m2=2;

m2=2;sol1=NDSolve[{x1''[t] m1 == F1 + F[x1[t]], x2''[t] m2 == F2 + F[x2[t]],x1[0]==0,x1'[0]==-3, x2[0]==2 , x2'[0]==3}, {x1[t],x2[t]}, { t, 0 , T}];
X1[t_]=x1[t]/.sol1[[1]]; X2[t_]=x2[t]/.sol1[[1]];
Plot[{X1[t],X2[t]}, {t, 0, T}]

Q2. [10 marks]

The velocity of an object travelling in one dimension is measured as a function of time.  The data are stored in the table below.

Remove["Global`*"]
vdata={{0.,8.677},{0.1,8.514},{0.2,8.359},{0.3,8.193},{0.4,8.016},{0.5,7.854},{0.6,7.714},{0.7,7.567},{0.8,7.38},{0.9,7.157},{1.,6.947},{1.1,6.767},{1.2,6.591},{1.3,6.399},{1.4,6.199},{1.5,6.01},{1.6,5.821},{1.7,5.606`},{1.8,5.355},{1.9,5.109},{2.,4.91},{2.1,4.744},{2.2,4.576},{2.3,4.376},{2.4,4.14},{2.5,3.897},{2.6,3.67},{2.7,3.451},{2.8,3.219},{2.9,2.976},{3.,2.75},{3.1,2.565},{3.2,2.413},{3.3,2.271},{3.4,2.11},{3.5,1.905},{3.6,1.648},{3.7,1.371},{3.8,1.125},{3.9,0.928},{4.,0.765}};

a) 3 marks

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

cd[d_,i_]:=(((d[[i+1,2]]-d[[i-1,2]]))/((d[[i+1,1]]-d[[i-1,1]])));
a=Table[{vdata[[i,1]],cd[vdata,i]},{i,2,Length[vdata]-1}];
ListLinePlot[a,AxesLabel->{"t[s]","a[m/(s^2)]"}]

b) 2 marks

Using trpezoidal rule, determine the displacement of the particle over the time that the data are taken.

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]]));

xmax=DNITrap[vdata,Length[vdata]]

c) 3 marks

Now use trapezoidal rule to determine the displacement as a function of time.  Be careful to only evaluate the integral for times allowed by the algorithm.  Plot your result.

x=Table[{vdata[[i,1]],DNITrap[vdata,i]},{i,2,Length[vdata]-1}];
ListLinePlot[x,AxesLabel->{"t[s]","x[m]"}]

d) 2 marks

Using your results from above, plot the displacement as a function of velocity.  Do so by first defining a table that stores ordered pairs of velocities and displacements correspond to the same time.

xvel=Table[{vdata[[i,2]],x[[i,2]]},{i,2,Length[vdata]-1}];
ListLinePlot[xvel,AxesLabel->{"v [m/s]","x [m]"}]