Survey
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts

Corecursion wikipedia, lookup

Parameter (computer programming) wikipedia, lookup

Transcript
```MTH4105 Introduction to
Mathematical Computing
Chapter 2
School of Mathematical
Sciences
© 2016 by Dr Francis J. Wright
Introduction to Maple functions
After explaining how to separate Maple input from text, we begin a survey of how to use
the standard "calculus" functions provided by Maple.
Execution groups and output labels
In Chapter 1, we learnt how to use Maple to write mathematical documents, including
how to evaluate an expression and display the result within the text of the document.
Now we are going to move on to learn how to solve more complicated problems, for
which it often makes more sense to keep the Maple computations separate from the
main text. For this purpose, Maple provides execution groups, which look like this:
>
You can always insert an execution group by clicking on the >_ button on the toolbar.
(You can also use the Insert / Execution Group submenu.) The opening square
bracket at the left of an execution group expands as necessary and always shows the
extent of the execution group. The > symbol is a prompt that indicates where to enter
Maple input. Pressing the Enter key when the cursor is anywhere within Maple input
in an execution group will execute all the input in the execution group. Any output
generated by the Maple input will appear at the bottom of the execution group
containing the input, centred on a line below the input and with an output label on the
right (by default, although you can turn off labels; for example, see the Format /
Equation Labels submenu). An execution group with input and output looks like this:
N
>
> n1
n=1
2
1 2
π
6
Note that Ctrl+= is equivalent to Enter in execution groups.
(1.1.1)
Maple always displays output labels within parentheses. The precise format of the
output label can be controlled, but by default it begins with the numbers of any
sections and subsections that contain the output. Output labels can be used within
input expressions to refer to output without needing to recompute it. To enter an
output label within input press Ctrl+L or use the Input / Label… menu item and type
the label identifier into the Insert Label dialogue box exactly as it appears on the
output (except that the parentheses are unnecessary), e.g.
> (1.1.1)
1 2
π
(1.1.2)
6
When a worksheet is edited, output labels are automatically re-numbered as
necessary in both output and input, so that a label always reliably refers to the right
output. If the output to which a label refers is deleted then the label is replaced by ??
Page 1 of 18
24-Sep-2016
until the output is recomputed.
Exercise
N
Use the Expression palette to enter the sum
> n1
n=1
2
after the input prompt in the
execution group in the box below and then press Enter to evaluate it. Note that
after Maple executes input in an execution group it automatically moves to the next
execution group or creates a new execution group if necessary. At the new input
prompt, compute the square root of the value of the sum by using the previous
output label to refer to it; do not re-enter the sum.
>
Solution
N
>
> n1
n=1
2
1 2
π
6
>
(1.1.1.1.1)
(1.1.1.1.1)
1
6
6 π
(1.1.1.1.2)
The difference between a Maple worksheet and a Maple document is that a
worksheet starts with an execution group and (by default) consists entirely of
execution groups, whereas a document (like this one) starts blank and may contain
no execution groups at all, or just a few where appropriate. To develop a Maple
program that includes little or no text, it makes sense to start with a worksheet,
whereas to write a Maple document that includes little of no Maple programming, it
makes sense to start with a document. But it's your choice!
Aside: Document blocks
The above paragraph is not strictly true, although superficially it appears to be. A
Maple document is really a worksheet in which some or all of the execution groups
are hidden within document blocks. It is also possible for a Maple document to
contain large programs that are similarly hidden. This allows Maple documents to
be interactive, much like pages in a web browser. If you are interested, you can
explore these aspects of Maple for yourself using the Maple help and other
information on the web.
Never type English text after a Maple input prompt! It will not be formatted
correctly and if press the Return or Enter keys you will get an ugly error message.
Selecting text mode after a prompt does not make the input into English text, it makes
it plain text Maple input in which mathematical notation is disabled. If you want to
include text within an execution group then first insert a paragraph using the Insert /
Paragraph submenu, like this:
Here is an example of a divergent sum:
N
>
> 1n
n=1
Maple indicates this by returning a value of infinity:
N
Page 2 of 18
(1.1.3)
24-Sep-2016
You can remove the prompt from an execution group in order to input English text by
using the Insert / Text menu item, as illustrated by this sentence. But it is still an
execution group, as indicated by the opening square bracket at the left.
More elegantly, you can hide the execution group delimiter by clicking on the Edit /
Document Blocks / Show Execution Group menu item to deselect it, or insert text
below the current stack of execution groups by clicking the T button on the toolbar.
Maple functions
Most nontrivial use of Maple involves functions. Only the most elementary
mathematical functions are included in the palettes; the rest you have to type
yourself. The rules for using functions in Maple are much the same as in
mathematics: the name of the function must be followed immediately by an
opening parenthesis, zero or more values separated by commas, and a closing
parenthesis. Rules like this constitute the syntax or grammar of a language and in a
programming language the syntax must be followed without exception or an error will
result.
If Maple recognizes a function name as a standard mathematical function then it
switches the font from italic to roman. This is standard practice in mathematical
typesetting, as illustrated by the first three functions below:
log x , ln 1 , sec theta , f x , g
, foo a, b, c
The quantities within the parentheses are called the arguments of the function and
they can be arbitrary expressions (of the right type). A function can take no
arguments at all, but its name must still be followed immediately by empty
parentheses, which are an essential part of Maple's function syntax.
In Maple math-mode input there must be no space between a function name
and the following opening parenthesis. Any space turns the function into an
implicit multiplication.
Exercise
Type the above sequence of functions exactly as shown after the prompt in the
box below, with no space after any function name. Then press the Enter key.
>
You should see that Maple represents log as ln and theta as θ, but otherwise the
output is the same as the input. (If not then you have entered it wrongly!) A feature
of many functions in Maple is that they may evaluate to themselves or remain
symbolic, which means that Maple cannot evaluate or simplify them any further.
Now go back to the box above, copy your line of input to the second input prompt,
edit it by inserting one or more spaces after each function name and execute it.
You should get an error message complaining about an implicit product and
indicating specifically that g
is the problem. Type 1 inside the parentheses and
re-execute the input. The output shows that Maple has interpreted each "function"
as a product and has discarded the redundant parentheses. If you are still not
convinced, note for example that
> whattype 'foo a, b, c '
function
(1.2.1.1)
but with a space we get
Page 3 of 18
24-Sep-2016
> whattype 'foo a, b, c '
`*`
(1.2.1.2)
This output means that Maple regards the input expression within the quotes as a
product, not a function.
Function arguments and nested functions
Function arguments can be arbitrarily complicated expressions and can include other
functions. For example, you can use output labels to build complicated expressions,
like this:
> g x
g x
(1.3.1)
> a (1.3.1)2 Cb (1.3.1)Cc
2
a g x Cb g x Cc
(1.3.2)
> f (1.3.2)
f a g x 2 Cb g x Cc
Or you can just enter the expression directly, like this:
> f ag x
2
(1.3.3)
Cb g x Cc
f a g x 2 Cb g x Cc
(1.3.4)
It can be useful to develop solutions step by step, using output labels, and then
combine the steps once the solution works.
Try it
>
It is quite common for one or more function arguments to be other functions, e.g.
π
> log sin
2
0
(1.3.5)
> simplify log x
2
, symbolic
2 ln x
(1.3.6)
Try it
>
We will come back to the simplify function later.
Exercise
After the input prompt in the box below, enter the Maple function called op applied
2
to the polynomial a x Cb x Cc and execute the input. Then copy your input to
the new prompt and include the integer 1 as a new first argument to op,
separating it from the existing argument by a comma. Try different integer
arguments that are close to 1 instead of 1. Can you see what the function op
does? Use the Maple help to check your conclusion or find out if you can't guess.
>
Now copy your input to a new prompt and use op twice to extract the sub2
expression x from the polynomial in two steps using an output label. Then do it
again in one step using nested calls of op.
Solution
Page 4 of 18
24-Sep-2016
2
> op a x Cb x Cc
op with one argument returns a sequence of all the operands of an expression,
in this case all the terms of the polynomial. This is a very important use of
the function op.
2
a x , b x, c
(1.3.1.1.1)
2
> op 1, a x Cb x Cc
op with two arguments returns the specified operand, in this case the first
term of the polynomial.
a x2
(1.3.1.1.2)
> op 2, (1.3.1.1.2)
In this case, op returns the second factor of the monomial.
x2
(1.3.1.1.3)
The above result can be obtained using a single input expression containing
nested functions like this:
2
> op 2, op 1, a x Cb x Cc
x2
(1.3.1.1.4)
Elementary mathematical functions
So-called algebraic functions are related to polynomials but are not necessarily
polynomial. For example, the square root function arises as the inverse of the
2
(polynomial) squaring function x 1 x . The square root of x is often written using the
special notation x , for which there is a template in the Expression palette, e.g. 4 =
2, but it can also be written in Maple (and most other programming languages) as
sqrt x , e.g. sqrt 4 = 2. Apart from a few very common functions, most mathematical
functions can only be input using syntax of the form function x, y, z , and all can also
be input using this syntax. For example, ex can also be input in Maple (and most other
x
programming languages) as exp x = e .
Exercise
In the box below, input and execute the following sequence of functions exactly as
written:
sqrt x , sqrt 18 , exp y , exp 0 , exp 1 , factorial n , factorial 10
They should all evaluate to something different from the input; if they don't then
you have done something wrong! Remember: there must be no space after the
function name.
>
Solution
> sqrt x , sqrt 18 , exp y , exp 0 , exp 1 , factorial n , factorial 10
x , 3 2 , ey, 1,e, n!, 3628800
(1.4.1.1.1)
Some key functions
sqrt x =
surd x, n =
x
n
x
exp x = ex
log x = ln x
factorial n =
n!
The six trigonometric functions have the standard names: sin, cos, tan, sec, csc, cot.
Page 5 of 18
24-Sep-2016
If you don't know how any of these functions are defined then look them up in the
Maple help. Note that they all require their arguments to be expressed in radians, not
π
degree, e.g. sin
= 1. Their inverses have "arc" prepended and return angles
2
1
expressed in radians, not degree, e.g. arcsin 1 =
π.
2
Exercise
In the box below, compute the values of the six trigonometric functions applied to
π
the angle
radians. They should all evaluate to exact numerical values; if they
3
don't then you have done something wrong! Then apply the corresponding inverse
trigonometric function to each result and make sure you get the original value,
π
namely , in every case.
3
>
Solution
> sin
π
π
π
, cos
, tan
, sec
3
3
3
1
1
3 , , 3 , 2,
2
2
> arcsin
1
2
arccot
3 , arccos
1
3
π
, csc
3
2
1
3,
3
3
1
, arctan
2
π
, cot
3
π
3
3
3 , arcsec 2 , arccsc
(1.4.2.1.1)
2
3
3 ,
3
Note that Maple always outputs
x
where n is a number in the equivalent form
n
1
x.
n
1
1
1
1
1
1
π,
π,
π,
π,
π,
π
3
3
3
3
3
3
(1.4.2.1.2)
The hyperbolic analogues of the trigonometric functions have the same names with
"h" appended, e.g. sinh 0 = 0, arcsinh 0 = 0. Searching for help on "trig" (or clicking
on the link) will give you details of the full set of trigonometric and hyperbolic
functions, and help on "invtrig" (or clicking on the link) will give you details of their
inverses. Together with the functions in the Expression palette, this covers all the
elementary transcendental functions, which are those closely related to the
exponential function.
Maple math-mode input supports the standard trigonometric power convention that, e.
2
K1
g. sin x = sin x 2 and sin x = arcsin x , which works also for hyperbolic functions.
But beware that other powers will not necessarily behave as you expect, e.g.
K2
1
sin x =
, and for other functions power syntax never gives inverse
sin x 2
K1
1
.
functions, e.g. ln x =
ln x
Note that sqrt 4 = 2, whereas you might have expected the result G2. When Maple
th
evaluates a multivalued function such as an n root or inverse trigonometric function it
Page 6 of 18
24-Sep-2016
always returns just the principal value; if you want a different value then you have to
construct it yourself from the principal value, e.g. Ksqrt 4 = K2.
Exercise
In the box below, compute the values of the trigonometric expression
π π π
2
2
sin θ Ccos θ for θ = , ,
and with θ left symbolic.
2 3 4
>
Solution
2
> sin
2
> sin
2
> sin
2
π
2
π
3
π
4
2
Ccos
2
Ccos
2
Ccos
π
2
1
(1.4.3.1.1)
1
(1.4.3.1.2)
1
(1.4.3.1.3)
π
3
π
4
2
> sin θ Ccos θ
sin θ
2
Ccos θ
2
(1.4.3.1.4)
But note that
> simplify (1.4.3.1.4)
1
(1.4.3.1.5)
π and e
There are two important numbers that arise in the context of the elementary
transcendental functions, which are sometimes referred to as the circle constant and
the base of natural logarithms or Euler's number (not Euler's constant). They are
denoted by the special symbols π and e, which are available as the first two entries in
the Common Symbols palette. Do not try to enter these special symbols using the
keyboard! The symbols π and e represent transcendental irrational numbers,
which means that they cannot be represented by any finite string of digits. This is why
they are always represented by symbols. They can, however, be approximated
arbitrarily accurately, which we will come back to later: e.g. evalf π = 3.141592654,
evalf e = 2.718281828. As you would expect, Maple understands how these important
numbers relate to the elementary transcendental functions, e.g. sin π = 0, cos π =
K1, ln e = 1. However…
Aside: You must use the right versions of π and e!
The meaning of symbols like π and e in mathematics depends on context and they
need not always have the same meaning as above. If you always use the palettes
to enter them they will always work as above, but if you type them you will
probably not get what you expect. We can ask Maple to decode the two symbols π
and e in the palettes by converting them to 1-D Math Input, which gives
respectively: Pi, exp(1). The only way to enter these two symbolic constants
using the keyboard is to type them as Pi, exp(1). In particular, if e is shown as
an italic e in Maple output or math-mode input then it is an arbitrary variable called
e and not the base of natural logarithms. Remembering this should explain any
apparent inability Maple may have to evaluate or simplify expressions involving π
Page 7 of 18
24-Sep-2016
and e, such as these: sin pi = sin π , ln e = ln e .
Floating-point is approximate and contagious
A decimal number containing a point, such as 0.5, is called a floating-point number
in Maple (and most other programming languages). This slightly strange name relates
1
to the internal data structure. You might expect that 0.5 is the same as , but it isn't.
2
Maple regards all floating-point numbers as approximations and treats them
1
1
accordingly. For example, 0.5 = 0.7071067812 whereas
=
2 . Once there
2
2
is one approximation in an expression there is little point keeping other parts of the
expression exact, so Maple will often approximate the whole of an expression that
contains a floating-point number. In this sense, floating-point approximation is
contagious. In particular, it is contagious through polynomial expressions. For
1
1
5
1.0
1
1
1
example, compare
C
=
and
C
= 0.8333333333 or 1.0
C
=
6
2
3
2
3
2
3
0.8333333333. However, symbolic constants are immune to floating-point contagion: e.
e
g. 1.0 Cπ = 1.0 Cπ and
= 0.5000000000 e. Also, functions are immune to floating2.0
1
point contagion from outside, e.g. sin 0.5 = 0.4794255386 but 1.0 Csin
=
2
1
1.0 Csin
. It is necessary to use the function evalf to perform full floating-point
2
approximation reliably, as we will see later.
Exercise
In the box below, compute the value of each of the following expressions:
1
1
2
3
C C , 2 C 3 , ln 2 C ln 3 , e 2 . Then add a decimal point after one
2
3
4
number in each expression and re-evaluate it.
>
Solution
1
2
3
>
C C ,
2
3
4
2 C 3 , ln 2 C ln 3 , e
23
,
12
1
2
2 C 3 , ln 2 Cln 3 , e
1
2
(1.5.1.1.1)
1.
1
2
3
>
C
C , 2. C 3 , ln 2 C ln 3. , e 2
2
3.
4
1.916666667, 1.414213562 C 3 , ln 2 C1.098612289, 1.648721271
(1.5.1.1.2)
Operators as functions
Operations like addition, subtraction, multiplication and division are conventionally
represented in both mathematics and programming languages by symbols like
C,K,#,Ocalled operators. They are primarily used as binary infix operators,
meaning that the operator appears between its two operands like this: 2 C3 = 5, 2 K3
2
= K1, 2 # 3 = 6, 2 O3 = . Some can also be used as unary prefix operators,
3
meaning that the operator appears before its single operand like this: C5 = 5, K1 =
Page 8 of 18
24-Sep-2016
K1. There is one very common unary postfix operator, meaning that it appears after
its single operand, namely "!" denoting factorial, which is used like this: 10! = 3628800.
Maple can display a large number of operator symbols, most of which are available in
either the Common Symbols palette or the Operators palette. However, beware that
not all of these symbols have any associated meaning, so Maple may not be able to
evaluate an expression containing an arbitrary operator symbol, and some of the
more obscure symbols may not have the meaning you expect!
The difference between an operator and a function is purely one of syntax and
nomenclature: an operator operates on operands whereas a function is applied to
arguments. In Maple, as in most programming languages, a symbol is recognised as
a function name only if it is followed immediately by parentheses, whereas an
operator is always recognised and does not require parentheses, although
parentheses may be necessary for expression grouping.
Active Maple operators have associated functions, which correspond to the way they
are represented internally, and most operator names can be used as function names
provided they are enclosed in backquotes (backward quotes). The backquote symbol
can normally be found on a UK computer keyboard in the top left corner immediately
to the left of the 1 key. (Not all operator names need to be backquoted in math-mode
input to be used as function names, but it is generally safest to do so.) For example:
`C` 2, 3 = 5, `-` 2, 3 = K1. The operators #,Oare not active as functions, but the
alternative operators * and / more commonly used in computing can be used as
2
active functions: `*` 2, 3 = 6, `/` 2, 3 = . Using an operator with function syntax
3
provides a very convenient way to apply the operator to a lot of operands. For
example, suppose we have computed a long sequence of numbers, such as the
following (where you can ignore the Maple input):
> r d rand K99 ..99 : 'r '\$100
K7, 22, K55, K94, 87, K56, 0, K62, 97, K73, K4, K83, K10, 62, K82, 80, K44, 71,
(1.6.1)
K17, K75, K10, K7, K40, 42, K50, 23, 75, K92, 6, 74, 72, 37, K23, 87, 44, 29, 98,
K23, 10, K61, K8, K29, 95, 11, K49, K47, 40, K81, 91, 68, K10, 31, K51, 77, 95,
1, 1, 55, K28, 16, 30, K27, K15, K59, K96, 72, K87, 47, K90, 43, 92, K91, K88,
K48, 53, K28, 5, 13, K10, K82, 71, 16, 83, 9, K60, K83, 98, K48, K19, 62, 37, 5,
96, K17, 25, 91, 0, 98, K64, 64
A succinct way to add these numbers is to use Cas a function applied to the
sequence like this:
> `C` (1.6.1)
424
(1.6.2)
As we will see shortly, there are other (less succinct) ways to do this, but using
Cconventionally as a binary infix operator is not one of them!
Exercise
In the box below, compute the sum of the smallest 10 positive integers using
Cboth as a binary infix operator and as a function. Then compute the product of
the smallest 10 positive integers using * both as a binary infix operator and as a
function and compare your result with 10! (or factorial 10 ).
>
Solution
> 1 C2 C3 C4 C5 C6 C7 C8 C9 C10
55
Page 9 of 18
(1.6.1.1.1)
24-Sep-2016
> `C` 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
55
(1.6.1.1.2)
> 1\$2\$3\$4\$5\$6\$7\$8\$9\$10
Note that Maple displays an asterisk used as an infix operator as a small
centred dot…
3628800
(1.6.1.1.3)
> `*` 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
…whereas it displays an asterisk in backquotes as an asterisk (unless you
type both quotes first).
3628800
(1.6.1.1.4)
> 10!
3628800
(1.6.1.1.5)
In the box below, enter and evaluate the sum a Cb Cc Cd Ce. Then apply the
function op to the result to extract all the operands (summands) and apply * as a
function to the resulting sequence of operands to multiply them. You can use
either output labels or nested function calls. In this way, you have converted a sum
into a product. Then use the same approach to convert the product back to a sum.
Using the function op like this can be a good way to convert one data structure into
another.
>
Solution
> a Cb Cc Cd Ce
a Cb Cc Cd Ce
(1.6.1.2.1)
a, b, c, d, e
(1.6.1.2.2)
abcde
(1.6.1.2.3)
> op (1.6.1.2.1)
> `*` (1.6.1.2.2)
or you can use a single input expression, like this:
> `*` op (1.6.1.2.1)
abcde
(1.6.1.2.4)
> `C` op (1.6.1.2.4)
a Cb Cc Cd Ce
(1.6.1.2.5)
Computational functions
Maple supports two kinds of functions: conventional mathematical functions, for which
Maple uses (one of) the standard names, and computational functions used to convey
information, which generally do not exist in other programming languages and so do
not have standard names.
Computational functions are similar to mathematical functions but they often return a
value of different type from their argument(s), or perhaps no value at all, and they
often require more than one argument but return only one value. The Maple function
whattype is a useful example that returns information about the type of its argument,
1
e.g. whattype 1 = integer, whattype
= fraction, whattype 0.5 = float,
2
whattype x = symbol, whattype "some text" = string. It accepts any type of input but
always returns a name (which is of type symbol). It is intended primarily for interactive
use and is not usually the best way to test types in a program.
Page 10 of 18
24-Sep-2016
All the structures available as templates in the Expression, Calculus, Layout
and other palettes are also available as Maple functions, which we will now
begin to explore. The function versions are often easier to use and more
robust, but less pretty and less like conventional mathematical notation. You
can use whichever versions you prefer and the result of executing the template
and function version of any expression should always be the same.
Derivatives: diff
d
3
2
f x , e.g. diff a x , x = 3 a x
dx
The function diff differentiates the expression supplied as its first argument with
respect to the variable supplied as its second argument. If the first argument does not
explicitly contain the second then the result will be zero because Maple assumes it is
differentiating a constant, which may surprise you, e.g. diff y, x = 0.
• diff f x , x =
• diff f x , x, x =
d2
dx2
f x , diff f x , x, x, x =
d3
dx3
f x , diff f x , x\$5 =
d5
3
f x , e.g. diff a x , x\$3 = 6 a
5
dx
You can repeat the variable as many times as necessary to indicate a repeated or
higher-order derivative. However, it is generally better to use the syntax
dn
th
diff f x , x\$n = n f x to denote an n order derivative. In fact, x\$n is just an
dx
expression constructed using \$ as a binary infix operator, which evaluates to an
expression sequence of n copies of x, e.g. x\$5 = x, x, x, x, x. (Higher-order derivatives
can also be input using the appropriate derivative template in the Calculus palette, as
explained in Chapter 1.)
v
v2
3 3
f x, y , diff f x, y , x, y =
f x, y , e.g. diff a x y , x
vx
vy vx
3 3
2 3
2 2
= 3 a x y , diff a x y , x, y = 9 a x y
The function diff returns the partial derivative of a function of more than one variable,
which is indicated by the curly ∂ used instead of the roman d in the symbolic results
shown above, and for which there is a separate template in the Calculus palette. (You
will meet partial derivatives in the Calculus II module.)
• diff f x, y , x =
Exercise
In the box below, differentiate the expression sin 2 π x once and then twice with
respect to x using both the function diff and the derivative templates in the
Calculus palette.
>
Solution
Note that the output is the same regardless of whether 1-dimensional
(functional) or 2-dimensional (palette) input is used.
> diff sin 2 π x , x , diff sin 2 π x , x\$2
2
2 cos 2 π x π, K4 sin 2 π x π
(1.8.1.1.1)
2
>
d
d
sin 2 π x ,
sin 2 π x
2
dx
dx
2
2 cos 2 π x π, K4 sin 2 π x π
Page 11 of 18
(1.8.1.1.2)
24-Sep-2016
Integrals: int
1 3
x
3
The function int integrates the expression supplied as its first argument with respect to
the variable supplied as its second argument. If the second argument is just a
variable then int performs indefinite integration, but it never includes an explicit
constant of integration. If you want one then you need to provide it yourself, e.g.
int f x , x Cc = f x dx Cc.
2
• int f x , x = f x dx, e.g. int x , x =
b
• int f x , x = a ..b =
2
f x dx, e.g. int x , x = 0 ..2 =
a
8
3
If the second argument is an equation with a variable on the left and a range on the
right then int performs definite integration over the interval specified by the range.
Note that a range is specified using the range operator .., which is two full stop or
period symbols next to each other. (It is not the ellipsis symbol …, which is a single
character consisting of three dots, although Maple accepts this in math mode to
indicate a range.) Ranges are widely used in Maple to specify intervals. However,
there is no way to specify whether the ends of a range are open or closed – the
distinction comes from the context if it matters, although generally it doesn't – so
x = a ..b could correspond to any of the intervals a ! x ! b, a % x ! b, a ! x % b or a
% x % b.
Incidentally, various different inequality symbols are available in the Common
Symbols palette, but % and R can be entered using the keyboard by typing <
followed by = and > followed by = (which are standard), and s can be entered using
the keyboard either by typing < followed by > or (in math mode only) ! followed by =
(as used in the programming languages C, Java, etc.)
Exercise
In the box below, compute the indefinite integral of sin 2 π x with respect to x and
then check it by differentiating the result, using both function syntax and the
Expression or Calculus palettes. Use output labels as appropriate; do not copy and
paste.
>
Solution
> int sin 2 π x , x
K
1 cos 2 π x
2
π
(1.9.1.1.1)
> diff (1.9.1.1.1), x
sin 2 π x
>
sin 2 π x dx
K
>
(1.9.1.1.2)
1 cos 2 π x
2
π
(1.9.1.1.3)
d
(1.9.1.1.3)
dx
(1.9.1.1.4)
Page 12 of 18
24-Sep-2016
sin 2 π x
(1.9.1.1.4)
In the box below, compute the definite integral of sin 2 π x with respect to x from
1
0 to 1. To see why the result is as it is, compute the same integral from 0 to
and
2
1
from
to 1.
2
>
Solution
You can alternatively use the 2-dimensional input template from the Calculus
palette.
> int sin 2 π x , x = 0 ..1
0
(1.9.1.2.1)
> int sin 2 π x , x = 0 ..
1
2
1
π
> int sin 2 π x , x =
(1.9.1.2.2)
1
..1
2
K
1
π
(1.9.1.2.3)
2
In the box below, compute the derivative of x C1 with respect to x and then
compute the indefinite integral of the result. What value does the constant of
2
integration need to be to recover the original expression x C1 ?
>
Solution
>
x C1
2
x C1
2
(1.9.1.3.1)
> diff (1.9.1.3.1), x
2 x C2
(1.9.1.3.2)
x2 C2 x
(1.9.1.3.3)
> int (1.9.1.3.2), x
The constant of integration needs to be 1.
You can determine this using Maple as follows:
> (1.9.1.3.1)K(1.9.1.3.3)
x C1 2 Kx2 K2 x
> simplify (1.9.1.3.4)
We will meet the simplify function next week.
1
(1.9.1.3.4)
(1.9.1.3.5)
Synoptic exercises
Attempt the following in the boxes provided or in a new Maple worksheet (or
document).
Page 13 of 18
24-Sep-2016
Question 1
Compute each of the following values exactly by using a single input expression
for each, although you can experiment with multi-step computations to work out
what the single input expression should be if you want:
• the (natural) logarithm of '2 cubed' (as opposed to 'the logarithm of 2' cubed);
π
• the (natural) logarithm of the trigonometric sine of
3
• the (natural) logarithm of the exponential of 2;
• the exponential of the (natural) logarithm of 2;
• the logarithm to base 10 of 1000;
• the inverse tangent of the tangent of 'π divided by 5';
• the (natural) logarithm of the square root of the variable x.
(I have used quotes above to avoid ambiguity where necessary, but don't use
quotes in your Maple input!)
>
3
> log 2
3 ln 2
> log sin
(1.10.1.1.1)
π
3
ln
1
2
3
(1.10.1.1.2)
> log e2
> elog
2
(1.10.1.1.3)
2
(1.10.1.1.4)
3
(1.10.1.1.5)
1
π
5
(1.10.1.1.6)
1
ln x
2
(1.10.1.1.7)
2
> log10 1000
> arctan tan
π
5
> log sqrt x
Question 2
Compute the sum and product of the integers from 1 to 5 inclusive using an
appropriate operator as a function, and check it using the operator normally.
Subtraction and division are not normally applied to more than two operands,
although Maple allows these operators to be used as functions. Apply the minus
operator as a function to the sequence of integers from 1 to 5 inclusive and then
use minus as an operator to compute the same value, which shows how Maple
evaluated the function. Do the same with the division operator.
>
Page 14 of 18
24-Sep-2016
>
> `C` 1, 2, 3, 4, 5
15
(1.10.2.1.1)
15
(1.10.2.1.2)
120
(1.10.2.1.3)
120
(1.10.2.1.4)
K13
(1.10.2.1.5)
K13
(1.10.2.1.6)
1
120
(1.10.2.1.7)
> 1 C2 C3 C4 C5
> `*` 1, 2, 3, 4, 5
> 1\$2\$3\$4\$5
> `-` 1, 2, 3, 4, 5
> 1 K2 K3 K4 K5
> `/` 1, 2, 3, 4, 5
To get the same result by using "/" as a binary infix operator entered using the
keyboard, you also need to use parentheses:
1
2
3
4
>
5
1
(1.10.2.1.8)
120
Entering "/" from a palette does not require parentheses and is analogous to
using "-" as a binary infix operator above:
> 1/ 2/ 3/4/ 5
1
(1.10.2.1.9)
120
Question 3
Use both functional syntax and 2-dimensional math input using the Calculus
palette to compute each of the following derivatives:
• the derivative with respect to x of the general quadratic polynomial
2
a x Cb x Cc;
• the derivative with respect to x of the square of the trigonometric sine of x;
2
• the derivative with respect to x of the trigonometric sine of x ;
• the fourth derivative with respect to θ of 'the trigonometric sine of θ plus the
trigonometric cosine of θ' and explain the result;
• the derivative with respect to θ of 'the square of the trigonometric sine of θ plus
the square of the trigonometric cosine of θ' and explain the result.
>
Page 15 of 18
24-Sep-2016
2
> diff a x Cb x Cc, x
2 a x Cb
Note that this requires parentheses around the polynomial:
d
2
>
a x Cb x Cc
dx
2 a x Cb
(1.10.3.1.1)
(1.10.3.1.2)
2
> diff sin x , x
>
(1.10.3.1.3)
2 sin x cos x
(1.10.3.1.4)
2 cos x2 x
(1.10.3.1.5)
2 cos x2 x
(1.10.3.1.6)
d
2
sin x
dx
> diff sin x
>
2 sin x cos x
2
,x
d
2
sin x
dx
> diff sin θ Ccos θ , θ\$4
sin θ Ccos θ
(1.10.3.1.7)
Note that this requires parentheses around the sum:
d4
>
sin θ Ccos θ
4
dθ
sin θ Ccos θ
(1.10.3.1.8)
This result is the same as the initial expression because sine differentiates to
cosine and cosine differentiates to minus sine, so differentiating sine or cosine
twice produces minus sine or cosine and differentiating sine or cosine four
times takes it back to itself.
2
2
> diff sin θ Ccos θ , θ
0
2
(1.10.3.1.9)
2
The expression sin θ Ccos θ is identically equal to the constant value 1 by
Pythagoras' Theorem and therefore differentiates to 0. Alternatively, the sum
cancels because
d
2
>
sin θ
dθ
2 cos θ sin θ
(1.10.3.1.10)
>
d
2
cos θ
dθ
K2 cos θ sin θ
(1.10.3.1.11)
Question 4
Use either functional syntax or the 2-dimensional math input templates in the
Expression or Calculus palettes, as you prefer.
• Compute the indefinite integral of 'x to the general power n'.
• Compute the derivative of the previous result with respect to x. Is the result what
you would expect? Apply the function simplify to it.
• There is one value of n for which the previous general result is not valid. What is
it? Compute the integral of x to this specific power.
• Compute the derivative of the previous result with respect to x. Is the result what
Page 16 of 18
24-Sep-2016
•
you would expect?
>
n
> int x , x
n C1
x
n C1
(1.10.4.1.1)
> diff (1.10.4.1.1), x
n C1
x
x
(1.10.4.1.2)
> simplify (1.10.4.1.2)
xn
(1.10.4.1.3)
The above integral is not valid for n = K1 because it leads to division by zero,
but
> xK1 dx
>
ln x
(1.10.4.1.4)
1
x
(1.10.4.1.5)
d
(1.10.4.1.4)
dx
Maple tends to avoid negative powers:
> xK1
1
x
(1.10.4.1.6)
Question 5 (non-examinable optional extra)
Use the Maple help to find one or more ways to answer this question. Compute
sin 30° , i.e. the trigonometric sine function of 30 degrees, as elegantly as
possible and with Maple doing all of the work. You need to find a way to convert
degrees to radians or a way to enter degrees as the unit of measurement.
>
Either
> sin convert 30, units, degrees, radians
1
2
or, more elegantly,
> with Units Natural :
and then any of the following:
> sin 30 degrees
1
2
(1.10.5.1.1)
(1.10.5.1.2)
> sin 30 degree
Page 17 of 18
(1.10.5.1.3)
24-Sep-2016
1
2
(1.10.5.1.3)
1
2
(1.10.5.1.4)
> sin 30 deg
Page 18 of 18
24-Sep-2016
```
Related documents