Differentiation

You will explore some of the attributes of the approximations of the derivative that we will need when we solve Newton's Laws and other differential equations.

1. Necessary Commands.

Some of the commands that you might find useful in this computational laboratory are shown here with comments describing their purpose.

(* Defining a function. *)
f[x_] := Sin[x];

(* Making a table of f(x) from 0->10 in steps of 2. *)
table1 = Table[{x,f[x]},{x,0,10,2}]

(* Getting the size of the table. *)
TableSize = Length[table1]

(* Make two curve and put them on one plot. Use
a function for plot1 and the table above for plot2. *)

plot1 = Plot[f[x],{x,0,30},AxesLabel->{"x","f(x)"}]
plot2 = ListPlot[table1, Joined->True,
AxesLabel->{"x","Table"},
PlotStyle->{RGBColor[1,0,0],Dashing[0.02],Thickness[0.01]}]
Show[{plot1,plot2}]

Some additional commands are listed below for manipulating arrays. Be sure to execute the first cell in this section first.

(* Make a second table. The semicolon at the end of the line suppresses the ourput. *)
table2 = Table[{x,Sin[2*x]},{x,0,10,2}];
(* To access one of the elements of the table use the following commands. *)
table2[[2]]
table2[[2,1]]
table2[[2,2]]
(* Take the difference between the second component of each element of the table and plot it.*)
table3 = Table[{table2[[i,1]],table2[[i,2]] - table1[[i,2]]},{i,1,Length[table2]}]
plot3 = ListPlot[table3,Joined->True,
AxesLabel->{"x","Table"},
PlotStyle->{RGBColor[1,0,0],Dashing[0.02],Thickness[0.01]}]

2. Round-Off Error.

There are limits to the accuracy of any computation done on a machine. This limit is important when you are differentiating because you may have to take the difference between two large numbers. One of the standard tests of computer accuracy is to calculate the sum S=x+1-x where x is some large number. Calculate S for different values of x and find the limit of accuracy on your machine.

3. Calculating Velocity and Acceleration.

The position of an object is given by the following equation

                                                       x(t) = b(t^3) - (ct^2) + dt

where b = 3.0 m/(s^3), c = 8.0 m/(s^2), and d = 1.0 m/s.

a. Generate two tables of ordered pairs of {t,x(t)} for the first 4.0 seconds of the objects's motion. For one table use a stepsize h=0.2 s and use h=0.02 s for the second. Make a plot with both curves on it. How many ordered pairs are in each table?

b. Using the 2-point, forward difference formula for the first derivative calculate the velocity  of the object at each point along its path for the two tables from part 3.a. How many ordered pairs are in these velocity tables versus the tables from Part 3.a?  Put these curves on one plot. What is the analytical form of the velocity? Use Mathematica's Plot command to add this third curve to your plot. What happens as the stepsize shrinks?

c. Create two new tables or ordered pairs of time t and the difference between your calculated velocity from Part 3.b and the analytical form. Plot these two curves and compare them. Which method is better? Be quantitative in your answer.

d. Using the two tables from Part 3.b calculate the acceleration using the 2-point, forward difference formula for the derivative of the velocity of the object at each point along its path. How many ordered pairs are in these acceleration tables versus the position and velocity tables?  Plot your results on one graph. What is the analytical form of the acceleration? Use Mathematica's Plot command to add this third curve to your plot.

e. Create two new tables of ordered pairs of time t and the difference between your calculated acceleration from Part 3.d and the analytical form. Plot these two curves. What method is better? How do these curves compare with the ones from Part 3.c?

4. Non-Simple Harmonic Oscillators

Oscillatory systems are found throughout physics (stars, atomic nuclei, bridges). If 
the oscillating system has some sort of damping in it (typically friction), then the 
harmonic motion of the system will eventually fade away. For example, the time
dependent behavior of a mass on a spring that is bouncing up and down in a liquid 
can be described by

                                                           x(t) = A (e^(-t)) cos ω t

where  t is time, ω is the angular frequency, and x is the displacement from equilibrium.

a. Make a plot of the displacement using the Table command in Mathematica for the first  six seconds of the motion when  ω=5.0 rad/s, A=1.0 m, and h=0.1 s.

b. Calculate analytically the velocity of the mass and plot it for the same period. Use the  centered derivative formula and a stepsize of 0.1 s to calculate the velocity again and plot  both curves together. Are there any significant differences?

c.  Plot the difference between the analytical expression for the velocity and the velocity  you calculated with the centered derivative formula. In other words, calculate

                                                      (Subscript[δ, 1]) (t) = x'(t) - g(t)

where g(t) is the approximation to x'(t) given by the centered derivative formula.
When is the centered derivative formula most accurate?

d.  Now plot the normalized difference between the analytical expression for the velocity  and the velocity you calculated with the centered derivative formula. In other words, calculate

                                                      (Subscript[δ, 2]) (t) = ((x'(t) - g(t))/(x'(t) ))

where the quantities are defined as they were in the previous part. When is the centered derivative formula most accurate when viewed with this method?  Are  your results consistent? Explain.