0% found this document useful (0 votes)
116 views

Mathematica 4 Calc

Mathematica is a powerful software system for performing mathematical calculations. It can calculate arithmetic, functions like sin and log, simplify algebraic expressions, graph functions, and integrate and differentiate. The document discusses how to use Mathematica cells and commands like Plot, D, and Integrate to perform these calculations. Examples are provided to illustrate how to calculate derivatives, integrals, and plot functions using Mathematica notation and syntax.

Uploaded by

rogerio092
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
116 views

Mathematica 4 Calc

Mathematica is a powerful software system for performing mathematical calculations. It can calculate arithmetic, functions like sin and log, simplify algebraic expressions, graph functions, and integrate and differentiate. The document discusses how to use Mathematica cells and commands like Plot, D, and Integrate to perform these calculations. Examples are provided to illustrate how to calculate derivatives, integrals, and plot functions using Mathematica notation and syntax.

Uploaded by

rogerio092
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Using Mathematica for Calculus

(If you are reading this document interactively within Mathematica, then we need to do some housekeeping to make it work right. We need to make sure that all
the variables we will use start out with no prior values. Put the cursor in the word "Remove" and press shift-enter. Please excuse the interruption.)

In[1]:=

Remove@a, b, c, d, e, f, g, h, x, yD

Introduction
The following section is just for reading. It will show you what Mathematica can do.
Mathematica is a software system for doing mathematical calculations. It is the Mark McGwire of calculators, much more
powerful than anything you can carry in your pocket. Mathematica will perform calculations:
In[122]:=
Out[122]=

[email protected]
0.255541

simplify algebraic expressions:


In[123]:=

Out[123]=

E
+ 2 x2 x 2
10
1
7

3 H2 + xL
6 H1 + xL
2 H1 + xL
ApartA

3x4

x3

graph functions:
In[124]:=

Plot@Sin@x2 D, 8x, 1, 3<D


1
0.5

-1

1
-0.5
-1

Out[124]=

Graphics

integrate and differentiate:

Mathematica4Calc.nb

In[125]:=

Out[125]=

2
x sinH2 xL cosH3 xL x

1
H250 Cos@xD + 125 x2 Cos@xD +
250
2 Cos@5 xD 25 x2 Cos@5 xD 250 x Sin@xD + 10 x Sin@5 xDL

and solve equations.


In[126]:=
Out[126]=

8x 0.450184<

FindRoot[Cos[x] == 2*x, {x, 1}]

Mathematica will do many other mathematical operations too, most of which you have not yet learned about. As the
famous entertainer, Dr. Science, says: "Mathematica knows more than you do." But that is not really true. Although
Mathematica knows a lot of functions, it cannot do word problems. It cannot prove theorems or build models. It cannot
create equations; it can only solve them. The hard parts of mathematics still have to be done by people, but Mathematica
will help you by taking over some of the routine.
The document you are looking at, either on paper or on a screen, is a Mathematica notebook, a collection of text paragraphs, mathematical calculations, and graphs. The text paragraphs can include mathematical expressions, like this:
d
sin t = cos t
dt
Whenever you use Mathematica, you will create a Mathematica notebook. Notebooks can be saved and reloaded, printed,
or passed around by email. Once you leave Mathematica, your notebook is just a file like a spreadsheet or word-processing
file. You could do an entire homework assignment in a Mathematica notebook, print it, and turn it in.
The purpose of this lesson is to teach you to use Mathematica as a calculator. You are not going to learn how to create text
paragraphs. You are just going to learn to do calculations.

How to Use This Worksheet


Read the text while sitting before a computer running Mathematica, and do all of the "Try it Yourself" sections. The
expected time to complete this worksheet is 1-2 hours. Your teacher may ask you to work on selected subsections.

Mathematica4Calc.nb

Getting Started
Try It Yourself
If you are reading this on a computer, place the cursor in the cell labelled (* empty cell *) just below. Put the cursor right
after the right parenthesis. Otherwise start your computer and get Mathematica running. Type
a = 2+2
and press (Shift-Enter). Your formula should appear as input, and the result should appear as output. Make sure this
works before proceeding. You have to press after every entry to execute it.
H empty cell L

Every bit of text and formula in Mathematica is contained in a cell. The cells are outlined on the right. If you press the upand down-arrow keys, you will see the cursor change from a vertical line to a horizontal line, and then back to a vertical
line as you pass from one cell to another. If you start typing while the cursor is a long horizontal line, you will open a new
cell.
Before going to the next section, let's put your name on the worksheet. Move the cursor to a location between two cells,
and type your name as a comment between the symbols (* ... *) , like this:
(* Your Name *)
If there are more than one of your working on this computer, everyone should put their names on the worksheet

