Lists

We now have functions {\tt xpos} and {\tt ypos} that parametrically specify the
x-y coordinates of our destroyer as a function of time. If we want to know the
coordinates of the destroyer at some particular time, say $t = 5$, what do we
need to do?

Click here for the answer

It'd be convenient, though, to have a single function that would return
both parts of the coordinates of the destroyer at a particular time t.
This is easily accomplished in Mathematica by using a list.

In Mathematica, we can create a list of one or more values simply by enclosing them
in curly brackets and separating them with commas. Once created, a list can
be treated as a single entity or can be decomposed into its individual
components. For example, here is the list {20,30,40}.

{20,30,40}  

We can name a list just like any other value:

numbers = {20,30,40}

Having done that, we can examine all three numbers in the list at once with

numbers

We can also access any of the members of the list by using subscripting. For
example, let's extract the second element of the list:

numbers[[2]]

By taking advantage of lists, we can define a single function called
position that takes a time t as an argument and returns the x-y position of
the destroyer at that time.

position [t_]:= {xpos[t], ypos[t]} 

Look carefully at the function definition. We have constructed the body so that
it returns a list of values. The body of the function consists of two
expressions, separated by a comma and enclosed in square brackets.

Now if we want to know the position of the destroyer at time t=5, we simply
do:

position[5]
     {75.8527, 130.692}

Since position[t] is a pair of expressions involving t (try it and
see), we can easily use position to produce a parametric plot:

ParametricPlot[position[t], {t, 0, 26}];

Not surprisingly, this is exactly what we obtained with our earlier parametric
plot of the destroyer's trajectory.