Wolfram ResearchProductsPurchasingServices & ResourcesAbout UsOur Sites

Only the first nine parts of the Basic Tutorial are included in this draft.

Basic Tutorial (part 1 of 10)

1 First Calculations

This is the first part of the ten part Basic Tutorial for learning to use Mathematica. This tutorial is designed to provide broad experience with Mathematica and to provide a foundation for exploring advanced features of the system.

No prior experience with Mathematica is assumed or required. The only prerequisites for this tutorial are familiarity with common operations in elementary mathematics and familiarity with the use of menus, dialog boxes, and other general features of modern computer software.

This tutorial includes a large number of examples and exercises. It is designed to be used in conjunction with a copy of Version 4 of Mathematica so that you can experiment with the examples and work out solutions to the exercises. If you are not currently working with a copy of Mathematica then many of the comments and examples will not apply to you.

In this first part of the Basic Tutorial you will learn about:

  • How to use these tutorials
  • Common conventions in Mathematica input
  • Performing simple calculations
  • Assignments and definitions
  • Finding information in online help

Getting started

To use this tutorial you should know how to start Mathematica, how to switch from one window to another, how to scroll up and down in a window using the keyboard or a mouse, and how to select an item from a menu.

If you have had difficulties getting started with Mathematica, or if you are interested in a brief introductory tour of the system, we recommend the Getting Started guide or the Tour of Mathematica, both of which can be found using the Help Browser, which is available under the Help menu.

Entering and evaluating input

This section describes how to perform a simple calculation, such as adding 2 plus 2, using Mathematica.  If you already know how to do this then you may wish to skip ahead to the next section, Syntax Conventions.  Otherwise, the remainder of this section describes the basic steps in performing a simple calculation.

When you start Mathematica you will be presented with an empty window similar to the window shown here:

[Graphics:Images/Basic1_gr_1.gif]

You can open a new window in your copy of Mathematica by selecting New from the File menu. The appearance of this window will be different in different versions of Mathematica and on different types of computers, but it is normally an empty window with a title bar across the top, a scroll bar across the bottom, and a scroll bar on one side.

To enter your input, select the new window by clicking on it, and start typing. Your input will appear near the top of the window, much as in a typical word processor. Unlike most word processors, however, you will not see a blinking input cursor until you start typing.

After entering your input, the window will look something like this:

[Graphics:Images/Basic1_gr_2.gif]

To evaluate your input, press Shift-Return (press the return key while holding down the shift key).  When the calculation is finished, the result is displayed just below your input, as in:

[Graphics:Images/Basic1_gr_3.gif]

You can repeat this process indefinitely with additional inputs. For example, after a second input and a second evaluation, your notebook might look something like this:

[Graphics:Images/Basic1_gr_4.gif]

When you are finished with your calculations you can end your Mathematica session (which will close this window) by selecting Quit from the File menu. Do not select Quit now unless you want to end this tutorial session.

Syntax conventions

For a thorough discussion of Mathematica syntax, and for definitive reference information, see The Mathematica Book or online help, especially Sections 1.1.6, 2.1.3, 2.8.14, A.2, and A.3.  The summary presented here is adequate for all of the inputs in this tutorial and for most work with Mathematica.

Calculations are done in Mathematica by evaluating functions. For example, you can use the Plus function to compute the sum of [Graphics:Images/Basic1_gr_5.gif] and [Graphics:Images/Basic1_gr_6.gif]:

[Graphics:Images/Basic1_gr_7.gif]
     5

This calculation is rarely entered this way. This calculation is normally be entered using the more familiar notation [Graphics:Images/Basic1_gr_8.gif].

[Graphics:Images/Basic1_gr_9.gif]
     5

In both of these examples the function that is used is the Plus function, and 2 and 3 are the arguments of the function. [Graphics:Images/Basic1_gr_10.gif] is just another way of entering [Graphics:Images/Basic1_gr_11.gif].

