Mathematica Tutorial: Core Language
Total Page:16
File Type:pdf, Size:1020Kb
Wolfram M athematica ® Tutorial Collection CORE LANGUAGE For use with Wolfram Mathematica® 7.0 and later. For the latest updates and corrections to this manual: visit reference.wolfram.com For information on additional copies of this documentation: visit the Customer Service website at www.wolfram.com/services/customerservice or email Customer Service at [email protected] Comments on this manual are welcomed at: [email protected] Printed in the United States of America. 15 14 13 12 11 10 9 8 7 6 5 4 3 2 ©2008 Wolfram Research, Inc. All rights reserved. No part of this document may be reproduced or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without the prior written permission of the copyright holder. Wolfram Research is the holder of the copyright to the Wolfram Mathematica software system ("Software") described in this document, including without limitation such aspects of the system as its code, structure, sequence, organization, “look and feel,” programming language, and compilation of command names. Use of the Software unless pursuant to the terms of a license granted by Wolfram Research or as otherwise authorized by law is an infringement of the copyright. Wolfram Research, Inc. and Wolfram Media, Inc. ("Wolfram") make no representations, express, statutory, or implied, with respect to the Software (or any aspect thereof), including, without limitation, any implied warranties of merchantability, interoperability, or fitness for a particular purpose, all of which are expressly disclaimed. Wolfram does not warrant that the functions of the Software will meet your requirements or that the operation of the Software will be uninterrupted or error free. As such, Wolfram does not recommend the use of the software described in this document for applications in which errors or omissions could threaten life, injury or significant loss. Mathematica, MathLink, and MathSource are registered trademarks of Wolfram Research, Inc. J/Link, MathLM, .NET/Link, and webMathematica are trademarks of Wolfram Research, Inc. Windows is a registered trademark of Microsoft Corporation in the United States and other countries. Macintosh is a registered trademark of Apple Computer, Inc. All other trademarks used herein are the property of their respective owners. Mathematica is not associated with Mathematica Policy Research, Inc. Contents Building Up Calculations Using Previous Results . 1 Defining Variables . 2 Values for Symbols . 4 The Four Kinds of Bracketing in Mathematica . 8 Sequences of Operations . 8 Lists Making Lists of Objects . 10 Collecting Objects Together . 11 Making Tables of Values . 12 Manipulating Elements of Lists . 16 Vectors and Matrices . 17 Getting Pieces of Lists . 23 Testing and Searching List Elements . 25 Adding, Removing and Modifying List Elements . 26 Combining Lists . 28 Lists as Sets . 29 Rearranging Lists . 30 Grouping and Combining Elements of Lists . 31 Ordering in Lists . 32 Rearranging Nested Lists . 33 Manipulating Lists Constructing Lists . 35 Manipulating Lists by Their Indices . 37 Nested Lists . 44 Partitioning and Padding Lists . 47 Sparse Arrays . 51 Expressions Everything Is an Expression . 57 The Meaning of Expressions . 59 Special Ways to Input Expressions . 60 Parts of Expressions . 62 Manipulating Expressions like Lists . 65 Expressions as Trees . 66 Levels in Expressions . 68 Patterns Introduction to Patterns . 72 Finding Expressions That Match a Pattern . 75 Naming Pieces of Patterns . 77 Specifying Types of Expression in Patterns . 79 Putting Constraints on Patterns . 80 Patterns Involving Alternatives . 86 Pattern Sequences . 87 Flat and Orderless Functions . 88 Functions with Variable Numbers of Arguments . 92 Optional and Default Arguments . 94 Setting Up Functions with Optional Arguments . 96 Repeated Patterns . 99 Verbatim Patterns . 101 Patterns for Some Common Types of Expression . 101 An Example: Defining Your Own Integration Function . 104 Transformation Rules and Definitions Applying Transformation Rules . 107 Manipulating Sets of Transformation Rules . 111 Making Definitions . 112 Special Forms of Assignment . 114 Making Definitions for Indexed Objects . 118 Making Definitions For Functions . 120 The Ordering of Definitions . 122 Immediate and Delayed Definitions . 124 Functions That Remember Values They Have Found . 129 Associating Definitions with Different Symbols . 132 Defining Numerical Values . 136 Modifying Built-in Functions . 138 Manipulating Value.