Queen Mary and Westfield College
UNIVERSITY OF LONDON
B.Sc. EXAMINATION
MAS/104 Computational Mathematics II
Summer 1999
The duration of this examination is 2 hours.
This paper has two Sections and you should attempt both Sections. Please read carefully the instructions given at the beginning of each Section.
SECTION A:
This section carries 40 marks and each question carries 4 marks. You should attempt ALL 10 questions.
SECTION B:
This section carries 60 marks and each question carries 20 marks. You may attempt all 4 questions but only marks for the best 3 questions will be counted.
Calculators may be used in this examination but any programming, graph plotting or algebraic facility may not be used. Please state on your answer book the name and type of machine used.
SECTION A
This section carries 40 marks and each question carries 4 marks. You should attempt ALL 10 questions.
Do
NOT
begin each answer in this section on a fresh page. Write the number of the question in the
left
margin.
Write the
Maple
statements necessary to perform each of the following computations:
1.
Generate the sequence consisting of all the integers between 1 and 100 inclusive in reverse order, i.e. 100,99,98,...,3,2,1 (
without
writing every element explicitly).
2.
The variable
L
evaluates to a list containing the element
a
. Delete this element from the list, i.e. construct a copy of the list
L
without the element
a
.
3.
Construct from an arbitrary list
L
the list with the same elements in reverse order.
4.
The variable
S
evaluates to a set of sets. Construct the union (i.e. the set of all the elements) of all the sets in
S
.
5.
Find the number of elements in the largest set in a set
S
of sets.
6.
Define the mapping
E
such that
.
The definition must allow
n
to be symbolic, in which case it will attempt to evaluate the sum symbolically and remain as a symbolic summation if it fails.
7.
Define the mapping
f
such that
and plot it on the domain [-1, 1].
8.
Define a mapping
dfseq
that takes as arguments (
y
,
x
,
n
) an expression
y
that depends on a variable
x
and a positive integer
n
, and returns a sequence of
y
followed by its first
n
derivatives with respect to
x
, e.g.
9.
Evaluate
exactly, and evaluate
numerically, accurate to 15 significant figures,
without
attempting to evaluate it exactly.
10.
Plot the curve in two dimensions defined parametrically by
for
.
SECTION B
This section carries 60 marks and each question carries 20 marks. You may attempt all 4 questions but only marks for the best 3 questions will be counted.
Begin each answer in this section on a fresh page. Write the number of the question at the
top
of
each
page.
Except in Question 1, all
Maple
functions and procedures
must
check that their arguments are of the correct types, and they should declare and use local variables where appropriate.
Write the
Maple
statements necessary to perform the following computations:
1.
A point
in two dimensions is defined, in terms of a parameter
, to have Cartesian coordinates (
) such that
, where
.
(a) [3 marks] Load the
plots
package, and set the default for two-dimensional plotting so that the scaling is the same in all directions and no axes are plotted.
(b) [2 marks] Write a mapping
r
that implements the above definition of
r
as a function of
.
(c) [2 marks] Write a mapping
S
that returns a plot of the locus of
as defined above for
.
(d) [2 marks] Write a mapping L that returns a plot of the straight line from the origin to the point
.
(e) [2 marks] Write a mapping B that combines the curve S and the line L.
(f) [3 marks] Animate the line L tracing out the curve S for
using a total of 32 frames.
(g) [3 marks] Plot the space curve in three dimensions defined in terms of a parameter
to have Cartesian coordinates (
) such that
, where
,
for
, using normal axes through the origin.
(h) [3 marks] Plot the surface in three dimensions defined in terms of parameters
to have Cartesian coordinates (
) such that
,
for
, where
, and
.
2.
(a) [5 marks] Write a procedure called
E2D
that takes as its argument
E
a relative error that must be numerical and returns the corresponding value for
Digits
, by
using exact arithmetic
to compute and return the smallest positive integer
d
such that
.
(b) [15 marks] Write a procedure called
Newton
that takes three arguments (
f
,
x0
,
RelErr
), where
f
must be a mapping (taking one argument, which you are not required to check) and
x0
and
RelErr
must be numerical values. The procedure should find a numerical approximation to a zero of
f
near to
x0
to an estimated maximum relative error
RelErr
by implementing the following algorithm.
1. Determine and set an appropriate value for the precision of the numerical computation, based on the value of
RelErr.
2. Compute the derivative of the mapping
f
.
3. Initialise the variable
to the
floating point approximation
to
x0.
4. Compute
where
f '
denotes the derivative of
f
.
5. If the
magnitude
of the difference between
and
relative
to the
magnitude
of
is smaller than
RelErr
then return the value of
. (You may assume that
will never be zero.)
6. Otherwise, assign the value of
to the variable
and repeat the algorithm from step 4.
3.
[20 marks] Write a procedure called
Area
that takes two arguments (
y
,
var
), where
y
must be a polynomial with numerical coefficients and
var
must have the form
, where
x
is a variable name and
a
and
b
are both numerical. The procedure should calculate a numerical approximation (accurate to the current default precision) to the total geometrical area bounded by the
x
-axis, the graph of
y
(a polynomial in
x
) and the lines
and
. The procedure must regard all areas as positive, regardless of whether the graph is above or below the
x
-axis, by dividing the area into sub-areas bounded by segments of the graph that do not cross the
x
-axis and adding the magnitudes of these sub-areas. (You may assume that the Maple equation solvers return numerical solutions in increasing numerical order.)
4.
[6 marks] Write procedure
N2D
that takes two arguments (
B
,
n
), where
B
must be a positive integer and
n
must be a non-negative integer, and returns the digit sequence that corresponds to the positional representation of
n
in base (radix)
B
. (You may assume
B
< 10.)
[8 marks] Write procedure
D2N
that takes one required argument
B
, which must be a positive integer, followed by a sequence of an arbitrary number of non-negative integers that represent the digits of the positional representation of
n
in base
B
, and returns the corresponding integer.
The procedures should work like this:
>
N2D(10, 123);
>
D2N(10, 1, 2, 3);
[6 marks] Write procedure
ConvertBase(DigitList, OldBase, NewBase)
that calls procedures
N2D
and
D2N
as appropriate to convert a
list
of digits representing a number in base
OldBase
to the
list
of digits representing the same number in base
NewBase
. Do this by applying
N2D
to the value returned by
D2N
, and converting between sequences and lists as necessary. The procedure must check that its arguments have appropriate types. It should work as follows.
>
ConvertBase([1,2,3], 10, 2);
>
ConvertBase([1,1,1,1,0,1,1], 2, 10);