More complicated inputs can be entered using functions as arguments in other functions. For example, the product of 7 and [Graphics:Images/Basic1_gr_12.gif] can be entered using the Times function.

[Graphics:Images/Basic1_gr_13.gif]
     35

This calculation can also be entered as [Graphics:Images/Basic1_gr_14.gif]. Parentheses are used here for grouping.  Entering 7 and [Graphics:Images/Basic1_gr_15.gif] adjacent to one another indicates that these expressions are to be multiplied.

[Graphics:Images/Basic1_gr_16.gif]
     35

In this example, the arguments of the Times function are 7 and [Graphics:Images/Basic1_gr_17.gif].

The most general way to enter Mathematica functions is by giving the name of the function followed by square brackets that enclose the argument or arguments of the function. This notation is called FullForm notation, since the FullForm function can be used to display expressions in this form. [Graphics:Images/Basic1_gr_18.gif] and [Graphics:Images/Basic1_gr_19.gif] are examples of FullForm notation.

Alternatives to FullForm notation are available for many common inputs. For example, [Graphics:Images/Basic1_gr_20.gif] is an alternative to the FullForm input [Graphics:Images/Basic1_gr_21.gif], and [Graphics:Images/Basic1_gr_22.gif] is an alternative to the FullForm input [Graphics:Images/Basic1_gr_23.gif].  Other arithmetic operations can be entered using standard notations from mathematics and computer programming.  For example, [Graphics:Images/Basic1_gr_24.gif] denotes [Graphics:Images/Basic1_gr_25.gif] minus [Graphics:Images/Basic1_gr_26.gif], [Graphics:Images/Basic1_gr_27.gif] denotes [Graphics:Images/Basic1_gr_28.gif] divided by [Graphics:Images/Basic1_gr_29.gif], and [Graphics:Images/Basic1_gr_30.gif] denotes [Graphics:Images/Basic1_gr_31.gif] to the power [Graphics:Images/Basic1_gr_32.gif].  Multiplication can be indicated either by adjacent expressions, as in [Graphics:Images/Basic1_gr_33.gif], by one or more spaces between expressions, or with an asterisk, as in [Graphics:Images/Basic1_gr_34.gif].

Adjacent expressions can be used to indicate multiplication only if the factors to be multiplied are distinct expressions even when there is nothing between them. For example, 7 multiplied by 5 can be entered either as [Graphics:Images/Basic1_gr_35.gif], with a space between the 7 and the 5, or as 7*5, but 75, with no space between the 7 and the 5, is the integer 75, not 7 multiplied by 5. This is also true if the factors are symbolic variables.  For example, while [Graphics:Images/Basic1_gr_36.gif] indicates x multiplied by y, the input xy, with no space between the x and the y, is a new symbolic variable.  In some situations it is useful to include an asterisk so that the intended meaning is clear, even when the asterisk is not necessary.

These notations for arithmetic are also listed in Section 1.1.1 of The Mathematica Book. A complete list of all special notations in Mathematica can be found in Section A.2. You do not need to know all of these notations to use Mathematica.  Most of the more common notations, such as the notations for arithmetic, are probably familiar, and any other notations that you might need can be learned when you learn about the corresponding functions.

Some typical inputs

In most cases the most convenient way to enter Mathematica inputs will involve a mixture of FullForm notation and other notations. For example, here is an input that illustrates the most common syntax for using the Solve function to find the solution of an equation.

[Graphics:Images/Basic1_gr_37.gif]
[Graphics:Images/Basic1_gr_38.gif]

Since there is no short notation for Solve, the Solve function is entered in FullForm notation. The name Solve is followed by square brackets that enclose the arguments of the function. The first argument is the equation [Graphics:Images/Basic1_gr_39.gif], entered here using special notation for the Equal function. The Equal function is the function that is used in Mathematica for representing equations. The [Graphics:Images/Basic1_gr_40.gif] character is entered as two [Graphics:Images/Basic1_gr_41.gif] signs. The second argument, [Graphics:Images/Basic1_gr_42.gif], specifies the variable for which to solve.

