Date post: | 07-Jul-2015 |
Category: |
Engineering |
Upload: | erdi-karacal |
View: | 30 times |
Download: | 2 times |
Lists
ME 443
Mathematica for Engineers
Collecting Objects Together We first encountered lists in previous courses as a way of collecting
numbers together. In this chapter, we shall see many different ways to
use lists. You will find that lists are some of the most flexible and
powerful objects in Mathematica. You will see that lists in
Mathematica represent generalizations of several standard concepts in
mathematics and computer science.
At a basic level, what a Mathematica list essentially does is to provide
a way for you to collect together several expressions of any kind.
The mathematical functions that are built into Mathematica are
mostly set up so that they act separately on each element of a list. This
is, however, not true of all functions in Mathematica. Unless you set it
up specially, a new function f that you introduce will treat lists just as
single objects. In later courses we will describe how you can use Map
to apply a function like this separately to each element in a list.
Making Tables of Values You can use lists as tables of values. You can generate the tables, for
example, by evaluating an expression for a sequence of different
parameter values.
Sometimes you may want to generate a table by evaluating a
particular expression many times, without incrementing any
variables.
All the examples so far have been of tables obtained by varying a
single parameter. You can also make tables that involve several
parameters. These multidimensional tables are specified using the
standard Mathematica iterator notation, discussed in Section 6.6.
The table in this example is a list of lists. The three elements of the
outer list correspond to successive values of i. The pairs of elements
of each inner list correspond to successive values of j, with i fixed.
Getting Pieces of Lists
The functions in this section allow you to pick out pieces that occur at
particular positions in lists. Later, we will see how we can use
functions like Select and Cases to pick out elements of lists based not
on their positions, but instead on their properties.
Testing and Searching List Elements
The previous section discussed how to extract pieces of lists based on
their positions or indices. Mathematica also has functions that search
and test for elements of lists, based on the values of those elements.
The functions Count and Position, as well as MemberQ and FreeQ,
can be used not only to search for particular list elements, but also to
search for classes of elements which match specific "patterns".
Adding, Removing and Modifying List
Elements
Combining Lists
Lists as Sets Mathematica usually keeps the elements of a list in exactly the order
you originally entered them. If you want to treat a Mathematica list
like a mathematical set, however, you may want to ignore the order of
elements in the list.
Rearranging Lists
Grouping and Ungrouping
Elements of Lists
You should realize that because of the way Mathematica stores lists, it
is usually less efficient to add a sequence of elements to a particular
list than to create a nested structure that consists, for example, of lists
of length 2 at each level. When you have built up such a structure, you
can always reduce it to a single list using Flatten.