Download 1.2.3 Making Lists of Objects

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
1. A Practical Introduction to Mathematica
58
1.2.3 Making Lists of Objects
In doing calculations, it is often convenient to collect together several objects, and treat them as a single entity. Lists give you a way to make collections of objects in Mathematica. As you will see later, lists
are very important and general structures in Mathematica.
A list such as {3, 5, 1} is a collection of three objects. But in many ways, you can treat the whole
list as a single object. You can, for example, do arithmetic on the whole list at once, or assign the whole
list to be the value of a variable.
Here is a list of three numbers.
In 1]:= {3, 5, 1}
Out 1]= {3, 5, 1}
This squares each number in the list,
and adds 1 to it.
In 2]:= {3, 5, 1}^2 + 1
This takes differences between
corresponding elements in the two lists.
The lists must be the same length.
In 3]:= {6, 7, 8} - {3.5, 4, 2.5}
The value of % is the whole list.
In 4]:= %
Out 2]= {10, 26, 2}
Out 3]= {2.5, 3, 5.5}
Out 4]= {2.5, 3, 5.5}
You can apply any of the mathematical
functions in Section 1.1.3 to whole lists.
In 5]:= Exp % ] // N
Out 5]= {12.1825, 20.0855, 244.692}
Just as you can set variables to be numbers, so also you can set them to be lists.
This assigns v to be a list.
In 6]:= v = {2, 4, 3.1}
Out 6]= {2, 4, 3.1}
Wherever v appears, it is replaced by
the list.
In 7]:= v / (v - 1)
4
Out 7]= {2, -, 1.47619}
3
Web sample page from The Mathematica Book, Second Edition, by Stephen Wolfram, published by Addison-Wesley Publishing Company (hardcover ISBN 0-201-51502-4; softcover ISBN 0-201-51507-5). To order Mathematica or this book contact Wolfram Research: [email protected];
http://www.wolfram.com/; 1-800-441-6284.
 1991 Wolfram Research, Inc.
Permission is hereby granted for web users to make one paper copy of this page for their personal use. Further reproduction, or any copying of machine-readable files (including this one) to any server computer, is strictly prohibited.