The result [Graphics:Images/Basic1_gr_43.gif] illustrates two other special notations. The curly braces { and } are used to represent List expressions, and the arrow [Graphics:Images/Basic1_gr_44.gif] is used to represent a Rule expression. The same result in FullForm notation is [Graphics:Images/Basic1_gr_45.gif]. The use of this type of result will be discussed later in this tutorial.

The notations that have been introduced so far can be used to enter any system of algebraic equations. Here is an example showing the use of Solve to solve a pair of equations in two variables. The pair of equations is entered using a List expression in the first argument of Solve, and the two variables are specified using the [Graphics:Images/Basic1_gr_46.gif] expression [Graphics:Images/Basic1_gr_47.gif] in the second argument of Solve. The result is a List expression containing the two solutions. Each solution is a list of Rule expressions that give the values of [Graphics:Images/Basic1_gr_48.gif] and [Graphics:Images/Basic1_gr_49.gif] for that solution.

[Graphics:Images/Basic1_gr_50.gif]
[Graphics:Images/Basic1_gr_51.gif]

Here is an example showing the use of the Plot function to plot a sine curve. The first argument [Graphics:Images/Basic1_gr_52.gif] shows the Mathematica notation for the sine of [Graphics:Images/Basic1_gr_53.gif]. The second argument [Graphics:Images/Basic1_gr_54.gif] is a List expression that gives the name and the minimum and maximum values of the variable. In FullForm notation this input would be [Graphics:Images/Basic1_gr_55.gif]. There isn't an alternate notation for [Graphics:Images/Basic1_gr_56.gif] or for the Plot function, but this input is made significantly more readable and compact by using the alternate notations for List and for Times.

[Graphics:Images/Basic1_gr_57.gif]

[Graphics:Images/Basic1_gr_58.gif]

[Graphics:Images/Basic1_gr_59.gif]

You may want to take some time to experiment with these examples to see the effect of simple changes. For example, you could try typing your own equation in to the Solve example, or inserting [Graphics:Images/Basic1_gr_60.gif] or some other function in place of [Graphics:Images/Basic1_gr_61.gif] in the Plot example. For more information about these functions, see the documentation for Solve and Plot in The Mathematica Book.

Assignments and definitions

A single [Graphics:Images/Basic1_gr_62.gif] sign, as in [Graphics:Images/Basic1_gr_63.gif], is used for entering assignments. The notation [Graphics:Images/Basic1_gr_64.gif] is a special notation for Set[c,5]. Evaluation of [Graphics:Images/Basic1_gr_65.gif] will assign [Graphics:Images/Basic1_gr_66.gif] as the value of [Graphics:Images/Basic1_gr_67.gif], after which [Graphics:Images/Basic1_gr_68.gif] will be replaced by [Graphics:Images/Basic1_gr_69.gif] whenever [Graphics:Images/Basic1_gr_70.gif] is evaluated. For example:

[Graphics:Images/Basic1_gr_71.gif]
[Graphics:Images/Basic1_gr_72.gif]
[Graphics:Images/Basic1_gr_73.gif]
[Graphics:Images/Basic1_gr_74.gif]

You can remove the assigned value of [Graphics:Images/Basic1_gr_75.gif] by evaluating Clear[c], after which [Graphics:Images/Basic1_gr_76.gif] will remain symbolic during evaluation. It is generally a good idea to clear assignments that are no longer in use so that the assigned values do not interfere with subsequent calculations.

[Graphics:Images/Basic1_gr_77.gif]
[Graphics:Images/Basic1_gr_78.gif]
[Graphics:Images/Basic1_gr_79.gif]

Assignments can be used for defining constants, for keeping track of intermediate results, and for defining functions.

Here is an example in which assignments to eq1 and eq2 are used to build up the equations that are passed to Solve. This way of using assignments to keep track of intermediate results can be invaluable in large calculations.

