Professional Documents
Culture Documents
Calculus
1
Expressions vs. functions.
Making your own functions.
Limits.
Derivatives and applications.
Taylor Polynomials.
Integrals.
Series.
2
Give the file any name you want, but make sure to
save it with the .mw extension (not .mws).
As usual, you should enter the commands from
the slides into Maple on your own.
Also, as usual, this is NOT to be submitted for
grading.
3
You’ve learned many calculus concepts in Math
1910 and 1920.
You’ve seen limits, derivatives, integrals, series,
and applications of all of these concepts.
In this chapter, we’re going to see how Maple
handles these ideas and solve a few problems
that couldn’t be done by hand in your first year
courses!
4
Maple has many pre-defined functions, many of
which you saw in the chapter on algebra.
Most mathematics you do are JUST on a set of
standardized functions! You usually work on some
sort of transcendental combination of them!
You can define your own functions in two ways.
◦ An expression (you’ve already used these).
◦ A function (slightly different way, but can be more
convenient at times).
5
To make an expression and store it in a variable,
you’ve already seen the syntax:
myExpression:=formulaInvolvingX
Example: Make your expression 𝑥 2 :
f:=x^2
This is good for graphing or solving an equation,
but one other thing you might need to do is
substitute values into your function, e.g., evaluate
f(5).
What happens when you type f(5)?
Certainly not the result you were expecting!
6
Syntax: To substitute values into an expression,
you need to issue a somewhat bulky command:
subs(x=value, myExpression)
Example: subs(x=5, f) is what you would use
to evaluate f(5).
Why didn’t Maple use the standard f(5) notation?
The answer is, it DOES, but you must define f as a
function and not an expression!
7
Syntax: To define a function called myFunction,
of a variable called myVariable:
myFunction:=myVariable->formulaInMyVariable
Example: f:=x->x^2
defines a function called f in the variable x and is
equal to x squared.
Now you can use the standard notation f(5).
8
You’ve plotted/solved expressions before. If you had
an expression called f and you wanted to plot it, you
used plot(f, x) or solve(f=number, x), etc.
Try the same command now on your new function f:
plot(f, x) What’s happening?
In order to plot the function, use the full notation f(x)
rather than just f. This turns the function into an
expression (internally; you won’t see any conversion
happen) and you can plot as you have done before:
plot(f(x), x)
Similar rules apply to solving, factoring, etc.
9
Recall shifting and scaling of functions?
You could come up with the new formula and type
it directly in to Maple, or, use the convenient
function notation!
Example: Take our function 𝑓 𝑥 = 𝑥 2 and plot the
new function resulting from vertically scaling the
function by a factor of -2, shifting it left by 3 units
and down by 4 units.
plot(-2*f(x+3)-4, x)
10
As a brief note, you can also declare functions of 2 or
more independent variables (for plotting surfaces, etc).
Syntax:
fName:=(var1, var2, …)->formula
Example: Create and plot the function
𝜋
𝑧= 𝑥3 + sin(𝑦 2 ). Use it to evaluate 8 + sin .
2
h:=(x,y)->x^3 + sin(y^2)
plot3d(h(x, y), x=-2..2, y=-2*Pi..2*Pi)
evalf(h(2, (Pi/2)^(1/4)))
11
Recall that a piecewise function changes its
formula depending on the value input.
Syntax:
fName:=x->piecewise(range1, formula1,
range2, formula2, …)
You can have as many conditions as you like.
You can use the usual =, >, >=, <, <= symbols.
You can graph these like any other function.
12
2
Example: Define the function 𝑓 𝑥 = ቊ 𝑥 if 𝑥 < 1
1+𝑥 if 1 ≤ 𝑥 < 10
13
There are easy limits (ones you can just substitute
numbers into, those that are easy to factor, etc),
and there are hard limits (squeeze theorem,
l’Hospital’s rule, etc).
No matter what kind of limit you have, Maple has
all of these techniques programmed internally and
will automatically choose the best one to evaluate
the limit.
You can do regular limits, or one-directional limits.
14
Syntax:
limit(function, var=value, option)
◦ options can be left or right. If omitted, Maple
computes both and returns the value if they’re both
equal, or “undefined” otherwise.
If you are using Maple as a word processor (as we
saw in Chapter 1) and you actually want to see the
standard limit notation, use a capital L:
Limit(function, var=value, option)
◦ This will not evaluate the limit and will merely write limit
notation.
◦ You could then evaluate it using value() or evalf().
15
Example: Write the limit notation for the following, then
evaluate the limit: 𝑥→4
lim (2𝑥 − cos(𝜋𝑥/4)
limit(ln(x)/x, x=infinity)
16
You can also do limits on piecewise functions,
both normally and directionally.
𝜋sin(𝜋𝑥) if 𝑥 < 1
Example: If 𝑓 𝑥 = ቊ
𝜋𝑥 + cos(𝜋𝑥) if 𝑥 ≥ 1
lim 𝑓 𝑥 , lim 𝑓(𝑥) , and lim 𝑓(𝑥)
evaluate 𝑥→1 − +
𝑥→1 𝑥→1
f:=x->piecewise(x<1, Pi*sin(Pi*x),
x>=1, Pi*x + cos(Pi*x))
limit(f(x), x=1)
limit(f(x), x=1, left)
limit(f(x), x=1, right)
17
Maple can compute derivatives for even extremely
complicated functions.
The standard derivative formulas for all basic functions
are all programmed into Maple, along with the product
rule, quotient rule, and chain rule.
Maple knows when to use each rule on its own, so you
don’t have to “help” it along.
You can get Maple to find derivatives of both
expressions and functions.
◦ The syntax is different for each type, but will produce the same
results.
◦ There’s no major advantage to using one form vs. the other.
18
If you are working with an expression, e.g.,
f:=expression (NOT f:=x->formula), then…
Syntax:
diff(expression, variable)
will give the first derivative of the expression.
Alternatively, you can use “normal” notation, f’
Syntax:
diff(expression, variable$order)
will give the derivative specified by order (an integer
at least 2).
You can also use standard notation as above, for
example, f’’’ would give the third derivative.
19
If you are using function style (f:=x->formula),
then…
Syntax:
D(f) or f’(x)
will give the first derivative (note that it’s
f’(x)and NOT just f’ like in expression format!)
To get higher derivatives, you need to use extra
D’s or primes. For example, D(D(D(f))) or
f’’’(x) will give the third derivative.
20
Example: Find the derivative of
𝑓 𝑥 = 5𝑥 2 + sin(𝑥) .
f:=5x^2+sin(x)
diff(f,x)
---OR---
f:=x->5x^2+sin(x)
f’(x)
Example: Find the third derivative of (in
𝑥 2 −1
expression format) 𝑓 𝑥 =
3𝑥 −1
diff(sqrt(x^2-1)/(3^x-1), x$3)
21
Recall that the derivative represents the slope of
the tangent line to the graph at any value of x.
When you substitute a number into the derivative,
the result is the slope of the line at that one point,
or, 𝑓′(𝑎).
The equation of a tangent line to 𝑓(𝑥) at the point
𝑥 = 𝑎 is given by
𝑦 = 𝑓 𝑎 + (𝑓 ′ 𝑎 )(𝑥 − 𝑎)
This is also called the Linear Approximation.
22
Example: Find the slope of the tangent line to 𝑓 𝑥 =
tan(𝑥) at the point 𝑥 = 𝜋/4. There are many ways this
can be done in Maple. Here are two (one with
expression and one with function).
f:=tan(x)
fp:=f’
subs(x=Pi/4, fp)
---OR---
f:=x->tan(x)
f’(Pi/4)
23
Example: Find the equation of the tangent line to
𝑓 𝑥 = 𝑥 3 + 2𝑥 2 − 5𝑥 − 6 at 𝑎 = −3. (Again in this
case, it might be easier to use functions)
f:=x->x^3+2x^2-5x-6
tline:=f(-3)+f’(-3)*(x-(-3))
24
Recall that these problems involved finding the
best value for a function (global max or min) and
the value of x at which it occurs.
When modeling a real-world situation, Maple
CANNOT come up with the function to be
optimized nor the interval of validity. YOU have to
do that!
What Maple CAN do is find the optimal value for
you, by using the methods you learned in first year
calculus, along with graphs for visualization.
25
Recall that the optimal value of a continuous function
occurs only at endpoints or critical points (derivative is zero
or undefined).
Therefore, once YOU have analyzed the problem and
come up with the objective function and the constraints,
you then use Maple to do the computations to find the
optimal value.
Once you have found the function and interval, use the
following:
◦ Syntax: maximize(expression, interval, location=true)
◦ Syntax: minimize(expression, interval, location=true)
If an interval is something like 0 ≤ 𝑥 ≤ 4 then you need to
enter TWO intervals, i.e., 𝑥 ≥ 0, 𝑥 ≤ 4.
26
Example: There are several pairs of positive real
numbers which add to give 100. Of all such pairs,
find the two giving the maximum possible product.
27
Recall that all differentiable functions can be
approximated by a Taylor polynomial (any degree)
centered at a point 𝑎.
This is merely a generalization of the linear
approximation (it’s a Taylor polynomial of degree
1).
The higher the degree used, the more accurately it
approximates the function.
𝑓′′ 𝑎
𝑝𝑛 𝑥 = 𝑓 𝑎 + 𝑓 ′ 𝑎 𝑥 − 𝑎 + 𝑥−𝑎 2 +
2!
𝑓3 𝑎 3 𝑓𝑛 𝑎
𝑥−𝑎 + ⋯+ 𝑥−𝑎 𝑛
3! 𝑛!
28
You’ll recall these were not difficult, but incredibly
tedious, to do by hand.
◦ It was easy for simple functions like 𝑒 𝑥 , sin(𝑥), etc.
2
◦ But what about for a function like 𝑥𝑒 ? If you had to
−𝑥
take, say, the 5th Taylor polynomial, the product and chain
rules explode very quickly into a massive expression!
You could use Maple’s derivative commands that
you have already learned to construct these
yourself, but Maple has a handy command that
does it all at once.
29
Syntax:
taylor(expression, x=a, n)
Produces the Taylor polynomial OF ORDER n-1
centered at x=a.
Note the use of the word EXPRESSION. Don’t
use function format there!
30
Example: Compute the first, second, and third degree
𝑥−𝑥 2
Taylor Polynomials for the function 𝑓 𝑥 = 𝑥𝑒 at 𝑎 = 0.
Then, graph 𝑓(𝑥) (black, thickness 5) and each of these
polynomials (red, blue, gold, each thickness 1) on the same
screen.
f:=x*exp(x-x^2) #expression, not function!
taylor(f,x=0, 2) #order 1
taylor(f,x=0, 3) #order 2
taylor(f,x=0, 4) #order 3
To graph, copy and paste everything from each of these
outputs (except the 𝑂(𝑥 𝑛 ) at the end) into a plot command
with appropriate syntax that you’ve seen before.
31
Maple has the ability to calculate both definite and
indefinite integrals.
When possible, Maple will evaluate a definite
integral exactly. Otherwise, you can ask it to
approximate using a numerical integration rule.
All integration methods, such as substitution,
integration by parts, etc., are done automatically.
Syntax:
int(expression, x=a..b) → Definite
int(expression, x) → Indefinite
32
Example: Find the antiderivative of
2 1
𝑓 𝑥 =1−𝑥 +
1−𝑥 2
int(1-x^2-1/sqrt(1-x^2), x)
Example: Find the net area bounded by 𝑓 𝑥 =
9 − 𝑥 2 and the x-axis, between -3 and 3.
int(sqrt(9-x^2), x=-3..3)
33
Recall that Riemann sums, and the trapezoid rule
and Simpson’s rule, are where you approximate
an integral using left/right endpoints, midpoints,
trapezoids, and parabolas, using a finite number
of sub-intervals.
Maple has facilities by which you can draw in the
geometric figures and compute the
approximations.
34
To show the partitioning on the graph, or to make the
computations, you need to load the Student Calculus1
package:
with(Student[Calculus1])
Syntax:
ApproximateInt(expression, x=a..b,
method=methodType,
partition=numRectangles, options)
methodType can be left, right, midpoint,
trapezoid, simpson.
common options:
output=plot, output=animation
35
You would not use numerical integration in Maple
for functions that have a closed form antiderivative
(such as 𝑥 2 , sin(𝑥), etc.).
◦ This is because using int() on these functions will
return an exact value, rather than an approximation.
−𝑥 2 1
However, for other functions, like 𝑒 , , and
ln 𝑥
the like, which do not have an elementary
antiderivative, ApproximateInt() provides
good approximations.
36
14 1
Example: Approximate 2 ln 𝑥 𝑑𝑥 with the
Midpoint rule, using 4 subintervals. Include the
animation plot with the outputs. Change the
frames per second to 1 and then play the
animation.
ApproximateInt(1/ln(x), x=2..14,
method=midpoint, partition=4,
output=animation)
37
Recall the absolute error bounds in the Midpoint,
Trapezoid, and Simpson’s rule were the following
maximal values:
𝑘 𝑏−𝑎 3 𝑘 𝑏−𝑎 3 𝑐 𝑏−𝑎 5
𝐸𝑀 = 2
, 𝐸𝑇 = 2
, 𝐸𝑆 =
24𝑛 12𝑛 180𝑛4
Where 𝑘 = max |𝑓 ′′ 𝑥 | , 𝑐 = max |𝑓 (4) 𝑥 |
[𝑎,𝑏] [𝑎,𝑏]
You may recall that in math 1920, these were
“easy” to find, except for the values of k and c.
Often you needed a graph to do this. Now we can
easily get these graphs!
38
Example: A few slides back, we approximated
14 1
2 ln 𝑥 𝑑𝑥 with the midpoint rule using 4
subintervals. This gave us an approximation, but
we don’t know roughly how “good” it is. Use the
Midpoint error bound formula to get this estimate
of “goodness”.
We know that 𝑎 = 2, 𝑏 = 14, 𝑛 = 4. We need the
𝑑2 1
value of 𝑘 = max 2 .
[2,14] 𝑑𝑥 ln 𝑥
By hand, this is difficult. In Maple, this is much
easier!
39
Example continued:
f:=1/ln(x)
g:=diff(f, x$2)
plot(|g|, x=1.5..12.5)
From the graph, it appears that k, which is the farthest
distance the function travels vertically from the x-axis,
occurs at 𝑥 = 2. Thus, we can take 𝑘 = 𝑔(2):
k:=subs(x=2, g)
Alternatively, Maple can maximize this for you:
maximize(|g|, x=2..12)
Warning: Sometimes Maple won’t be able to do it this way
because it’s too complicated Mathematically. In these
cases, Maple will either output “junk” or just seem to hang
for a long time. If this happens, just use the graph.
40
Example continued:
So, the error is bounded by
Em:=k*(14-2)^3/(24*4^2)
41
Recall that the length of a differentiable function
on the interval [𝑎, 𝑏] is
𝑏
2
න 1+ 𝑓′ 𝑥 𝑑𝑥
𝑎
Due to the square root, it’s very often impossible
to find the exact length as the integral may be
impossible.
Thus, you often have to use a numerical method
to approximate the integral.
42
Example: If possible, find the length of the curve
ln(sec 𝑥 ) on the interval [0, 𝜋/4].
f:=ln(sec(x))
int(sqrt(1+(f’)^2), x=0..Pi/4)
Note that the exact value was given here (actually, this
is also quite easy to do by hand!)
Example: Repeat this example for 𝑓 𝑥 = sin(𝑥) on
[0, 𝜋].
f:=sin(x)
int(sqrt(1+(f’)^2), x=0..Pi)
Note that this time, Maple outputs odd looking stuff!
Therefore, it’s time to approximate with a numerical
method.
43
Example continued: Suppose we use Simpson’s
rule with n=10 to approximate this integral:
ApproximateInt(sqrt(1+(f’)^2),
x=0..Pi, partition=10, output=value)
evalf(%)
44
Summations in Maple are similar to integration in
that Maple will try to find the exact value first. If it
can’t, it will use an approximation.
Syntax:
sum(formula, var=a..b)
Note: formula is anything involving the variable,
and either a or b, or both, can be infinite.
To write the notation only, use
Sum(formula, var=a..b)
◦ This writes out the notation and does not evaluate the
summation.
45
Maple knows formulas for computing exact values
(such as geometric series).
It also has a few tricks up its sleeve that you likely
won’t learn until a higher-level math course (e.g.,
Fourier Series).
Example: Evaluate the geometric series
1 3𝑛+1
σ∞
𝑛=2 2 ⋅ −
7
sum(2*(-1/7)^(3n+1), n=2..infinity)
46
Example: When you learned p-series, you could
only get approximate values because the
techniques required to evaluate them exactly were
too advanced for first year calculus. Maple has
those techniques, so, evaluate the p-series
∞ 1
σ𝑛=1 2
𝑛
sum(1/n^2, n=1..infinity)
47
There are, however, some series that Maple can’t
do. It won’t even give you an approximate answer.
In this case, you have to approximate it yourself.
∞ 1
Example: Evaluate σ𝑛=2 2 if possible. If not,
𝑛 ln 𝑛
use a finite number of terms to approximate the
series to within 0.001 of its exact value using trial
and error (keep increasing n until the value of the
series changes by less than 0.001).
48
Example continued:
sum(1/(n^2*ln(n)), n=2..infinity)
Maple refuses to evaluate it, even with evalf()!
Therefore, approximate. Start with, say, a range of 2 to 10
and then go to 11 and compare:
sum(1/(n^2*ln(n)), n=2..10)
sum(1/(n^2*ln(n)), n=2..11)
The difference is more than 0.001, so go to 12, and so on,
until the difference is less than 0.001. It’s quickest to go up
in increments of more than 1 (say 10), and then check the
next one for the difference.
sum(1/(n^2*ln(n)), n=2..20)
sum(1/(n^2*ln(n)), n=2..21)
49
Example continued: The difference here is less
than 0.001, so use the approximation from 2 to 21
as the approximate value.
50
Calculus has a wide range of applications, and
we’ve seen how to get Maple to do the grunt work
for us. This again only scratches the surface.
Next up: Programming!
Now, don’t forget to finish the Chapter 4
Assignment and submit to Moodle by the indicated
deadline!
51