+ All Categories
Home > Engineering > Me 443 5 lists

Me 443 5 lists

Date post: 07-Jul-2015
Category:
Upload: erdi-karacal
View: 30 times
Download: 2 times
Share this document with a friend
Description:
Wolfram Mathematica Mechanical Engineering University of Gaziantep
Popular Tags:
23
Lists ME 443 Mathematica for Engineers
Transcript
Page 1: Me 443   5 lists

Lists

ME 443

Mathematica for Engineers

Page 2: Me 443   5 lists

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.

Page 3: Me 443   5 lists
Page 4: Me 443   5 lists

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.

Page 5: Me 443   5 lists

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.

Page 6: Me 443   5 lists

Sometimes you may want to generate a table by evaluating a

particular expression many times, without incrementing any

variables.

Page 7: Me 443   5 lists

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.

Page 8: Me 443   5 lists

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.

Page 9: Me 443   5 lists

Getting Pieces of Lists

Page 10: Me 443   5 lists
Page 11: Me 443   5 lists
Page 12: Me 443   5 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.

Page 13: Me 443   5 lists

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.

Page 14: Me 443   5 lists
Page 15: Me 443   5 lists

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".

Page 16: Me 443   5 lists

Adding, Removing and Modifying List

Elements

Page 17: Me 443   5 lists

Combining Lists

Page 18: Me 443   5 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.

Page 19: Me 443   5 lists

Rearranging Lists

Page 20: Me 443   5 lists
Page 21: Me 443   5 lists

Grouping and Ungrouping

Elements of Lists

Page 22: Me 443   5 lists
Page 23: Me 443   5 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.


Recommended