Calculating with Numbers


Arithmetic
Your first goal should be to make Mathematica do what your calculator can do. You can enter numbers into Mathematica
with or without decimal points. Numbers entered without decimal points are considered "exact", numbers with decimal
points are approximate. Calculations with exact numbers have exact results; calculations with decimal numbers have
decimal results. Addition and subtraction are denoted with the usual symbols + and - , and division is / . Here are some
examples:

Mathematica4Calc.nb

In[128]:=
Out[128]=

In[129]:=
Out[129]=

b = 34 + 79
55
36

c = 3.0 4.0 + 7.0 9.0


1.52778

Multiplication is denoted by a space between the factors:


In[130]:=
Out[130]=

d = 345

H 345 L

60

Powers are expressed with the caret ^ :


In[131]:=
Out[131]=

e = 3 ^ 100
515377520732011331036461129765621272702107522001

This last calculation shows that calculations with exact numbers have exact results.
Two points.
1. It is a very good idea to assign each calculation to a variable. Then you can use the variable to recall the result of a
calculation.
2. If a calculation has an exact results, you can get the decimal equivalent with the function N[..] . Note the square brackets. For example:
In[132]:=
Out[132]=

f = N@eD
5.15378 1047

2+3
You can use parentheses to organize your calculations. For example, to calculate
, you would enter:
7
In[133]:=
Out[133]=

g = H2 + 3L 7
5
7

Try It Yourself
Calculate the following results exactly:
1. a = 23 - 14

2. b = aH 34 - 27 L
3. c = b3
4. Find the decimal approximation of c.

Functions
Mathematica knows all the standard functions. Here they are.

Mathematica4Calc.nb

In[134]:=

a = [email protected]
b = [email protected]
c = [email protected]
d = [email protected]
H square root L
e = [email protected]
H the natural log ln is spelled Log L
f = E ^ 3.4
H E stands for e=2.71828... L

Out[134]=

0.255541

Out[135]=

0.966798

Out[136]=

0.264317

Out[137]=

1.84391

Out[138]=

1.22378

Out[139]=

29.9641

Two things to notice:


1. Every function name starts with a capital letter. Mathematica is VERY fussy about that.
2. The arguments are surrounded by SQUARE BRACKETS, not parentheses. Parentheses are used to prioritize mathematical operations.
The value p can be entered as an exact value into Mathematica with the symbol Pi. For example:
In[140]:=

Out[140]=

a = Sin@Pi 3D
!!!
3
2

If you use exact numbers with functions, you get exact output, which sometimes cannot be simplified. Consider these
examples:
In[141]:=

b = Cos@3D
c = [email protected]

Out[141]=

Cos@3D

Out[142]=

0.989992

Since Cos[3] cannot be simplified; it is retained as written. But Cos[3.0] returns an approximate value for the cosine.
Neither is more correct than the other. You have to use whichever is appropriate for your problem.

Try It Yourself
Verify that the following formulas all evaluate to 0:
1. 2 sin p6 - 1
2. ln e2 - 2
!!!!!!!!
3. 225 - 15
4. eln 3 - 3

Mathematica4Calc.nb

Plotting Graphs
To graph an expression in Mathematica, you have to specify the expression, the graphing variable, and the domain for the
variable. The variable and its domain are all specified in a list, a sequence of expressions contained between curly braces
{...}. For example, to plot x e-x on the domain -1 x 2, enter the formula:
In[143]:=

Plot@x E ^ HxL, 8x, 1, 2<D


0.3
0.2
0.1
-1

-0.5
-0.1

0.5

1.5

-0.2
Out[143]=

Graphics

Notice the space between x and E^(-x), indicating that these factors are to be multiplied. Without the space, you would
have raised the unknown symbol xE to the power -x .

Try It Yourself
1. Plot the function xx for 0 x 2 and estimate the minimum point.
2. In the next cell write a comment, text placed between the symbols (*...*), in which you record the x- and y-coordinates
of the minimum. Your comment should look like

(* I think the minimum is at x = ???? and y = ???? *)

You replace ???? with the correct values.

Mathematica4Calc.nb

Calculus--Integrals and Derivatives


Derivatives
To take the derivative of an expression, use the D[..] operator. You have to specify the variable for differentiation, because
you may differentiate a formula that has more than one variable.
In[144]:=
Out[144]=

