Introduction to Mathematica – Calculus 2 Page 1 of 90 Introduction To Mathematica For Calculus II Students Mathematica is a math programming language that allows us to do almost any mathematical process you could imagine. In this Tutorial, you will learn how to do the following. 1. How to Get Mathematica as an Olympic College Student. Pages 2 - 5 2. Initial Startup of the Mathematica Program. Pages 6 - 7 3. The Structure and Syntax of Mathematica Commands. Pages 8 - 9 4. Sigma Notation Pages 10 - 13 5. How to Estimate the Area under a curve Numerically. Pages 14 – 29 6. How to calculate the Exact Area under a curve. Pages 30 – 42 7. How to find the Area between two curves. Pages 43 – 45 8. How to find the Indefinite Integral of a function Pages 46 - 50 9. Volumes of Revolution Pages 51 – 54 10.Improper Integrals Pages 55 – 56 11. Arc Length Page 57 12. Surface Area Page 58 13.Application of Integrals Pages 59 – 64 14.Numerical Integration Pages 65 – 71 15.Introduction to Differential Equations Pages 72 – 76 16. Direction Fields Pages 77 – 79 17. Solving Differential Equations Pages 80 – 84 18.Applications of Differential Equations Pages 85 – 90
90
Embed
Introduction to Mathematica Calculus 2 Introduction To ... · Introduction to Mathematica – Calculus 2 Page 8 of 90 3. The Structure and Syntax of Mathematica Commands. Mathematica
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Introduction to Mathematica – Calculus 2
Page 1 of 90
Introduction To Mathematica For Calculus II Students
Mathematica is a math programming language that allows us to do almost any
mathematical process you could imagine. In this Tutorial, you will learn how to do the
following.
1. How to Get Mathematica as an Olympic College Student. Pages 2 - 5
2. Initial Startup of the Mathematica Program. Pages 6 - 7
3. The Structure and Syntax of Mathematica Commands. Pages 8 - 9
4. Sigma Notation Pages 10 - 13
5. How to Estimate the Area under a curve Numerically. Pages 14 – 29
6. How to calculate the Exact Area under a curve. Pages 30 – 42
7. How to find the Area between two curves. Pages 43 – 45
8. How to find the Indefinite Integral of a function Pages 46 - 50
9. Volumes of Revolution Pages 51 – 54
10. Improper Integrals Pages 55 – 56
11. Arc Length Page 57
12. Surface Area Page 58
13. Application of Integrals Pages 59 – 64
14. Numerical Integration Pages 65 – 71
15. Introduction to Differential Equations Pages 72 – 76
16. Direction Fields Pages 77 – 79
17. Solving Differential Equations Pages 80 – 84
18. Applications of Differential Equations Pages 85 – 90
Introduction to Mathematica – Calculus 2
Page 2 of 90
1. How to Get Mathematica as an Olympic College Student. You can obtain Mathematica as a stand-alone program by following these instructions. First you must Create an Account with Wolfram
1. Create an account with Wolfram.
a. Go to https://user.wolfram.com/portal/login.html
b. Click "Create Wolfram ID"
c. Fill out the “Create a Wolfram ID” form.
d. In the “Your email address (this will be your Wolfram ID)” field, type your Olympic College @student.olympic.edu email address when creating your account.
e. After entering information in all the required fields, click “Create Wolfram ID”
f. You will receive a success message after creating your ID.
2. Initial Startup of the Mathematica Program. You will begin by loading up the Mathematica program its icon will look like The program will then load up and you will see a welcome screen similar to this one below. Click on the Tab to start a new notebook and you will have your first program ready to type.
The notebook screen will now look like this.
Introduction to Mathematica – Calculus 2
Page 7 of 90
A very useful addition is to the setup is to add the Basic Math Assistant Palette as this will allow you to
type many math characters and symbols in a more intuitive way.
To do this click on the Palettes Tab and Highlight Basic Math Assistant and click on it.
You will now see on the Right-Hand Corner the Basic Math Assistant.
As can be seen on the Righthand side.
The Basic Math Assistant contains an easy to use set of icons that will
allow you to type in the following items.
Fractions, Powers, Square roots.
Greek letters such as 𝜃 , ∅ , 𝜋.
Special characters such as ∞ , i = √−1 or ! (Factorial).
Common Functions such as Sin , Cos , ArcTan , ex , Log.
It also has Derivative and Integral Commands.
It also has an Advanced Tab that allows for even more choices.
Introduction to Mathematica – Calculus 2
Page 8 of 90
3. The Structure and Syntax of Mathematica Commands.
Mathematica is a specialized programming language and has a very particular structure and the rules of
how you type in command and their Syntax need to be followed carefully.
Rule1: Wolfram Language commands begin with capital letters
and are enclosed by square brackets [.....].
For Example, the Command
Factor[x2 – 5 x + 6] will factor the expression x2 – 5x + 6 and give you the output
(−3 + 𝑥)(−2 + 𝑥)
If however you type factor[x2 – 5 x + 6] or Factor(x2 – 5 x + 6) it will not work.
Also there are many predetermined Functions including Sin[x] , Cos[x], Exp[x], Log[x],
ArcSin[x], Pi, Infinity etc….
These Functions all start with a CAPITOL letter followed by square brackets [……]
So Sin[Pi/4] will give you the exact value of sin( 𝜋
4) =
√2
2
ArcTan[Infinity] will give you the exact value of tan-1(∞) = 𝜋
2
In Mathematica your program commands and output will look like this .
Note 1: If in the above two examples we did not use a Capital letter first such as sin[Pi/4] or
arctan[Infinity] or we did not use Square Brackets such as Sin(Pi/4) or ArcTan{Infinity}
then the command would not work. So, it is important that you get the rule that all
Commands start with a CAPITAL letter followed by square brackets. […..] for if you do
not follow this syntax exactly the programs often fail to work.
Note 2: When you have finished your Mathematica program then you must hit the Numeric
Keypad ENTER button Not the normal Keyboard ENTER button.
The Numeric Keyboard ENTER button tells Mathematica to run the program, while the
normal keyboard ENTER button just jumps to the next line in your program.
Introduction to Mathematica – Calculus 2
Page 9 of 90
Rule 2: All variable names must be in lower case. Variables in Mathematica can have any name you like as long as the variable name does not contain any
spaces and the first letter must always be in lower case.
The following are a list of possible variable names.
These are valid names for variables: x , y , z, max , profit, energy , velocity1, account1a
These are not valid names for variables: X , Max , xvalue 1, Sin
X is not valid as it is a Capitol Letter
Max is not valid as it is a Capitol Letter
xvalue 1 is not valid as it has a space in it.
Sin starts with a Capitol letter and is also a Mathematica command for the sine function.
There are some variable names that are allowed but they should not be used as they tend to cause
confusion when reading and interpreting a program.
For Example :
Don’t use variable names that have a similar name to a command such as using variable names like
factor, print or simplify. For although factor, print and simplify are acceptable variable names they can
easily be mistaken by someone reading your program as the commands Factor , Print and Simplify.
Don’t use variable names that are too long or have no obvious meaning as they make your program
difficult to read.
For Example, don’t use a variable name such as thelargestvalueofafunctionf or xyttppp2. Note: It is a good idea to name your variable, whenever possible, to reflect its meaning or content, so if
a variable is used to store the x coordinate of a point you should call it x or x-coord, if the
variable is the velocity of an object you could call it v or velocity.
So the rule of thumb here is that you should name your variables intelligently so that your
program is easy to read and to understand what your program is doing and the meaning behind
each variables value.
It is also good practice in your program to insert comments next to important parts of your
program such as telling the reader what each variables job is and what the program is doing at
specific points. This can be done by adding on the far right hand side of the same line of the
command the relevant comment, this can be done by using by using the comment feature in
Mathematica the comment feature has the syntax (* put comment here*)
Introduction to Mathematica – Calculus 2
Page 10 of 90
4. Sigma Notation
Sigma Notation allows us to express a sum of terms in a very concise way, in its general form it is
written as
n
i
if1
)( each part of the notation has a specific meaning.
For example we would read as “the sum from k = 1 to n of f(k)” .
∑ 𝑓(𝑘) = 𝑓(1) + 𝑓(2) + 𝑓(3) + ⋯ … 𝑓(𝑛)
𝑛
𝑘=1
In Mathematica, you can do Sigma Notation very intuitively by using the Sigma command.
First, you go to the Basic Math Template and look for 𝑑 ∫ ∑ then choose the Sigma ∑ ∎00=0 icon.
∑ 𝑓(𝑘)
𝑛
𝑘=1
The Sigma Icon
Introduction to Mathematica – Calculus 2
Page 11 of 90
You will now see the following
To complete the Sigma Command, Click on each part of the template above.
index will be replaced by the counting variable, normally k.
start will be replaced by first value of k that sigma starts with.
end will be replaced by the last value of k that sigma ends with.
expr will be replaced by the function f(k) with (……) round it.
So, for example if we wanted to evaluate )20(20
1
2
k
kk we would do the following
Get the sigma template
index will be replaced by k
start will be replaced with 1
end will be replaced by 20
expr will be replaced by (k2 + k + 2)
You then press the Number Pad ENTER Key.
The output will be 3120
Introduction to Mathematica – Calculus 2
Page 12 of 90
Here are some examples of sigma notation being used to simplify repeated addition situations.
Example 1: Use Mathematica to evaluate following sums.
(a)
5
1
2
k
k
(b)
7
3
2
k
k (c)
5
0
2 5k
kk
Input 1(a):
5
1
2
k
k Output 55
Input 1(b):
7
3
2
k
k Output 135
Input 1(c):
5
0
2 )5(k
kk Output 130
Note: In example 1(c) To calculate
5
0
2 5k
kk we needed a set of brackets round the expression
(k2 + 5k) , if you did not do this you would get the correct result. So, for example if you used
5
0
2 5k
kk would get an output of 55 + 5𝑘 this is because Mathematica will interpret
5
0
2 5k
kk as
5
0
2 5)(k
kk .
The syntax rule is if there is more than one term in the expression when you are doing a sigma
sum you must put brackets round the expression.
It is possible to evaluate by hand these sums for extremely large number of terms, but it becomes
impractical in these situations so it is more effective to use Mathematica.
Example 2: Evaluate
100
1
2 153k
kk
Input: )153(100
1
2
k
kk Output 321 700
Introduction to Mathematica – Calculus 2
Page 13 of 90
We can generalize the sigma sums by replacing the end term by n
Example 3: Find the general formulas for the following sigma sums.
(a)
n
k 1
1 (b)
n
k
k1
(c)
n
k
k1
2 (d)
n
k
k1
3
Input 1(a):
n
k 1
1 Output 𝑛
Input 1(b):
n
k
k1
Output 1
2𝑛(1 + 𝑛)
Input 1(c):
n
k
k1
2 Output 1
6𝑛(1 + 𝑛)(1 + 2𝑛)
Input 1(d):
n
k
k1
3 0utput 1
4𝑛2(1 + 𝑛)2
It can be shown that the following properties involving the summation of terms using sigma notation are true but we will in this class just accept their validity.
Property 1: For any constant c nccn
k
1
Property 2: For any constant c
n
k
k
n
k
i acca11
Property 3: The addition property
n
k
k
n
k
kk
n
k
k baba111
Property 4: The subtraction property
n
k
k
n
k
kk
n
k
k baba111
Note 1: It is not true that
n
k
k
n
k
kk
n
k
k baba111
Note 2: It is not true that
n
k
k
n
k
kn
k k
k
a
a
b
a
1
1
1
Introduction to Mathematica – Calculus 2
Page 14 of 90
5. How to Estimate the Area under a curve Numerically.
The essential problem here is how to estimate the area under a curve using numerical methods..
Example 4: Estimate the area under the curve f(x) = 5 + 4𝑥 − 𝑥2 − 𝑥3 from x = 0 to 2 using 4 strips.
If you graph f(x) in the Domain [0,2] you get the following curve.
One approach is split the shape into 4 equally spaced strips in the interval [0,2] , We will call the size of
any one of these strips ∆𝑥 = 2−0
4 = 0.5 (∆𝑥 is called delta x). The 4 strips will generate five
x coordinates they will be called x0 = 0 , x1 = 0.5 , x2 = 1 , x3 = 1.5 and x4 = 2
We will then have a diagram that looks like the following.
0.0 0.5 1.0 1.5 2.0
2
4
6
8
0.0 0.5 1.0 1.5 2.0
2
4
6
8
Introduction to Mathematica – Calculus 2
Page 15 of 90
From these 4 strips, we can create 4 rectangles and the total area of these 4 rectangles will give us a
numerical approximation of the area under this curve.
We do however have a choice here because for each strip you could use either the left endpoint or the
right endpoint to define the rectangles heights.
So, the convention is to use the notation L4 to indicate we are using the Left endpoint and R4 to indicate
we are using the Right endpoint to define the heights of the rectangles.
These two choices result in different approximations to the area under the curve.
The value of L4 is an estimate for the area under the curve f(x) = 1 + 6x – x2 – x3 from x = 0 to x = 2
L4 = ∆𝑥𝑓(𝑥0) + ∆𝑥𝑓(𝑥1) + ∆𝑥𝑓(𝑥2) + ∆𝑥𝑓(𝑥3)
= 0.5𝑓(0) + 0.5𝑓(0.5) + 0.5𝑓(1.0) + 0.5𝑓(1.5)
= 0.5(5) + 0.5(6.625) + 0.5(7) + 0.5(5.375)
L4 = 12
Note 1: The width of each strip is found by calculating ∆𝑥 = 2−0
4 this can be generalized to n
strips. So, if you wish to find the width of a single strip ∆𝑥 when the interval from x = a
to x = b is split into n strips we use the formula
∆𝑥 = 𝑏−𝑎
𝑛
Note 2: We ca also generalize the values of the x coordinates x0 , x1 , etc… by using the formula
𝑥𝑘 = 𝑎 + 𝑘∆𝑥
0.0 0.5 1.0 1.5 2.0
2
4
6
8
Introduction to Mathematica – Calculus 2
Page 16 of 90
If we use the Right endpoints and calculate R4 as an estimate for the area under the curve we get the
situation below.
The value of R4 is an estimate for the area under the curve f(x) = 5 + 4𝑥 − 𝑥2 − 𝑥3 from x = 0 to 2.
R4 = ∆𝑥𝑓(𝑥1) + ∆𝑥𝑓(𝑥2) + ∆𝑥𝑓(𝑥3) + ∆𝑥𝑓(𝑥4)
= 0.5𝑓(0.5) + 0.5𝑓(1.0) + 0.5𝑓(1.5) + 0.5𝑓(2)
= 0.5(6.625) + 0.5(7) + 0.5(5.375) + 0.5(1)
R4 = 10
We could reduce the workload by letting Mathematica do most of the number crunching for us
We start by realizing that the general formula for calculating R4 is
R4 =
4
1
][k
kxfx where ∆𝑥 = 𝑏−𝑎
𝑛 and xk = a + ∆𝑥𝑘
In this example R4 =
4
1
]0[k
kxfx as ∆𝑥 = 2−0
4 and xk = 0 + ∆𝑥𝑘
The code for finding R4 is Input: 𝑓[x_]: = 5 + 4𝑥 − 𝑥2 − 𝑥3
deltax =2−0
4;
∑ deltax𝑓[0 + deltax 𝑘]4
𝑘=1
Output: 10
Note : We called the variable ∆x , deltax as all variables need to start with small alphanumeric
letters also we needed to add a space between the variables deltax and k to separate the two
variables.
0.0 0.5 1.0 1.5 2.0
2
4
6
8
Introduction to Mathematica – Calculus 2
Page 17 of 90
In a similar fashion the code for calculating L4 is.
Input: 𝑓[x_]: = 5 + 4𝑥 − 𝑥2 − 𝑥3
deltax =2−0
4;
3
0
]0[k
kdeltaxfdeltax
Output: 12
Note 1: There is a semicolon” ; “after the command deltax =2−0
4; this is just a suppressant
command, it tells Mathematica to do the command but not show the result as part of the
output. This is a useful trick as it can be a distraction to see all the outputs from various
calculations in a Mathematica program, when all you want to see if the final result.
Note 2: The estimates L4 = 12 and R4 = 10 are different, this is very common in using these
estimates and it is often not obvious that any one of the two is a better estimate than the
other.
Note 2: If you want to get a more accurate estimate then you will need to evaluate more
rectangles so instead of n = 4 strips you could use n = 10 strips or n = 400 strips.
Example 5: Estimate the area under the curve f(x) = 5 + 4𝑥 − 𝑥2 − 𝑥3 from x = 0 to 2 using right
and left endpoints for the following number of strips
(a) n = 10 strips. (b) n = 40 strips. (c) n = 1,000 strips
Example 6: Estimate the area under the curve f(x) = sin(𝑥) + 𝑥2 from x = 0 to 2𝜋 using 20 strips.
Input: 𝑓[x_]: = Sin[𝑥] + 𝑥2
deltax =2𝜋−0
20;
∑ deltax 𝑓[0 + deltax 𝑘]19
𝑘=0; (*the value of L20 *)
𝑁[∑ deltax 𝑓[0 + deltax 𝑘]9
𝑘=0]
Output: 77.5855
Input: 𝑓[x_]: = Sin[𝑥] + 𝑥2
deltax =2𝜋−0
20;
∑ deltax 𝑓[0 + deltax 𝑘]20
𝑘=1; (*the value of L20 *)
𝑁[∑ deltax 𝑓[0 + deltax 𝑘]20
𝑘=1]
Output: 88.988
Introduction to Mathematica – Calculus 2
Page 19 of 90
Example 7. Estimate the area under the graph f(x) = 9 – x2 from x = – 2 to x = 2 by calculating using 4 approximating rectangles L4 , R4
Solution: If we wish to do it by hand then we will do The following.
We start by calculating a table of values for the function f(x) = 9 – x2
starting with x = – 2 with a ∆x = 𝑏−𝑎
𝑛 =
2−(−2)
4 = 1
The next step is to estimate the area under the curve by calculation L4 , called the Left estimate, this is done by using the 4 left end points as the sample points.
The interval size will be ∆x = 𝑏−𝑎
𝑛 =
2−(−2)
4 = 1
The sample points will be x0 = – 2 x1 = – 1 x2 = 0 and x3 = 1
= 5 + 8 + 9 + 8 L4 = 30 If we use Mathematica the code will be as follows Input: 𝑓[x_]: = 9 − 𝑥2 𝑎 = −2; (* 𝑎 = −2 *) 𝑏 = 2; (* 𝑏 = 2 *) 𝑛 = 4; (* the number of strips 𝑛 = 4 *)
deltax =𝑏−𝑎
4;
∑ deltax 𝑓[𝑎 + deltax 𝑘]𝑛−1
𝑘=0; (* the value of L4 *)
𝑁[∑ deltax 𝑓[𝑎 + deltax 𝑘]𝑛−1
𝑘=0]
Output: 30 Note 1: We generalized the formula by creating the estimate L4 by using the variables called a , b , n and
delta x this allowed us to create a program that would be adaptable to many other situations. For example, if you wanted 10 strips – just change the value of n to n = 10.
If you wanted to change the start or finish values, just change the values of a and b in the code or you could even change the function by changing f[x_].
Note 2: Notice that for L4 the sigma notation is ∑ … … … . ]𝑛−1
𝑘=0
x0 x1 x2 x3 x4
x – 2 – 1 0 1 2
f(x) 5 8 9 8 5
x0 x1 x2 x3 x4
x – 2 – 1 0 1 2
f(x) 5 8 9 8 5
Introduction to Mathematica – Calculus 2
Page 20 of 90
Solution: We estimate the area under the curve by calculation R4 , called the Right estimate, this is done by using the 4 right end points as the sample points.
The interval size will be ∆x = 𝑏−𝑎
𝑛 =
2−(−2)
4 = 1
The sample points will be x1 = – 1 x2 = 0 x3 = 1 and x4 = 2
= 8 + 9 + 8 + 5 = 30 If we use Mathematica the code will be as follows Input: 𝑓[x_]: = 9 − 𝑥2 𝑎 = −2; (* 𝑎 = −2 *) 𝑏 = 2; (* 𝑏 = 2 *) 𝑛 = 4; (* the number of strips 𝑛 = 4 *)
deltax =𝑏−𝑎
4;
∑ deltax 𝑓[𝑎 + deltax 𝑘]𝑛
𝑘=1; (*the value of R4* )
𝑁[∑ deltax 𝑓[𝑎 + deltax 𝑘]𝑛
𝑘=1]
Output: 30 Note 1: We generalized the formula by creating the estimate R4 by using the variables called a , b , n
and delta x this allowed us to create a program that would be adaptable to many other situations. For example, if you wanted 10 strips – just change the value of n to n = 10.
If you wanted to change the start or finish values, just change the values of a and b in the code or you could even change the function by changing f[x_].
Note 2: Notice that for R4 the sigma notation is ∑ … … … . ]𝑛
𝑘=1
Note 3: Both these estimates of the area under the curve are identical , this is very unusual situation
and typically the two estimates will be different values.
x0 x1 x2 x3 x4
x – 2 – 1 0 1 2
f(x) 5 8 9 8 5
Introduction to Mathematica – Calculus 2
Page 21 of 90
Example 8. Estimate the area under the graph f(x) = √𝑥 from x = 0 to x = 8 by calculating the 4 approximating rectangles L4 , R4 and M4
We start by calculating a table of values
for the function f(x) = √𝑥 starting with x = 0
with a ∆x = 𝑏−𝑎
𝑛 =
8−0
4 = 2
Solution: We estimate the area under the curve by calculation L5 , called the Left estimate, this is done by
using the 4 left end points as the sample points. The interval size will be ∆x = 𝑏−𝑎
𝑛 =
8−0
2 = 4
The sample points will be x0 = 0 x1 = 2 x2 = 4 x3 = 6
Solution: We estimate the area under the curve by calculation R4 , called the Right estimate, this is done by using the 4 right end points as the sample points.
The interval size will be ∆x = 𝑏−𝑎
𝑛 =
8−0
2 = 4
The sample points will be x1 = 2 x2 = 4 x3 = 6 x4 = 8
Example 9: An interesting question is to decide, which of any of these three estimates is the most accurate.
If you do a sketch of f(x) = √𝑥 you can see that it is an increasing function on the interval [0,8]
Since f(x) = √𝑥 is an increasing function on the interval [0,8], this means that R4 will be an overestimate of the true area and L4 will be an underestimate. So since L4 = 11.728 and R4 = 17.384 the exact area must be somewhere between 11.728 and 17.384 . As a reasonable compromise, we could choose the average of the two estimates.
Average = 11.728+17.384
2 = 14.556
It is known that the exact value of this area is 16
3√8 = 15.085….,
This means that the error in using the varying estimates are
L4 = 11.728 Error = 3.357
R4 = 17.384 Error = 2.299
Av = 14.556 Error = 0.525
M4 = 15.288 Error = 0.203
So, in this situation the value of M4 = 15.288 is the most accurate.
In general, the LEFT, RIGHT or MIDPOINT estimates vary in accuracy depending on
the shape of the curve whose area is being estimated and it is possible, in certain
circumstances, for any of the three to be the most accurate.
2 4 6 8
0.5
1.0
1.5
2.0
2.5
Introduction to Mathematica – Calculus 2
Page 25 of 90
Example 10: Estimate the area under the curve given by the table of values, using N= 6 (6 strips) and using
(a) L6 (b) R6 (c) M6
Solution: Since we are using n = 6 strips we will have ∆x = 𝑏−𝑎
𝑛 =
12−0
6 = 2 and the sample points in the
table will be. x0 = 0 x1 = 2 x2 = 4 x3 = 6 x4 = 8 x5 = 10 and x6 = 12
We estimate the area under the curve by calculation L6 , called the Left estimate, this is done by using the 6 left end points as the sample points.
The interval size will be ∆x = 𝑏−𝑎
𝑛 =
12−0
6 = 2
The sample points will be x0 = 0 x1 = 2 x2 = 4 x3 = 6 x4 = 8 and x5 = 10
Solution: We estimate the area under the curve by calculation R6 , called the Right estimate, this is done by using the 6 right end points as the sample points.
The interval size will be ∆x = 𝑏−𝑎
𝑛 =
12−0
6 = 2
The sample points will be x1 = 2 x2 = 4 x3 = 6 x4 = 8 x5 = 10 and x6 = 12
Solution: We estimate the area under the curve by calculation M6 , called the Mid-point estimate, this is done by using the 6 mid-points as the sample points.
Example 11: The velocity of a motorcycle over a 60 second period is given in the table below Find an estimate for the distance travelled by the motorcycle over 60 seconds Solution: The distance travelled by the motorcycle over 60 seconds is the same as the area under
the curve in the interval [0,60], as our first estimate we will use L5.
The interval size will be ∆t = 𝑏−𝑎
𝑛 =
60−0
5 =12
The sample points will be t0 = 0 t1 = 12 t2 = 24 t3 = 36 and t4 = 48
Output: 1512 So in conclusion we have two estimates for the total distance travelled is 1548 ft and 1512 ft since the motorcycle has a velocity that is decreasing we can assume that 1512 feet is an underestimate and that 1548 feet and so we can conclude that the exact value of the distance travelled is between 1512 and 1548 ft.
t0 t1 t2 t3 t4 t5
t 0 12 24 36 48 60
V(t) 9 8.9 8.8 8.5 8.2 7.8
Introduction to Mathematica – Calculus 2
Page 30 of 90
6. How to calculate the Exact Area under a curve.
We use the notation ∫ 𝑓(𝑥)𝑑𝑥𝑏
𝑎 to indicate the exact area under the curve y = f(x) from
x = a to x = b , this is called the Definite Integral of the function f(x)
The syntax for finding the area under the curve is very intuitive in Mathematica.
First you go to the Basic Math Template and look for 𝑑 ∫ ∑ then choose the Integral ∫ ∎𝑑 ⊡0
0 icon.
The Integral Icon
Introduction to Mathematica – Calculus 2
Page 31 of 90
You will now see the following
To complete the Integral Command, Click on each part of the template above.
lower will be replaced by the value of a.
upper will be replaced by the value of b.
expr will be replaced by the function f(x) with (……) round it.
var Will be replaced by the variable (usually x).
Example 12: Find the exact value of ∫ (𝑥3 − 𝑥 + 1)𝑑𝑥5
1
Get the integral template,
lower will be replaced by 1.
upper will be replaced with 5.
expr will be replaced by (x3 – x +1)
var will be replaced by x
You then press the Number Pad ENTER Key. The output will be 148
Introduction to Mathematica – Calculus 2
Page 32 of 90
Example 13: Find the exact area under the curve for the following functions.
(a) ∫ (2𝑥3 − 𝑥2)𝑑𝑥3
1
(b) ∫ (sin(𝑥) + 2cos (𝑥))𝑑𝑥2𝜋
−𝜋
(c) ∫ (𝑥
𝑥+1) 𝑑𝑥
4
0
(d) ∫ (𝑥2 − 9)𝑑𝑥3
−3
Input (a): ∫ (2𝑥3 − 𝑥2) 𝑑𝑥3
1
Output: 94
3
Input (b): ∫ (Sin[𝑥] + 2Cos[𝑥]) 𝑑𝑥𝜋
−𝜋
Output: 0
Input (c): ∫ (𝑥
𝑥+1) 𝑑𝑥
4
0
Output: 4 − Log[5]
Input (d): ∫ (2𝑥3 − 𝑥2) 𝑑𝑥3
1:
Output: −36
Note: The area under a curve can be any value, positive negative or even zero.
This becomes clearer when you see the areas graphically.
Introduction to Mathematica – Calculus 2
Page 33 of 90
Example 14: Graph the area under the curve for the following functions.
Choice 3: If we choose the midpoint of each sub-interval we get the following situation.
The midpoint of any subinterval xk-1 to xk is called 𝑥𝑘∗ =
𝑥𝑘−1+𝑥𝑘
2
xk-1 = 𝑎 + ∆𝑥 (𝑘 − 1)
xk = 𝑎 + ∆𝑥 𝑘
𝑥𝑘∗ =
𝑎+∆𝑥 𝑘+𝑎+∆𝑥 𝑘(𝑘−1)
2
= 2𝑎+ ∆𝑥(2 𝑘−1)
2
𝑥𝑘∗ = 𝑎 +
∆𝑥(2 𝑘−1)
2
Notice that the rectangles use the midpoint of each subinterval for the height of the rectangle.
If we then add all these rectangles together we can obtain an estimate for the area under
the curve.
Midpoint Area using n strips = ∆𝑥𝑓(𝑥1∗) + ∆𝑥𝑓(𝑥1
∗) + ∆𝑥𝑓(𝑥1∗) + ⋯ + ∆𝑥𝑓(𝑥𝑛
∗ )
Mn = ∆𝑥[𝑓(𝑥1∗) + 𝑓(𝑥1
∗) + 𝑓(𝑥1∗) + ⋯ + 𝑓(𝑥𝑛
∗ )]
Mn = xxfn
k
k 1
* )(
The Mathematica code for this last line would be ∑ deltax𝑓[𝑎 +deltax(2𝑘−1)
2]
𝑛
𝑘=1
In general, the greater the number of strips that are used the more accurate the estimate of the area under
the curve will be. So, for example, if we use n = 200 strips it will generate a more accurate estimate than
if we only use n = 10 strips.
∆𝑥 ∆𝑥 ∆𝑥 ∆𝑥 ∆𝑥 ∆𝑥 ∆𝑥 ∆𝑥
y = f(x)
y
x X0=a Xn=b X1 X2 X3 ………………………….
Xn-1 Xn-2 Xn-3
Introduction to Mathematica – Calculus 2
Page 40 of 90
We can now generalise this problem to come up with the following definitions for finding the area under
the curve A by making the number of strips tend to infinity.
Definition: The area exact area A that lies under the curve y = f(x) from x = a to x = b can be found
by taking an infinite number of strips and using either left, right or midpoints.
So A = lim𝑛→∞
𝐿𝑛 = lim𝑛→∞
∑ 𝑓(𝑥𝑘)∆𝑥𝑛−1𝑖=0
A = lim𝑛→∞
𝑅𝑛 = lim𝑛→∞
∑ 𝑓(𝑥𝑘)∆𝑥𝑛𝑖=1
A = lim𝑛→∞
𝑀𝑛 = lim𝑛→∞
∑ 𝑓(𝑥𝑘∗ )∆𝑥𝑛
𝑖=1
Where ∆𝑥 = 𝑏−𝑎
𝑛
xk = a + ∆𝑥 k
𝑥𝑘∗ = 𝑎 +
∆𝑥(2𝑘−1)
2
Example 16: Find the exact area of the integral ∫ (2𝑥3 − 𝑥2)𝑑𝑥2
0 using Ln , Rn and Mn
Input: 𝑓[x_]: = 2𝑥3 − 𝑥2
deltax =2−0
𝑛;
Limit[∑ deltax𝑓[0 + deltax𝑘]𝑛−1
𝑘=0, 𝑛 → ∞] (* using limit of Ln as 𝑛 → ∞*)
Output: 16
3
Input: 𝑓[x_]: = 2𝑥3 − 𝑥2
deltax =2−0
𝑛;
Limit[∑ deltax𝑓[0 + deltax𝑘]𝑛
𝑘=1, 𝑛 → ∞] (* using limit of Ln as 𝑛 → ∞*)
Output: 16
3
Input: 𝑓[x_]: = 2𝑥3 − 𝑥2
deltax =2−0
𝑛;
Limit[∑ deltax𝑓[0 +deltax(2𝑘−1)
2]
𝑛
𝑘=1, 𝑛 → ∞] (* using limit of Ln as 𝑛 → ∞*)
Output: 16
3
Note: All three methods generate the same result so we typically use Rn in these type of questions as it
has the simplest form
Introduction to Mathematica – Calculus 2
Page 41 of 90
In some situations, it is possible to generalise the process by using the variables a and b.
Example 17: Find the exact area of the integral ∫ (2𝑥3 − 𝑥2)𝑑𝑥𝑏
𝑎 using Rn.
Input: 𝑓[x_]: = 2𝑥3 − 𝑥2
deltax =𝑏−𝑎
𝑛;
Limit[∑ deltax𝑓[0 + deltax𝑘]𝑛
𝑘=1, 𝑛 → ∞] (* using limit of Ln as 𝑛 → ∞*)
Output: 1
6(2𝑎3 − 3𝑎4 + 𝑏3(−2 + 3𝑏))
We can alter the look of the output by using this code
𝑓[x_]: = 2𝑥3 − 𝑥2
deltax =𝑏−𝑎
𝑛;
Expand[
Limit [∑ deltax𝑓[0 + deltax𝑘]
𝑛
𝑘=1
, 𝑛 → ∞]
]
Output: 𝑎3
3−
𝑎4
2−
𝑏3
3+
𝑏4
2
Introduction to Mathematica – Calculus 2
Page 42 of 90
C. Using Your Calculator to calculate areas under a curve We can use our calculator to check our estimates for the area under the curve y = f(x) by using the option
∫ 𝑓(𝑥)𝑑𝑥 on the TI 84 calculator.
Example Use your calculator to find an estimate for ∫ 𝑐𝑜𝑠𝑥. 𝑑𝑥𝜋
20
Solution: We can use our TI 84 calculator to get the area below the curve y = cos x from x = 0 to x = 𝜋
2
In order to do this we follow these steps. 1) Press y = button
2) Type in the desired function in this case Y1 = cos(x) 3) Press the WINDOWS button and choose
Xmin = – 1 Xmax = 2 Xscl = 1 Ymin = – 1 Ymax = 1 Yscl = 1 4) Press 2nd Trace to get the CALC menu 5) choose option 7:∫ 𝑓(𝑥)𝑑𝑥 (this is the numerical integration menu) 6) We tell the computer the Lower Limit by typing 0 and pressing ENTER.
We tell the computer the Lower Limit by typing x =𝜋
2 = 1.57 (or as close as you wish to the true
value 𝜋
2 of ) and pressing ENTER.
The screen will now have the desired area in this case A = 1.0165799 (Approximately)
Example Use your calculator to find an estimate for ∫ ln (𝑥). 𝑑𝑥4
1
Solution: We can use our TI 84 calculator to get the below the curve y = ln(x) from x = 1 to x = 4 In order to do this we follow these steps. 1) Press y = button 2) Type in the desired function in this case Y1 = ln(x) 3) Press the WINDOWS button and choose
Xmin = – 1 Xmax = 5 Xscl = 1 Ymin = – 1 Ymax = 3 Yscl = 1 4) Press 2nd Trace to get the CALC menu 5) choose option 7:∫ 𝑓(𝑥)𝑑𝑥 (this is the numerical integration menu) 6) We tell the computer the Lower Limit by typing 1 and pressing ENTER.
We tell the computer the Lower Limit by typing 4 and pressing ENTER.
The screen will now have the desired area in this case A = 2.6041663 (Approximately)
Introduction to Mathematica – Calculus 2
Page 43 of 90
7. How to find the Area between two curves
To find the area between two curves y = f(x) and y = g(x) from x = a to x = b you
evaluate the integral.
∫(𝑓(𝑥) − 𝑔(𝑥))𝑑𝑥
𝑏
𝑎
Where f(x) is larger than g(x) in the domain [a,b]
Example 18: Find the area between the two curves f(x) = x2 and g(x) = √𝑥
from x = 0 to x = 1
Solution: We can draw a graph of f(x) and g(x) to see which is greater.
Example 25: Find the volume created by rotating the curve f(x) = x2 about the y-axis
from x= 0 to x = 1.
Solution: Since we are rotating about the y – axis we use the formula in terms of x.
See diagram below.
V = b
a
dxheightradius ))((2
V = b
a
dxxxf2
= 1
0
2.2 dxxx
= 1
0
3.2 dxx
= 1
0
4
2
1
x
xx
= 𝜋
2
The Mathematica Code for this question is.
Input: 𝑓[x_]: = 𝑥2
𝑎 = 0; 𝑏 = 1;
∫ (2𝜋𝑥𝑓[𝑥]) 𝑑𝑥𝑏
𝑎
Output: 𝜋
2
Note: By setting up the code in this general format it is easy to adapt the code it to other similar
situations. So, if the function was f(x) = x3 + x2 – 1 we only need to change one line of
code , namely we change 𝑓[x_]: = 𝑥2 and replace it with 𝑓[x_] : = 𝑥3 + 𝑥2 − 1
y axis
x = 1 0
y = x2
Radius = x
Height = y = f(x)
Introduction to Mathematica – Calculus 2
Page 54 of 90
Example 26: Find the volume created by rotating the region between the two curves f(x) = 3 + 2x – x2
and g(x) = 3 – x about the y-axis
Solution: Since we are rotating about the y – axis we use the formula in terms of x.
So, radius of a typical shell is x and the
RaDius = x
Height = f(x) – g(x)
= (3 + 2x – x2 ) – (3 – x)
= 3 + 2x – x2 – 3 + x
= 3x – x2
The values of a and b are found by finding where f(x) = 3 + 2x – x2 and g(x) = 3 – x
intersect. In this case, a = 0 and b = 3, See diagram below.
V = b
a
dxheightradius ))((2
V =
b
a
dxxgxfx ))()((2
=
3
0
23.2 dxxxx
=
3
0
32 )2.6( dxxx
= 1
0
43
2
12
x
xxx
V = 27𝜋
2
The Mathematica Code for this question is.
Input: 𝑓[x_]: = 3 + 2𝑥 − 𝑥2
𝑔[x_]: = 3 − 𝑥
Solve[𝑓[𝑥] == 𝑔[𝑥], {𝑥}, Reals]
Output: {{𝑥 → 0}, {𝑥 → 3}}
Input: 𝑓[x_]: = 3 + 2𝑥 − 𝑥2
𝑔[x_]: = 3 − 𝑥
𝑎 = 0; 𝑏 = 3;
∫ (2𝜋𝑥(𝑓[𝑥] − 𝑔[𝑥])) 𝑑𝑥𝑏
𝑎
Output: 27𝜋
2
Radius = x
y axis
3 0 g(x) = 3 – x
f(x) = 3 + 2x – x2
Height = f(x) – g(x)
Introduction to Mathematica – Calculus 2
Page 55 of 90
10. Improper Integrals
There are two types of Improper Integrals – Improper Integrals of Type 1 have the property that at least
one of the two end-points of integration is infinity.
For example, the following three integrals are all Improper Integrals of Type 1.
∫10
𝑥3 𝑑𝑥∞
1 ∫
𝑥
𝑥2+1𝑑𝑥
5
−∞ ∫
4
𝑥2+1𝑑𝑥
∞
−∞
The method used is to use limits to accommodate the infinities.
∫10
𝑥3 𝑑𝑥∞
1 = lim
𝑏→∞(∫
10
𝑥3 𝑑𝑥𝑏
1)
∫𝑥
𝑥2+1𝑑𝑥
5
−∞ = lim
𝑏→−∞(∫
𝑥
𝑥2+1𝑑𝑥
5
𝑏)
∫4
𝑥2+1𝑑𝑥
∞
−∞ = lim
𝑏→∞(∫
𝑥
𝑥2+1𝑑𝑥
𝑏
0) + lim
𝑏→−∞(∫
𝑥
𝑥2+1𝑑𝑥
0
𝑏)
Mathematica copes with Improper Integrals in a very intuitive way as the following examples show
Example 27: Find the value of the following three Type 1 improper Integrals.
(𝑎) ∫10
𝑥3 𝑑𝑥∞
1 (b) ∫
4
𝑥2+1𝑑𝑥
∞
−∞ (𝑐) ∫
𝑥
𝑥2+1𝑑𝑥
5
−∞
Input (a) 𝑓[x_]: =10
𝑥3
∫ 𝑓[𝑥] 𝑑𝑥∞
1 Output: 5
Input (b) 𝑓[x_]: = 𝑓[x_]: =4
𝑥2+1
∫ 𝑓[𝑥] 𝑑𝑥∞
1 Output: 4𝜋
Input (c) 𝑓[x_]: =10
𝑥3
∫ 𝑓[𝑥] 𝑑𝑥∞
1
Output: Integrate: Integral of 𝑥
𝑥2+1 does not converge on {1,∞}.
Note: The Output statement Integrate: Integral of 𝑥
𝑥2+1 does not converge on {1,∞} in this
situation is essentially saying that the area under the curve is infinitely large.
Introduction to Mathematica – Calculus 2
Page 56 of 90
Improper Integrals of Type 2 have the property that there is a vertical asymptote at one of the endpoints
or between the endpoints.
For example, the following three integrals are all Improper Integrals of Type 2.
∫𝑥
(𝑥−3)𝑑𝑥
3
1 ∫
𝑥
(𝑥+4)3 𝑑𝑥6
−4 ∫
1
𝑥𝑑𝑥
𝜋
−𝜋
The method used is to use limits to accommodate the vertical asymptotes.
∫𝑥
(𝑥−3)𝑑𝑥
3
1 = lim
𝑏→3−(∫
𝑥
(𝑥−3)𝑑𝑥
𝑏
1)
∫𝑥
(𝑥+4)3 𝑑𝑥6
−4 = lim
𝑏→4+(∫
𝑥
(𝑥+4)3 𝑑𝑥6
𝑏)
∫1
𝑥𝑑𝑥
𝜋
−𝜋 = lim
𝑏→0−(∫
1
𝑥𝑑𝑥
𝑏
−𝜋) + lim
𝑏→0+(∫
1
𝑥𝑑𝑥
𝜋
𝑏)
Mathematica copes with Improper Integrals in a very intuitive way as the following examples show
Example 28: Find the value of the following three Type 2 improper Integrals.
(𝑎) ∫𝑥
(𝑥−3)𝑑𝑥
3
1 (b) ∫
𝑥
√6−𝑥𝑑𝑥
6
−4 (𝑐) ∫
1
𝑥2 𝑑𝑥𝜋
−𝜋
Input (a) 𝑓[x_]: =𝑥
𝑥−3
∫ 𝑓[𝑥] 𝑑𝑥3
1
Output: Integrate: Integral of 𝑥
𝑥−3 does not converge on {1,3}.
Input (b) 𝑓[x_]: =𝑥
√6−𝑥
∫ 𝑓[𝑥] 𝑑𝑥6
−4 Output:
16√10
3
Input (c) 𝑓[x_]: =10
𝑥3
∫ 𝑓[𝑥] 𝑑𝑥𝜋
−𝜋
Output: Integrate: Integral of 10
𝑥3 does not converge on {1,∞}.
Note: The Output statement Integrate Integrate: Integral of 𝑥
𝑥−3 does not converge on {1,3}.in
this situation is essentially saying that the area under the curve is infinitely large.
Introduction to Mathematica – Calculus 2
Page 57 of 90
11. Arc Length
To find the length of the arc along the curve y = f(x) from x = a to x = b is
L = ∫ √1 + (𝑓′(𝑥))2𝑑𝑥𝑏
𝑎
Example 29: Find the exact value of the arc length for the curve f(x) = 4x + 7 from x = 1 to x = 3
Input: 𝑓[x_]: = 4𝑥 + 7
𝑎 = 1; 𝑏 = 3;
∫ √1 + (𝑓′[𝑥])2 𝑑𝑥𝑏
𝑎
Output: 2√17
Example 30: Find the exact value of arc length for the curve f(x) = 𝑒𝑥 +1
4𝑒−2𝑥 from x = 0 to x = ln(4)
Input: 𝑓[x_]: = 2𝑒𝑥 +1
8𝑒−𝑥
𝑎 = 0; 𝑏 = 𝐿𝑜𝑔[4];
∫ √1 + (𝑓′[𝑥])2 𝑑𝑥𝑏
𝑎
Output: 195
32
Example 31: Find the numerical estimate for the arc length for the curve f(x) = 𝑥 + sin (𝑥)
from x = 0 to x = 1
Input: 𝑓[x ]: = 𝑥 + 𝑆𝑖𝑛[𝑥]
𝑎 = 0; 𝑏 = 1;
𝑁[∫ √1 + (𝑓′[𝑥])2 𝑑𝑥, 4𝑏
𝑎]
Output: 2.097
Note : There are situations where you will not be able to find the exact arc length and in these
situations, you can only find a numerical estimate.
Example 31 is such a situation, in fact it takes Mathematica about 1 minute to perform
this numerical estimate.
Introduction to Mathematica – Calculus 2
Page 58 of 90
12. Surface Area
To find the area of the surface generated by rotating the graph of the function y = f(x) about the x-axis
from x = a to x = b is
S = ∫ 2𝜋𝑓(𝑥)√1 + (𝑓′(𝑥))2𝑑𝑥𝑏
𝑎
Example 32: Find the exact value of the surface area when the graph of f(x) = 6 – 2x is rotated about
the x-axis from x = 0 to x = 3
Input: 𝑓[x_]: = 6 − 2𝑥
𝑎 = 0; 𝑏 = 3;
∫ 2𝜋𝑓[𝑥]√1 + (𝑓′[𝑥])2 𝑑𝑥𝑏
𝑎
Output: 18√5𝜋
Example 33: Find the exact value of arc length for the curve f(x) = 𝑒𝑥 +1
4𝑒−2𝑥 from x = 0 to x = ln(2)
Input: 𝑓[x_]: = 2𝑒𝑥 +1
8𝑒−𝑥
𝑎 = 0; 𝑏 = 𝐿𝑜𝑔[4];
∫ √1 + (𝑓′[𝑥])2 𝑑𝑥𝑏
𝑎
Output: 𝜋(61455
1024+ Log[4])
Example 34: Find the numerical estimate for the arc length for the curve f(x) = 𝑥 + sin (𝑥)
from x = 0 to x =
Input: 𝑓[x_]: = Sin[𝑥] + Cos[𝑥] 𝑎 = 0;
𝑏 =𝜋
2;
𝑁[∫ 2𝜋𝑓[𝑥]√1 + (𝑓′[𝑥])2 𝑑𝑥𝑏
𝑎, 3]
Output: 14.4
Note : There are situations where you will not be able to find the exact value of the Surface
Area. Example 34 is such a situation, in fact it takes Mathematica about 1 minute to
perform this numerical estimate.
Introduction to Mathematica – Calculus 2
Page 59 of 90
13. Application of Integrals
There are many applications of Integrals, here are some practical examples.
A. Finding velocity and position functions
B. Average Value of a Function
C. Work Done Problems
D. Hydrostatic Problems
C. Finding velocity and position functions
Example 35: The acceleration of a moving object is given by the formula a(t) = t2 + 6t , find the
velocity function v(t) and the position function s(t) when v(1) = 5 and s(1) = 0
Solution: We use the fact that v(t) = ∫ 𝑎(𝑡)𝑑𝑡 and that s(t) = ∫ 𝑣(𝑡)𝑑𝑡
v(t) = ∫ 𝑎(𝑡)𝑑𝑡 = ∫(𝑡2 + 6t )𝑑𝑡
Input: ∫ (𝑡2 + 6𝑡) 𝑑𝑡 Output: 3𝑡2 +𝑡3
3
This means that v(t) = 3𝑡2 +𝑡3
3+ 𝐶 so to find the value of C we solve v(1) = 5.
Input: 𝑣[t_]: = 3𝑡2 +𝑡3
3+ 𝐶
Solve[𝑣[1] == 5] Output: {{𝐶 →5
3}}
This means that v(t) = 3𝑡2 +𝑡3
3+
5
3 so to find the value s(t)
We now find s(t) = ∫ 𝑣(𝑡)𝑑𝑡 = ∫(3𝑡2 +𝑡3
3+
5
3)𝑑𝑡
Input: ∫ (3𝑡2 +𝑡3
3+
5
3) 𝑑𝑡 Output:
5𝑡
3+ 𝑡3 +
𝑡4
12
This means that S(t) = 5𝑡
3+ 𝑡3 +
𝑡4
12+ 𝐶 so to find the value of C we solve s(1) = 0.
Input: 𝑠[t_]: =5𝑡
3+ 𝑡3 +
𝑡4
12+ 𝐶
Solve[𝑠[1] == 0] Output: {{𝐶 → −11
4}}
This means that s(t) = 5𝑡
3+ 𝑡3 +
𝑡4
12−
11
4
Introduction to Mathematica – Calculus 2
Page 60 of 90
D. Average Value of a function
Example 36: (a) Find the average value of the function f(x) = 2
√𝑥+1 from x = 0 to x = 3
(b) Find the value(s) of x where the function is equal to the average value.
(c) Show this information graphically.
Solution (a): The formula for the average value of a function f(x) from x = a to x = b is:-
fave = 1
𝑏−𝑎∫ 𝑓(𝑥)𝑑𝑥
𝑏
𝑎
In this question fave = 1
3−0∫ (
2
√𝑥+1) 𝑑𝑥
3
0
Input: 𝑓[x_]: =2
√𝑥+1
𝑎 = 0; 𝑏 = 3;
fave =1
𝑏−𝑎∫ (
2
√𝑥+1) 𝑑𝑥
𝑏
𝑎
Output: 4
3 So, the average value of the function is fave =
4
3
Solution (b): To find the value(s) of x where the function is equal to the average value we need to
solve for what values of x is f(x) = fave
In this question, we need to solve f(x) = 4
3
Input: 𝑓[x_]: =2
√𝑥+1
𝑎 = 0; 𝑏 = 3;
fave =1
𝑏−𝑎∫ (
2
√𝑥+1) 𝑑𝑥
𝑏
𝑎
Solve[𝑓[𝑥] == fave&&𝑎 ≤ 𝑥 ≤ 𝑏, {𝑥}, Reals]
Output: {{𝑥 →5
4}}
So, x = 5
4 is the point where the function f(x) has the same value as the
average value fave.
Introduction to Mathematica – Calculus 2
Page 61 of 90
Solution (c): To show this information graphically we will graph y = f(x) and y = 4
3
Input: 𝑓[x_]: =2
√𝑥+1 (* this is f(x) *)
𝑔[x ]: =4
3 (* this is g(x) *)
Plot[ (* start of Plot Command *)
{𝑓[𝑥], 𝑔[𝑥]}, (* two functions to graph *) {𝑥, 0,3}, (* the range of x- values *)
PlotRange → {0,2}, (* the range of x- values *)
PlotLegends → {"f(x) =2
√x+1", "g(x)=
4
3"} (* legend at side of graph *)
Ticks → {{0,1
4,
1
2,
3
4, 1,
5
4,
3
2,
7
4, 2,
9
4,
5
2,
11
4, 3}, {0,
1
3,
2
3, 1,
4
3,
5
3, 2}} (* scales on x and y-axes *)
GridLines → {{0,1
4,
1
2,
3
4, 1,
5
4,
3
2,
7
4, 2,
9
4,
5
2,
11
4, 3}, {0,
1
3,
2
3, 1,
4
3,
5
3, 2}} (* gridlines on x and y-axes *)
] (* end of Plot Command *)
Output:
Note 1: The point of intersection is at (5
4,
4
3)
Note 2: The code for the graphing of the function contains Plot Options
such as PlotRange , PlotLegends,Ticks and GridLines. These are optional but they do add
some detail to the graphs to help with the overall appearance.
Introduction to Mathematica – Calculus 2
Page 62 of 90
E. Work Done Problems
Example 37: A heavy rope 50ft long, weighs 0.5 pounds per foot and hangs over the edge of a building 120 ft high. How much work is done in pulling the rope to the top of the building?
The total height of the building (200ft ) is not important - only The work done in pulling the rope up is important.
We break the problem into a smaller simpler situation first. Suppose we have the rope at a height of xi above the ground and we raise it up by a small amount called ∆𝑥 then the work done by pulling the rope up this extra ∆𝑥 is given by the formula. W = FD = 0.5xi∆𝑥.
If we sum this up over the entire 50 ft we get
W = lim𝑛→∞
∑ 0.5xi∆𝑥𝑛𝑖=1
which becomes the integral W = ∫ 0.5𝑥𝑑𝑥50
0
W = [0.25𝑥2]𝑥=0𝑥=50
W = 625 ft lb
The Mathematica Code for this question is. Input: 𝑤[x_]: = 0.5𝑥 𝑎 = 0; 𝑏 = 50;
∫ (𝑤[𝑥]) 𝑑𝑥𝑏
𝑎
Output: 625.
Example 38: A cable weighs 2lb per foot is used to lift 800 pounds of coal up a mine shaft 500 ft deep.
Find the work done. Input: 𝑤[x ]: = 800 + 2𝑥 𝑎 = 0; 𝑏 = 500;
∫ (𝑤[𝑥]) 𝑑𝑥𝑏
𝑎
Output: 650000
Note: w(x) is the work function it is made up of a fixed 800 pounds plus x ft of rope that weigh 2 lb per foot so the total weight at point x is w(x) = 800 + 2x
50 ft
xi xi +∆𝑥
Introduction to Mathematica – Calculus 2
Page 63 of 90
F. Hydrostatic Problems
Example 39: Find the hydrostatic pressure on the rectangular plate shown below.
Water has a weight of 62.5 pounds per cubic feet.
Solution: The pressure function p(x) is the pressure at depth xk.
P(xk) = Pressure at depth xk
= 62.5xk (62.5x when feet)
A(xk) = Area of a typical strip at depth xk
= 6∆𝑥
Force Function at xk F(xk) = P(xk)A(xk)
= (62.5xk )( 6∆𝑥)
= 375𝑥𝑘∆𝑥
Total Force F = lim𝑛→∞
∑ 0.5x𝑘 ∆𝑥𝑛𝑘=1
= ∫ 375𝑥𝑑𝑥6
2
= (375
2𝑥2)
𝑥 = 6𝑥 = 2
= 6750 – 750
Total Force F = 6000 lb
The Mathematica Code for this question is.
Input: 𝑎 = 2; 𝑏 = 6; 𝑓[x_]: = 375𝑥
∫ 𝑓[𝑥] 𝑑𝑥𝑏
𝑎
Output: 6000
∆𝑥
xk
Introduction to Mathematica – Calculus 2
Page 64 of 90
Example 40: Find the hydrostatic pressure on the rectangular plate shown below.
Water has a weight of 62.5 pounds per cubic feet.
P(x) = Pressure at depth xk = 62.5x (125
2 x when feet , 9810x when in m)
A(x) = Area of a typical strip at position d = w∆𝑥
We use similar triangles to find w in terms of d the distance from the top of the triangle
3
4 =
3−𝑑
𝑤
3w = 4(3 – d)
3w = 12 – 4d
w = 12 – 4d
3
w = 4 −4
3𝑑
Since d = x – 1 we can calculate the
width of a typical strip in terms of x.
w = 4 −4
3(𝑥𝑘 − 1)
w = 4 −4
3𝑥𝑘 +
4
3
w = 16
3−
4
3𝑥𝑘
Area of a typical strip at depth xk A(xk ) = 𝑤∆𝑥 = (16
3−
4
3𝑥𝑘)∆𝑥
Force Function at xk
F(xk) = P(xk )A(xk ) = (125
2 xk)(
16
3−
4
3𝑥𝑘)∆𝑥 = (
1000
3xk –
250
3𝑥𝑘
2)∆𝑥
Total Force F = lim𝑛→∞
∑1000
3 xk –
250
3 𝑥𝑘
2)∆𝑥𝑛𝑘=1 = ∫ (
1000
3x –
250
3 𝑥2)𝑑𝑥
4
1
= (500
3𝑥2 −
250
9𝑥3)
𝑥 = 4𝑥 = 1
= 750 lb
The Mathematica Code for this question is.
Input: 𝑎 = 1; 𝑏 = 4;
𝑓[x_]: =1000
3𝑥 −
250
3𝑥2
∫ 𝑓[𝑥] 𝑑𝑥𝑏
𝑎
Output: 750
d w ∆𝑥
x
Introduction to Mathematica – Calculus 2
Page 65 of 90
14. Numerical Integration
We have three methods for approximating the Area under a curve the y are Ln , Rn and Mn
These three methods use the technique of splitting the area into rectangles and can be very accurate
if you take enough strips. Two other techniques can also be used to estimate the area under a curve.
These numerical methods are called the Trapezoid Rule and Simpsons Rule.
A. Trapezoid Rule.
We now find a method for getting the approximate area under a curve.
We begin by splitting the area into n strips as shown above, each of width ∆𝑥 = 𝑏−𝑎
𝑛 and xk = a + k∆𝑥 .
To find the area of one these strips we find the area of a trapezium similar to the ones drawn above.