- Broschiertes Buch
- Merkliste
- Auf die Merkliste
- Bewerten Bewerten
- Teilen
- Produkt teilen
- Produkterinnerung
- Produkterinnerung
As the leading software application for symbolic mathematics, Mathematica is standard in many environments that rely on math, such as science, engineering, financial analysis, software development, and many other fields. This cookbook provides practical solutions on a wide range of topics for anyone using this remarkable program. Whether you want to use it for high school algebra, PhD-level computation, simple graphs, financial analysis, or advanced engineering models, you'll find the recipes in Mathematica Cookbook extremely useful and informative.
With key support from Mathematica's…mehr
Andere Kunden interessierten sich auch für
- David J PineIntroduction to Python for Science and Engineering180,99 €
- Philipp K. JanertData Analysis with Open Source Tools33,99 €
- Christian JacobIllustrating Evolutionary Computation with Mathematica121,99 €
- S M BlinderMATHEMATICS, PHYSICS & CHEMISTRY WITH WOLFRAM LANGUAGE87,99 €
- Douwe OsingaDeep Learning Cookbook62,99 €
- Rachel SchuttDoing Data Science47,99 €
- Anthony ScopatzEffective Computation in Physics65,99 €
-
-
-
As the leading software application for symbolic mathematics, Mathematica is standard in many environments that rely on math, such as science, engineering, financial analysis, software development, and many other fields. This cookbook provides practical solutions on a wide range of topics for anyone using this remarkable program. Whether you want to use it for high school algebra, PhD-level computation, simple graphs, financial analysis, or advanced engineering models, you'll find the recipes in Mathematica Cookbook extremely useful and informative.
With key support from Mathematica's developer, Wolfram Research, this authoritative cookbook covers Mathematica 7, the major new release of the software, with recipes on three-dimensional imagining, audio processing, calculations from mathematics and physics, image processing, distributed computing, and much more from key people in the Mathematica community.
If you need a sophisticated tool with animation and interaction features for data visualization, or just want to play around with math in a visual way, Mathematica Cookbook is ideal for professionals and hobbyists from all walks of life.
Hinweis: Dieser Artikel kann nur an eine deutsche Lieferadresse ausgeliefert werden.
With key support from Mathematica's developer, Wolfram Research, this authoritative cookbook covers Mathematica 7, the major new release of the software, with recipes on three-dimensional imagining, audio processing, calculations from mathematics and physics, image processing, distributed computing, and much more from key people in the Mathematica community.
If you need a sophisticated tool with animation and interaction features for data visualization, or just want to play around with math in a visual way, Mathematica Cookbook is ideal for professionals and hobbyists from all walks of life.
Hinweis: Dieser Artikel kann nur an eine deutsche Lieferadresse ausgeliefert werden.
Produktdetails
- Produktdetails
- Verlag: O'Reilly Media
- Seitenzahl: 826
- Erscheinungstermin: 8. Juni 2010
- Englisch
- Abmessung: 233mm x 179mm x 48mm
- Gewicht: 1410g
- ISBN-13: 9780596520991
- ISBN-10: 0596520999
- Artikelnr.: 26488046
- Verlag: O'Reilly Media
- Seitenzahl: 826
- Erscheinungstermin: 8. Juni 2010
- Englisch
- Abmessung: 233mm x 179mm x 48mm
- Gewicht: 1410g
- ISBN-13: 9780596520991
- ISBN-10: 0596520999
- Artikelnr.: 26488046
Sal Mangano has been developing software since the days Borland Turbo C and has worked with an eclectic mix of programming languages and technologies. Sal worked on many mission-critical applications, especially in the area of financial-trading applications. In his day job, he works mostly with mainstream languages like C++ and Java so he chooses to play with more interesting technology whenever he gets a chance. Sal's two books (XSLT Cookbook and Math Mathematica Cookbook) may seem to be an odd pair of technologies for a single author but there is a common theme that reflects his view at what makes a language powerful. Both Mathematica and XSLT rest on the idea of pattern matching and transformation. They may use these patterns in different ways and transformations to achieve different ends but they are both good at what they do and interesting to program in for a common reason. Sal's passion for these languages and ideas comes through in both these cookbooks. He also likes to push technologies as far as they can go and into every nook and cranny of application. This is reflected in the wide mix of recipes he assembled for these books. Sal has a Master's degree in Computer Science from Polytechnic University.
Preface
Introduction
MathematicaCookbook.com
Structure of This Book
Acknowledgments
Conventions Used in This Book
Using Code Examples
Safari® Enabled
How to Contact Us
Chapter 1: Numerics
1.1 1.0 Introduction
1.2 1.1 Controlling Precision and Accuracy
1.3 1.2 Mixing Different Numerical Types
1.4 1.3 Representing Numbers in Other Bases
1.5 1.4 Extracting the Digits of a Number
1.6 1.5 Working with Intervals
1.7 1.6 Converting Between Numerical Types
1.8 1.7 Displaying Numbers in Alternate Forms
Chapter 2: Functional Programming
2.1 2.0 Introduction
2.2 2.1 Mapping Functions with More Than One Argument
2.3 2.2 Holding Arbitrary Arguments
2.4 2.3 Creating Functions That Automatically Map Over Lists
2.5 2.4 Mapping Multiple Functions in a Single Pass
2.6 2.5 Keeping Track of the Index of Each Item As You Map
2.7 2.6 Mapping a Function over a Moving Sublist
2.8 2.7 Using Prefix and Postfix Notation to Produce More Readable Code
2.9 2.8 Defining Indexed Functions
2.10 2.9 Understanding the Use of Fold As an Alternative to Recursion
2.11 2.10 Incremental Construction of Lists
2.12 2.11 Computing Through Repeated Function Application
2.13 2.12 Building a Function Through Iteration
2.14 2.13 Exploiting Function Composition and Inverse Functions
2.15 2.14 Implementing Closures
2.16 2.15 Currying in Mathematica
2.17 2.16 Creating Functions with Default Values
2.18 2.17 Creating Functions That Accept Options
Chapter 3: Data Structures
3.1 3.0 Introduction
3.2 3.1 Ensuring the Most Efficient Representation of Numerical Lists
3.3 3.2 Sorting Lists
3.4 3.3 Determining Order Without Sorting
3.5 3.4 Extracting the Diagonals of a Matrix
3.6 3.5 Constructing Matrices of Specific Structure
3.7 3.6 Constructing Permutation and Shift Matrices
3.8 3.7 Manipulating Rows and Columns of Matrices
3.9 3.8 Using Sparse Arrays to Conserve Memory
3.10 3.9 Manipulating Deeply Nested Lists Using Functions with Level Specifications
3.11 3.10 Implementing Bit Vectors and Using Format to Customize Their Presentation
3.12 3.11 Implementing Trees and Traversals Using Lists
3.13 3.12 Implementing Ordered Associative Lookup Using a Red-Black Tree
3.14 3.13 Exploiting Mathematica's Built-In Associative Lookup
3.15 3.14 Constructing Graphs Using the Combinatorica' Package
3.16 3.15 Using Graph Algorithms to Extract Information from Graphs
Chapter 4: Patterns and Rule-Based Programming
4.1 4.0 Introduction
4.2 4.1 Collecting Items That Match (or Don't Match) a Pattern
4.3 4.2 Excluding Items That Match (or Don't Match) a Pattern
4.4 4.3 Counting Items That Match a Pattern
4.5 4.4 Replacing Parts of an Expression
4.6 4.5 Finding the Longest (or Shortest) Match for a Pattern
4.7 4.6 Implementing Algorithms in Terms of Rules
4.8 4.7 Debugging Infinite Loops When Using ReplaceRepeated
4.9 4.8 Preventing Evaluation Until Replace Is Complete
4.10 4.9 Manipulating Patterns with Patterns
4.11 4.10 Optimizing Rules
4.12 4.11 Using Patterns As a Query Language
4.13 4.12 Semantic Pattern Matching
4.14 4.13 Unification Pattern Matching
Chapter 5: String and Text Processing
5.1 5.0 Introduction
5.2 5.1 Comparing Strings
5.3 5.2 Removing and Replacing Characters from Strings
5.4 5.3 Extracting Characters and Substrings
5.5 5.4 Duplicating a String
5.6 5.5 Matching and Searching Text
5.7 5.6 Tokenizing Text
5.8 5.7 Working with Natural Language Dictionaries
5.9 5.8 Importing XML
5.10 5.9 Transforming XML Using Patterns and Rules
5.11 5.10 Transforming XML Using Recursive Functions (à la XSLT)
5.12 5.11 Writing Parsers and Grammars in Mathematica
Chapter 6: Two-Dimensional Graphics and Plots
6.1 6.0 Introduction
6.2 6.1 Plotting Functions in Cartesian Coordinates
6.3 6.2 Plotting in Polar Coordinates
6.4 6.3 Creating Plots Parametrically
6.5 6.4 Plotting Data
6.6 6.5 Mixing Two or More Graphs into a Single Graph
6.7 6.6 Displaying Multiple Graphs in a Grid
6.8 6.7 Creating Plots with Legends
6.9 6.8 Displaying 2D Geometric Shapes
6.10 6.9 Annotating Graphics with Text
6.11 6.10 Creating Custom Arrows
Chapter 7: Three-Dimensional Graphics and Plots
7.1 7.0 Introduction
7.2 7.1 Plotting Functions of Two Variables in Cartesian Coordinates
7.3 7.2 Plotting Functions in Spherical Coordinates
7.4 7.3 Plotting Surfaces in Cylindrical Coordinates
7.5 7.4 Plotting 3D Surfaces Parametrically
7.6 7.5 Creating 3D Contour Plots
7.7 7.6 Combining 2D Contours with 3D Plots
7.8 7.7 Constraining Plots to Specified Regions
7.9 7.8 Plotting Data in 3D
7.10 7.9 Plotting 3D Regions Where a Predicate Is Satisfied
7.11 7.10 Displaying 3D Geometrical Shapes
7.12 7.11 Constructing Wireframe Models from Mesh
7.13 7.12 Controlling Viewing Geometry
7.14 7.13 Controlling Lighting and Surface Properties
7.15 7.14 Transforming 3D Graphics
7.16 7.15 Exploring Polyhedra
7.17 7.16 Importing 3D Graphics from CAD and Other 3D Software
Chapter 8: Image Processing
8.1 8.0 Introduction
8.2 8.1 Extracting Image Information
8.3 8.2 Converting Images from RGB Color Space to HSV Color Space
8.4 8.3 Enhancing Images Using Histogram Equalization
8.5 8.4 Correcting Images Using Histogram Specification
8.6 8.5 Sharpening Images Using Laplacian Transforms
8.7 8.6 Sharpening and Smoothing with Fourier Transforms
8.8 8.7 Detecting Edges in Images
8.9 8.8 Image Recognition Using Eigenvectors (Eigenimages)
Chapter 9: Audio and Music Processing
9.1 9.0 Introduction
9.2 9.1 Creating Musical Notes
9.3 9.2 Creating a Scale or a Melody
9.4 9.3 Adding Rhythm to a Melody
9.5 9.4 Controlling the Volume
9.6 9.5 Creating Chords
9.7 9.6 Playing a Chord Progression
9.8 9.7 Writing Music with Traditional Chord Notation
9.9 9.8 Creating Percussion Grooves
9.10 9.9 Creating More Complex Percussion Grooves
9.11 9.10 Exporting MIDI files
9.12 9.11 Playing Functions As Sound
9.13 9.12 Adding Tremolo
9.14 9.13 Adding Vibrato
9.15 9.14 Applying an Envelope to a Signal
9.16 9.15 Exploring Alternate Tunings
9.17 9.16 Importing Digital Sound Files
9.18 9.17 Analyzing Digital Sound Files
9.19 9.18 Slicing a Sample
Chapter 10: Algebra
10.1 10.0 Introduction
10.2 10.1 Solving Algebraic Equations
10.3 10.2 Finding a Polynomial from a Given Root
10.4 10.3 Transforming Expressions to Other Forms
10.5 10.4 Generating Polynomials
10.6 10.5 Decomposing Polynomials into Their Constituent Parts
10.7 10.6 Dividing Polynomials by Other Polynomials
Chapter 11: Calculus: Continuous and Discrete
11.1 11.0 Introduction
11.2 11.1 Computing Limits
11.3 11.2 Working with Piecewise Functions
11.4 11.3 Using Power Series Representations
11.5 11.4 Differentiating Functions
11.6 11.5 Integration
11.7 11.6 Solving Differential Equations
11.8 11.7 Solving Minima and Maxima Problems
11.9 11.8 Solving Vector Calculus Problems
11.10 11.9 Solving Problems Involving Sums and Products
11.11 11.10 Solving Difference Equations
11.12 11.11 Generating Functions and Sequence Recognition
Chapter 12: Statistics and Data Analysis
12.1 12.0 Introduction
12.2 12.1 Computing Common Statistical Metrics of Numerical and Symbolic Data
12.3 12.2 Generating Pseudorandom Numbers with a Given Distribution
12.4 12.3 Working with Probability Distributions
12.5 12.4 Demonstrating the Central Limit Theorem
12.6 12.5 Computing Covariance and Correlation of Vectors and Matrices
12.7 12.6 Measuring the Shape of Data
12.8 12.7 Finding and Adjusting for Outliers
12.9 12.8 Fitting Data Using a Linear Model
12.10 12.9 Fitting Data Using a Nonlinear Model
12.11 12.10 Creating Interpolation Functions from Data
12.12 12.11 Testing for Statistically Significant Difference Between Groups Using ANOVA
12.13 12.12 Hypothesis Testing with Categorical Data
12.14 12.13 Grouping Data into Clusters
12.15 12.14 Creating Common Statistical Plots
12.16 12.15 Quasi-Random Number Generation
12.17 12.16 Creating Stochastic Simulations
Chapter 13: Science and Engineering
13.1 13.0 Introduction
13.2 13.1 Working with Element Data
13.3 13.2 Working with Chemical Data
13.4 13.3 Working with Particle Data
13.5 13.4 Working with Genetic Data and Protein Data
13.6 13.5 Modeling Predator-Prey Dynamics
13.7 13.6 Solving Basic Rigid Bodies Problems
13.8 13.7 Solving Problems in Kinematics
13.9 13.8 Computing Normal Modes for Coupled Mass Problems
13.10 13.9 Modeling a Vibrating String
13.11 13.10 Modeling Electrical Circuits
13.12 13.11 Modeling Truss Structures Using the Finite Element Method
Chapter 14: Financial Engineering
14.1 14.0 Introduction
14.2 14.1 Leveraging Mathematica's Bundled Financial Data
14.3 14.2 Importing Financial Data from Websites
14.4 14.3 Present Value of Future Cash Flows
14.5 14.4 Interest Rate Sensitivity of Bonds
14.6 14.5 Constructing and Manipulating Yield Curves
14.7 14.6 Black-Scholes for European Option Pricing
14.8 14.7 Computing the Implied Volatility of Financial Derivatives
14.9 14.8 Speeding Up NDSolve When Solving Black-Scholes and Other PDEs
14.10 14.9 Developing an Explicit Finite Difference Method for the Black-Scholes Formula
14.11 14.10 Compiling an Implementation of Explicit Trinomial for Fast Pricing of American Options
14.12 14.11 Modeling the Value-at-Risk of a Portfolio Using Monte Carlo and Other Methods
14.13 14.12 Visualizing Trees for Interest-Rate Sensitive Instruments
Chapter 15: Interactivity
15.1 15.0 Introduction
15.2 15.1 Manipulating a Variable
15.3 15.2 Manipulating a Symbolic Expression
15.4 15.3 Manipulating a Plot
15.5 15.4 Creating Expressions for Which Value Dynamically Updates
15.6 15.5 Intercepting the Values of a Control Attached to a Dynamic Expression
15.7 15.6 Controlling Updates of Dynamic Values
15.8 15.7 Using DynamicModule As a Scoping Construct in Interactive Notebooks
15.9 15.8 Using Scratch Variables with DynamicModule to Balance Speed Versus Space
15.10 15.9 Making a Manipulate Self-Contained
15.11 15.10 Remembering the Values Found Using Manipulate
15.12 15.11 Improving Performance of Manipulate by Segregating Fast and Slow Operations
15.13 15.12 Localizing a Function in a Manipulate
15.14 15.13 Sharing DynamicModule Variables across Cell or Window Boundaries
15.15 15.14 Creating Your Own Custom Controls
15.16 15.15 Animating an Expression
15.17 15.16 Creating Custom Interfaces
15.18 15.17 Managing a Large Number of Controls in Limited Screen Real Estate
Chapter 16: Parallel Mathematica
16.1 16.0 Introduction
16.2 16.1 Configuring Local Kernels
16.3 16.2 Configuring Remote Services Kernels
16.4 16.3 Sending a Command to Multiple Kernels for Parallel Evaluation
16.5 16.4 Automatically Parallelizing Existing Serial Expressions
16.6 16.5 Distributing Data Segments in Parallel and Combining the Results
16.7 16.6 Implementing Data-Parallel Algorithms by Using ParallelMap
16.8 16.7 Decomposing a Problem into Parallel Data Sets
16.9 16.8 Choosing an Appropriate Distribution Method
16.10 16.9 Running Different Algorithms in Parallel and Accepting the First to Complete
16.11 16.10 Sharing Data Between Parallel Kernels
16.12 16.11 Preventing Race Conditions When Multiple Kernels Access a Shared Resource
16.13 16.12 Organizing Parallel Processing Operations Using a Pipeline Approach
16.14 16.13 Processing a Massive Number of Files Using the Map-Reduce Technique
16.15 16.14 Diagnosing Parallel Processing Performance
16.16 16.15 Measuring the Overhead of Parallelization in Your Environment
Chapter 17: Interfacing Mathematica
17.1 17.0 Introduction
17.2 17.1 Calling External Command Line Programs from Mathematica
17.3 17.2 Launching Windows Programs from Mathematica
17.4 17.3 Connecting the Frontend to a Remote Kernel
17.5 17.4 Using Mathematica with C and C++
17.6 17.5 Using Mathematica with Java
17.7 17.6 Using Mathematica to Interact with Microsoft's .NET Framework
17.8 17.7 Using the Mathematica Kernel from a .NET Application
17.9 17.8 Querying a Database
17.10 17.9 Updating a Database
17.11 17.10 Introspection of Databases
Chapter 18: Tricks of the Trade
18.1 18.0 Introduction
18.2 18.1 Cleaning Up During Incremental Development
18.3 18.2 Modifying Built-in Functions and Constants
18.4 18.3 Locating Undocumented Functions
18.5 18.4 Packaging Your Mathematica Solutions into Libraries for Others to Use
18.6 18.5 Compiling Functions to Improve Performance
18.7 18.6 Automating and Standardizing the Appearance of Notebooks Using Stylesheets
18.8 18.7 Transforming Notebooks into Other Forms
18.9 18.8 Calling into the Mathematica Frontend
18.10 18.9 Initializing and Cleaning Up Automatically
18.11 18.10 Customizing Frontend User Interaction
Chapter 19: Debugging and Testing
19.1 19.0 Introduction
19.2 19.1 Printing as the First Recourse to Debugging
19.3 19.2 Debugging Functions Called Many Times
19.4 19.3 Stack Tracing to Debug Recursive Functions
19.5 19.4 Taming Trace to Extract Useful Debugging Information
19.6 19.5 Creating a Poor Man's Mathematica Debugger
19.7 19.6 Debugging Built-In Functions with Evaluation and Step Monitors
19.8 19.7 Visual Debugging with Wolfram Workbench
19.9 19.8 Writing Unit Tests to Help Ensure Correctness of Your Code
19.10 19.9 Creating MUnit Tests Where Success Is Not Based on Equality Testing
19.11 19.10 Organizing and Controlling MUnit Tests and Test Suites
19.12 19.11 Integrating Wolfram Workbench's MUnit Package into the Frontend
About the Author
Colophon
Introduction
MathematicaCookbook.com
Structure of This Book
Acknowledgments
Conventions Used in This Book
Using Code Examples
Safari® Enabled
How to Contact Us
Chapter 1: Numerics
1.1 1.0 Introduction
1.2 1.1 Controlling Precision and Accuracy
1.3 1.2 Mixing Different Numerical Types
1.4 1.3 Representing Numbers in Other Bases
1.5 1.4 Extracting the Digits of a Number
1.6 1.5 Working with Intervals
1.7 1.6 Converting Between Numerical Types
1.8 1.7 Displaying Numbers in Alternate Forms
Chapter 2: Functional Programming
2.1 2.0 Introduction
2.2 2.1 Mapping Functions with More Than One Argument
2.3 2.2 Holding Arbitrary Arguments
2.4 2.3 Creating Functions That Automatically Map Over Lists
2.5 2.4 Mapping Multiple Functions in a Single Pass
2.6 2.5 Keeping Track of the Index of Each Item As You Map
2.7 2.6 Mapping a Function over a Moving Sublist
2.8 2.7 Using Prefix and Postfix Notation to Produce More Readable Code
2.9 2.8 Defining Indexed Functions
2.10 2.9 Understanding the Use of Fold As an Alternative to Recursion
2.11 2.10 Incremental Construction of Lists
2.12 2.11 Computing Through Repeated Function Application
2.13 2.12 Building a Function Through Iteration
2.14 2.13 Exploiting Function Composition and Inverse Functions
2.15 2.14 Implementing Closures
2.16 2.15 Currying in Mathematica
2.17 2.16 Creating Functions with Default Values
2.18 2.17 Creating Functions That Accept Options
Chapter 3: Data Structures
3.1 3.0 Introduction
3.2 3.1 Ensuring the Most Efficient Representation of Numerical Lists
3.3 3.2 Sorting Lists
3.4 3.3 Determining Order Without Sorting
3.5 3.4 Extracting the Diagonals of a Matrix
3.6 3.5 Constructing Matrices of Specific Structure
3.7 3.6 Constructing Permutation and Shift Matrices
3.8 3.7 Manipulating Rows and Columns of Matrices
3.9 3.8 Using Sparse Arrays to Conserve Memory
3.10 3.9 Manipulating Deeply Nested Lists Using Functions with Level Specifications
3.11 3.10 Implementing Bit Vectors and Using Format to Customize Their Presentation
3.12 3.11 Implementing Trees and Traversals Using Lists
3.13 3.12 Implementing Ordered Associative Lookup Using a Red-Black Tree
3.14 3.13 Exploiting Mathematica's Built-In Associative Lookup
3.15 3.14 Constructing Graphs Using the Combinatorica' Package
3.16 3.15 Using Graph Algorithms to Extract Information from Graphs
Chapter 4: Patterns and Rule-Based Programming
4.1 4.0 Introduction
4.2 4.1 Collecting Items That Match (or Don't Match) a Pattern
4.3 4.2 Excluding Items That Match (or Don't Match) a Pattern
4.4 4.3 Counting Items That Match a Pattern
4.5 4.4 Replacing Parts of an Expression
4.6 4.5 Finding the Longest (or Shortest) Match for a Pattern
4.7 4.6 Implementing Algorithms in Terms of Rules
4.8 4.7 Debugging Infinite Loops When Using ReplaceRepeated
4.9 4.8 Preventing Evaluation Until Replace Is Complete
4.10 4.9 Manipulating Patterns with Patterns
4.11 4.10 Optimizing Rules
4.12 4.11 Using Patterns As a Query Language
4.13 4.12 Semantic Pattern Matching
4.14 4.13 Unification Pattern Matching
Chapter 5: String and Text Processing
5.1 5.0 Introduction
5.2 5.1 Comparing Strings
5.3 5.2 Removing and Replacing Characters from Strings
5.4 5.3 Extracting Characters and Substrings
5.5 5.4 Duplicating a String
5.6 5.5 Matching and Searching Text
5.7 5.6 Tokenizing Text
5.8 5.7 Working with Natural Language Dictionaries
5.9 5.8 Importing XML
5.10 5.9 Transforming XML Using Patterns and Rules
5.11 5.10 Transforming XML Using Recursive Functions (à la XSLT)
5.12 5.11 Writing Parsers and Grammars in Mathematica
Chapter 6: Two-Dimensional Graphics and Plots
6.1 6.0 Introduction
6.2 6.1 Plotting Functions in Cartesian Coordinates
6.3 6.2 Plotting in Polar Coordinates
6.4 6.3 Creating Plots Parametrically
6.5 6.4 Plotting Data
6.6 6.5 Mixing Two or More Graphs into a Single Graph
6.7 6.6 Displaying Multiple Graphs in a Grid
6.8 6.7 Creating Plots with Legends
6.9 6.8 Displaying 2D Geometric Shapes
6.10 6.9 Annotating Graphics with Text
6.11 6.10 Creating Custom Arrows
Chapter 7: Three-Dimensional Graphics and Plots
7.1 7.0 Introduction
7.2 7.1 Plotting Functions of Two Variables in Cartesian Coordinates
7.3 7.2 Plotting Functions in Spherical Coordinates
7.4 7.3 Plotting Surfaces in Cylindrical Coordinates
7.5 7.4 Plotting 3D Surfaces Parametrically
7.6 7.5 Creating 3D Contour Plots
7.7 7.6 Combining 2D Contours with 3D Plots
7.8 7.7 Constraining Plots to Specified Regions
7.9 7.8 Plotting Data in 3D
7.10 7.9 Plotting 3D Regions Where a Predicate Is Satisfied
7.11 7.10 Displaying 3D Geometrical Shapes
7.12 7.11 Constructing Wireframe Models from Mesh
7.13 7.12 Controlling Viewing Geometry
7.14 7.13 Controlling Lighting and Surface Properties
7.15 7.14 Transforming 3D Graphics
7.16 7.15 Exploring Polyhedra
7.17 7.16 Importing 3D Graphics from CAD and Other 3D Software
Chapter 8: Image Processing
8.1 8.0 Introduction
8.2 8.1 Extracting Image Information
8.3 8.2 Converting Images from RGB Color Space to HSV Color Space
8.4 8.3 Enhancing Images Using Histogram Equalization
8.5 8.4 Correcting Images Using Histogram Specification
8.6 8.5 Sharpening Images Using Laplacian Transforms
8.7 8.6 Sharpening and Smoothing with Fourier Transforms
8.8 8.7 Detecting Edges in Images
8.9 8.8 Image Recognition Using Eigenvectors (Eigenimages)
Chapter 9: Audio and Music Processing
9.1 9.0 Introduction
9.2 9.1 Creating Musical Notes
9.3 9.2 Creating a Scale or a Melody
9.4 9.3 Adding Rhythm to a Melody
9.5 9.4 Controlling the Volume
9.6 9.5 Creating Chords
9.7 9.6 Playing a Chord Progression
9.8 9.7 Writing Music with Traditional Chord Notation
9.9 9.8 Creating Percussion Grooves
9.10 9.9 Creating More Complex Percussion Grooves
9.11 9.10 Exporting MIDI files
9.12 9.11 Playing Functions As Sound
9.13 9.12 Adding Tremolo
9.14 9.13 Adding Vibrato
9.15 9.14 Applying an Envelope to a Signal
9.16 9.15 Exploring Alternate Tunings
9.17 9.16 Importing Digital Sound Files
9.18 9.17 Analyzing Digital Sound Files
9.19 9.18 Slicing a Sample
Chapter 10: Algebra
10.1 10.0 Introduction
10.2 10.1 Solving Algebraic Equations
10.3 10.2 Finding a Polynomial from a Given Root
10.4 10.3 Transforming Expressions to Other Forms
10.5 10.4 Generating Polynomials
10.6 10.5 Decomposing Polynomials into Their Constituent Parts
10.7 10.6 Dividing Polynomials by Other Polynomials
Chapter 11: Calculus: Continuous and Discrete
11.1 11.0 Introduction
11.2 11.1 Computing Limits
11.3 11.2 Working with Piecewise Functions
11.4 11.3 Using Power Series Representations
11.5 11.4 Differentiating Functions
11.6 11.5 Integration
11.7 11.6 Solving Differential Equations
11.8 11.7 Solving Minima and Maxima Problems
11.9 11.8 Solving Vector Calculus Problems
11.10 11.9 Solving Problems Involving Sums and Products
11.11 11.10 Solving Difference Equations
11.12 11.11 Generating Functions and Sequence Recognition
Chapter 12: Statistics and Data Analysis
12.1 12.0 Introduction
12.2 12.1 Computing Common Statistical Metrics of Numerical and Symbolic Data
12.3 12.2 Generating Pseudorandom Numbers with a Given Distribution
12.4 12.3 Working with Probability Distributions
12.5 12.4 Demonstrating the Central Limit Theorem
12.6 12.5 Computing Covariance and Correlation of Vectors and Matrices
12.7 12.6 Measuring the Shape of Data
12.8 12.7 Finding and Adjusting for Outliers
12.9 12.8 Fitting Data Using a Linear Model
12.10 12.9 Fitting Data Using a Nonlinear Model
12.11 12.10 Creating Interpolation Functions from Data
12.12 12.11 Testing for Statistically Significant Difference Between Groups Using ANOVA
12.13 12.12 Hypothesis Testing with Categorical Data
12.14 12.13 Grouping Data into Clusters
12.15 12.14 Creating Common Statistical Plots
12.16 12.15 Quasi-Random Number Generation
12.17 12.16 Creating Stochastic Simulations
Chapter 13: Science and Engineering
13.1 13.0 Introduction
13.2 13.1 Working with Element Data
13.3 13.2 Working with Chemical Data
13.4 13.3 Working with Particle Data
13.5 13.4 Working with Genetic Data and Protein Data
13.6 13.5 Modeling Predator-Prey Dynamics
13.7 13.6 Solving Basic Rigid Bodies Problems
13.8 13.7 Solving Problems in Kinematics
13.9 13.8 Computing Normal Modes for Coupled Mass Problems
13.10 13.9 Modeling a Vibrating String
13.11 13.10 Modeling Electrical Circuits
13.12 13.11 Modeling Truss Structures Using the Finite Element Method
Chapter 14: Financial Engineering
14.1 14.0 Introduction
14.2 14.1 Leveraging Mathematica's Bundled Financial Data
14.3 14.2 Importing Financial Data from Websites
14.4 14.3 Present Value of Future Cash Flows
14.5 14.4 Interest Rate Sensitivity of Bonds
14.6 14.5 Constructing and Manipulating Yield Curves
14.7 14.6 Black-Scholes for European Option Pricing
14.8 14.7 Computing the Implied Volatility of Financial Derivatives
14.9 14.8 Speeding Up NDSolve When Solving Black-Scholes and Other PDEs
14.10 14.9 Developing an Explicit Finite Difference Method for the Black-Scholes Formula
14.11 14.10 Compiling an Implementation of Explicit Trinomial for Fast Pricing of American Options
14.12 14.11 Modeling the Value-at-Risk of a Portfolio Using Monte Carlo and Other Methods
14.13 14.12 Visualizing Trees for Interest-Rate Sensitive Instruments
Chapter 15: Interactivity
15.1 15.0 Introduction
15.2 15.1 Manipulating a Variable
15.3 15.2 Manipulating a Symbolic Expression
15.4 15.3 Manipulating a Plot
15.5 15.4 Creating Expressions for Which Value Dynamically Updates
15.6 15.5 Intercepting the Values of a Control Attached to a Dynamic Expression
15.7 15.6 Controlling Updates of Dynamic Values
15.8 15.7 Using DynamicModule As a Scoping Construct in Interactive Notebooks
15.9 15.8 Using Scratch Variables with DynamicModule to Balance Speed Versus Space
15.10 15.9 Making a Manipulate Self-Contained
15.11 15.10 Remembering the Values Found Using Manipulate
15.12 15.11 Improving Performance of Manipulate by Segregating Fast and Slow Operations
15.13 15.12 Localizing a Function in a Manipulate
15.14 15.13 Sharing DynamicModule Variables across Cell or Window Boundaries
15.15 15.14 Creating Your Own Custom Controls
15.16 15.15 Animating an Expression
15.17 15.16 Creating Custom Interfaces
15.18 15.17 Managing a Large Number of Controls in Limited Screen Real Estate
Chapter 16: Parallel Mathematica
16.1 16.0 Introduction
16.2 16.1 Configuring Local Kernels
16.3 16.2 Configuring Remote Services Kernels
16.4 16.3 Sending a Command to Multiple Kernels for Parallel Evaluation
16.5 16.4 Automatically Parallelizing Existing Serial Expressions
16.6 16.5 Distributing Data Segments in Parallel and Combining the Results
16.7 16.6 Implementing Data-Parallel Algorithms by Using ParallelMap
16.8 16.7 Decomposing a Problem into Parallel Data Sets
16.9 16.8 Choosing an Appropriate Distribution Method
16.10 16.9 Running Different Algorithms in Parallel and Accepting the First to Complete
16.11 16.10 Sharing Data Between Parallel Kernels
16.12 16.11 Preventing Race Conditions When Multiple Kernels Access a Shared Resource
16.13 16.12 Organizing Parallel Processing Operations Using a Pipeline Approach
16.14 16.13 Processing a Massive Number of Files Using the Map-Reduce Technique
16.15 16.14 Diagnosing Parallel Processing Performance
16.16 16.15 Measuring the Overhead of Parallelization in Your Environment
Chapter 17: Interfacing Mathematica
17.1 17.0 Introduction
17.2 17.1 Calling External Command Line Programs from Mathematica
17.3 17.2 Launching Windows Programs from Mathematica
17.4 17.3 Connecting the Frontend to a Remote Kernel
17.5 17.4 Using Mathematica with C and C++
17.6 17.5 Using Mathematica with Java
17.7 17.6 Using Mathematica to Interact with Microsoft's .NET Framework
17.8 17.7 Using the Mathematica Kernel from a .NET Application
17.9 17.8 Querying a Database
17.10 17.9 Updating a Database
17.11 17.10 Introspection of Databases
Chapter 18: Tricks of the Trade
18.1 18.0 Introduction
18.2 18.1 Cleaning Up During Incremental Development
18.3 18.2 Modifying Built-in Functions and Constants
18.4 18.3 Locating Undocumented Functions
18.5 18.4 Packaging Your Mathematica Solutions into Libraries for Others to Use
18.6 18.5 Compiling Functions to Improve Performance
18.7 18.6 Automating and Standardizing the Appearance of Notebooks Using Stylesheets
18.8 18.7 Transforming Notebooks into Other Forms
18.9 18.8 Calling into the Mathematica Frontend
18.10 18.9 Initializing and Cleaning Up Automatically
18.11 18.10 Customizing Frontend User Interaction
Chapter 19: Debugging and Testing
19.1 19.0 Introduction
19.2 19.1 Printing as the First Recourse to Debugging
19.3 19.2 Debugging Functions Called Many Times
19.4 19.3 Stack Tracing to Debug Recursive Functions
19.5 19.4 Taming Trace to Extract Useful Debugging Information
19.6 19.5 Creating a Poor Man's Mathematica Debugger
19.7 19.6 Debugging Built-In Functions with Evaluation and Step Monitors
19.8 19.7 Visual Debugging with Wolfram Workbench
19.9 19.8 Writing Unit Tests to Help Ensure Correctness of Your Code
19.10 19.9 Creating MUnit Tests Where Success Is Not Based on Equality Testing
19.11 19.10 Organizing and Controlling MUnit Tests and Test Suites
19.12 19.11 Integrating Wolfram Workbench's MUnit Package into the Frontend
About the Author
Colophon
Preface
Introduction
MathematicaCookbook.com
Structure of This Book
Acknowledgments
Conventions Used in This Book
Using Code Examples
Safari® Enabled
How to Contact Us
Chapter 1: Numerics
1.1 1.0 Introduction
1.2 1.1 Controlling Precision and Accuracy
1.3 1.2 Mixing Different Numerical Types
1.4 1.3 Representing Numbers in Other Bases
1.5 1.4 Extracting the Digits of a Number
1.6 1.5 Working with Intervals
1.7 1.6 Converting Between Numerical Types
1.8 1.7 Displaying Numbers in Alternate Forms
Chapter 2: Functional Programming
2.1 2.0 Introduction
2.2 2.1 Mapping Functions with More Than One Argument
2.3 2.2 Holding Arbitrary Arguments
2.4 2.3 Creating Functions That Automatically Map Over Lists
2.5 2.4 Mapping Multiple Functions in a Single Pass
2.6 2.5 Keeping Track of the Index of Each Item As You Map
2.7 2.6 Mapping a Function over a Moving Sublist
2.8 2.7 Using Prefix and Postfix Notation to Produce More Readable Code
2.9 2.8 Defining Indexed Functions
2.10 2.9 Understanding the Use of Fold As an Alternative to Recursion
2.11 2.10 Incremental Construction of Lists
2.12 2.11 Computing Through Repeated Function Application
2.13 2.12 Building a Function Through Iteration
2.14 2.13 Exploiting Function Composition and Inverse Functions
2.15 2.14 Implementing Closures
2.16 2.15 Currying in Mathematica
2.17 2.16 Creating Functions with Default Values
2.18 2.17 Creating Functions That Accept Options
Chapter 3: Data Structures
3.1 3.0 Introduction
3.2 3.1 Ensuring the Most Efficient Representation of Numerical Lists
3.3 3.2 Sorting Lists
3.4 3.3 Determining Order Without Sorting
3.5 3.4 Extracting the Diagonals of a Matrix
3.6 3.5 Constructing Matrices of Specific Structure
3.7 3.6 Constructing Permutation and Shift Matrices
3.8 3.7 Manipulating Rows and Columns of Matrices
3.9 3.8 Using Sparse Arrays to Conserve Memory
3.10 3.9 Manipulating Deeply Nested Lists Using Functions with Level Specifications
3.11 3.10 Implementing Bit Vectors and Using Format to Customize Their Presentation
3.12 3.11 Implementing Trees and Traversals Using Lists
3.13 3.12 Implementing Ordered Associative Lookup Using a Red-Black Tree
3.14 3.13 Exploiting Mathematica's Built-In Associative Lookup
3.15 3.14 Constructing Graphs Using the Combinatorica' Package
3.16 3.15 Using Graph Algorithms to Extract Information from Graphs
Chapter 4: Patterns and Rule-Based Programming
4.1 4.0 Introduction
4.2 4.1 Collecting Items That Match (or Don't Match) a Pattern
4.3 4.2 Excluding Items That Match (or Don't Match) a Pattern
4.4 4.3 Counting Items That Match a Pattern
4.5 4.4 Replacing Parts of an Expression
4.6 4.5 Finding the Longest (or Shortest) Match for a Pattern
4.7 4.6 Implementing Algorithms in Terms of Rules
4.8 4.7 Debugging Infinite Loops When Using ReplaceRepeated
4.9 4.8 Preventing Evaluation Until Replace Is Complete
4.10 4.9 Manipulating Patterns with Patterns
4.11 4.10 Optimizing Rules
4.12 4.11 Using Patterns As a Query Language
4.13 4.12 Semantic Pattern Matching
4.14 4.13 Unification Pattern Matching
Chapter 5: String and Text Processing
5.1 5.0 Introduction
5.2 5.1 Comparing Strings
5.3 5.2 Removing and Replacing Characters from Strings
5.4 5.3 Extracting Characters and Substrings
5.5 5.4 Duplicating a String
5.6 5.5 Matching and Searching Text
5.7 5.6 Tokenizing Text
5.8 5.7 Working with Natural Language Dictionaries
5.9 5.8 Importing XML
5.10 5.9 Transforming XML Using Patterns and Rules
5.11 5.10 Transforming XML Using Recursive Functions (à la XSLT)
5.12 5.11 Writing Parsers and Grammars in Mathematica
Chapter 6: Two-Dimensional Graphics and Plots
6.1 6.0 Introduction
6.2 6.1 Plotting Functions in Cartesian Coordinates
6.3 6.2 Plotting in Polar Coordinates
6.4 6.3 Creating Plots Parametrically
6.5 6.4 Plotting Data
6.6 6.5 Mixing Two or More Graphs into a Single Graph
6.7 6.6 Displaying Multiple Graphs in a Grid
6.8 6.7 Creating Plots with Legends
6.9 6.8 Displaying 2D Geometric Shapes
6.10 6.9 Annotating Graphics with Text
6.11 6.10 Creating Custom Arrows
Chapter 7: Three-Dimensional Graphics and Plots
7.1 7.0 Introduction
7.2 7.1 Plotting Functions of Two Variables in Cartesian Coordinates
7.3 7.2 Plotting Functions in Spherical Coordinates
7.4 7.3 Plotting Surfaces in Cylindrical Coordinates
7.5 7.4 Plotting 3D Surfaces Parametrically
7.6 7.5 Creating 3D Contour Plots
7.7 7.6 Combining 2D Contours with 3D Plots
7.8 7.7 Constraining Plots to Specified Regions
7.9 7.8 Plotting Data in 3D
7.10 7.9 Plotting 3D Regions Where a Predicate Is Satisfied
7.11 7.10 Displaying 3D Geometrical Shapes
7.12 7.11 Constructing Wireframe Models from Mesh
7.13 7.12 Controlling Viewing Geometry
7.14 7.13 Controlling Lighting and Surface Properties
7.15 7.14 Transforming 3D Graphics
7.16 7.15 Exploring Polyhedra
7.17 7.16 Importing 3D Graphics from CAD and Other 3D Software
Chapter 8: Image Processing
8.1 8.0 Introduction
8.2 8.1 Extracting Image Information
8.3 8.2 Converting Images from RGB Color Space to HSV Color Space
8.4 8.3 Enhancing Images Using Histogram Equalization
8.5 8.4 Correcting Images Using Histogram Specification
8.6 8.5 Sharpening Images Using Laplacian Transforms
8.7 8.6 Sharpening and Smoothing with Fourier Transforms
8.8 8.7 Detecting Edges in Images
8.9 8.8 Image Recognition Using Eigenvectors (Eigenimages)
Chapter 9: Audio and Music Processing
9.1 9.0 Introduction
9.2 9.1 Creating Musical Notes
9.3 9.2 Creating a Scale or a Melody
9.4 9.3 Adding Rhythm to a Melody
9.5 9.4 Controlling the Volume
9.6 9.5 Creating Chords
9.7 9.6 Playing a Chord Progression
9.8 9.7 Writing Music with Traditional Chord Notation
9.9 9.8 Creating Percussion Grooves
9.10 9.9 Creating More Complex Percussion Grooves
9.11 9.10 Exporting MIDI files
9.12 9.11 Playing Functions As Sound
9.13 9.12 Adding Tremolo
9.14 9.13 Adding Vibrato
9.15 9.14 Applying an Envelope to a Signal
9.16 9.15 Exploring Alternate Tunings
9.17 9.16 Importing Digital Sound Files
9.18 9.17 Analyzing Digital Sound Files
9.19 9.18 Slicing a Sample
Chapter 10: Algebra
10.1 10.0 Introduction
10.2 10.1 Solving Algebraic Equations
10.3 10.2 Finding a Polynomial from a Given Root
10.4 10.3 Transforming Expressions to Other Forms
10.5 10.4 Generating Polynomials
10.6 10.5 Decomposing Polynomials into Their Constituent Parts
10.7 10.6 Dividing Polynomials by Other Polynomials
Chapter 11: Calculus: Continuous and Discrete
11.1 11.0 Introduction
11.2 11.1 Computing Limits
11.3 11.2 Working with Piecewise Functions
11.4 11.3 Using Power Series Representations
11.5 11.4 Differentiating Functions
11.6 11.5 Integration
11.7 11.6 Solving Differential Equations
11.8 11.7 Solving Minima and Maxima Problems
11.9 11.8 Solving Vector Calculus Problems
11.10 11.9 Solving Problems Involving Sums and Products
11.11 11.10 Solving Difference Equations
11.12 11.11 Generating Functions and Sequence Recognition
Chapter 12: Statistics and Data Analysis
12.1 12.0 Introduction
12.2 12.1 Computing Common Statistical Metrics of Numerical and Symbolic Data
12.3 12.2 Generating Pseudorandom Numbers with a Given Distribution
12.4 12.3 Working with Probability Distributions
12.5 12.4 Demonstrating the Central Limit Theorem
12.6 12.5 Computing Covariance and Correlation of Vectors and Matrices
12.7 12.6 Measuring the Shape of Data
12.8 12.7 Finding and Adjusting for Outliers
12.9 12.8 Fitting Data Using a Linear Model
12.10 12.9 Fitting Data Using a Nonlinear Model
12.11 12.10 Creating Interpolation Functions from Data
12.12 12.11 Testing for Statistically Significant Difference Between Groups Using ANOVA
12.13 12.12 Hypothesis Testing with Categorical Data
12.14 12.13 Grouping Data into Clusters
12.15 12.14 Creating Common Statistical Plots
12.16 12.15 Quasi-Random Number Generation
12.17 12.16 Creating Stochastic Simulations
Chapter 13: Science and Engineering
13.1 13.0 Introduction
13.2 13.1 Working with Element Data
13.3 13.2 Working with Chemical Data
13.4 13.3 Working with Particle Data
13.5 13.4 Working with Genetic Data and Protein Data
13.6 13.5 Modeling Predator-Prey Dynamics
13.7 13.6 Solving Basic Rigid Bodies Problems
13.8 13.7 Solving Problems in Kinematics
13.9 13.8 Computing Normal Modes for Coupled Mass Problems
13.10 13.9 Modeling a Vibrating String
13.11 13.10 Modeling Electrical Circuits
13.12 13.11 Modeling Truss Structures Using the Finite Element Method
Chapter 14: Financial Engineering
14.1 14.0 Introduction
14.2 14.1 Leveraging Mathematica's Bundled Financial Data
14.3 14.2 Importing Financial Data from Websites
14.4 14.3 Present Value of Future Cash Flows
14.5 14.4 Interest Rate Sensitivity of Bonds
14.6 14.5 Constructing and Manipulating Yield Curves
14.7 14.6 Black-Scholes for European Option Pricing
14.8 14.7 Computing the Implied Volatility of Financial Derivatives
14.9 14.8 Speeding Up NDSolve When Solving Black-Scholes and Other PDEs
14.10 14.9 Developing an Explicit Finite Difference Method for the Black-Scholes Formula
14.11 14.10 Compiling an Implementation of Explicit Trinomial for Fast Pricing of American Options
14.12 14.11 Modeling the Value-at-Risk of a Portfolio Using Monte Carlo and Other Methods
14.13 14.12 Visualizing Trees for Interest-Rate Sensitive Instruments
Chapter 15: Interactivity
15.1 15.0 Introduction
15.2 15.1 Manipulating a Variable
15.3 15.2 Manipulating a Symbolic Expression
15.4 15.3 Manipulating a Plot
15.5 15.4 Creating Expressions for Which Value Dynamically Updates
15.6 15.5 Intercepting the Values of a Control Attached to a Dynamic Expression
15.7 15.6 Controlling Updates of Dynamic Values
15.8 15.7 Using DynamicModule As a Scoping Construct in Interactive Notebooks
15.9 15.8 Using Scratch Variables with DynamicModule to Balance Speed Versus Space
15.10 15.9 Making a Manipulate Self-Contained
15.11 15.10 Remembering the Values Found Using Manipulate
15.12 15.11 Improving Performance of Manipulate by Segregating Fast and Slow Operations
15.13 15.12 Localizing a Function in a Manipulate
15.14 15.13 Sharing DynamicModule Variables across Cell or Window Boundaries
15.15 15.14 Creating Your Own Custom Controls
15.16 15.15 Animating an Expression
15.17 15.16 Creating Custom Interfaces
15.18 15.17 Managing a Large Number of Controls in Limited Screen Real Estate
Chapter 16: Parallel Mathematica
16.1 16.0 Introduction
16.2 16.1 Configuring Local Kernels
16.3 16.2 Configuring Remote Services Kernels
16.4 16.3 Sending a Command to Multiple Kernels for Parallel Evaluation
16.5 16.4 Automatically Parallelizing Existing Serial Expressions
16.6 16.5 Distributing Data Segments in Parallel and Combining the Results
16.7 16.6 Implementing Data-Parallel Algorithms by Using ParallelMap
16.8 16.7 Decomposing a Problem into Parallel Data Sets
16.9 16.8 Choosing an Appropriate Distribution Method
16.10 16.9 Running Different Algorithms in Parallel and Accepting the First to Complete
16.11 16.10 Sharing Data Between Parallel Kernels
16.12 16.11 Preventing Race Conditions When Multiple Kernels Access a Shared Resource
16.13 16.12 Organizing Parallel Processing Operations Using a Pipeline Approach
16.14 16.13 Processing a Massive Number of Files Using the Map-Reduce Technique
16.15 16.14 Diagnosing Parallel Processing Performance
16.16 16.15 Measuring the Overhead of Parallelization in Your Environment
Chapter 17: Interfacing Mathematica
17.1 17.0 Introduction
17.2 17.1 Calling External Command Line Programs from Mathematica
17.3 17.2 Launching Windows Programs from Mathematica
17.4 17.3 Connecting the Frontend to a Remote Kernel
17.5 17.4 Using Mathematica with C and C++
17.6 17.5 Using Mathematica with Java
17.7 17.6 Using Mathematica to Interact with Microsoft's .NET Framework
17.8 17.7 Using the Mathematica Kernel from a .NET Application
17.9 17.8 Querying a Database
17.10 17.9 Updating a Database
17.11 17.10 Introspection of Databases
Chapter 18: Tricks of the Trade
18.1 18.0 Introduction
18.2 18.1 Cleaning Up During Incremental Development
18.3 18.2 Modifying Built-in Functions and Constants
18.4 18.3 Locating Undocumented Functions
18.5 18.4 Packaging Your Mathematica Solutions into Libraries for Others to Use
18.6 18.5 Compiling Functions to Improve Performance
18.7 18.6 Automating and Standardizing the Appearance of Notebooks Using Stylesheets
18.8 18.7 Transforming Notebooks into Other Forms
18.9 18.8 Calling into the Mathematica Frontend
18.10 18.9 Initializing and Cleaning Up Automatically
18.11 18.10 Customizing Frontend User Interaction
Chapter 19: Debugging and Testing
19.1 19.0 Introduction
19.2 19.1 Printing as the First Recourse to Debugging
19.3 19.2 Debugging Functions Called Many Times
19.4 19.3 Stack Tracing to Debug Recursive Functions
19.5 19.4 Taming Trace to Extract Useful Debugging Information
19.6 19.5 Creating a Poor Man's Mathematica Debugger
19.7 19.6 Debugging Built-In Functions with Evaluation and Step Monitors
19.8 19.7 Visual Debugging with Wolfram Workbench
19.9 19.8 Writing Unit Tests to Help Ensure Correctness of Your Code
19.10 19.9 Creating MUnit Tests Where Success Is Not Based on Equality Testing
19.11 19.10 Organizing and Controlling MUnit Tests and Test Suites
19.12 19.11 Integrating Wolfram Workbench's MUnit Package into the Frontend
About the Author
Colophon
Introduction
MathematicaCookbook.com
Structure of This Book
Acknowledgments
Conventions Used in This Book
Using Code Examples
Safari® Enabled
How to Contact Us
Chapter 1: Numerics
1.1 1.0 Introduction
1.2 1.1 Controlling Precision and Accuracy
1.3 1.2 Mixing Different Numerical Types
1.4 1.3 Representing Numbers in Other Bases
1.5 1.4 Extracting the Digits of a Number
1.6 1.5 Working with Intervals
1.7 1.6 Converting Between Numerical Types
1.8 1.7 Displaying Numbers in Alternate Forms
Chapter 2: Functional Programming
2.1 2.0 Introduction
2.2 2.1 Mapping Functions with More Than One Argument
2.3 2.2 Holding Arbitrary Arguments
2.4 2.3 Creating Functions That Automatically Map Over Lists
2.5 2.4 Mapping Multiple Functions in a Single Pass
2.6 2.5 Keeping Track of the Index of Each Item As You Map
2.7 2.6 Mapping a Function over a Moving Sublist
2.8 2.7 Using Prefix and Postfix Notation to Produce More Readable Code
2.9 2.8 Defining Indexed Functions
2.10 2.9 Understanding the Use of Fold As an Alternative to Recursion
2.11 2.10 Incremental Construction of Lists
2.12 2.11 Computing Through Repeated Function Application
2.13 2.12 Building a Function Through Iteration
2.14 2.13 Exploiting Function Composition and Inverse Functions
2.15 2.14 Implementing Closures
2.16 2.15 Currying in Mathematica
2.17 2.16 Creating Functions with Default Values
2.18 2.17 Creating Functions That Accept Options
Chapter 3: Data Structures
3.1 3.0 Introduction
3.2 3.1 Ensuring the Most Efficient Representation of Numerical Lists
3.3 3.2 Sorting Lists
3.4 3.3 Determining Order Without Sorting
3.5 3.4 Extracting the Diagonals of a Matrix
3.6 3.5 Constructing Matrices of Specific Structure
3.7 3.6 Constructing Permutation and Shift Matrices
3.8 3.7 Manipulating Rows and Columns of Matrices
3.9 3.8 Using Sparse Arrays to Conserve Memory
3.10 3.9 Manipulating Deeply Nested Lists Using Functions with Level Specifications
3.11 3.10 Implementing Bit Vectors and Using Format to Customize Their Presentation
3.12 3.11 Implementing Trees and Traversals Using Lists
3.13 3.12 Implementing Ordered Associative Lookup Using a Red-Black Tree
3.14 3.13 Exploiting Mathematica's Built-In Associative Lookup
3.15 3.14 Constructing Graphs Using the Combinatorica' Package
3.16 3.15 Using Graph Algorithms to Extract Information from Graphs
Chapter 4: Patterns and Rule-Based Programming
4.1 4.0 Introduction
4.2 4.1 Collecting Items That Match (or Don't Match) a Pattern
4.3 4.2 Excluding Items That Match (or Don't Match) a Pattern
4.4 4.3 Counting Items That Match a Pattern
4.5 4.4 Replacing Parts of an Expression
4.6 4.5 Finding the Longest (or Shortest) Match for a Pattern
4.7 4.6 Implementing Algorithms in Terms of Rules
4.8 4.7 Debugging Infinite Loops When Using ReplaceRepeated
4.9 4.8 Preventing Evaluation Until Replace Is Complete
4.10 4.9 Manipulating Patterns with Patterns
4.11 4.10 Optimizing Rules
4.12 4.11 Using Patterns As a Query Language
4.13 4.12 Semantic Pattern Matching
4.14 4.13 Unification Pattern Matching
Chapter 5: String and Text Processing
5.1 5.0 Introduction
5.2 5.1 Comparing Strings
5.3 5.2 Removing and Replacing Characters from Strings
5.4 5.3 Extracting Characters and Substrings
5.5 5.4 Duplicating a String
5.6 5.5 Matching and Searching Text
5.7 5.6 Tokenizing Text
5.8 5.7 Working with Natural Language Dictionaries
5.9 5.8 Importing XML
5.10 5.9 Transforming XML Using Patterns and Rules
5.11 5.10 Transforming XML Using Recursive Functions (à la XSLT)
5.12 5.11 Writing Parsers and Grammars in Mathematica
Chapter 6: Two-Dimensional Graphics and Plots
6.1 6.0 Introduction
6.2 6.1 Plotting Functions in Cartesian Coordinates
6.3 6.2 Plotting in Polar Coordinates
6.4 6.3 Creating Plots Parametrically
6.5 6.4 Plotting Data
6.6 6.5 Mixing Two or More Graphs into a Single Graph
6.7 6.6 Displaying Multiple Graphs in a Grid
6.8 6.7 Creating Plots with Legends
6.9 6.8 Displaying 2D Geometric Shapes
6.10 6.9 Annotating Graphics with Text
6.11 6.10 Creating Custom Arrows
Chapter 7: Three-Dimensional Graphics and Plots
7.1 7.0 Introduction
7.2 7.1 Plotting Functions of Two Variables in Cartesian Coordinates
7.3 7.2 Plotting Functions in Spherical Coordinates
7.4 7.3 Plotting Surfaces in Cylindrical Coordinates
7.5 7.4 Plotting 3D Surfaces Parametrically
7.6 7.5 Creating 3D Contour Plots
7.7 7.6 Combining 2D Contours with 3D Plots
7.8 7.7 Constraining Plots to Specified Regions
7.9 7.8 Plotting Data in 3D
7.10 7.9 Plotting 3D Regions Where a Predicate Is Satisfied
7.11 7.10 Displaying 3D Geometrical Shapes
7.12 7.11 Constructing Wireframe Models from Mesh
7.13 7.12 Controlling Viewing Geometry
7.14 7.13 Controlling Lighting and Surface Properties
7.15 7.14 Transforming 3D Graphics
7.16 7.15 Exploring Polyhedra
7.17 7.16 Importing 3D Graphics from CAD and Other 3D Software
Chapter 8: Image Processing
8.1 8.0 Introduction
8.2 8.1 Extracting Image Information
8.3 8.2 Converting Images from RGB Color Space to HSV Color Space
8.4 8.3 Enhancing Images Using Histogram Equalization
8.5 8.4 Correcting Images Using Histogram Specification
8.6 8.5 Sharpening Images Using Laplacian Transforms
8.7 8.6 Sharpening and Smoothing with Fourier Transforms
8.8 8.7 Detecting Edges in Images
8.9 8.8 Image Recognition Using Eigenvectors (Eigenimages)
Chapter 9: Audio and Music Processing
9.1 9.0 Introduction
9.2 9.1 Creating Musical Notes
9.3 9.2 Creating a Scale or a Melody
9.4 9.3 Adding Rhythm to a Melody
9.5 9.4 Controlling the Volume
9.6 9.5 Creating Chords
9.7 9.6 Playing a Chord Progression
9.8 9.7 Writing Music with Traditional Chord Notation
9.9 9.8 Creating Percussion Grooves
9.10 9.9 Creating More Complex Percussion Grooves
9.11 9.10 Exporting MIDI files
9.12 9.11 Playing Functions As Sound
9.13 9.12 Adding Tremolo
9.14 9.13 Adding Vibrato
9.15 9.14 Applying an Envelope to a Signal
9.16 9.15 Exploring Alternate Tunings
9.17 9.16 Importing Digital Sound Files
9.18 9.17 Analyzing Digital Sound Files
9.19 9.18 Slicing a Sample
Chapter 10: Algebra
10.1 10.0 Introduction
10.2 10.1 Solving Algebraic Equations
10.3 10.2 Finding a Polynomial from a Given Root
10.4 10.3 Transforming Expressions to Other Forms
10.5 10.4 Generating Polynomials
10.6 10.5 Decomposing Polynomials into Their Constituent Parts
10.7 10.6 Dividing Polynomials by Other Polynomials
Chapter 11: Calculus: Continuous and Discrete
11.1 11.0 Introduction
11.2 11.1 Computing Limits
11.3 11.2 Working with Piecewise Functions
11.4 11.3 Using Power Series Representations
11.5 11.4 Differentiating Functions
11.6 11.5 Integration
11.7 11.6 Solving Differential Equations
11.8 11.7 Solving Minima and Maxima Problems
11.9 11.8 Solving Vector Calculus Problems
11.10 11.9 Solving Problems Involving Sums and Products
11.11 11.10 Solving Difference Equations
11.12 11.11 Generating Functions and Sequence Recognition
Chapter 12: Statistics and Data Analysis
12.1 12.0 Introduction
12.2 12.1 Computing Common Statistical Metrics of Numerical and Symbolic Data
12.3 12.2 Generating Pseudorandom Numbers with a Given Distribution
12.4 12.3 Working with Probability Distributions
12.5 12.4 Demonstrating the Central Limit Theorem
12.6 12.5 Computing Covariance and Correlation of Vectors and Matrices
12.7 12.6 Measuring the Shape of Data
12.8 12.7 Finding and Adjusting for Outliers
12.9 12.8 Fitting Data Using a Linear Model
12.10 12.9 Fitting Data Using a Nonlinear Model
12.11 12.10 Creating Interpolation Functions from Data
12.12 12.11 Testing for Statistically Significant Difference Between Groups Using ANOVA
12.13 12.12 Hypothesis Testing with Categorical Data
12.14 12.13 Grouping Data into Clusters
12.15 12.14 Creating Common Statistical Plots
12.16 12.15 Quasi-Random Number Generation
12.17 12.16 Creating Stochastic Simulations
Chapter 13: Science and Engineering
13.1 13.0 Introduction
13.2 13.1 Working with Element Data
13.3 13.2 Working with Chemical Data
13.4 13.3 Working with Particle Data
13.5 13.4 Working with Genetic Data and Protein Data
13.6 13.5 Modeling Predator-Prey Dynamics
13.7 13.6 Solving Basic Rigid Bodies Problems
13.8 13.7 Solving Problems in Kinematics
13.9 13.8 Computing Normal Modes for Coupled Mass Problems
13.10 13.9 Modeling a Vibrating String
13.11 13.10 Modeling Electrical Circuits
13.12 13.11 Modeling Truss Structures Using the Finite Element Method
Chapter 14: Financial Engineering
14.1 14.0 Introduction
14.2 14.1 Leveraging Mathematica's Bundled Financial Data
14.3 14.2 Importing Financial Data from Websites
14.4 14.3 Present Value of Future Cash Flows
14.5 14.4 Interest Rate Sensitivity of Bonds
14.6 14.5 Constructing and Manipulating Yield Curves
14.7 14.6 Black-Scholes for European Option Pricing
14.8 14.7 Computing the Implied Volatility of Financial Derivatives
14.9 14.8 Speeding Up NDSolve When Solving Black-Scholes and Other PDEs
14.10 14.9 Developing an Explicit Finite Difference Method for the Black-Scholes Formula
14.11 14.10 Compiling an Implementation of Explicit Trinomial for Fast Pricing of American Options
14.12 14.11 Modeling the Value-at-Risk of a Portfolio Using Monte Carlo and Other Methods
14.13 14.12 Visualizing Trees for Interest-Rate Sensitive Instruments
Chapter 15: Interactivity
15.1 15.0 Introduction
15.2 15.1 Manipulating a Variable
15.3 15.2 Manipulating a Symbolic Expression
15.4 15.3 Manipulating a Plot
15.5 15.4 Creating Expressions for Which Value Dynamically Updates
15.6 15.5 Intercepting the Values of a Control Attached to a Dynamic Expression
15.7 15.6 Controlling Updates of Dynamic Values
15.8 15.7 Using DynamicModule As a Scoping Construct in Interactive Notebooks
15.9 15.8 Using Scratch Variables with DynamicModule to Balance Speed Versus Space
15.10 15.9 Making a Manipulate Self-Contained
15.11 15.10 Remembering the Values Found Using Manipulate
15.12 15.11 Improving Performance of Manipulate by Segregating Fast and Slow Operations
15.13 15.12 Localizing a Function in a Manipulate
15.14 15.13 Sharing DynamicModule Variables across Cell or Window Boundaries
15.15 15.14 Creating Your Own Custom Controls
15.16 15.15 Animating an Expression
15.17 15.16 Creating Custom Interfaces
15.18 15.17 Managing a Large Number of Controls in Limited Screen Real Estate
Chapter 16: Parallel Mathematica
16.1 16.0 Introduction
16.2 16.1 Configuring Local Kernels
16.3 16.2 Configuring Remote Services Kernels
16.4 16.3 Sending a Command to Multiple Kernels for Parallel Evaluation
16.5 16.4 Automatically Parallelizing Existing Serial Expressions
16.6 16.5 Distributing Data Segments in Parallel and Combining the Results
16.7 16.6 Implementing Data-Parallel Algorithms by Using ParallelMap
16.8 16.7 Decomposing a Problem into Parallel Data Sets
16.9 16.8 Choosing an Appropriate Distribution Method
16.10 16.9 Running Different Algorithms in Parallel and Accepting the First to Complete
16.11 16.10 Sharing Data Between Parallel Kernels
16.12 16.11 Preventing Race Conditions When Multiple Kernels Access a Shared Resource
16.13 16.12 Organizing Parallel Processing Operations Using a Pipeline Approach
16.14 16.13 Processing a Massive Number of Files Using the Map-Reduce Technique
16.15 16.14 Diagnosing Parallel Processing Performance
16.16 16.15 Measuring the Overhead of Parallelization in Your Environment
Chapter 17: Interfacing Mathematica
17.1 17.0 Introduction
17.2 17.1 Calling External Command Line Programs from Mathematica
17.3 17.2 Launching Windows Programs from Mathematica
17.4 17.3 Connecting the Frontend to a Remote Kernel
17.5 17.4 Using Mathematica with C and C++
17.6 17.5 Using Mathematica with Java
17.7 17.6 Using Mathematica to Interact with Microsoft's .NET Framework
17.8 17.7 Using the Mathematica Kernel from a .NET Application
17.9 17.8 Querying a Database
17.10 17.9 Updating a Database
17.11 17.10 Introspection of Databases
Chapter 18: Tricks of the Trade
18.1 18.0 Introduction
18.2 18.1 Cleaning Up During Incremental Development
18.3 18.2 Modifying Built-in Functions and Constants
18.4 18.3 Locating Undocumented Functions
18.5 18.4 Packaging Your Mathematica Solutions into Libraries for Others to Use
18.6 18.5 Compiling Functions to Improve Performance
18.7 18.6 Automating and Standardizing the Appearance of Notebooks Using Stylesheets
18.8 18.7 Transforming Notebooks into Other Forms
18.9 18.8 Calling into the Mathematica Frontend
18.10 18.9 Initializing and Cleaning Up Automatically
18.11 18.10 Customizing Frontend User Interaction
Chapter 19: Debugging and Testing
19.1 19.0 Introduction
19.2 19.1 Printing as the First Recourse to Debugging
19.3 19.2 Debugging Functions Called Many Times
19.4 19.3 Stack Tracing to Debug Recursive Functions
19.5 19.4 Taming Trace to Extract Useful Debugging Information
19.6 19.5 Creating a Poor Man's Mathematica Debugger
19.7 19.6 Debugging Built-In Functions with Evaluation and Step Monitors
19.8 19.7 Visual Debugging with Wolfram Workbench
19.9 19.8 Writing Unit Tests to Help Ensure Correctness of Your Code
19.10 19.9 Creating MUnit Tests Where Success Is Not Based on Equality Testing
19.11 19.10 Organizing and Controlling MUnit Tests and Test Suites
19.12 19.11 Integrating Wolfram Workbench's MUnit Package into the Frontend
About the Author
Colophon