D@x E ^ Ha xL, xD
E

!!!!
3 x
2

1 !!! !!!!32 x
x
3 E
2

Oops. You see in the above formula one of the frequently encountered difficulties using Mathematica. We had already
defined a to have a value, and that value was used in the last calculation. But we want to start with an undefined variable a
in this example, so we have to erase the previous value. That is done with the command Remove[..].
In[145]:=

Remove@aD

In[146]:=

D@x E ^ Ha xL, xD

Out[146]=

Ea x + a Ea x x

You can take higher derivatives of an expression by adding an order of differentiation to the expression, combining the
variable and the order in a list. Parameters for commands are often combined into lists.
In[147]:=
Out[147]=

D@x E ^ Ha xL, 8x, 3<D H third derivative L


3 a2 Ea x + a3 Ea x x

Integrals
One of the original purposes of Mathematica was to perform integration faster and better than most people. The purpose
has been achieved. Integrals, both indefinite and definite, are calculated with the Integrate[..] command. To calculate an
anti-derivative (without arbitrary constant), just specify the expression to be integrated and the variable. First we find
x e-x x:
In[148]:=
Out[148]=

Integrate@x E ^ HxL, xD
Ex H1 xL

You can guess how to compute a definite integral. You add the limits of integration to the variable in a list. Here's how you
2
would calculate 0 x e-x x:
In[149]:=
Out[149]=

Integrate@x E ^ HxL, 8x, 0, 2<D


1

3
E2

Mathematica4Calc.nb

1 !!!!!!!!
!!!!!
1 - x4

Sometimes even Mathematica cannot do an integral exactly. Let's try 0


In[7]:=

Integrate@Sqrt@1 x ^ 4D, 8x, 0, 1<D

2 EllipticK@1D
3

Out[7]=

The result is not very helpful. You can get a numerical result for any integral with the command NIntegrate[..]
In[8]:=
Out[8]=

NIntegrate@Sqrt@1 x ^ 4D, 8x, 0, 1<D

0.874019

Try It Yourself
1. Find the derivative of the expression xx . Give the derivative a name by entering something like
y = D[...] .
2. Plot the derivative on the domain 0 x 2. Use the command
Plot[y, ...]
Estimate the point where the graph crosses the x-axis enter this value into a comment. This should be the same value as
you got for the minimum of xx in the exercise above, because a local minimum of a function usually occurs where the
derivative is 0.
3. Find the area below the curve xx for 0 x 1. Can you do this exactly, or do you have to approximate?

Solving Equations
Hang onthis is the last section. To find the approximate solution to an equation f HxL = gHxL , use the command FindRoot[..] . You have to specify the variable to solve for and an estimate of the solution. To solve the equation cos x = 2 x
with an estimate of x = 1.
In[150]:=
Out[150]=

FindRoot@Cos@xD == 2 x, 8x, 1<D


8x 0.450184<

Notice two points:


1. You must use the double-equals sign == between the two sides of the equation.
2. The answer comes out in weird form. To assign the solution to the variable x , copy-and-paste the output to another
input cell, and replace the arrow with an ordinary equals sign. Here's what you get after copy-and-paste:
x 0.450183621502111197`
After replacing the arrow with "=" and executing you get:

Mathematica4Calc.nb

In[151]:=
Out[151]=

x = 0.450183621502111197`
0.450184

Here is a real problem and its solution:


Find the minimum of the function x ln x .
Begin by plotting the function to get some idea of the solution:
In[152]:=

Plot@x Log@xD, 8x, 0, 3<D


3
2.5
2
1.5
1
0.5
0.5

Out[152]=

1.5

2.5

Graphics

There appears to be a minimum near x = 0.5 . To find the minimum, we will find where the derivative of x ln x is 0. We
have to begin by erasing a previous value from the variable x .
In[153]:=

Out[154]=

In[155]:=
Out[155]=

Remove@xD
y = D@x Log@xD, xD
1 + Log@xD
FindRoot@y, 8x, 0.5<D
8x 0.367879<

The minimum occurs at x = 0.367879 . The y-value at the minimum is:


In[156]:=

Out[156]=

x = 0.367879441171048249;
H semicolon suppresses output of already known xvalue L
y = x Log@xD
0.36787944117144232

Try It Yourself
Let y = x4 - x3 - x2 + x + 1 .
1. Plot y and show that y = 0 has no real solutions.
2. Find all maxima and minima on the curve

You might also like