Discover millions of ebooks, audiobooks, and so much more with a free trial

From $11.99/month after trial. Cancel anytime.

Schaum's Outline of Mathematica, 2ed
Schaum's Outline of Mathematica, 2ed
Schaum's Outline of Mathematica, 2ed
Ebook841 pages9 hours

Schaum's Outline of Mathematica, 2ed

Rating: 3.5 out of 5 stars

3.5/5

()

Read preview

About this ebook

Tough Test Questions? Missed Lectures? Not Enough Time?

Fortunately for you, there's Schaum's Outlines. More than 40 million students have trusted Schaum's to help them succeed in the classroom and on exams. Schaum's is the key to faster learning and higher grades in every subject. Each Outline presents all the essential course information in an easy-to-follow, topic-by-topic format. You also get hundreds of examples, solved problems, and practice exercises to test your skills.

This Schaum's Outline gives you

  • Practice problems with full explanations that reinforce knowledge
  • Coverage of the most up-to-date developments in your course field
  • In-depth review of practices and applications

Fully compatible with your classroom text, Schaum's highlights all the important facts you need to know. Use Schaum's to shorten your study time-and get your best test scores!

Schaum's Outlines-Problem Solved.

LanguageEnglish
Release dateMay 1, 2009
ISBN9780071608299
Schaum's Outline of Mathematica, 2ed

Read more from Eugene Don

Related to Schaum's Outline of Mathematica, 2ed

Related ebooks

Study Aids & Test Prep For You

View More

Related articles

Reviews for Schaum's Outline of Mathematica, 2ed

Rating: 3.25 out of 5 stars
3.5/5