[Graphics:Images/Basic1_gr_80.gif]
[Graphics:Images/Basic1_gr_81.gif]
[Graphics:Images/Basic1_gr_82.gif]
[Graphics:Images/Basic1_gr_83.gif]
[Graphics:Images/Basic1_gr_84.gif]
[Graphics:Images/Basic1_gr_85.gif]

Here is an example of a definition for a function f.

[Graphics:Images/Basic1_gr_86.gif]
[Graphics:Images/Basic1_gr_87.gif]

The notation f[p_] on the left side of the definition is used to indicate that this definition should be invoked whenever an expression of the form f[expr] is evaluated, where expr is any expression. For example:

[Graphics:Images/Basic1_gr_88.gif]
[Graphics:Images/Basic1_gr_89.gif]

Function definitions are used extensively in Mathematica programming, and will be discussed again in Part 7 and in Part 8 of this tutorial. For now it is necessary only to recognize the use of simple assignments to define constants and to keep track of intermediate results.

For other examples of the use of assignments, see Sections 1.2.2 and 1.7.1 in The Mathematica Book.

Before continuing, evaluate [Graphics:Images/Basic1_gr_90.gif] to clear the definitions that were introduced in this section.

[Graphics:Images/Basic1_gr_91.gif]

Names and symbols

Names such as Plus and Solve are names of symbols. Symbols are used in Mathematica both as variables and as functions, and play an essential role in all Mathematica calculations.

The name of a symbol can include any combination of letters, numbers, or other characters, except that the first character cannot be a number, and the name cannot include operators or other characters that already have some other meaning. For example, the name of a symbol cannot include a plus sign or a minus sign, since those characters are used for arithmetic. Section A.1.2 of The Mathematica Book discusses valid symbol names and typical names for symbols.

Some examples of valid names for symbols are x, y, x3, yf17s, alpha, α, gβ12, and SpeedOfLight. Some examples of invalid names for symbols are 3x, alpha_0, and file.ext.  The input 3x is an invalid name because the first character is a number. 3x will be interpreted as 3 multiplied by x, even if there is no space between the 3 and the x. The inputs alpha_0 and file.ext are invalid names because they include characters that have other meanings.  The underscore character in alpha_0 is used in Mathematica to indicate a pattern expression, and the period (or decimal point) in file.ext indicates a dot product.

Mathematica input is case-sensitive, so capitalization is important. If you make an error in the spelling or capitalization of the name of a symbol, the misspelled name will in most cases be undefined, and Mathematica will return the input unchanged.

For example, if [Graphics:Images/Basic1_gr_92.gif] is used instead of Solve, the following input will normally return unchanged.

[Graphics:Images/Basic1_gr_93.gif]
[Graphics:Images/Basic1_gr_94.gif]

An error in spelling or capitalization of the name of a function is the most common reason for Mathematica returning an input unchanged. The input above using [Graphics:Images/Basic1_gr_95.gif] rather than Solve is valid Mathematica syntax, and could be useful if you had, for example, defined your own function and used [Graphics:Images/Basic1_gr_96.gif] as the name of that function.  In most cases, however, this input is probably an error.

Square brackets, curly braces, and parentheses

The use of square brackets [ and ], curly braces { and }, and parentheses in Mathematica is discussed in Sections 1.2.5 and A.2.6 in The Mathematica Book.

Parentheses are used in Mathematica for grouping in arithmetic, square brackets are used for enclosing the arguments of functions, and curly braces are used for entering [Graphics:Images/Basic1_gr_97.gif] expressions (as in [Graphics:Images/Basic1_gr_98.gif] for [Graphics:Images/Basic1_gr_99.gif]).

One other common type of bracketing is the use of double square brackets for entering the Part function. The Part function is used to pick out parts of expressions, such as elements in a vector or matrix. For example, [Graphics:Images/Basic1_gr_100.gif] is an alternate notation for [Graphics:Images/Basic1_gr_101.gif], which gives the element at position [Graphics:Images/Basic1_gr_102.gif] in the list [Graphics:Images/Basic1_gr_103.gif].  For example:

