Programming with Mathematica-: An Introduction
Format: PDF / Kindle (mobi) / ePub
Starting from first principles, this book covers all of the foundational material needed to develop a clear understanding of the Mathematica language, with a practical emphasis on solving problems. Concrete examples strewn throughout the text demonstrate how the language can be used to solve problems in science, engineering, economics/finance, computational linguistics, geoscience, bioinformatics and a range of other fields. The book will appeal to students, researchers and programmers wishing to further their understanding of Mathematica. Designed to suit users of any ability, it assumes no formal knowledge of programming so it is ideal for self-study. Over 275 exercises are provided to challenge the reader's understanding of the material covered and these provide ample opportunity to practise using the language. Mathematica notebooks containing examples, programs and solutions to exercises are available from www.cambridge.org/9781107009462.
nums = Range@10 000D; In:= Total@numsD Out= 50 005 000 % In:= Length@numsD 10 001 Out= 2 With the notebook interface, you can input as many lines as you like within an input cell; Mathematica will evaluate them all, in order, when you enter ˜ÎÛÏ. Alternative input syntax There are several different ways to write expressions in Mathematica. Usually, you will simply use the traditional notation, fun@xD, for example. But you should be aware of several alternatives to this
its arguments with commas. This is the form of every normal expression in Mathematica. Regardless of how an atomic or normal expression may appear in your notebook, its structure is uniquely determined by its head and parts as seen using FullForm . This is important for understanding the Mathematica evaluation mechanism which depends on the matching of patterns based on their internal representation, a subject we will turn to in detail in Chapter 4. The number of elements in any expression is
operations Predicates When working with many kinds of data, you are often presented with the problem of extracting values that meet certain criteria. Similarly, when you write programs, what to do next at any particular point in your program will often depend upon some test or condition being met. Every programming language has constructs for testing data or conditions. Some of the most useful constructs for these sorts of tests are called predicates. A predicate is a function that returns a
sense, a program is a mathematical function and the inputs to a program are the arguments of the function. Executing a program is equivalent to applying a function to its arguments or, as it is often referred to, making a function call. Building up programs Using the output of one function as the input of another is one of the keys to functional programming. This nesting of functions is commonly referred to by mathematicians as “composition of functions.” In Mathematica, this sequential
in a matrix. Create a message for this function that is issued whenever a row index greater than the size of the matrix is used as an argument. For example, In:= mat = RandomInteger@80, 9<, 84, 4