2 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Schaum's Outline of Mathematica, 2ed - Eugene Don

    CHAPTER 1

    Getting Acquainted

    1.1 Notation and Conventions

    Mathematica is a language that is best learned by experimentation. Therefore, the reader is urged to try as many examples and problems as possible and experiment by changing options and parameters. In fact, this chapter may be considered a tutorial for those readers who want to get their hands on Mathematica right away.

    New commands are introduced with a bullet, and options associated with them are bulleted with a · symbol for easy reference.

    In keeping with Mathematica’l conventions, all commands and instructions will be written in Courier bold face type and Mathematica output in Courier light face type.

    This line is written in Courier bold face type.

    This line is written in Courier light face type.

    Menu commands in this text are described using double arrow ( ). For example, Format Style Input, written in Arial font, means go to the Format menu, then to the Style submenu, and then click on Input.

    Mathematica occasionally uses a special symbol, ′, which we call a backquote. Do not confuse this with an apostrophe.

    Finally, most Mathematica commands use an arrow, →, to specify options within the command. You may use –> (– followed by >) as an alternate, if you wish. Mathematica will automatically convert this sequence to →. In a similar manner, the sequence ! = is automatically converted to ≠, <= is replaced by ≤, and >= is changed to ≥.

    The examples used in this book were executed using Mathematica versions 6 and 7. You may notice some differences on your computer if you are using earlier versions of the software. Most noticeably, graphics, particularly three-dimensional graphics, have been enhanced in the later version and many computational algorithms have been improved, resulting in greater efficiency and speed.

    1.2 The Kernel and the Front End

    The kernel is the computational engine of Mathematica. You input instructions and the kernel responds with answers in the form of numbers, graphs, matrices, and other appropriate displays. The kernel works silently in the background and, for the most part, is invisible.

    The interface between the user and the kernel is called the front end and the medium of the front end is the Mathematica notebook. The notebook not only enables you to communicate with the kernel, but is a convenient tool for documenting your work.

    To execute an instruction, type the instruction and then press [ENTER]. Most PCs have two [ENTER] keys, but only the [ENTER] key to the far right of the keyboard will execute instructions. The other [ENTER] key must be pressed with the [SHIFT] key held down; otherwise you will merely get a new line. This is especially important if you are using a laptop. If you are using a Macintosh computer, do not confuse the [ENTER] key with the [RETURN] key.

    The picture in Example 1 shows the standard Mathematica display. The symbols on the right-hand side form the Basic Math Input palette and allow access by mouse-click to the most common mathematical symbols. (If you don’t see the palette on your screen, click on Palettes BasicMathlnput or Palettes Other Basic Math Input and it should appear.) Other palettes such as Basic Math Assistant and Classroom Assistant (version 7 and above) are available for specialized purposes and can be accessed via the Palettes menu.

    Each symbol is accessed by clicking on the palette. If you use the palette, your notebooks will look like pages from a math textbook. Most examples in this book take full advantage of the Basic Math Input palette. However, each Mathematica symbol has an alternative descriptive format that can be typed manually. For example, π can be represented as Pi and can be written Sqrt [5]. These representations are useful for experienced Mathematica users who prefer not to use the mouse.

    The notebook in Example 1, labeled Untitled– 1, is where you input your commands and where Mathematica places the result of its calculations. The picture shows the input and output of Example 1. (The display on a Macintosh computer will look slightly different.)

    EXAMPLE 1 Add 2 and 3.

    Notice that the kernel has assigned "ln[1] to the input expression and Out[1] to the output. This enables you to keep track of the order in which the kernel evaluates instructions. These labels are important because the order of evaluation does not always correspond to the physical position of the instruction within the notebook. In this book, however, we shall not include In and Out" labels in our examples.

    In working out the examples and problems in this book, you may find that your answers do not agree with the answers given in the text. This may occur if you have defined a symbol to have a specific value. For example, if x has been defined as 3, all occurrences of x will be replaced by 3. You should clear the symbol (see Section 1.5) and try the problem again. All examples and problems assume that symbols have been cleared prior to execution.

    You can work on several different notebooks in a single Mathematica session. However, if you are using only one kernel, changes to symbols in one notebook will affect identical symbols in all notebooks.

    There are times when you may wish to evaluate only part of an expression. To do this, select the portion of the expression you wish to evaluate. Then press [CTRL] + [SHIFT] + [ENTER] on a PC or [COMMAND] + [RETURN] on a Mac.

    EXAMPLE 2 Suppose we wish only to perform the multiplication in the expression 2 * 3 + 5.

    First select 2 * 3:

    2 * 3 + 5

    Then press [CTRL] + [SHIFT] + [ENTER] (PC) or [COMMAND] + [RETURN] (Mac).

    6 + 5

    A semicolon (;) at the end of a Mathematica command will suppress output. This is useful in long sequences of calculations when only the final answer is important.

    EXAMPLE 3 Suppose we wish to define a = 1, b = 2, c = 3 and then display their sum. Here are two ways to write this problem.

    a = 1            a = 1;

          b = 2            b = 2;

          c = 3            c = 3;

          a + b + c        a + b + c

          1                6

          2

          3

          6

    Occasionally you may introduce an instruction that takes an excessively long time to execute, or you may inadvertently create an infinite loop. To abort a calculation, go to Evaluation Abort Evaluation. Alternatively, you may press [ALT] + [.] to abort ([COMMAND] + [.] on the Macintosh). On the rare occasion when this does not work, you will have to terminate the kernel by going to Evaluation Quit Kernel Local. However, by doing so, you will lose all your defined symbols and values. Your Mathematica notebook will not be lost, however, so they can easily be restored.

    As with all computer software, there are times when Mathematica will crash completely. The only remedy is to close Mathematica and reload it. On rare occasions, you may have to reboot your computer. In either event, your notebook changes will be lost. It is therefore extremely important to back up your notebook often!

    Finally, there may be times when you wish to include comments within your Mathematica commands. Anything written within (* and *) is ignored by the Mathematica kernel.

    EXAMPLE 4

    12 + (* these words will be ignored by the kernel *) 3

       15

    SOLVED PROBLEMS

    1.1 Multiply 12 by 17 and then add 9.

    SOLUTION

    12 * 17 + 9

       213

    1.2 Multiply the 12 by 17 in Problem 1.1, but do not add the 9.

    SOLUTION

    Press [CTRL] + [SHIFT] + [ENTER] or [COMMAND] + [RETURN] on a Mac.

    204 + 9

    1.3 The following program is an infinite loop. Execute it and then abort the evaluation.

    x = 1;

    While [x > 0, x = x + 1]

    SOLUTION

    x = 1;

    While [x > 0, x = x + 1]

    [ALT] +.

    $Aborted

    1.4 Multiply 17.2 by 16.3 and then add 4.7.

    SOLUTION

    17.2 * 16. 3 + 4. 7

    285.06

    1.5 Multiply 17.2 by the sum of 16.3 and 4.7.

    SOLUTION

    17.2 * (16. 3 + 4.7)

    361.2

    1.6 Compute the sum of 2x + 3, 5x + 9, and 4x + 2.

    SOLUTION

    (2x + 3) + (5x + 9) + (4x + 2)

    14 + 11x

    1.3 Mathematica Quirks

    Mathematica is case sensitive.

    For example, Integrate and integrate are different. All Mathematica-defined symbols, commands and functions begin with a capital letter. Some symbols, such as FindRoot, use more than one capital letter. To avoid conflicts, it is a good idea for all user-defined symbols to begin with a lowercase letter.

    Different brackets are used for different purposes.

    • Square brackets are used for function arguments: Sin [x] not Sin(x).

    • Round brackets are used for grouping: (2 + 3) * 4 means add 2 + 3 first, then multiply by 4. Never type [2 + 3] * 4.

    • Curly brackets are used for lists: {1, 2, 3, 4}. More about lists in Chapter 3.

    Use E, not e, for the base of the natural logarithm.

    Since every Mathematica symbol begins with a capital letter, the base of the natural logarithm is E. This causes a bit of confusion, so be careful. Similarly, I (not i) is the imaginary unit. The symbols and from the Basic Math Input palette may be freely used if desired.

    Polynomials are not written in standard form.

    Mathematica writes polynomials with the constant term first and increasing powers from left to right. Thus, the polynomial x² + 2x – 3 would be converted to –3 + 2x + x². To see the expression in a more conventional format, the command TraditionalForm may be used.

    TraditionalForm [expression] prints expression in a traditional mathematical format.

    EXAMPLE 5 Evaluate the sum of x² + 3, 2x + 5, and x³ + 2 and express the answer using TraditionalForm.

    (x² + 3) + (2 x + 5) + (x³ + 2)

       10 + 2x + x² + x³

       TraditionalForm [(x² + 3) + (2x + 5) + (x³ + 2)]

    x³ + x² + 2x + 10

    SOLVED PROBLEMS

    1.7 Compute using the Sqrt function. What happens if you do not use a capital S?

    SOLUTION

    sqrt[81]

       9

    sqrt[81]

    1.8 Use parentheses to multiply the sum of 2 and 3 by the sum of 5 and 7. What happens if you use square brackets?

    SOLUTION

    (2 + 3) (5 + 7)

       60

    [2 + 3] [5 + 7]

    Syntax::sntxb: Expression cannot begin with ′[2+3][5+7]′.

    Syntax::tsntxi: ′[2+3]′ is incomplete; more input is needed.

    Syntax::sntxi: Incomplete expression; more input is needed.

    1.9 Use the Sin function to compute sin(π/2). What happens if you use round parentheses?

    SOLUTION

    1.10 Alexis typed [4 + 1] * [6 + 2] during a Mathematica session. Why didn’t she get an answer of 40?

    SOLUTION

    Square brackets cannot be used for grouping. Round parentheses must be used.

    1.11 Why didn’t Ariel get an answer of 3 when she typed sqrt [9]?

    SOLUTION

    Mathematica functions must begin with a capital letter.

    1.12 Why didn’t Lauren get an answer of 1 when she typed Cos (0)?

    SOLUTION

    Square brackets, not round parentheses, must be used to contain arguments of functions.

    1.4 Mathematica Gives Exact Answers

    Mathematica is designed to work as a mathematician works: with 100% precision. You do not get the 10- or 12-digit numerical approximation a calculator would give, but instead get a symbolic mathematical expression.

    EXAMPLE 6

    EXAMPLE 7

    EXAMPLE 8

    π + π

    EXAMPLE 9

    SOLVED PROBLEMS

    1.13 Simplify .

    SOLUTION

    1.14 Compute the sum of the reciprocals of 3, 5, 7, 9, and 11.

    SOLUTION

    1.15 Compute the square root of π exactly using the Sqrt function.

    SOLUTION

    Sqrt[Pi]

    1.16 Multiply by .

    SOLUTION

    1.17 Simplify leaving your answer in radical form.

    SOLUTION

    1.5 Mathematica Basics

    In this section we discuss some of the simpler concepts within Mathematica. Each will be explained in greater detail in a subsequent chapter.

    Symbols are defined using any sequence of alphanumeric characters (letters, digits, and certain special characters) not beginning with a digit. Once defined, a symbol retains its value until it is changed, cleared, or removed.

    Arithmetic operations are performed in the obvious manner using the symbols +, –, *, and /. Exponentiation is represented by a caret, ^, so x^y means xy. Just as in algebra, a missing symbol implies multiplication, so 2a is the same as 2*a. Be careful, however, when multiplying two symbols, since ab represents the single symbol beginning with a and ending with b. To multiply a by b you must separate the two letters with * or × (on the Basic Math Input palette) or a space: a * b, a × b, or a b.

    EXAMPLE 10

    a = 2

       b = 3

       c = a + b

       2

       3

       5

    Notice that the result of each calculation is displayed. This is sometimes annoying, and can be suppressed by using a semicolon (;) to the right of the instruction.

    EXAMPLE 11

    a = 2;

       b = 3;

       c = a + b

       5

    Operations are performed in the following order: (a) exponentiation, (b) multiplication and division, (c) addition and subtraction. If the order of operations is to be modified, parentheses, (), must be used. Be careful not to use [] or {} for this purpose.

    EXAMPLE 12

    2 + 3 * 5

       17

    (2 + 3) * 5

       25

    Each symbol in Mathematica represents something. Perhaps it is the result of a simple numerical calculation or it may be a complicated mathematical expression.

    EXAMPLE 13

    a = 3;

    Here, a is a symbol representing the numerical value 3 and b is a symbol representing an algebraic expression.

    If you ever forget what a symbol represents, simply type ? followed by the symbol name to recall its definition.

    EXAMPLE 14 (continuation of Example 13)

    To delete a symbol so that it can be used for a different purpose, the Clear or the Remove command can be used.

    Clear [symbol] clears symbol’s definition and values, but does not clear its attributes, messages, or defaults, symbol remains in Mathematica’s symbol list. Typing symbol =. will also clear the definition of symbol.

    Remove [symbol] removes symbol completely, symbol will no longer be recognized unless it is redefined.

    You may have noticed that when you begin to type the name of a symbol, it appears with a blue font until it is recognized as a Mathematica command or symbol (possibly user-defined) having some value. Then it turns black. If the symbol is cleared or removed, all instances of the symbol turn blue once again.

    Parentheses, brackets, and braces remain purple until completed with a matching mate. Errors caused by having two left parentheses, but only one right parenthesis, for example, can be conveniently spotted.

    EXAMPLE 15 (continuation of Example 13)

    Clear[a]

    Remove[b]

    ?b

    Information :: notfound: Symbol b not found.

    (Clicking on gives more information about the error.)

    The N command allows you to compute a numerical approximation.

    N[expression] gives the numerical approximation of expression to six significant digits (Mathematica’s default).

    N[expression, n] attempts to give an approximation accurate to n significant digits.

    A convenient shortcut is to use //N to the right of the expression being approximated. Thus, expression//N is equivalent to N[expression].// can be used for other Mathematica commands as well.

    expression //COMMAND is equivalent to Command [expression].

    Another shortcut is to type a decimal point anywhere in the expression. This will cause Mathematica to evaluate the expression numerically.

    EXAMPLE 16

    EXAMPLE 17

    N[x] or π //N

       3.14159

    N[7C, 50]

       3.1415926535897932384626433832795028841971693993751

    The Mathematica kernel keeps track of the results of previous calculations. The symbol % returns the result of the previous calculation, %% gives the result of the calculation before that, %%% gives the result of the calculation before that and so forth. Using % wisely can save a lot of typing time.

    EXAMPLE 18 To construct we could type: Sqrt [Pi+Sqrt[Pi+Sqrt[Pi]]]. A less confusing way of accomplishing this is to type

    Using the Basic Math Input palette, we can type

    SOLVED PROBLEMS

    1.18 Define a = 3, b = 4, and c = 5. Then multiply the sum of a and b by the sum of b and c. Print only the final answer.

    SOLUTION

    a = 3;

       b = 4;

       c = 5;

       (a + b) * (b + c)

       63

    1.19 Let a = l, b = 2, and c = 3 and add a, b, and c. Then clear a, b, and c from the kernel’s memory and add again.

    SOLUTION

    a = 1;

       b = 2;

       c = 3;

       a + b + c

       6

    Clear[a, b, c]

       a + b + c

       a + b + c

    1.20 Obtain a 25-decimal approximation of e, the base of the natural logarithm.

    SOLUTION

    2.7182818284590452353602875

    1.21 (a) Express as a single fraction.

    (b) Obtain an approximation accurate to 15 decimal places.

    SOLUTION

    N[%, 15]

    0.182286820730757

    1.22 Compute (a) exactly and (b) approximately to 25 significant digits.

    SOLUTION

    N[%, 25]

    31.11269837220809107363715

    1.23 Multiply 12 by 6. Then multiply 15 by 7. Then use % and %% to add the two products.

    SOLUTION

    12 * 6

       72

    15 * 7

       105

    % + %%

       177

    SOLUTION

    1.25 Compute the value of 1 + (1 + (1 + (1 + (1 + 1)²)²)²)².

    SOLUTION

    1 + 1

       2

    1 + %^2

       5

    1 + %^2

       26

    1 + %^2

       677

    1 + %^2

       458 330

    1.6 Cells

    Cells are the building blocks of a Mathematica notebook. Cells are indicated by brackets at the right-hand side of the notebook. (Most likely you have already noticed these brackets and were wondering what they meant.) Cells can contain sub-cells, which may in turn contain sub-sub-cells, and so forth.

    The kernel evaluates a notebook on a cell-by-cell basis, so if you have several instructions within a single cell, they will all be executed with a single press of the [ENTER] key.

    EXAMPLE 19

          3

          9

          12

    A new cell can be formed by moving the mouse until the cursor becomes horizontal, and then clicking. A horizontal line will appear across the screen to mark the beginning of the new cell. Existing cells can be divided by clicking on the menu Cell Divide Cell. The cell will be divided into two cells, the break occurring at the point where the cursor is positioned. As a shortcut, you can divide a cell by pressing (simultaneously) [SHIFT] + [CTRL] + [D].

    Cells can be combined (merged) by selecting the appropriate cell brackets (a vertical black line should appear) and then clicking on Cell Merge Cells. Alternatively, you can press [SHIFT] + [CTRL] + [M].

    To avoid extremely long notebooks, cells can be closed (or compressed) by double-clicking on the cell bracket. The bracket will change appearance, looking something like a fish hook. Double-clicking a second time will open the cell.

    There are different types of cells for different purposes. Only input cells can be fed to the kernel for evaluation. Text cells are used for descriptive purposes. Other cell types such as Title, Subtitle, Section, Subsection, etc. can be found by clicking on the menu Format Style. The cell type can also be seen and changed using a drop-down box located in a toolbar at the top of your notebook. If you do not see the toolbar, go to Window Show Toolbar to display it.

    SOLVED PROBLEMS

    1.26 Let a = 2x + 3 and b = 5x + 6. Then compute a + b.

    (a) Place each instruction in a separate cell and execute them individually.

    (b) Place all three instructions in a single cell and execute them simultaneously.

    SOLUTION

    This is what the output looks like after execution:

    1.27 Let a = 2x + 3y + 4z, b = x + 3y + 5z, and c = 3x + y +z. Compute the sum of a, b, and c. Place four lines within a single cell and execute, printing only the final result.

    SOLUTION

    1.7 Getting Help

    There are many sources of help in Mathematica. First and foremost is the Documentation Center (as shown in the following figure) available from the Help menu. There you will find all available commands grouped by topic, or you can search for the help you need by typing in a few keywords. The Function Navigator contains a listing of all the functions available in Mathematica arranged by topic, and the entire Mathematica manual may be accessed by going to the Virtual Book.

    The help files contain numerous examples that you may want to explore. Feel free to make any changes in the help files without fear of modifying their content. These files are protected and your changes will not be permanent.

    If you know the name of the command you want, you can use a question mark, ?, followed by the name of the command to determine its syntax. More extensive information about the command, including attributes and options, can be obtained using ??. Or you can type the name of the command, place the cursor within its name, and then press F1. You will be taken to a page with a complete description and illustrative examples.

    Occasionally, when you make an error, Mathematica will beep or the cell will change color. If you are not sure what you did to cause this, you can get a clue by going to Help Why The Beep? or Help Why The Coloring?

    EXAMPLE 20 Suppose you know that the command Plot graphs a function, but you cannot remember its syntax.

    ?Plot

    If information is needed about attributes or optional settings (and their defaults), ?? can be used.

    ??Plot

    Attributes[Plot]={HoldAll, Protected}

    Options[Plot] = {AlignmentPoint → Center, ,

          Axes → True, AxesLabel → None, AxesOrigin → Automatic, AxesStyle → {},

          Background → None, BaselinePosition → Automatic, BaseStyle → {},

          ClippingStyle → None, ColorFunction → Automatic, ColorFunctionScaling → True,

          ColorOutput → Automatic, ContentSelectable → Automatic,

          DisplayFunction: → $DisplayFunction, Epilog → {},

          Evaluated → System′Private′$Evaluated, EvaluationMonitor → None,

          Exclusions → Automatic, ExclusionsStyle → None, Filling → None,

          FillingStyle → Automatic, FormatType: → TraditionalForm, Frame → False,

          FrameLabel → None, FrameStyle → {}, FrameTicks → Automatic,

          FrameTicksStyle → {}, GridLines → None, GridLinesStyle → {},

          Imagemargins → 0 ., ImagePadding → All, ImageSize → Automatic,

          LabelStyle → {}, MaxRecursion → Automatic, Mesh → None,

          MeshFunctions → {#1&}, MeshShading → None, MeshStyle → Automatic,

          Method → Automatic, PerformanceGoal: → $PerformanceGoal,

          PlotLabel → None, PlotPoints → Automatic, PlotRange → {Full, Automatic},

          PlotRangeClipping → True, PlotRangePadding → Automatic,

          PlotRegion → Automatic, PlotStyle → Automatic,

          PreservelmageOptions → Automatic, Prolog → {}, RegionFunction → (True &),

          RotateLabel → True, Ticks → Automatic, TicksStyle → {},

          WorkingPrecision → MachinePrecision}

    Options can also be obtained using the Options command. This is useful if you want to specify an option but cannot remember its name.

    EXAMPLE 21

    Options[Solve]

       {InverseFunctions → Automatic, MakeRules → False, Method → 3, Mode → Generic,

        Sort → True, VerifySolutions → Automatic, WorkingPrecision → ∞}

    Very often you may remember part of a symbol name, but not the whole name. If you know the beginning is Arc, for example, type in the part you know and then press [CTRL] + [K]. This will generate a menu of all commands and functions beginning with Arc. Then click on the one you want. If you are using a Macintosh computer, use [COMMAND] + [K]. (The [COMMAND] key is the key with the apple on it.)

    EXAMPLE 22 Type Arc and then press [CTRL] + [K] or [COMMAND] +[K].

    Another way of determining symbol names is to use ? together with wildcards. The character * acts as a wildcard and takes the place of any sequence of characters. Wildcards can be used anywhere, at the beginning, middle, or end of a symbol.

    EXAMPLE 23 Output may vary depending upon your version of Mathematica

    (a) Find all commands beginning with Inv.

    ?Inv*

    (b) Find all commands ending with in.

    ?*in

    (c) Find all commands with our in the middle.

    ? *our*

    Wildcards can also be used to determine which symbols have been used thus far by the kernel. Typing ?′* returns a list of all symbols that have been defined during your Mathematica session. The character ′ (backquote) stands for global—you want a list of all global symbols. (See the appendix for a discussion of global symbols.)

    EXAMPLE 24 Note: The results of this example may be slightly different on your computer, depending upon the symbols you have defined.

    a = 3;

       b2xy = 4;

       xyz7 = 5;

       ?′ *

    Enjoying the preview?
    Page 1 of 1