[Graphics:Images/Basic1_gr_104.gif]
[Graphics:Images/Basic1_gr_105.gif]
[Graphics:Images/Basic1_gr_106.gif]
[Graphics:Images/Basic1_gr_107.gif]

Parentheses, square brackets, and curly braces are used in a variety of ways in traditional mathematics and in other computer languages. An occasional source of error in Mathematica is using brackets, braces, or parentheses as they might be used somewhere else.

For example, curly braces and square brackets are sometimes used in traditional mathematics for grouping arithmetic expressions, and curly braces are often used in computer programming languages for identifying blocks of statements. Curly braces and square brackets are not used in these ways in Mathematica. For example, an input such as [Graphics:Images/Basic1_gr_108.gif][Graphics:Images/Basic1_gr_109.gif], which might represent 7 multiplied by [Graphics:Images/Basic1_gr_110.gif] in traditional mathematical notation, would be very unusual in Mathematica, since the 7 would be interpreted as the name of a function.  Similarly, [Graphics:Images/Basic1_gr_111.gif] in Mathematica represents 7 multiplied by the list [Graphics:Images/Basic1_gr_112.gif], which is not the same as multiplying 7 by [Graphics:Images/Basic1_gr_113.gif].  

Probably the most prominent departure from traditional mathematical notation in Mathematica is the use of square brackets rather than parentheses to enclose the arguments of a function. Using square brackets to enclose function arguments avoids the ambiguity in traditional mathematical notation between parentheses that enclose function arguments and parentheses that are used for grouping arithmetic operations. For example, in traditional mathematical notation, [Graphics:Images/Basic1_gr_114.gif] sometimes indicates y multiplied by [Graphics:Images/Basic1_gr_115.gif] and sometimes indicates a function y evaluated at [Graphics:Images/Basic1_gr_116.gif].  In default Mathematica notation, [Graphics:Images/Basic1_gr_117.gif] always indicates y multiplied by [Graphics:Images/Basic1_gr_118.gif] and [Graphics:Images/Basic1_gr_119.gif] always indicates a function y evaluated at [Graphics:Images/Basic1_gr_120.gif].

For further discussion of these and other aspects of Mathematica syntax, see Section 1.1.6 in The Mathematica Book.

Getting information about special notations

If you know the name of a function you can find special notations, if any, for that function by finding the function in The Mathematica Book. The special notations that have been mentioned so far in this tutorial include notations for Times, Plus, Power, Equal, List, and Rule.

If you know the operator or character that is used in a special notation you can usually find the corresponding function by entering that operator or character into the help browser. For example, if you enter [Graphics:Images/Basic1_gr_121.gif] (a dash followed by a "greater than" character) or the [Graphics:Images/Basic1_gr_122.gif] character in the Help Browser and click the Go To: button, the Help Browser will display documentation for Rule.

Many notations involve special characters that are not found on a typical computer keyboard. For example, multiplication can be indicated by a [Graphics:Images/Basic1_gr_123.gif] character, as in [Graphics:Images/Basic1_gr_124.gif], and division can be indicated by the [Graphics:Images/Basic1_gr_125.gif] character, as in [Graphics:Images/Basic1_gr_126.gif].  The [Graphics:Images/Basic1_gr_127.gif] character can be entered using ÷i*÷i (the escape key followed by the * key followed by the escape key) or by typing out \[Times].  The [Graphics:Images/Basic1_gr_128.gif] character can be entered using  ÷idiv÷i or \[Divide].

All special characters have a full name, such as \[Times] or \[Divide]. Special characters can always be entered by typing out that name. Many characters can also be entered using an alias, such as ÷i*÷i for the [Graphics:Images/Basic1_gr_129.gif] character or  ÷idiv÷i for the [Graphics:Images/Basic1_gr_130.gif] character.  Some characters have several aliases.

For more information on special characters see Sections 3.10 and A.1.2 in The Mathematica Book.  In the documentation, aliases such as  ÷idiv÷i are typically given using the notation ÷hdiv÷h.  

