introduction to mathematical modeling in mathematica

63
©1998, Bruce E. Shapiro Introduction to Mathematical Modeling in Mathematica Bruce E. Shapiro Department of Biomathematics UCLA School of Medicine and Jet Propulsion Laboratory California Institute of Technology [email protected] 3 June 1998 Presented as part of Medical Informatics: A Course for Health Professionals Sponsored by the National Library of Medicine and Marine Biology Laboratory Water Street Woods Hole, MA 02543

Upload: katja-goite

Post on 08-Sep-2015

26 views

Category:

Documents


5 download

DESCRIPTION

Introduction to Mathematical Modeling in Mathematica

TRANSCRIPT

  • 1998, Bruce E. Shapiro

    Introduction toMathematical Modeling

    in Mathematica

    Bruce E. Shapiro

    Department of BiomathematicsUCLA School of Medicine

    andJet Propulsion Laboratory

    California Institute of Technology

    [email protected]

    3 June 1998

    Presented as part ofMedical Informatics: A Course for Health Professionals

    Sponsored by theNational Library of Medicine

    andMarine Biology Laboratory

    Water StreetWoods Hole, MA 02543

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 2Woods Hole, 1998

    Introduction............................................3Features of Mathematica........................4Commercially Available Applications.........8System Requirements.............................10Front End vs.Kernel...............................11

    Starting Mathematica............................12Arithmetic and Algebra...........................15Exact and Approximate Results................16Special Constants..................................17Vectors, Matrices and Lists.....................17Function..............................................19Loops.................................................21Local Variables.....................................22

    An Example Population Biology...........23Mathematica Reference Outline............24

    Numerical Computation.........................24Numerical Evaluation.........................24Equation Solving..............................24Sums and Products............................24Integration.......................................25Optimization....................................25Data Manipulation.............................25

    Curve Fitting...............................25Fourier Transform.........................26Selection of special elements...........26Set Manipulation..........................26

    Matrices and Vectors..........................27Matrix Operations.........................27Systems of Linear Equations...........27Matrix Decompositions..................27

    Complex Numbers............................28Number Representation......................28

    Heads..........................................28Digits, Exponents, and Mantissas.....28Change of Representation...............29Infinity........................................29

    Numerical Precision...........................29Evaluation Accuracy and Precision....29Intervals......................................29Machine Accuracy and Precision.......30

    Options...........................................30Algebraic Computation..........................30

    Basic Algebra...................................30Formula Manipulation.......................31

    Simplification..............................31Expansion....................................31Rearrangement..............................31Parts of an Expression....................32Numerators and Denominators.........32Trigonometric Function Manipulation..................................................32Root and Radical Manipulation........32Other Manipulations......................32

    Equation Solving..............................33Calculus..........................................33

    Derivatives...................................33Integration...................................34Limits, Residues, and Series............34Polynomial Manipulation...............35

    Mathematical Functions.........................37Basic Arithmetic...............................37Mathematical Constants.....................37Numerical Functions..........................37Random Numbers..............................38Elementary Functions........................38Factorial-Based Functions...................38Combinatorial Functions....................39Functions from Number Theory...........40Zeta Function...................................40Hypergeometric and Related Functions..41Orthogonal Polynomials.....................42Elliptic Functions.............................42Elliptic Integrals...............................43Mathieu Functions............................43

    Lists...................................................44Construction....................................44Element Extraction............................44List Testing.....................................45List Operations.................................46Structure Manipulations.....................47

    Graphics and Sound...............................48Data Plots........................................48Function Plots..................................48Parametric Plots................................48Sound Generation..............................48Combinations of Plots.......................48Options...........................................49Primitives........................................50

    Programming.......................................53Assignment......................................53Testing............................................53Flow of Control................................54

    Compound Expressions..................54Logical Testings: If, Which, Switch.55Looping: Do, While, For................55Transfer of Control........................55

    Functions........................................56Pattern Matching...............................56Rules..............................................58Strings............................................58

    References............................................59Appendices

    Lotka Volterra Notebook (On Disk) .........64Wolfram Tutorials (On Disk)...................71Tour of Mathematica (On Disk) ......91

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 3Woods Hole, 1998

    Introduction to Modeling inMathematica: Goal

    To develop a basic understanding of whatMathematica is and how it can be used to do

    Modeling through examples and hands-on experience.

    What is Mathematica?

    Mathematica is literally A system for doingmathematics on the computer. [Wolfram

    Research, Inc.]

    Mathematica is essentially a chalkboard fordoing mathematical computations on the

    computer.

    It is also a computer language - but you donthave to learn the language to use Mathematica.

    It was developed in the late 1980s by StevenWolfram and first released in 1988.

    Version 3.0 was released in 1996.

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 4Woods Hole, 1998

    Features of MathematicaIt can be used as a calculator

    Solves complicated numerical equations

    Solves complicated algebraic equations

    Two and three dimensional plotting

    No limit on numerical precision

    WYSIWYG interface available (on version 3.0)

    A powerful programming language

    A word processor which can also handlecomplicated Mathematical expressions

    Import/Export data, text, and graphics in standardformats

    Data manipulation - not just numbers

    No limit on the complexity of diagrams orequations

    Simple palettes and/or pull down menus forfunctions, special characters, and math symbols.

    Direct interfaces with Excel and Word (must bepurchased separately)

    Standardized ASCII file format to makeMathematica Notebooks transportable between

    platforms.

    Standardized ASCII format requires long learningcurve if something happens to your raw data file.

    Specialized Reader Program MathReader isavailable for free to read Mathematica Files.

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 5Woods Hole, 1998

    A specialized program, Mathreader, is required tounderstand the ASCII file.

    Front end and Kernel can be run on separatecomputers.

    Can be run directly off of CD-ROM.

    Takes a lot of hard disk space (doesnt everythingthese days?)

    Easy to get simple problems programmed quicklybut takes a long time to learn the whole language

    Language is list based (like LISP and SAS)

    Expensive (Windows Full Version: $1495;Educational Price at UCLA store $919; Student

    Edition: $139).

    The reference manual is over 1400 pages (is thisgood or bad?)

    Need a password to get it started the first time.Will randomly ask for password at subsequentsessions; this may be a virus, because it only

    seems to happen to me.

    Kernel/Front End Separation means long wait toexecute first command while Kernel is Loading.

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 6Woods Hole, 1998

    An Example: Write a Function to Solve aQuadratic Equation.

    What you enter (Version 3.0 Front End):

    What you enter (Version 2.2 Front End orVersion 3.0 Front End or Kernel):

    quadraticRoot[a_,b_, c_] := {(-b+Sqrt[b^2-4 a c])/2,

    (-b - Sqrt[b^2-4 a c])/2};

    What gets stored in the notebook file:

    \!\(\(quadraticRoot[a_, b_, c_]\ := \ {\(\(-b\) + \@\(b\^2 - 4\ a\c\)\)\/\(2 a\), \ \(\(-b\) - \@\(b\^2 - 4\ a\c\)\)\/\(2 a\)}; \)\)

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 7Woods Hole, 1998

    Screen Session for Quadratic

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 8Woods Hole, 1998

    Commercially Available Applications

    Application Company Description

    3D Explorer Conix OpenGL Graphics

    Calculus &Mathematica

    Bill Davis, AddisonWesley

    Undergraduate Calculus Course

    Calculus UsingMathematica

    K. D. Stroyan,Academic Press

    Three semester undergraduatecalculus course; includes separatescientific applications volume.

    Control SystemProfessional

    Wolfram Comprehensive SimulationEnvironment

    Cool Economics Pack Thomas Cool Econometrics and Statistics

    Derivatives Expert Innova Securities and Financial Analysis

    Electrical Engr.Examples

    Wolfram Circuits, Antennas, TransmissionLines

    Experimental DataAnalyst

    Wolfram Data fitting, error analysis,visualization

    Financial Essentials Wolfram Design of Financial Systems

    Fuzzy Logic Wolfram Fuzzy logic systems design

    Geometrica Wolfram Precise Geometric Design

    Global Optimization Loehle Nonlinear optimization

    Industrial Thermics Visual Analysis Thermal analysis

    Interactive Calculus Wolfram Learn calculus at your own pace

    InterCall Analytica IMSL & NAG direct access

    Leibniz Joe Gregg Alternative Front End

    Math Tensor MathTensor Tensor Analysis

    Mathematica Labs forCalculus Instruction

    Wolfram &Houghton Mifflin

    Lab notebooks and text for calculusinstruction.

    Mathlink for MS Excel Wolfram Put notebooks in Excel documents

    Mathlink for MS Word Wolfram Put notebooks in Word documents

    Mechanical Systems Wolfram Rigid body motion analysis

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 9Woods Hole, 1998

    Commercially Available Applications(continued)

    Application Company Description

    Nodal Macallan Linear Circuit Analysis

    Optica Wolfram Optical systems design & analysis

    Scientific Astronomer Wolfram General Astronomy System

    Signals and Systems Wolfram Signal processing

    Technical Trader Wolfram Trading

    Tensors in Physics Scandinavian Univ.Press

    CARTAN tensor package

    The Joy of Mathematica Alan Shuchat andFred Shultz,

    Addison Wesley

    Mathematica Tutorial

    Time Series Wolfram Time dependent data analysis

    TSiControsl Techno-Sciences Control Systems Design

    TSiDynamics Techno-Sciences Dynamical Systems

    Wavelet Explorer Wolfram Signal and image analysis

    Source: http://www.wolfram.com

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 10Woods Hole, 1998

    Mathematica System Requirements

    Platform Ver. HardDisk

    RAM

    MB: Rec./Min.

    Microsoft WindowsWindows 95Windows NT 3.51

    3.0.1 116/30 16/8

    Front End Only 3.0.1 75 16/8

    Macintosh 680x0, OS 7.1 3.0.1 118/30 12/9Power PC OS 7.1 3.0.1 122/32 12/9Front End Only 3.0.1 75 5/5

    Linux x86x86 a.out 1.2ELF 2.0 or higher

    3.0.2 125 32/16

    Unix SPARCSunOS 4.1.2Solaris 2.4

    3.0.2 115 32/16

    DEC AXP Digital Unix OSF/1.3.0 or higher

    3.0.2 110 32/16

    HP PA-RISC HP-UX 10.10 3.0.2 115 32/16IBM RS/6000 AIX 4.1 3.0.2 100 32/16Silicon Graphics IRIX 5.3 3.0.2 115 32/16

    Front End Only 3.0.2 75 32/16

    NEXTSTEP 3.0 Motorola 3.0.2 100 32/16x86 3.0.2 100 32/16HP PA-RISC 3.0.2 100 32/16Sparc 3.0.2 100 32/16

    IBM OS/2 2.0 2.2.3 10 16/8

    DEC OpenVMS 7.0 2.2.3 21 32/16

    Source: http://www.wolfram.com

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 11Woods Hole, 1998

    Front End Kernel

    Front End

    Kernel

    Identical on all computers Can be on a different computer Computational Engine

    Platform Dependent GUI

    Platform Indepenent Ascii Interface

    Ascii Notebook Files

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 12Woods Hole, 1998

    Starting Mathematica in Windows 95

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 13Woods Hole, 1998

    Using Mathematica

    Type 3+3 and then [Shift][Enter]

    The kernel will take a while to load.

    Things to notice:

    The cell brackets

    The line indicating the current cell - anything you enter atthe keyboard will go immediately beneath this line.

    To create a new cell, move cursor to the end of a cell and

    press [Enter] (Windows)

    press [Return] (Macintosh)

    To evaluate the current cell

    press [Shift][Enter] (Windows)

    press [Enter] Macintosh

    To enter multiple lines within a cell, place cursor within thecell and press [Return].

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 14Woods Hole, 1998

    Text will automatically wrap-around to the next line.

    The text will unwrap if you make the window wider:

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 15Woods Hole, 1998

    Arithmetic

    Multiplication

    Variable Assignment

    Implied Multiplication

    Minus

    Addition

    Subtraction

    Power

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 16Woods Hole, 1998

    Square Root

    ex

    Natural Logarithm

    loge(x)

    logb(x)

    Trig Functions

    Pi,

    Exact and ApproximateResults

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 17Woods Hole, 1998

    Special Constants

    First 20 Digits of

    Vectors, Matrices and Lists

    First 743 Digitsof

    First 743 Digits of e

    /180

    Catalans Constant to 6 digits

    Golden Ratio

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 18Woods Hole, 1998

    Vector Dot Product

    Element by ElementMultiplication

    Multiplication by aConstant

    Apply Square Root toEvery Element of a List

    Matrices as a list of Lists

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 19Woods Hole, 1998

    List Multiplication vs Matrix Multiplication

    Definition of a Function

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 20Woods Hole, 1998

    Application of a Function to a Matrix

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 21Woods Hole, 1998

    Loops

    Simple Do Loop

    Do Loop with multiplestatements.

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 22Woods Hole, 1998

    Local Variables

    Function toCompute

    x,x2, x3

    sum is a Global Variable

    sum is a Local Variable

    Function Evaluation

    value of sum is unchanged

    Function ReturnValue is a list of 3

    numbers

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 23Woods Hole, 1998

    An Example from Population Biology

    Source: J. D. Murray, Mathematical Biology, Springer-Verlag, 1989, page 67. Reproducedfor classroom use only.

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 24Woods Hole, 1998

    Mathematica Reference Outline

    I. Numerical ComputationA. Numerical Evaluation

    N[expr] gives the numerical value of expr.

    N[expr, n] attempts to give a result with n-digit precision.

    B.Equation SolvingDSolve[eqn, y, x] solves a differential equation for the function y, withindependent variable x.

    FindRoot[lhs==rhs, {x, a}] searches for a numerical solution to the equationlhs==rhs, starting with x=a.

    NDSolve[eqns, y, {x, xmin, xmax}] finds a numerical solution to the ordinarydifferential equations eqns for the function y with the independent variable x in therange xmin to xmax.

    NDSolve[eqns, y, {x, xmin, xmax}, {t, tmin, tmax}] finds a numericalsolution to the partial differential equations eqns.

    NDSolve[eqns, {y1, y2, ...}, {x, xmin, xmax}] finds numerical solutions for thefunctions yi.

    NSolve[lhs==rhs, var] gives a list of numerical approximations to the roots of apolynomial equation.

    Solve[eqns, vars] attempts to solve an equation or set of equations for thevariables vars.

    Solve[eqns, vars, elims] attempts to solve the equations for vars, eliminatingthe variables elims.

    C. Sums and ProductsSum[f, ai, imaxa] evaluates a sum

    Sum[f, {i, imin, imax}] starts with i = imin.

    Sum[f, {i, imin, imax, di}] uses steps di.

    Sum[f, {i, imin, imax}, {j, jmin, jmax}, ] evaluates a multiple sum

    NSum[f, {i, imin, imax}] gives a numerical approximation to a sum.

    NSum[f, {i, imin, imax, di}] uses a step di in the sum.

    Product[f, {i, imax}] evaluates the product i=1imax f

    Product[f, {i, imin, imax}] starts with i = imin.

    Product[f, {i, imin, imax, di}] uses steps di.

    Product[f, {i, imin, imax}, {j, jmin, jmax}, ] evaluates the multiple

    product i=iminimax j= jminjmax ... f

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 25Woods Hole, 1998

    NProduct[f, {i, imin, imax}] gives a numerical approximation to a product.

    NProduct[f, {i, imin, imax, di}] uses a step di in a product.

    D. IntegrationIntegrate[f, x] gives the indefinite integral f (x)dxIntegrate[f, {x, xmin, xmax}] gives the definite integral.

    Integrate[f, {x, xmin, xmax}, {y, ymin, ymaxa] gives the multiple definiteintegral.

    NIntegrate[f, {x, xmin, xmax}] gives a numerical approximation to theintegral

    InterpolatingFunction[domain, table] represents an approximatefunction whose values are found by interpolation.

    See also NDSolve (I B. Equation Solving).

    E. OptimizationFindMinimum[f, {x, x0}] searches for a local minimum in f, starting from thepoint x=x0.

    ConstrainedMin[f, {inequalities}, {x, y, }]] finds the global minimumof f in the domain specified by the inequalities. The variables x, y, are allassumed to be non-negative.

    ConstrainedMax[f, {inequalities}, {x, y, }] finds the global maximumof f in the domain specified by the inequalities. The variables x, y, are allassumed to be non-negative.

    LinearProgramming[c, m, b] finds the vector x which minimizes the quantityc.x subject to the constraints m.xb and x 0.LatticeReduce[{a1, a2, ...}] gives a reduced basis for the set of vectors a.

    F. Data Manipulation1. Curve Fitting

    Fit[data, funs, vars] finds a least-squares fit to a list of data as a linearcombination of the functions funs of variables vars.

    Interpolation[data] constructs an InterpolatingFunction objectwhich represents an approximate function that interpolates the data.

    ListInterpolation[array] constructs an InterpolatingFunctionobject which represents an approximate function that interpolates the array ofvalues given.

    ListInterpolation[array, {{xmin, xmax}, {ymin, ymax}, }]specifies the domain of the grid from which the values in array are assumed tocome.

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 26Woods Hole, 1998

    FunctionInterpolation[expr, {x, xmin, xmax}] evaluates expr with xrunning from xmin to xmax and constructs an InterpolatingFunctionobject which represents an approximate function corresponding to the result.

    FunctionInterpolation[expr, {x, xmin, xmax}, {y, ymin, ymax}, ] constructs an InterpolatingFunction object with severalarguments.

    2. Fourier Transform

    Fourier[list] finds the discrete Fourier transform of a list of complexnumbers.

    InverseFourier[list] finds the discrete inverse Fourier transform of a listof complex numbers.

    3. Selection of special elementsMax[a1, a2, ] yields the numerically largest of the a.

    Max[{a1, a2, ...}, {b1, b2, ...}, ... ] yields the largest element of any of the lists.

    Min[a1, a2, ] yields the numerically smallest of the a.

    Min[{a1, a2, ...}, {b1, b2, ...}, ...] yields the smallest element of any of the lists.

    Select[list, crit] picks out all elements a of list for which crit[a] is True.

    Select[list, crit, n] picks out the first n elements for which crit[a] isTrue.

    Take[list, n] gives the first n elements of list.

    Take[list, -n] gives the last n elements of list.

    Take[list, am, na] gives elements m through n of list.

    Count[list, pattern] gives the number of elements in list that match pattern.

    Count[expr, pattern, levelspec] gives the total number of subexpressionsmatching pattern that appear at the levels in expr s

    Sort[list] sorts the elements of list into canonical order.

    Sort[list, p] sorts using the ordering function p.

    4. Set ManipulationUnion[l1, l2, ] gives a sorted list of all the distinct elements thatappear in any of the li.

    Union[list] gives a sorted version of a list, in which all duplicated elementshave been dropped.

    Intersection[list1, list2, ] gives a sorted list of the elements commonto all the listi.

    Complement[eall, list1, list2, ] gives the elements in eall which are notin any of the listi

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 27Woods Hole, 1998

    G. Matrices and Vectors1. Matrix Operations

    a.b.c or Dot[a, b, c] gives products of vectors, matrices and tensors

    Inverse[m] gives the inverse of a square matrix m.

    Transpose[list] transposes the first two levels in list.

    Det[m] gives the determinant of the square matrix m.

    DiagonalMatrix[list] gives a matrix with the elements of list on the leadingdiagonal, and 0 elsewhere.

    Eigenvalues[m] gives a list of the eigenvalues of the square matrix m.

    Eigenvectors[m] gives a list of the eigenvectors of the square matrix m.

    Eigensystem[m] gives a list avalues, vectorsa of the eigenvalues andeigenvectors of the square matrix m.

    IdentityMatrix[n] gives the n n identity matrix.MatrixPower[mat, n] gives the na matrix power of mat.

    MatrixExp[mat] gives the matrix exponential of mat.

    Outer[f, list1, list2, ] gives the generalized outer product of the listi,forming all possible combinations of the lowest-level elements in each of them.

    Outer[f, list1, list2, , n] treats as separate elements only sublists at leveln in the a.

    Outer[f, list1, list2, ..., n1, n2, ] treats as separate elements only sublistsat level ni in the corresponding listi

    2. Systems of Linear EquationsLinearSolve[m, b] finds an x which solves the matrix equation m.x==b.

    NullSpace[m] gives a list of vectors that forms a basis for the null space ofthe matrix m.

    RowReduce[m] gives the row-reduced form of the matrix m.

    Minors[m, k] gives a matrix consisting of the determinants of all asubmatrices of m.

    3. Matrix DecompositionsSingularValues[m] gives the singular value decomposition for anumerical matrix m. The result is a list au, w, va, where w is the list of singularvalues, and m can be written asConjugate[Transpose[u]].DiagonalMatrix[w].v.

    PseudoInverse[m] finds the pseudoinverse of a rectangular matrix.

    QRDecomposition[m] yields the QR decomposition for a numerical matrixm. The result is a list aq, ra, where q is an orthogonal matrix and r is an uppertriangular matrix.

    SchurDecomposition[m] yields the Schur decomposition for a numericalmatrix m. The result is a list aq, ta where q is an orthogonal matrix and t is ablock upper triangular matrix.

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 28Woods Hole, 1998

    LUDecomposition[m] generates a representation of the LU decompositionof a matrix m.

    LUBackSubstitution[data, b] takes the data generated byLUDecomposition[m] and yields the solution to the matrix equation a.

    LinearProgramming[c, m, b] (See Optimization)

    H. Complex NumbersI represents the imaginary unit i.

    Complex is the head used for complex numbers.

    Re[z] gives the real part of the complex number z.

    Im[z] gives the imaginary part of the complex number z.

    Abs[z] gives the absolute value of the real or complex number z.

    Arg[z] gives the argument of the complex number z.

    Conjugate[z] gives the complex conjugate a of the complex number z.

    I. Number Representation1. Heads (Beginning of the List)

    Integer is the head used for integers.

    Rational is the head used for rational numbers.

    Real is the head used for real (floating-point) numbers.

    Complex is the head used for complex numbers.

    Root[f, k] represents the ka root of the polynomial equation f[x] == 0.

    2. Parts of Numbers Digits, Exponents, and MantissasIntegerDigits[n] gives a list of the decimal digits in the integer n.

    IntegerDigits[n, b] gives a list of the base-b digits in the integer n.

    IntegerDigits[n, b, len] pads the list on the left with zeros to give a listof length len. RealDigits[x] gives a list of the digits in the approximate realnumber x, together with the number of digits that are to the left of the decimalpoint.

    RealDigits[x, b] gives a list of base-b digits in x.

    RealDigits[x, b, len] gives a list of len digits.

    RealDigits[x, b, len, n] gives len digits starting with the coefficient of a.

    FromDigits[list] constructs an integer from the list of its decimal digits.

    FromDigits[list, b] takes the digits to be given in base b.

    MantissaExponent[x] gives a list containing the mantissa and exponent ofan approximate real number x.

    Numerator[expr] gives the numerator of expr.

    Denominator[expr] gives the denominator of expr.

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 29Woods Hole, 1998

    3. Change of RepresentationRationalize[x] takes Real numbers in x that are close to rationals, andconverts them to exact Rational numbers.

    Rationalize[x, dx] performs the conversion whenever the error made issmaller in magnitude than dx.

    IntegerPart[x] gives the integer part of x.

    Chop[expr] replaces approximate real numbers in expr that are close to zeroby the exact integer 0.

    Chop[expr, delta] replaces numbers smaller in absolute magnitude than deltaby 0.

    4. InfinityInfinity or is a symbol that represents a positive infinite quantity.Indeterminate is a symbol that represents a numerical quantity whosemagnitude cannot be determined.

    ComplexInfinity represents a quantity with infinite magnitude, butundetermined complex phase.

    DirectedInfinity[ ] represents an infinite numerical quantity whosedirection in the complex plane is unknown.

    DirectedInfinity[z] represents an infinite numerical quantity that is apositive real multiple of the complex number z.

    J. Numerical Precision.1. Evaluation Accuracy and Precision

    N (see IA, Numerical Evaluation).

    Accuracy[x] gives the number of digits to the right of the decimal point inthe number x.

    Precision[x] gives the number of digits of precision in the number x.

    SetAccuracy[expr, n] yields a version of expr in which all numbers havebeen set to have an accuracy of n digits.

    SetPrecision[expr, n] yields a version of expr in which all numbers havebeen set to have a precision of n digits.

    $MaxPrecision gives the maximum number of digits of precision to beallowed in arbitrary-precision numbers.

    $MinPrecision gives the minimum number of digits of precision to beallowed in arbitrary-precision numbers.

    $MaxExtraPrecision gives the maximum number of extra digits ofprecision to be used in functions such as N.

    2. IntervalsInterval[{min, max}] represents the range of values between min andmax. Interval[{min1, max1}, {min2, max2},... ] represents the union of theranges {min1, max1}, {min2, max2}, ...

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 30Woods Hole, 1998

    IntervalMemberQ[interval, x] gives True if the number x lies within thespecified interval, and False otherwise.

    IntervalMemberQ[interval 1, interval 2] gives True if interval2 iscompletely contained within interval1

    IntervalUnion[interval1, interval2, ] gives the interval representing theset of all points in any of the intervali.

    IntervalIntersection[a interval1, interval2, ] gives the intervalrepresenting all points common to each of the intervali.

    3. Machine Accuracy and PrecisionMachineNumberQ[expr] returns True if expr is a machine-precision real orcomplex number, and returns False otherwise.

    $MachinePrecision gives the number of decimal digits of precision usedfor machine-precision numbers.

    $MachineEpsilon gives the smallest machine-precision number which canbe added to 1.0 to give a result that is distinguishable from 1.0.

    $MaxMachineNumber is the largest machine-precision number that can beused on a particular computer system.

    $MinMachineNumber is the smallest positive machine-precision number thatcan be used on a particular computer system.

    $MaxNumber gives the magnitude of the maximum arbitrary-precision numberthat can be represented on a particular computer system.

    $MinNumber gives the magnitude of the minimum positive arbitrary-precisionnumber that can be represented on a particular computer.

    K. OptionsCompiled is an option for various numerical and plotting functions whichspecifies whether the expressions they work with should automatically be compiled.

    AccuracyGoal is an option for various numerical operations (e.g. NIntegrate,NDSolve and FindRoot) which specifies how many digits of accuracy should besought in the final result.

    PrecisionGoal is an option for various numerical operations (e.g.NIntegrate and NDSolve) which specifies how many digits of precisionshould be sought in the final result.

    WorkingPrecision is an option for various numerical operations (e.g.NIntegrate and FindRoot) which specifies how many digits of precisionshould be maintained in internal computations.

    II. Algebraic ComputationA. Basic Algebra

    Expand[expr] expands out products and positive integer powers in expr.

    Expand[expr, patt] leaves unexpanded any parts of expr that are free of thepattern patt.

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 31Woods Hole, 1998

    Factor[poly] factors a polynomial over the integers. Factor[poly,Modulus->p] factors a polynomial modulo a prime p.

    Factor[poly, Extension->{a1, a2, ...}] factors a polynomial allowingcoefficients that are rational combinations of the algebraic numbers ai.

    Simplify[expr] performs a sequence of algebraic transformations on expr, andreturns the simplest form it finds.

    expr /. rules applies a rule or list of rules in an attempt to transform each subpartof an expression expr.

    B. Formula Manipulation1. Simplification

    Simplify (see Above, IIA, Basic Algebra)

    FullSimplify[expr] tries a wide range of transformations on exprinvolving elementary and special functions, and returns the simplest form itfinds.

    2. ExpansionPowerExpand[expr] expands all powers of products and powers.

    ComplexExpand[expr] expands expr assuming that all variables are real.

    ComplexExpand[expr, {x1, x2, ..}] expands expr assuming that variablesmatching any of the xi are complex.

    FunctionExpand[expr] tries to expand out special functions in expr, whenpossible reducing compound arguments to simpler ones.

    3. RearrangementCollect[expr, x] collects together terms involving the same powers ofobjects matching x.

    Collect[expr, {x1, x2, ...}] collects together terms that involve the samepowers of objects matching x1, x2, .

    Collect[expr, var, h] applies h to the expression that forms the coefficientof each term obtained.

    Together[expr] puts terms in a sum over a common denominator, andcancels factors in the result.

    Apart[expr] rewrites a rational expression as a sum of terms with minimaldenominators.

    Apart[expr, var] treats all variables other than var as constants.

    Cancel[expr] cancels out common factors in the numerator and denominatorof expr.

    ExpandAll[expr] expands out all products and integer powers in any part ofexpr.

    ExpandAll[expr, patt] avoids expanding parts of expr that do not containterms matching the pattern patt.

    FactorTerms[poly] pulls out any overall numerical factor in poly.

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 32Woods Hole, 1998

    FactorTerms[poly, x] pulls out any overall factor in poly that does notdepend on x.

    FactorTerms[poly, {x1, x2, ...}] pulls out any overall factor in poly thatdoes not depend on any of the xi.

    4. Select Parts of an ExpressionCoefficient[expr, form] gives the coefficient of form in the polynomialexpr.

    Coefficient[expr, form, n] gives the coefficient of form^n in expr.

    Exponent[expr, form] gives the maximum power with which form appearsin the expanded form of expr.

    Exponent[expr, form, h] applies h to the set of exponents with which formappears in expr.

    Numerator, Denominator (See Above, I.I Number Representation)

    expr[[i]] or Part[expr, i] gives the ia part of expr.

    expr[[-i]] counts from the end.

    expr[[0]] gives the head of expr.

    expr[[i, j, ]] or Part[expr, i, j, ] is equivalent to expr[[i]][[j]] .

    expr[[ {i1,i2,...} ]] gives a list of the parts i1, i2, of expr.

    5. Numerators and DenominatorsExpandNumerator[expr] expands out products and powers that appear inthe numerator of expr.

    ExpandDenominator[expr] expands out products and powers that appearas denominators in expr.

    6. Trigonometric Function ManipulationTrigExpand[expr] expands out trigonometric functions in expr.

    TrigFactor[expr] factors trigonometric functions in expr.

    TrigFactorList[expr] factors trigonometric functions in expr, yielding alist of lists containing trigonometric monomials and exponents.

    TrigReduce[expr] rewrites products and powers of trigonometric functionsin expr in terms of trigonometric functions with combined arguments.

    TrigToExp[expr] converts trigonometric functions in expr to exponentials.

    ExpToTrig[expr] converts exponentials in expr to trigonometric functions.

    7. Root and Radical ManipulationRootReduce[expr] attempts to reduce expr to a single Root object.

    ToRadicals[expr] attempts to express all Root objects in expr in terms ofradicals.

    8. Other Algebraic Manipulation

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 33Woods Hole, 1998

    ExcludedForms is an option for FullSimplify which can be set to a listof patterns for expressions that should not be touched if they are encountered atintermediate steps in the operation of FullSimplify.

    ComplexityFunction is an option for Simplify and FullSimplifywhich gives a function to rank the complexity of different forms of anexpression.

    TimeConstraint is an option for Simplify and FullSimplify whichgives the maximum number of seconds for which to try any particulartransformation on any subpart of an expression.

    C. Equation Solvinglhs == rhs returns True if lhs and rhs are identical.

    DSolve[eqn, y, x] solves a differential equation for the function y, withindependent variable x.

    DSolve[{eq1, eq1, ...}, {y1, y2, ...}, x] solves a list of differential equations.

    DSolve[eqn, y, {x1, x2, ...}] solves a partial differentialequation.

    Eliminate[eqns, vars] eliminates variables between a set of simultaneousequations.

    InverseFunction[f] represents the inverse of the function f, defined so thatInverseFunction[f][y] gives the value of x for which f[x] is equal to y.

    LogicalExpand[expr] expands out expressions containing logical connectivessuch as && and ||.

    Reduce[eqns, vars] simplifies the equations eqns, attempting to solve for thevariables vars. The equations generated by Reduce are equivalent to eqns, andcontain all the possible solutions.

    Reduce[eqns, vars, elims] simplifies the equations, trying to eliminate thevariables elims.

    Root[f, k] represents the ka root of the polynomial equation f[x] == 0.

    Solve[eqns, vars] attempts to solve an equation or set of equations for thevariables vars.

    Solve[eqns, vars, elims] attempts to solve the equations for vars, eliminatingthe variables elims.

    SolveAlways[eqns, vars] gives the values of parameters that make theequations eqns valid for all values of the variables vars.

    D. Calculus1. Derivatives

    D[f, x] gives the partial derivative

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 34Woods Hole, 1998

    D[f, {x,n}] gives the multiple derivative

    D[f, a, a, ] gives multiple Partial derivative

    NonConstants is an option for D which gives a list of objects to be taken todepend implicitly on the differentiation variables.

    Dt[f, x] gives the total derivative dfdx

    Dt[f] gives the total differential df

    Dt[f, {x,n}] gives the nth derivative derivative

    Dt[f, a, a, ] gives a multiple derivate wtt multiple variables.

    Constants is an option for Dt which gives a list of objects to be taken asconstants.

    f' represents the derivative of a function f of one argument.

    Derivative[n1, n2, ][f] is the general form, representing a functionobtained from f by differentiating n1 times with respect to the first argument, n2times with respect to the second argument, and so on.

    2. Integration. See Section I.D.PrincipalValue is an option for Integrate that specifies whether theCauchy principal value should be found for a definite integral.

    Assumptions is an option for Integrate and other functions thatspecifies what assumptions be made about relations between parameters.

    GenerateConditions is an option for Integrate that specifies whetherexplicit conditions on parameters should be generated in the results of definiteintegrals.

    3. Limits, Residues, and Series

    Limit[expr, x->a] finds the limiting value of expr when x approaches a.

    Residue[expr, {x, a}] finds the residue of expr at the point a.

    Series[f, {x, a, n}] generates a power series expansion for f about thepoint a to order (x-a)

    n.

    Series[f, {x, x0, nx}, {y, y0, ny}] successively finds series expansions withrespect to y, then x.

    Normal[expr] converts expr to a normal expression, from a variety of specialforms.

    SeriesCoefficient[series, n] finds the coefficient of the aa order termin a power series.

    InverseSeries[s, x] takes the series s generated by Series, and gives aseries for the inverse of the function represented by s.

    SeriesCoefficient[series, {n1, n2, ...}] finds a coefficient in amultivariate series.

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 35Woods Hole, 1998

    ComposeSeries[s1, s2, ] composes several power series, i.e., effectivelyreplaces the variable in s1 by s2 and so on.

    SeriesData[x, x0, {a0, a1, ...J}, nmin, nmax, den] represents a powerseries in the variable x about the point x0. The a are the coefficients in the powerseries. The powers of (x-x0) that appear are nmin/den, (nmin+1)/den, ,nmax/den.

    O[x]^n represents a term of order xn.

    O[x]^n is generated to represent omitted higher-order terms in power series.

    O[x, a]^n represents a term of order (x-a)n.

    4. Polynomial Manipulation

    (a) Existence

    PolynomialQ[expr, var] yields True if expr is a polynomial in var,and yields False otherwise.

    PolynomialQ[expr, {v1, v2, ...}] tests whether expr is a polynomial inthe vi.

    (b) Variables and Coefficients

    Variables[poly] gives a list of all independent variables in a polynomial.

    CoefficientList[poly, var] gives a list of coefficients of powers ofvar in poly, starting with power 0.

    CoefficientList[poly, {v1, v2,...}] gives an array of coefficients.

    Modulus->n is an option that can be given in certain algebraic functions tospecify that integers should be treated modulo n.

    (c) Polynomial Algebra

    PolynomialMod[poly, m] gives the polynomial poly reduced modulom.

    PolynomialMod[poly, {m1, m2, ...}] reduces modulo all of the mi.

    PolynomialQuotient[p, q, x] gives the quotient of p and q, treatedas polynomials in x, with any remainder dropped.

    PolynomialRemainder[p, q, x] gives the remainder from dividing pby q, treated as polynomials in x.

    PolynomialGCD[p1, p2, ] gives the greatest common divisor of thepolynomials pi.

    PolynomialGCD[p1, p2, , Modulus->p] evaluates the GCDmodulo the prime p.

    PolynomialLCM[p1, p2, ] gives the least common multiple of thepolynomials pi..

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 36Woods Hole, 1998

    PolynomialLCM[p1, p2, , Modulus->p] evaluates the LCMmodulo the prime p.

    PolynomialReduce[poly,{p1, p2, ...}, {x1, x2, ...}] yields a listrepresenting a reduction of poly in terms of the xi.

    Resultant[p1, p2, var] computes the resultant of the polynomials p1,p2 with respect to the variable var.

    Resultant[p1, p2,, Modulus->p] computes the resultant modulo theprime p.

    Decompose[poly, x] decomposes a polynomial, if possible, into acomposition of simpler polynomials.

    Root[f, k] represents the kth root of the polynomial equation f[x] == 0.

    RootSum[f, form] represents the sum of form[x] for all x that satisfy thepolynomial equation f[x] == 0.

    RootReduce[expr] attempts to reduce expr to a single Root object.

    ToRadicals[expr] attempts to express all Root objects in expr in termsof radicals.

    (d) Polynomial Factoring

    Factor[poly] factors a polynomial over the integers.

    Factor[poly, Modulus->p] factors a polynomial modulo a prime p.

    Factor[poly, Extension->{a1, a2, ...}] factors a polynomial allowingcoefficients that are rational combinations of the algebraic numbers a.

    FactorSquareFree[poly] pulls out any multiple factors in apolynomial.

    FactorTerms[poly] pulls out any overall numerical factor in poly.

    FactorTerms[poly, x] pulls out any overall factor in poly that does notdepend on x.

    FactorList[poly] gives a list of the factors of a polynomial, togetherwith their exponents.

    FactorSquareFreeList[poly] gives a list of square-free factors of apolynomial, together with their exponents.

    FactorTermsList[poly, {x1, x2, ...}] gives a list of factors of poly.The first element in the list is the overall numerical factor. The secondelement is a factor that does not depend on any of the xi. Subsequentelements are factors which depend on progressively more of the xi.

    GaussianIntegers is an option for FactorInteger, PrimeQ,Factor and related functions which specifies whether factorization shouldbe done over Gaussian integers.

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 37Woods Hole, 1998

    Extension is an option for Factor, PolynomialGCD and relatedfunctions which specifies what algebraic numbers to allow in the coefficientsof resulting polynomials.

    (e) Special Polynomials

    Cyclotomic[n, x] gives the cyclotomic polynomial of order n in x.

    GroebnerBasis[{p1, p2, ...}, {x1, x2, ...}] gives a list of polynomialsthat form a Grbner basis for the set of polynomials pi.

    GroebnerBasis[{p1, p2, ...}, {x1, x2, ...}, {y1, y2, ...}] finds a Grbnerbasis in which the yis have been eliminated.

    III. Mathematical FunctionsA. Basic Arithmetic

    Plus[x, y] or x + y + z represents a sum of terms.

    Subtract [x, y] or x - y is equivalent to x + (-1 * y).

    Minus[x] or -x is the arithmetic negation of x.

    Times[x, ...] or x*y*z, xyz or x y z represents a product of terms.

    Divide[x, y] or x/y is equivalent to x y^-1.

    Power[x, y] or x^y gives x to the power y.

    B. Mathematical Constants: Pi or p, E, Degree, GoldenRatio,EulerGamma, Catalan, I, Infinity

    C. Numerical FunctionsAbs[z] gives the absolute value of the real or complex number z.

    Sign[x] gives -1, 0 or 1 depending on whether x is negative, zero, or positive.

    Round[x] gives the integer closest to x.

    IntegerPart[x] gives the integer part of x.

    Chop[expr] replaces approximate real numbers in expr that are close to zero by theexact integer 0.

    Mod[m, n] gives the remainder on division of m by n.

    Quotient[n, m] gives the integer quotient of n and m.

    GCD[n1, n2, ] gives the greatest common divisor of the integers ni.

    LCM[n1, n2, ] gives the least common multiple of the integers ni

    PrimePi[x] gives the number of primes less than or equal to x..

    PowerMod[a, b, n] gives ab mod n

    Divisors[n] gives a list of the integers that divide n.

    Max, Min : See I.F.3. Data Manipulation

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 38Woods Hole, 1998

    Re, Im, Conjugate, Arg: See I.H. Complex Numbers

    D. Random NumbersRandom[ ] gives a uniformly distributed pseudorandom Real in the range 0 to 1.

    Random[type, range] gives a pseudorandom number of the specified type, lyingin the specified range. Possible types are: Integer, Real and Complex. Thedefault range is 0 to 1. You can give the range {min, max} explicitly; a rangespecification of max is equivalent to {0, max}. Random uses the Wolfram rule 30cellular automaton generator for integers. It uses a Marsaglia-Zaman subtract-with-borrow generator for real numbers.

    SeedRandom[n] resets the pseudorandom number generator, using the integer nas a seed.

    SeedRandom[ ] resets the generator, using as a seed the time of day.

    E. Elementary FunctionsLog[z] gives the natural logarithm of z (logarithm to base a).

    Log[b, z] gives the logarithm to base b.

    Exp[z] is the exponential function.

    Power[x, y] or x^y gives x to the power y.

    Sqrt[z] gives the square root of z.

    Sin[z], Cos[z], Tan[z], Csc[z], Sec[z], Cot[z]

    ArcSin[z], ArcCos[x],ArcTan[z], ArcTan[y,x] = tan-1(y/x),ArcCsc[z], ArcSec[z], ArcCot[z]

    Sinh[z], Cosh[z], Tanh[z], Sech[z], Csch[z], Coth[z]

    ArcSinh[z], ArcCosh[z], ArcTanh[z], ArcSech[z],ArcCsch[z], ArcCoth[z]

    F. Factorial-Based Functionsn! gives the factorial of n. = n(n-1)(n-2)...1

    n!! gives the double factorial of n. = n(n-2)(n-4)(n-6)...l

    Binomial[n, m] gives the binomial coefficient n

    m

    =n!/(n!(n-m)!)

    Multinomial[n1, n2, ] gives the multinomial coefficient(n1+n2+..)!/(n1!n2!...)

    Pochhammer[a, n] gives the Pochhammer symbol (a)n

    Gamma[z] is the Euler gamma function [z]

    Gamma[a, z] is the incomplete gamma function [a, z]

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 39Woods Hole, 1998

    Gamma[a, z1, x2] is the generalized incomplete gamma function [a,z1]-[a,z2]

    GammaRegularized[a, z] is the regularized incomplete gamma function Q(a,z)

    InverseGammaRegularized[a, s] gives the inverse of the regularizedincomplete gamma function.

    LogGamma[z] gives the logarithm of the gamma function log(z)

    Beta[a, b] gives the Euler beta function B[a,b]

    Beta[z, a, b] gives the incomplete beta function

    BetaRegularized[z, a, b] gives the regularized incomplete beta functionIz(a,b)

    InverseBetaRegularized[s, a, b] gives the inverse of the regularizedincomplete beta function.

    PolyGamma[z] gives the digamma function (x)

    PolyGamma[n, z] gives the nth derivative of the digamma function (n)(x)

    G. Combinatorial FunctionsBernoulliB[n] gives the Bernoulli number Bn.

    BernoulliB[n, x] gives the Bernoulli polynomial Bn(x)

    ClebschGordan[...] gives the Clebsch-Gordan coefficient from QuantumMechanics

    EulerE[n, x] gives the Euler polynomial En(x)

    Fibonacci[n] gives the Fibonacci number Fn.

    Fibonacci[n, x] gives the Fibonacci polynomial Fn(x)

    PartitionsP[n] gives the number a of unrestricted partitions of the integer a.

    PartitionsQ[n] gives the number a of partitions of the integer a into distinctparts.

    SixJSymbol[...] gives the values of the Racah 6-j symbol from QuantumMechanics

    Signature[list] gives the signature of the permutation needed to place theelements of list in canonical order.

    StirlingS1[n, m] gives the Stirling number of the first kind Sn( m )

    StirlingS2[n, m] gives the Stirling number of the second kind

    ThreeJSymbol[...] gives the values of the Wigner 3-j symbol from QuantumMechanics

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 40Woods Hole, 1998

    H. Functions from Number TheoryArithmeticGeometricMean[a, b] gives the arithmetic-geometric mean of aand b.

    Divisors[n] gives a list of the integers that divide n.

    DivisorSigma[k, n] gives the divisor function k(n)

    EulerPhi[n] gives the Euler totient function (x).

    ExtendedGCD[n, m] gives the extended greatest common divisor of the integersn and m.

    FactorInteger[n] gives a list of the prime factors of the integer n, togetherwith their exponents.

    GCD[n1, n2, ] gives the greatest common divisor of the integers ni.

    IntegerDigits[n] gives a list of the decimal digits in the integer n.

    JacobiSymbol[n, m] gives the Jacobi symbol n

    m

    LCM[n1, n2, ] gives the least common multiple of the integers ni

    MoebiusMu[n] gives the Mbius function (x)

    Mod[m, n] gives the remainder on division of m by n.

    PowerMod[a, b, n] gives ab mod n

    For negative b, PowerMod[a, b, n] gives modular inverses.

    Prime[n] gives the nth prime number.

    PrimePi[x] gives the number of primes less than or equal to x..

    PrimeQ[expr] yields True if expr is a prime number, and yields Falseotherwise.

    Quotient[n, m] gives the integer quotient of n and m.

    I. Zeta FunctionLerchPhi[z, s, a] gives the Lerch transcendent (z,s,a)

    PolyLog[n, z] gives the polylogarithm function Lin(z)

    RiemannSiegelTheta[t] gives the Riemann-Siegel function (t)

    RiemannSiegelZ[t] gives the Riemann-Siegel function Z[t]

    StieltjesGamma[n] gives the Stieltjes constant nZeta[s] gives the Riemann zeta function (s).

    Zeta[s, a] gives the generalized Riemann zeta function (s,a).

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 41Woods Hole, 1998

    J. Hypergeometric and Related FunctionsAiryAi[z] gives the Airy function Ai(z)

    AiryAiPrime[z] gives the derivative of the Airy function Ai(z)

    AiryBi[z] gives the Airy function Bi(z)

    AiryBiPrime[z] gives the derivative of the Airy function Bi(z)

    BesselJ[n, z] gives the Bessel function of the first kind Jn(z)

    BesselK[n, z] gives the modified Bessel function of the second kind Kn(z)

    BesselI[n, z] gives the modified Bessel function of the first kind In(z)

    BesselY[n, z] gives the Bessel function of the second kind Yn(z)

    CoshIntegral[z] gives the hyperbolic cosine integral Chi(z)

    CosIntegral[z] gives the cosine integral function Ci(z)

    Erf[z] gives the error function erf(z)

    Erf[z1, z2] gives the generalized error function erf(z2)-erf(z1)

    Erfc[z] gives the complementary error function erfc(z)

    Erfi[z] gives the imaginary error function erf(iz)/i

    ExpIntegralE[n, z] gives the exponential integral function En(z)

    ExpIntegralEi[z] gives the exponential integral function Ei(z)

    FresnelC[z] gives the Fresnel integral C(z)

    FresnelS[z] gives the Fresnel integral S(z)

    Hypergeometric1F1[a, b, z] is the Kummer confluent hypergeometricfunction 1F1(a; b; z)

    Hypergeometric1F1Regularized[a, b, z] is the regularized confluenthypergeometric function 1F1(a; b; z)/(b)Hypergeometric2F1[a, b, c, z] is the hypergeometric function 2F1(a; b; z)

    Hypergeometric2F1Regularized[a, b, c, z] is the regularizedhypergeometric function 2F1(a; b; z)/(c)Hypergeometric0F1[a, z] is the confluent hypergeometric function oF1(;a;z)

    Hypergeometric0F1Regularized[a, z] is the regularized confluenthypergeometric function oF1(;a;z)/(a)HypergeometricPFQ[{a1, ....,ap}, {b1, ..., bp}, z] is the generalizedhypergeometric function pFq(a; b; z)

    HypergeometricPFQRegularized[{a1, ....,ap}, {b1, ..., bp}, z] is theregularized generalized hypergeometric function pFq(a; b; z)/((b1)...(bq))HypergeometricU[a, b, z] is the confluent hypergeometric function U(a,b,z)

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 42Woods Hole, 1998

    MeijerG[{{a1,...,an},{an+1,...,ap}},{{b1,...,bm},{bm+1,...,bq}}, z] is the Meijer G

    function

    Gpq

    mn za1 ,K,apb1 ,K,bq

    LogIntegral[z] is the logarithmic integral function Li(z)

    SinIntegral[z] gives the sine integral function Si(z)

    SinhIntegral[z] gives the hyperbolic sine integral function Shi(z)

    K. Orthogonal PolynomialsChebyshevT[n, x] gives the Chebyshev polynomial of the first kind Tn(x)

    ChebyshevU[n, x] gives the Chebyshev polynomial of the second kind Un(x)

    GegenbauerC[n, m, x] gives the Gegenbauer polynomial Cn( m) (x)

    GegenbauerC[n, x] gives the renormalized form Cn( m) (x) /m

    HermiteH[n, x] gives the Hermite polynomial Hn(x)

    LaguerreL[n, x] gives the Laguerre polynomial Ln(x)

    LaguerreL[n, a, x] gives the generalized Laguerre polynomial Lna(x)

    JacobiP[n, a, b, x] gives the Jacobi polynomial Pn( a, b) (x)

    LegendreP[n, x] gives the Legendre polynomial Pn(x)

    LegendreP[n, m, x] gives the associated Legendre polynomial Pnm(x)

    SphericalHarmonicY[l, m, q, f] gives the spherical harmonic Ylm( , )

    L. Elliptic FunctionsDedekindEta[t] gives the Dedekind eta modular elliptic function ( )EllipticExp[u, aa, ba] is the inverse for EllipticLog.

    EllipticTheta[a, u, q] gives the theta function a(u,q)

    EllipticThetaPrime[a, u, q] gives the derivative with respect to a of thetheta function

    InverseEllipticNomeQ[q] gives the parameter m corresponding to the nomeq in an elliptic function.

    InverseJacobiSN[v, m], InverseJacobiCN[v, m], etc. give the inverseJacobi elliptic functions. There are a total of twelve functions, with names of theform InverseJacobiPQ, where P and Q can be any distinct pair of the letters S,C, D and N.

    JacobiAmplitude[u, m] gives the amplitude am(u|m) for Jacobi ellipticfunctions.

    KleinInvariantJ[t] gives the Klein invariant modular elliptic function J()

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 43Woods Hole, 1998

    InverseWeierstrassP[p, {g2, g3}] gives a value of u for which theWeierstrass function (u; g2 ,g3) is equal to p

    JacobiSN[u, m], JacobiCN[u, m], etc. give the Jacobi elliptic functionssn(u|m), cn(u|m), etc. There are a total of twelve functions, with the names of theform JacobiPQ, where P and Q can be any distinct pair of the letters S, C, D andN.

    ModularLambda[t] gives the modular lambda elliptic function ( )

    WeierstrassHalfPeriods[{g2, g3}] gives the half-periods {, }forWeierstrass elliptic functions corresponding to the invariants {g2, g3}.

    WeierstrassInvariants[{, }] gives the invariants{g2, g3} forWeierstrass elliptic functions corresponding to the half-periods , .

    WeierstrassP[u, {g2, g3}] gives the Weierstrass elliptic function(u; g2 ,g3)

    WeierstrassPPrime[u, {g2, g3}] gives the derivative of the Weierstrasselliptic function (u; g2 ,g3)

    WeierstrassSigma[u, {g2, g3}] gives the Weierstrass sigma (u; g2, g3)WeierstrassZeta[u, {g2, g3}] gives the Weierstrass zeta (u; g2, g3)

    M. Elliptic IntegralsEllipticE[m] gives the complete elliptic integral E(m)

    EllipticE[f, m] gives the elliptic integral of the second kind E(,m)

    EllipticF[f, m] gives the elliptic integral of the first kind F(|m)EllipticK[m] gives the complete elliptic integral of the first kind K(m)

    EllipticLog[{x, y},{a, b} ] gives the generalized logarithm associated with theelliptic curve y2=x3+ax2+bx

    EllipticNomeQ[m] gives the nome q corresponding to the parameter m in anelliptic function.

    EllipticPi[n, m] gives the complete elliptic integral of the third kind (n|m)

    EllipticPi[n, f, m] gives the incomplete elliptic integral (n; |m)

    JacobiZeta[f, m] gives the Jacobi zeta function Z(|m)

    N. Mathieu FunctionsMathieuC[a, q, z] gives the even Mathieu function with characteristic value aand parameter q.

    MathieuS[a, q, z] gives the odd Mathieu function with characteristic value aand parameter q.

    MathieuCPrime[a, q, z] gives the derivative with respect to z of the evenMathieu function with characteristic value a and parameter q.

    MathieuSPrime[a, q, z] gives the derivative with respect to z of the oddMathieu function with characteristic value a and parameter q.

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 44Woods Hole, 1998

    MathieuCharacteristicA[r, q] gives the characteristic value a for evenMathieu functions with characteristic exponent r and parameter q.

    MathieuCharacteristicB[r, q] gives the characteristic value a for oddMathieu functions with characteristic exponent r and parameter q.

    MathieuCharacteristicExponent[a, q] gives the characteristic exponenta for Mathieu functions with characteristic value a and parameter q.

    IV. ListsA. Construction

    {a, b, ...} or List[a, b, ...] is a list of elements.

    Array[f, n] generates a list of length n, with elements f[i].

    Array[f, {n1, n2, ...} ] generates an n1 n2 ... array of nested lists, withelements f[i1, i2, ].

    Array[f, dims, origin] generates a list using the specified index origin (default1).

    Array[f, dims, origin, h] uses head h, rather than List, for each level of thearray.

    Range[imax] generates the list {1, 2, , imax}.

    Range[imin, imax] generates the list {imin, , imax}.

    Range[imin, imax, di] uses step di.

    Table[expr, {i}] generates a list of i copies of expr.

    Table[expr, {i, imax}] generates a list of the values of expr when i runs from 1to imax.

    Table[expr, {i, imin, imax}] starts with i = imin.

    Table[expr, {i, imin, imax, di}] uses steps di.

    Table[expr, {i, imin, imax}, {j, jmin, jmax}, ] gives a nested list. Thelist associated with i is outermost.

    B. Element Extractionexpr[[i]] or Part[expr, i] gives the ith part of expr.

    expr[[-i]] counts from the end.

    expr[[0]] gives the head of expr.

    expr[[i, j, ]] or Part[expr, i, j, ] is equivalent to expr[[i]] [[j]]

    expr[[ {i1, i2, ...} ]] gives a list of the parts i1, i2, of expr.

    Cases[{e1, e2, ...}, pattern] gives a list of the ei that match the pattern.

    Cases[{e1, e2, ...}, pattern -> rhs] gives a list of the values of rhscorresponding to the ei that match the pattern.

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 45Woods Hole, 1998

    Cases[expr, pattern, levspec] gives a list of all parts of expr on levels specifiedby levspec which match the pattern.

    Cases[expr, pattern -> rhs, levspec] gives the values of rhs which match thepattern. Drop[list, n] gives list with its first n elements dropped.

    Drop[list, -n] gives list with its last n elements dropped.

    Drop[list, {n}] gives list with its nth element dropped.

    Drop[list, {m, n}] gives list with elements m through n dropped.Extract[expr, list] extracts the part of expr at the position specified by list.

    Extract[expr, {list1, list2, ...}] extracts a list of parts of expr.

    Extract[expr, , h] extracts parts of expr, wrapping each of them with head hbefore evaluation.

    First[expr] gives the first element in expr.

    Last[expr] gives the last element in expr.

    Head[expr] gives the head of expr.

    Rest[expr] gives expr with the first element removed.

    Select[list, crit] picks out all elements ei of list for which crit[ei] is True.

    Select[list, crit, n] picks out the first n elements for which crit[ei] is True.Take[list, n] gives the first n elements of list.

    Take[list, -n] gives the last n elements of list.

    Take[list, {m, n}] gives elements m through n of list.

    C. List TestingCount[list, pattern] gives the number of elements in list that match pattern.

    Count[expr, pattern, levelspec] gives the total number of subexpressionsmatching pattern that appear at the levels in expr specified by levelspec.

    Depth[expr] gives the maximum number of indices needed to specify any part ofexpr, plus one.

    Dimensions[expr] gives a list of the dimensions of expr.

    Dimensions[expr, n] gives a list of the dimensions of expr down to level n.

    FreeQ[expr, form] yields True if no subexpression in expr matches form, andyields False otherwise.

    FreeQ[expr, form, levelspec] tests only those parts of expr on levels specifiedby levelspec.

    Length[expr] gives the number of elements in expr.

    MatrixQ[expr] gives True if expr is a list of lists that can represent a matrix, andgives False otherwise.

    MatrixQ[expr, test] gives True only if test yields True when applied to eachof the matrix elements in expr.

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 46Woods Hole, 1998

    MemberQ[list, form] returns True if an element of list matches form, andFalse otherwise.

    MemberQ[list, form, levelspec] tests all parts of list specified by levelspec.

    Position[expr, pattern] gives a list of the positions at which objects matchingpattern appear in expr.

    Position[expr, pattern, levspec] finds only objects that appear on levelsspecified by levspec.

    TensorRank[expr] gives the depth to which expr is a full array, with all the partsat a particular level being lists of the same length.

    VectorQ[expr] gives True if expr is a list, none of whose elements arethemselves lists, and gives False otherwise.

    VectorQ[expr, test] gives True only if test yields True when applied to eachof the elements in expr.

    D. List OperationsAppend[expr, elem] gives expr with elem appended.

    Complement[eall, a, b, ] gives the elements in eall which are not in any ofthe a, b, ...

    Delete[expr, n] deletes the element at position n in expr. If n is negative, theposition is counted from the end.

    DeleteCases[expr, pattern] removes all elements of expr which match pattern.

    DeleteCases[expr, pattern, levspec] removes all parts of expr on levelsspecified by levspec which match pattern.

    Insert[list, elem, n] inserts elem at position n in list. If n is negative, theposition is counted from the end.

    Insert[expr, elem, {i,j,...}] inserts elem at position {i, j, } in expr.

    Intersection[a,b, ] gives a sorted list of the elements common to all thelists

    Join[a, b, ] concatenates lists together. Join can be used on any set ofexpressions that have the same head.

    Prepend[expr, elem] gives expr with elem prepended.

    ReplacePart[expr, new, n] yields an expression in which the nth part of expris replaced by new.

    Reverse[expr] reverses the order of the elements in expr.

    Sort[list] sorts the elements of list into canonical order.

    RotateLeft[expr, n] cycles the elements in expr n positions to the left.

    RotateLeft[expr] cycles one position to the left.

    RotateRight[expr, n] cycles the elements in expr n positions to the right.

    RotateRight[expr] cycles one position to the right.

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 47Woods Hole, 1998

    Sort[list, p] sorts using the ordering function p.

    Union[a, b, ] gives a sorted list of all the distinct elements that appear in anyof the a.

    Union[list] gives a sorted version of a list, in which all duplicated elements havebeen dropped.

    E. Structure ManipulationsFlatten[list] flattens out nested lists.

    Flatten[list, n] flattens to level n.

    Flatten[list, n, h] flattens subexpressions with head h.

    FlattenAt[list, n] flattens out a sublist that appears as the nth element of list. Ifn is negative, the position is counted from the end.

    Order[a, b] gives 1 if a is before b in canonical order, and -1 if a is after b incanonical order. It gives 0 if a is identical to b.

    OrderedQ[h[a, b, ]] gives True if the a, b, ... are in canonical order, andFalse otherwise.

    Partition[list, n] partitions list into non-overlapping sublists of length n.

    Partition[list, n, d] generates sublists with offset d.

    Permutations[list] generates a list of all possible permutations of the elementsin list.

    Sequence[a, b, ] represents a sequence of arguments to be splicedautomatically into any function.

    Signature[list] gives the signature of the permutation needed to place theelements of list in canonical order.

    Split[list] splits list into sublists consisting of runs of identical elements.

    Split[list, test] treats pairs of adjacent elements as identical whenever applyingthe function test to them yields True.

    Thread[f[args]] "threads" f over any lists that appear in args.

    Thread[f[args], h] threads f over any objects with head h that appear in args.

    Thread[f[args], h, n] threads f over objects with head h that appear in the firstn args.

    Thread[f[args], h, -n] threads over the last n args.

    Thread[f[args], h, am, na] threads over arguments m through n.

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 48Woods Hole, 1998

    V. Graphics and SoundA. Data Plots

    ListPlot[{a, b, c, ...}] plots a list of values. The x coordinates for each point aretaken to be 1, 2, .

    ListPlot[{a, b}, {c, d}, {e, f}, ...] plots a list of values with specified x and ycoordinates.

    ListPlot3D[array] generates a three-dimensional plot of a surface representingan array of height values.

    ListPlot3D[array, shades] generates a plot with each element of the surfaceshaded according to the specification in shades.

    ListContourPlot[array] generates a contour plot from an array of heightvalues.

    ListDensityPlot[array] generates a density plot from an array of heightvalues.

    B. Function PlotsPlot[f, {x, xmin, xmax}] generates a plot of f as a function of x from xmin toxmax.

    Plot[{f1, f2, ...}, {x, xmin, xmax}] plots several functions fi.

    Plot3D[f, {x, xmin, xmax}, {y, ymin, ymax}] generates a three-dimensionalplot of f as a function of x and y.

    ContourPlot[f, {x, xmin, xmax}, {y, ymin, ymax}] generates a contourplot of f as a function of x and y.

    DensityPlot[f, {x, xmin, xmax}, {y, ymin, ymax}] makes a density plot off as a function of x and y.

    C. Parametric PlotsParametricPlot[{fx, fy}, {t, tmin, tmax} ] produces aparametric plot with x and y coordinates fx and fy generated as a function of t.

    ParametricPlot3D[{fx, fy, fz}, {t, tmin, tmax} ] produces a three-dimensional space curve parametrized by a variable t which runs from tmin to tmax.

    D. Sound GenerationPlay[f, {t, tmin, tmax}] plays a sound whose amplitude is given by f as afunction of time t in seconds between tmin and tmax.

    ListPlay[{a, b, c, ...}] plays a sound whose amplitude is given by the sequenceof levels a, b, ....

    E. Combinations of PlotsShow[graphics, options] displays two- and three-dimensional graphics, using theoptions specified.

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 49Woods Hole, 1998

    Show[p1, p2, ] shows several plots combined.

    GraphicsArray[{a, b, }] represents a row of graphics objects.

    GraphicsArray[{{a, b, }, }] represents a two-dimensional array ofgraphics objects.

    F. Options.option -> value sets the option to the desired values. Options are specified ina list as the last element of the Plot[...] directive.

    AspectRatio is an option for Show and related functions which specifies theratio of height to width for a plot.

    AxesLabel -> None specifies that no labels should be given.

    AxesLabel -> label specifies a label for the y axis of a two-dimensional plot, andthe z axis of a three-dimensional plot.

    AxesLabel -> {xlabel, ylabel, } specifies labels for different axes

    Axes -> True draws all axes.

    Axes -> False draws no axes.

    Axes -> {False, True} draws a y axis but no x axis in two dimensions.

    AxesOrigin -> {x, y} specifies that the axes should cross at the point {x, y}.

    AxesOrigin -> Automatic uses an internal algorithm to determine where theaxes should cross

    AxesStyle -> style specifies that all axes are to be generated with the specifiedgraphics directive, or list of graphics directives. AxesStyle -> {{xstyle},{ystyle}, } specifies that axes should use graphics directives xstyle, . Thestyles must be enclosed in lists, perhaps of length one. Styles can be specifiedusing graphics directives such as Dashing, Hue and Thickness.

    The default color of axes is specified by the option DefaultColor.

    Epilog is an option for graphics functions which gives a list of graphics primitivesto be rendered after the main part of the graphics is rendered.

    Frame is an option for two-dimensional graphics functions which specifies whethera frame should be drawn around the plot. Frame -> True by default draws aframe with tick marks. If Ticks -> Automatic, setting Frame -> Truesuppresses tick marks on axes.

    FrameLabel is an option for two-dimensional graphics functions that specifieslabels to be placed on the edges of a frame around a plot. FrameLabel -> Nonespecifies that no labels should be given. FrameLabel -> {xmlabel, ymlabel}specifies labels for the bottom and left-hand edges of the frame.FrameLabel -> {xmlabel, ymlabel, xplabel, yplabel } specifies labels for eachof the edges of the frame, ordered clockwise starting from the bottom edge.

    FrameStyle is an option for two-dimensional graphics functions that specifieshow the edges of a frame should be rendered.

    FrameTicks is an option for two-dimensional graphics functions that specifiestick marks for the edges of a frame. Can be None, Automatica, {xgrid, ygrid}

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 50Woods Hole, 1998

    GraphicsSpacing is an option for GraphicsArray which specifies thespacing between elements in the array.

    GridLines is an option for two-dimensional graphics functions that specifies gridlines.

    PlotJoined is an option for ListPlot that specifies whether the points plottedshould be joined by a line.

    PlotLabel is an option for graphics functions that specifies an overall label for aplot. PlotLabel->None is default; PlotLabel->value to set.

    PlotRange is an option for graphics functions that specifies what points toinclude in a plot. Form is PlotRange->All, PlotRange->Automatic,PlotRange->{xmin, xmax}, PlotRange->{{xmin,xmax},{ymin,ymax}}

    PlotStyle is an option for Plot and ListPlot that specifies the style of linesor points to be plotted. PlotStyle -> style specifies that all lines or points are tobe generated with the specified graphics directive, or list of graphics directives.

    Prolog is an option for graphics functions which gives a list of graphics primitivesto be rendered before the main part of the graphics is rendered.

    Ticks->None no tickmarks

    Ticks->Automatic no tickmarks

    Ticks->{xtick, ytick} specifies tickmarks; xtick and ytick are a list ofvalues for each axis

    G. PrimitivesAbsoluteDashing[{ a,b, }] is a graphics directive which specifies thatlines which follow are to be drawn dashed, with successive segments havingabsolute lengths a, b (repeated cyclically).

    AbsolutePointSize[d] is a graphics directive which specifies that pointswhich follow are to be shown if possible as circular regions with absolute diameterd.

    AbsoluteThickness[d] is a graphics directive which specifies that lines whichfollow are to be drawn with absolute thickness d.

    Circle[{x, y}, r] is a two-dimensional graphics primitive that represents acircle of radius r centered at the point x, y.

    Circle[{x, y},{a, b}] yields an ellipse with semi-axes a and b.

    Circle[{x, y}, r, {1, 2}] represents a circular arc.

    Cuboid[{xmin, ymin, zmin}] is a three-dimensional graphics primitive thatrepresents a unit cuboid, oriented parallel to the axes.

    CMYKColor[cyan, magenta, yellow, black] is a graphics directive whichspecifies that graphical objects which follow are to be displayed in the color given.

    Cuboid[{xmin, ymin, zmin}, {xmax, ymax, zmax}] specifies a cuboid bygiving the coordinates of opposite corners.

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 51Woods Hole, 1998

    Dashing[{a, b, ...}] is a two-dimensional graphics directive which specifies thatlines which follow are to be drawn dashed, with successive segments of lengths a, b, (repeated cyclically). The a, b, ... is given as a fraction of the total width of thegraph.

    Disk[{x, y}, r] is a two-dimensional graphics primitive that represents a filleddisk of radius r centered at the point x, y.

    Disk{x, y},{a, b}] yields an elliptical disk with semi-axes a and a.

    Disk[{x, y}, r, {1, 2}] represents a segment of a disk.

    EdgeForm[g] is a three-dimensional graphics directive which specifies that edgesof polygons are to be drawn using the graphics directive or list of graphics directivesg.

    FaceForm[gf, gb] is a three-dimensional graphics directive which specifies thatthe front faces of polygons are to be drawn with the graphics primitive gf, and theback faces with gb.

    GrayLevel[level] is a graphics directive which specifies the gray-level intensitywith which graphical objects that follow should be displayed.

    Hue[h] is a graphics directive which specifies that graphical objects which followare to be displayed, if possible, in a color corresponding to hue h.

    Hue[h, s, b] specifies colors in terms of hue, saturation and brightness.

    Offset[{dx, dy}, position] gives the position of a graphical object obtained bystarting at the specified position and then moving by absolute offset adx, dya.

    PointSize[d] is a graphics directive which specifies that points which follow areto be shown if possible as circular regions with diameter d. The diameter d is givenas a fraction of the total width of the graph.

    Polygon[{p1, p2, ...}] is a graphics primitive that represents a filled polygon.Each pi is {x, y} or {x, y, z}

    PostScript["string"] is a graphics primitive which gives PostScript code toinclude verbatim in graphics output.

    Raster[{{a, b, }, }] is a two-dimensional graphics primitive whichrepresents a rectangular array of gray cells.

    RasterArray[[{{g11 , g12, }, }] is a two-dimensional graphics primitivewhich represents a rectangular array of cells colored according to the graphicsdirectives gij.

    Rectangle[{xmin, ymin}, {xmax, ymax}] is a two-dimensional graphicsprimitive that represents a filled rectangle, oriented parallel to the axes.

    Rectangle[{xmin, ymin}, {xmax, ymax}, graphics] gives a rectangle filledwith the specified graphics.

    RGBColor[red, green, blue] is a graphics directive which specifies thatgraphical objects which follow are to be displayed, if possible, in the color given.

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 52Woods Hole, 1998

    Scaled[{x, y, }] gives the position of a graphical object in terms ofcoordinates scaled to run from 0 to 1 across the whole plot in each direction.

    Scaled[{dx, dy, }, {x, y, ...}] gives a position obtained by starting atabsolute coordinates {x, y, ...}, then moving by a scaled offset {dx, dy, }.

    StyleForm[expr, options] prints using the specified style options.

    StyleForm[expr, "style"] prints using the specified cell style in the currentnotebook.

    SurfaceColor[dcol] is a three-dimensional graphics directive which specifiesthat the polygons which follow should act as diffuse reflectors of light with a colorgiven by dcol.

    SurfaceColor[dcol, scol] specifies that a specular reflection componentshould be included, with a color given by scol.

    SurfaceColor[dcol, scol, n] specifies that the reflection should occur withspecular exponent n.

    Text[expr, coords] is a graphics primitive that represents text corresponding tothe printed form of expr, centered at the point specified by coords.

    Thickness[r] is a graphics directive which specifies that lines which follow areto be drawn with a thickness r. The thickness r is given as a fraction of the totalwidth of the graph

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 53Woods Hole, 1998

    VI. ProgrammingA. Assignment

    lhs = rhs evaluates rhs and assigns the result to be the value of lhs. From then on,lhs is replaced by rhs whenever it appears.

    lhs := rhs assigns rhs to be the delayed value of lhs. rhs is maintained in anunevaluated form. When lhs appears, it is replaced by rhs, evaluated afresh eachtime.

    lhs =. removes any rules defined for lhs.

    Clear[a1, a2 ] clears values and definitions for the ai.

    x++ increases the value of x by 1, returning the old value of x.

    x += dx adds dx to x and returns the new value of x.

    x-- decreases the value of x by 1, returning the old value of x.

    x -= dx subtracts dx from x and returns the new value of x.

    ++x increases the value of x by 1, returning the new value of x.

    --x decreases the value of x by 1, returning the new value of x.

    x *= c multiplies x by c and returns the new value of x.

    x /= c divides x by c and returns the new value of x.

    AppendTo[s, elem] appends elem to the value of s, and resets s to the result.

    PrependTo[s, elem] prepends elem to the value of s, and resets s to the result.

    f/: lhs = rhs assigns rhs to be the value of lhs, and associates the assignment withthe symbol f.

    f/: lhs := rhs assigns rhs to be the delayed value of lhs, and associates theassignment with the symbol f.

    f/: lhs =. removes any rules defined for lhs, associated with the symbol f.

    lhs^=rhs assigns rhs to be the value of lhs, and associates the assignment withsymbols that occur at level one in lhs.

    lhs^:=rhs assigns rhs to be the delayed value of lhs, and associates the assignmentwith symbols that occur at level one in lhs.

    B. Testinglhs == rhs returns True if lhs and rhs are identical.

    lhs != rhs or lhs rhs returns False if lhs and rhs are identical.

    lhs === rhs yields True if the expression lhs is identical to rhs, and yields Falseotherwise.

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 54Woods Hole, 1998

    lhs =!= rhs yields True if the expression lhs is not identical to rhs, and yieldsFalse otherwise.

    x < y yields True if x is determined to be less than y.

    x > y yields True if x is determined to be greater than y.

    x = y or x y yields True if x is determined to be greater than or equal to y.

    EvenQ[expr] gives True if expr is an even integer, and False otherwise.

    IntegerQ[expr] gives True if expr is an integer, and False otherwise.

    MatrixQ[expr] gives True if expr is a list of lists that can represent a matrix, andgives False otherwise.

    MemberQ[list, form] returns True if an element of list matches form, andFalse otherwise.

    Negative[x] gives True if x is a negative number.

    NonNegative[x] gives True if x is a non-negative number.

    NonPositive[x] gives True if x is a non-positive number.

    NumberQ[expr] gives True if expr is a number, and False otherwise.

    NumericQ[expr] gives True if expr is a numeric quantity, and False otherwise.

    OddQ[expr] gives True if expr is an odd integer, and False otherwise.

    PolynomialQ[expr, var] yields True if expr is a polynomial in var, and yieldsFalse otherwise.

    Position[expr, pattern] gives a list of the positions at which objects matchingpattern appear in expr.

    Position[expr, pattern, levspec] finds only objects that appear on levelsspecified by levspec.

    Positive[x] gives True if x is a positive number.

    PrimeQ[expr] yields True if expr is a prime number, and yields Falseotherwise.

    VectorQ[expr] gives True if expr is a list, none of whose elements arethemselves lists, and gives False otherwise.

    VectorQ[expr, test] gives True only if test yields True when applied to eachof the elements in expr.

    C. Flow of Control1. Compound Expressions

    expression; expression; expression; ... evaluates each expression in turn,giving the last one as the result.

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 55Woods Hole, 1998

    2. Logical Testings: If, Which, SwitchIf[condition, t, f] gives t if condition evaluates to True, and f if it evaluatesto False.

    If[condition, t, f, u] gives u if condition evaluates to neither True norFalse.

    Which[test, value, test, value, ] evaluates each of the test in turn, returningthe value corresponding to the first one that yields True.

    Switch[expr, form, value, form, value, ... ] evaluates expr, then compares itwith each of the form in turn, evaluating and returning the value correspondingto the first match found.

    3. Looping: Do, While, ForDo[expr, {imax}] evaluates expr imax times.

    Do[expr, {i, imax}] evaluates expr with the variable i successively taking onthe values 1 through imax (in steps of 1).

    Do[expr, {i, imin, imax}] starts with i = imin.

    Do[expr, {i, imin, imax, di}] uses steps di.

    Do[expr, {i, imin, imax}, {j, jmin, jmax}, ] evaluates expr looping overdifferent values of j, etc. for each i.

    While[test, body] evaluates test, then body, repetitively, until test first fails togive True.

    For[start, test, incr, body] executes start, then repeatedly evaluates bodyand incr until test fails to give True.

    4. Transfer of Control: Return, Throw, Catch, Break,Continue, Goto, Label, Check, Interrupt, Abort,PrintReturn[expr] returns the value expr from a function.

    Return[ ] returns the value Null.

    Throw[value] stops evaluation and returns value as the value of the nearestenclosing Catch.

    Throw[value, tag] is caught only by Catch[expr, form] where form is apattern that matches tag.

    Catch[expr] returns the argument of the first Throw generated in theevaluation of expr.

    Catch[expr, form] returns value from the first Throw[value, tag] forwhich form matches tag.

    Catch[expr, form, f] returns f[value, tag].

    Break[ ] exits the nearest enclosing Do, For or While.

    Continue[ ] exits to the nearest enclosing Do, For or While in a proceduralprogram.

    Goto[tag] scans for Label[tag], and transfers control to that point.

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 56Woods Hole, 1998

    Label[tag] represents a point in a compound expression to which control canbe transferred using Goto.

    Check[expr, failexpr] evaluates expr, and returns the result, unless messageswere generated, in which case it evaluates and returns failexpr.

    CheckAbort[expr, failexpr] evaluates expr, returning failexpr if an abortoccurs. And my computer kept crashing every time I tried tocopy this line into MS Word! At exactly this spot!Interrupt[ ] generates an interrupt.

    Abort[ ] generates an interrupt to abort a computation.

    TimeConstrained[expr, t] evaluates expr, stopping after t seconds.

    MemoryConstrained[expr, b] evaluates expr, stopping if more than bbytes of memory are requested.

    AbortProtect[expr] evaluates expr, saving any aborts until the evaluation iscomplete.

    D. Input & OutputPrint[expression, expression, ] prints the expression followed by a newline(line feed).

    Input[ ] interactively reads in one Mathematica expression.

    Input["prompt"] requests input, using the specified string as a prompt.

    InputString[ ] interactively reads in a character string.

    InputString["prompt"] requests input, using the specified string as a prompt.

    Note: Mathematica contains an extensive number of input, output, and fileaccess facilities which are beyond the scope of this doucument.

    D. FunctionsfunctionName[arg1_, arg2_, arg3_, ...] := expression;defines a function with arguments arg1, arg2, arg3. expression may be asingle expression, a compound expression, or a list. The tag _ is not used in theright hand side of the function defintion when the arguments are being referenced.The expressions on the right hand side are evaluated sequentially, and the functionsreturn value is the last expression in the list. If the last expression ends in asemicolon : then the return value is null.

    Map[f, expr] or f /@ expr applies f to each element on the first level in expr.

    Apply[f, expr] or f @@ expr replaces the head of expr by f.

    Note: Mathematica contains an extensive number of functions which greatlyexpand the ability to write functions.

    E. Pattern Matching_ or Blank[ ] is a pattern object that can stand for any Mathematica expression.

    __ (two _ characters) or BlankSequence[ ] is a pattern object that can stand forany sequence of one or more Mathematica Expressions

  • Medical Informations: A Course for Health Professionals Mathematical Modeling

    Bruce E. Shapiro Page 57Woods Hole, 1998

    __h or BlankSequence[h] can stand for any sequence of one or moreexpressions, all of which have head h.___ (three _ characters) or BlankNullSequence[ ] is a pattern object that canstand for any sequence of zero or more Mathematica expressions.

    ___h or BlankNullSequence[h] can stand fo