We often ask a computer to do an operation many times. There are a large number of ways of doing these ``iterative''tasks in Mathematica. Here are two that you will need this week(look them up in the online help):
Table, Do
You will also need to learn how to plot lists of numbers using:
ListPlot, ListPlot3D
Finally, animation is
very simple in mathematica. Simply generate a series of
frames (e.g. using a ``Do'' loop) and then double click on one of the
frames. This automatically animates the set of frames.
Problem 1. (i) Listplot plots a list of numbers on the y axis of a graph. To see how this works, enter the following code
sintable=Table[Sin[x],{x,0,20,.1}]
ListPlot[sintable]
(ii) Three dimensional plots are just as easy. Enter and run the following code
sintable3D=Table[Sin[x*y],{x,0,4,.1},{y,0,4,0.1}]
ListPlot3D[sintable3D]
(iii) Using the Table function, generate
points to represent a circle for y>0. Plot this data using
ListPlot.
Problem 2.
Here is a code to sum the first n integers, with n running
from 1 to 100. The first command sets up an array which
is used to store the sums.
sumintegers=Range[100];
sumintegers[[1]]=1;
Do[
{sumintegers[[n]]=sumintegers[[n-1]]+n},
{n,2,100,1}
]
ListPlot[sumintegers]
The Riemann zeta function is defined by
. This
sum is convergent for p>1(why?). Write a program
to find as a function of the number of terms, N, included
in the sum. Plot
the value of this sum for p=3 as a function of N. How many
terms do you need to take until your answer appears
to be correct to 4 digit accuracy(how big does N need to be)?
Problem 3.
Enter and run the following code which animates
circular motion.
timestep = 0.1 Pi
tstart = 0
tend = timestep
x[a_]:= Cos[a]
y[a_]:= Sin[a]
Do[
{ParametricPlot[{x[t],y[t]},{t,tstart,tend}, PlotRange->{{-1,1},{-1,1}}];
tstart=tend;
tend=tend+timestep}, {i,1,20}
]
Modify
this code to animate the following projectile motion problem:
A mass of 20kg is
fired from a height of 2000 meters, with initial
angle to the horizontal of 60 degrees and initial
speed of 500m/s (ignore drag). Your animation should
begin at firing and end when the mass hits ground level.
DO NOT print out the frames
used to produce your animation. Instead show your animation to
your TA. However DO hand in your
Mathematica code.