Special characters are not required in Mathematica input.  For simplicity you may want to bypass them until you are more familiar with basic Mathematica operations.  Special characters are, however, sometimes used in output, even if you do not use them in your input.  If you see a special character in the display, you can get information about the character by selecting the character using the mouse and choosing Find Selected Function... from the Help menu.

Looking ahead

Here is an outline of the parts of this tutorial, and the topic to be covered in each part.

1 First calculations
2 Numerical calculations
3 Symbolic calculations
4 Plotting and graphics
5 Using notebooks
6 Typeset editing
7 Manipulating expressions
8 Programming
9 Working with files
10 Summary and exercises

Parts 2, 3, and 4 describe the use of standard Mathematica functions for mathematical calculations

Parts 4 and 5 describe the user interface of Mathematica, and facilities for formatting your output.

Parts 7 and 8 provide an introduction to Mathematica programming.

Part 9 describes operations such as reading data files in to Mathematica and saving results in external files.

Part 10 consists primarily of exercises designed to test your knowledge of the information in this tutorial.

The parts of this tutorial can be read in any order. The order shown in the outline is designed to provide a broad introduction to the entire system. If you are interested in a specific part of Mathematica, you may want to skip ahead to the corresponding part of this tutorial. Yet another approach is to start with the exercises at the end of each part of this tutorial and work back from that point to learn about the solutions.

You should not skip the exercises, however. Much of the essential information in these tutorials is covered in the exercises. Even if you do not work out solutions, you should still take the time to read through the exercises.

Getting help

If you would like assistance with this tutorial, experts are available to review your solutions to the exercises or to answer any questions that come up as you work through this tutorial. You can get information about assistance with this tutorial by sending an email request for information about tutorial assistance to Wolfram Research Technical Support (support@wolfram.com).

If you are a registered user of a supported version of Mathematica, you can get help with technical questions about Mathematica by sending your questions to Wolfram Research Technical Support at the email address support@wolfram.com, or using contact information included with your copy of Mathematica.

Exercises

Note: If you are intending to send in your solutions to the exercise for review, we recommending opening a new notebook and putting your work in the new notebook, rather than editing this tutorial notebook. You can also include any questions that you have in the new notebook.

Exercise 1.1 Solving an equation

Show how to use the Solve function to get the formula for the solutions of the quadratic equation [Graphics:Images/Basic1_gr_140.gif] for the variable x.  The result should look like:

[Graphics:Images/Basic1_gr_141.gif]

Exercise 1.2 Alternate notations for input

Show a shorter way to enter this input:

[Graphics:Images/Basic1_gr_142.gif]
[Graphics:Images/Basic1_gr_143.gif]

Exercise 1.3 Using rules

Rules, such as the Rule expressions in the result from Solve, can be used with the ReplaceAll function to make replacements in other expressions. For example:

[Graphics:Images/Basic1_gr_144.gif]
[Graphics:Images/Basic1_gr_145.gif]

Show how you might use ReplaceAll to replace x by 2 and y by 3 in the list [Graphics:Images/Basic1_gr_146.gif]. If you wish, this input can be entered using the alternate notation for ReplaceAll, which you can find by looking up ReplaceAll in The Mathematica Book.

Exercise 1.4 Making a table

A common exercise in programming textbooks for beginners is constructing a table of integers and squares of integers. There are many ways to do this in Mathematica. Here is one way, using the Do function, the Print function, and a string of spaces to separate the columns in the table.

[Graphics:Images/Basic1_gr_147.gif]
[Graphics:Images/Basic1_gr_148.gif]
[Graphics:Images/Basic1_gr_149.gif]
[Graphics:Images/Basic1_gr_150.gif]
[Graphics:Images/Basic1_gr_151.gif]
[Graphics:Images/Basic1_gr_152.gif]
[Graphics:Images/Basic1_gr_153.gif]
[Graphics:Images/Basic1_gr_154.gif]
[Graphics:Images/Basic1_gr_155.gif]
[Graphics:Images/Basic1_gr_156.gif]
[Graphics:Images/Basic1_gr_157.gif]

Modify this program to add a column that shows the cube of each integer.

Exercise 1.5 Formatting a table

One problem with the table in Exercise 1.4 is that the columns are not properly aligned. An effective solution to that problem is to construct the entire table and let the computer align the columns. This can be done in Mathematica using the Table function to generate a list of integers and squares of integers, and using the TableForm function to format that list.

[Graphics:Images/Basic1_gr_158.gif]
1 1
2 4
3 9
4 16
5 25
6 36
7 49
8 64
9 81
10 100

Modify this program to add a column that shows the cube of each integer.

Exercise 1.6 Online information

In addition to The Mathematica Book and online help (the Help Browser), you can also get information about functions and variables by typing a question mark followed by the name of the function or variable. For example, evaluating [Graphics:Images/Basic1_gr_159.gif] gives information about the Solve function:

[Graphics:Images/Basic1_gr_160.gif]
[Graphics:Images/Basic1_gr_161.gif]

You can also include an asterisk after the question mark to indicate any sequence of characters.  For example, [Graphics:Images/Basic1_gr_162.gif] will show all names that contain [Graphics:Images/Basic1_gr_163.gif].  

Enter [Graphics:Images/Basic1_gr_164.gif] to get the names of all of the functions that include [Graphics:Images/Basic1_gr_165.gif] in the name of the function.

Now enter [Graphics:Images/Basic1_gr_166.gif] and read the information about the Plot function. This information will be useful in the next exercise.

Exercise 1.7 Plotting more than one function at a time

Use the Plot function to plot [Graphics:Images/Basic1_gr_167.gif] and [Graphics:Images/Basic1_gr_168.gif] on the same plot, with [Graphics:Images/Basic1_gr_169.gif] ranging from [Graphics:Images/Basic1_gr_170.gif] to [Graphics:Images/Basic1_gr_171.gif].

If you are unsure of how to proceed, you can get information about using Plot to plot more than one function by entering and evaluating [Graphics:Images/Basic1_gr_172.gif], or by referring to the documentation for Plot or to Section 1.9.1 in The Mathematica Book.

You can find explicit examples of using Plot to plot more than one function both in Section 1.9.1 of The Mathematica Book and under Further Examples at the bottom of the help page for Plot. To open the Further Examples section of the help page, click on the triangle immediately to the left of the heading Further Examples.

Exercise 1.8 Adding a label to a plot

One way to add a label to a plot is to use the PlotLabel option. An option is an optional function argument that is entered using a rule. The Plot function is one of the many functions that accepts options.

Add a label to a plot of your choice by including [Graphics:Images/Basic1_gr_173.gif] as the last argument in Plot.

Examples showing the use of the PlotLabel option can be found under Further Examples at the bottom of the online help page for PlotLabel.

Other ways of labeling plots will be discussed in Part 4 of this tutorial.

Exercise 1.9 Solving an equation numerically

Use the FindRoot function to find the three real solutions of the equation [Graphics:Images/Basic1_gr_174.gif].

Here is an input that computes the smallest solution. The first argument in FindRoot is the equation to be solved and the second argument gives the variable and the starting value for that variable. The algorithm used by FindRoot begins with the specified starting value when it searches for a solution.

[Graphics:Images/Basic1_gr_175.gif]
[Graphics:Images/Basic1_gr_176.gif]

The approximate locations of the other two solutions can be seen by plotting the two sides of the equation on the same graph, and noting the points where the two lines intersect.

[Graphics:Images/Basic1_gr_177.gif]

[Graphics:Images/Basic1_gr_178.gif]

[Graphics:Images/Basic1_gr_179.gif]

By choosing a starting value near the solution that you want, you can cause FindRoot to compute a value for that solution.



 © 2008 Wolfram Research, Inc.  Terms of Use  Privacy Policy |
Sign up for our newsletter: