Exercises

Tutorial Exercise 0 - Introduction
Due at 5pm on Friday the 18th of July
(this tutorial is not counted for internal assessment)
Q1. (a) Derive the quadratic formula by completing the square on the following
quadratic equation.
ax2 + bx + c = 0
(b) Prove that the following formula also gives both roots of the quadratic.
x1,2 =
2c
√
−b ± b2 − 4ac
(c) Explain why small values of a or c relative to b could lead to subtractive
cancellation in the two formulas.
(d) Why is the following formula1 a better choice than the two above for
calculating the roots of a quadratic?
i
√
c
1h
q
x1 = , x2 = , where q = − b + sgn(b) b2 − 4ac
a
q
2
Q2. Which of the following expressions is best to use for evaluation of a fourth order polynomial on computer? Justify your answer by counting the operations
used for each.
(a) axxxx + bxxx + cxx + dx + e
(b) ax4 + bx3 + cx2 + dx + e
(c) e + x(d + x(c + x(b + xa)))
Q3. Consider quantities x̂ and ŷ that approximate x and y. Let x and y be
bounds on the magnitudes of the absolute errors in these approximations, so
that
|x − x̂| ≤ x ,
|y − ŷ| ≤ y .
(a) Determine the propagated error under the multiplication operation (i.e.
find a bound for |x · y − x̂ · ŷ|).
(b) Simplify your answer to the previous question by assuming that x y is
small enough to be neglected.
(c) Calculate the values of both your expression from part (a) and your
expression from part (b) for the particular case where
x̂ = 1.538, ŷ = 3.175, x = 0.001, y = 0.005.
1
Note that sgn(b) is the sign of b, i.e. +1 if b ≥ 0, -1 if b < 0.
Lab Exercise 0 - Introduction
Due at 5pm on Friday the 18th of July
(this exercise is not counted for internal assessment)
Q1. Write down the code for a function which calculates the roots of a quadratic.
Specify the quadratic by the coefficients a, b and c (so that the quadratic
being represented is ax2 + bx + c). Your code should use a formula that is
designed to avoid subtractive cancellation.
Q2. The bisection method is designed to find roots of a function. It solves the
following problem:
Given a continuous function f and points a and b, such
that f (a) and f (b) are of opposite sign, we wish to find a
value of x between a and b where f (x) = 0.
The method is very simple - at each step calculate f ( a+b
). If this is the same
2
sign as f (a) then a ← 12 (a + b), otherwise b ← 21 (a + b). The algorithm should
) is smaller than a given tolerance.
stop when f ( a+b
2
(a) Sketch, by hand, a picture illustrating the bisection method in action.
(b) Can there be precisely two roots between a and b?
(c) What happens when there are three roots between a and b?
(d) Consider the equation
x=
√
3
x + 2.
Let the initial values of a and b be 3 and 4 respectively.
i. Write down the resulting a and b values from three steps (iterations)
of the bisection method.
ii. √
Write down a function that uses the bisection method to solve x =
3
x + 2, where a = 3 and b = 4. Your function should stop when
|f ( a+b
)| < 10−4 .
2
iii. Enter and execute your function on computer, then write down the
approximate solution generated.
Tutorial Exercise 1 - Iterative Methods
Due at 5pm on Friday the 25th of July
Q1. Using
f 0 (s) ≈
and
xc − x b
xb − x a
xb − s ≈ (xa − s) f 0 (s)
derive Aitken’s approximation
s ≈ x ∗ ≡ xa −
(xb − xa )2
.
xc − 2xb + xa
Q2. Consider the equation x = e−x .
(a) Confirm that 0.567143 is an approximate solution to this equation by
evaluating e−0.567143 on your calculator.
(b) Again using your calculator, find xb and xc using the S.I.M., starting
with xa = 0.5.
(c) Calculate x∗ using the above expression.
(d) Calculate xd = f (xc ) using the standard iteration method. Is xd a better
or worse approximation to the solution than x∗ ?
Q3. It can be shown that
x∗n − s
= 0,
n→∞ xn − s
lim
where x∗n is the nth approximate solution calculated by Aitken’s method. What
does this say about Aitken’s ∆2 method compared to the S.I.M.?
Q4. (a) Could the bisection method be used to solve equations of the form
f (x) = x? Explain how. What circumstances could prevent your scheme
from being applied?
(b) Could the S.I.M. and Aitken’s ∆2 method be used to solve equations
of the form f (x) = 0? Explain how. When might your scheme fail to
produce the correct answer?
Lab Exercise 1 - Iterative Methods
Due at 5pm on Friday the 25th of July
Q1. Consider the equation
x = e−x ,
0.5 ≤ x ≤ 0.7,
which has the solution x = 0.5671432904... Let x0 = 0.5.
(a) Write down x0 through to x25 using the S.I.M., showing six digits after
the decimal place.
(b) Write down the first two approximations using Aitken’s Method, also
showing six digits after the decimal place.
(c) Write down the number of iterations and the number of evaluations of the
function f that each method requires to converge to six figure accuracy
in x.
(d) How many iterations and evaluations of f does the bisection method
require to converge to six figure accuracy for this problem?
Q2. Consider the function
g(x) = x − x1/3 − 2.
We wish to find the root of g(x) that is near to x = 3 using the standard
iterative method. Clearly g(x) = 0 needs to be rearranged to be in the form
f (x) = x if the S.I.M. is to be applied.
(a) Give two candidate functions for f (x) (hint: there are two x’s in the
expression).
(b) Show that the following function is also valid. Do this by substituting the
following function into f (x) = x and rearranging to arrive at g(x) = 0.
f (x) =
6 + 2x1/3
3 − x−2/3
(c) Write down x1 through to x9 , starting with x0 = 3, for each of the three
f (x) functions.
(d) Briefly comment on the three choices of f (x) based on the results of the
previous question.
Tutorial Exercise 2 - Newton’s Method
Due at 5pm on Friday the 1st of August
Q1. Show that Aitken’s approximation
s ≈ x ∗ ≡ xa −
(xb − xa )2
xc − 2xb + xa
can be expressed using ∆ notation as
x∗ = x a −
(∆xa )2
.
∆2 x a
Q2. Show that Newton’s Method gives the following iterative equation for finding
roots of the function g(x) = x − x1/3 − 2:
xn+1 =
6 + 2 xn (1/3)
(−2/3)
3 − xn
Recall that this expression was used in Lab Exercise 1 with the S.I.M.
Q3. Recall that in Lab Exercise 1 we compaired convergence of the S.I.M., Aitken’s
method and the bisection method for the equation x = e−x on the interval
0.5 ≤ x ≤ 0.7.
(a) Write down the iterative step of Newton’s method for this problem (substituting an appropriate f (x) into the standard expression and simplifying where possible).
(b) Calculate two iterations of Newton’s method using this equation, starting
with x0 = 0.5.
(c) Does Newton’s method converge faster than the other methods?
Q4. Write an algorithm for Newton’s method. Your algorithm should:
• Terminate successfully if |f (xk )| < , where is a fixed tolerance.
• Terminate if a maximal number of iterations has been reached.
• Check for divergence (i.e. stop with a “failure to converge” error if
|xk+1 − xk | is very large).
Lab Exercise 2 - Newton’s Method
Due at 5pm on Friday the 1st August
Q1. Write a function, together with supporting functions, that implements the
algorithm for Newton’s method from Q4 of Tutorial Exercise 2. Design your
code for easy modification of f (x) and f 0 (x).
Q2. A manufacturer of green plastic lamp shades collects data on distribution
costs. She defines CT as the total distribution cost. She discovers that
CT = p (ex − cos x − sin x)
fits the data well, where she distributes x thousand lamp shade boxes and
where p represents the profit made per thousand boxes exluding distribution
costs. The total profit made is then given by PT = p x − CT . She wants to
calculate the break-even point, where the total profit is zero.
(a) Derive an equation in terms of x that represents the break-even point.
(b) Use your answer to Q1 to find an approximate solution to your equation.
•
•
•
•
Start at x0 = 0.5 (representing 500 boxes).
Use a tolerance of 10−10 (i.e. stop when |f (xk )| < 10−10 ).
Use a maximum of 100 iterations.
Stop with a “failure to converge” message if |xk − xk−1 | > 10.
Q3. Consider
2
f (x) = sin(x) e−x −
1
.
10
(a) Use your answer to Q1 to solve f (x) = 0, with x0 = 1.5 and the other
parameters as in Q2. What are the final values of k and xk ?
(b) What happens when you start at x0 = 0.6? Sketch a graph of f (x) (with
the aid of computer) and use it to explain this behaviour.
Q4. We can approximate f 0 (x) in Newton’s method with the expression
f 0 (x) ≈
f (x + ζ) − f (x)
,
ζ
where |ζ| is small. This may reduce the convergence rate and could cause
stability issues, but we won’t have to calculate the derivative analytically!
(a) Implement this method, writing down the changes to the code from Q1.
(b) Use your implementation, starting at x0 = 1.5 and with ζ = 0.001, to
find an approximate solution to
1
.
10
Leave the other parameters as they were in Q2 and Q3.
2
f (x) = sin(x) e−x −
Tutorial Exercise 3 - Newton’s Method
Due at 5pm on Friday the 8th of August
Q1. Analysis of a radioactive compound results in the following three equations,
where a is the quantity of substance A, b is the quantity of substance B, and
α is the decay rate.
a − b e−α = 5
−a + 2b e−α = 3
b e−2α = 2
(a) Write down the column vector F~ and the matrix J for this problem in
preparation for using Newton’s method.
(b) Show that the matrix equation for Newton’s method, giving ak+1 , bk+1
and αk+1 in terms of ak , bk and αk , can be written as:



ak+1



 bk+1  = 
αk+1
13

−2eαk (−8 + eαk )
.
1
αk
2αk
(8e − 2e + bk αk )
bk

The following matrix inverse may help:

−1
1 −e−α
be−α


 −1 2e−α −2be−α 
0 e−2α −2be−2α


2
1
0

α
α
−e2α 
=  2e 2e
.
1 α 1 α
1 2α
e be −be
b
(c) Using the first two equations, a − b e−α = 5 and −a + 2b e−α = 3, show
that a must be 13. This provides a partial check on the answer to (b).
(d) How might the fact that a must be 13 have been used to simplify the
problem?
(e) Using your answer to (b), perform one iteration of Newton’s method
starting at




10
a0




 b0  =  30  .
1.3
α0
Q2. Use Lagrange Interpolation to find the polynomial of degree two which passes
through the points (a, 0), (b, 0) and (c, yc ). Check that your polynomial satisfies p2 (a) = 0, p2 (b) = 0 and p2 (c) = yc .
Lab Exercise 3 - Newton’s Method
Due at 5pm on Friday the 8th August
Q1. Answer ONE of the following (either part (a) or part (b)):
(a) With a = 13 the system from the tutorial exercise becomes be−α = 8 and
be−2α = 2. In Mathematica we can draw the contours f = 0 and g = 0
of the functions f (b, α) = be−α − 8 and g(b, α) = be−2α − 2 as follows:
Show@Map@
ContourPlot@ #, 8b, 30, 35<, 8Α, 1.3, 1.5<, Contours ® 80<, ContourShading ® False D &,
8b E ^ H-ΑL - 8, b E ^ H-2 ΑL - 2< D D ;
1.475
1.45
1.425
1.4
1.375
1.35
1.325
30
31
32
33
34
35
What does the crossing point of the two lines represent?
(b) Solve, with 10 iterations of Newton’s method, the system in the first
question of tutorial exercise 3.
Q2. A satellite travels in two dimensional circular motion, with position given by
p~ =
"
2π(t − τ )
xτ − r + r cos
T
#
"
2π(t − τ )
, yτ + r sin
T
#!
,
where t is time, and xτ , yτ , τ , r, and T are parameters.
(a) Show that at t = τ , the satellite’s position is p~ = (xτ , yτ ).
p
(b) Show that the velocity vector, d~
, of the satellite at time t = τ is (0, 2πr
).
dt
T
(c) Using the above information it is determined that τ = 57. Additionally
the following positional information is known:
t
x
y
77 87
−3 −4
−9 −8
i. Write down four scalar equations in terms of the remaining four
unknown paramters.
ii. Solve these equations using Newton’s method in MATLAB. Include
both your computer code and the output in your assignment. Use
reasonable guesses for the starting values (e.g. T = 150).
iii. Find the centre of the circular motion.
iv. Find the satellite’s position at t = 0.
Tutorial Exercise 4 - Interpolation,
Numerical Differentiation and Integration
Due at 5pm on Friday the 15th of August
Q1. Answer ONE of the following (either part (a) or part (b)):
(a) The algebraic derivation of b∗ , using matrices, for the least squares regression line y = a∗ + b∗ x yields
xi yi − N x̄ȳ
b = P 2
.
xi − N x̄2
∗
P
We showed in lecture that the numerator is equivalent to the numerator
in the following representation,
∗
b =
P
(xi − x̄)(yi − ȳ)
.
P
(xi − x̄)2
Prove that the denominators are also equivalent.
(b) Prove that with D =
a = ȳ − b x̄.
N
X
i=1
(a + bxi − yi )2 , setting
∂D
∂a
to zero leads to
Q2. Derive the trapezoid rule for integrating ab f (x). Start with n evenly spaced
sample points x1 , . . . , xn where x1 = a and xn = b, and ∀k, xk+1 − xk = h.
Then add up the areas of the trapezoids which are defined, for each k < n, by
the four corner points (xk , 0), (xk , f (xk )), (xk+1 , f (xk+1 )), (xk+1 , 0). Include
an illustration of the trapezoids to support your derivation.
R
Q3. [Challenging] Derive the central difference approximation to f 0 (x) from the
Lagrangian interpolating polynomial, as described in lecture.
Lab Exercise 4 - Interpolation, Numerical
Differentiation and Numerical Integration
Due at 5pm on Friday the 15th of August
Q1. Answer ONE of the following (either part (a) or part (b)):
(a) A deep space probe leaves the solar system. By measuring the delay
between its regular transmissions an estimate of the distance d between
the probe and Earth can be made, giving the following data, where t is
the number of days since the probe exited the solar system.
t, [days]
0
1
2
3
4
5
10
d, [10 km ] 0.8 1.3 1.75 2.2 2.85 3.1
i. Use your own linear regression routine to fit a straight line to this
data. Do not use Fit or polyfit. Hand in your code.
ii. Approximately how far from Earth will the probe be on day 19?
(b) The dizzy-seagull is a rare breed of bird that flies in large circles around
any shiny object. A tugboat captain hopes to find a missing shiny buoy
by tracking a dizzy-seagull’s flight path. He collects the following seagull
positional data:
1.29
0.43 −0.19 −0.11 0.62 1.44
x 1.74
y −8.31 −7.56 −7.46 −8.06 −8.93 −9.4 −9.12
i. Find the Lagrangian polynomial through these data points using Fit
(Mathematica) or polyfit (MATLAB).
ii. Is the polynomial a good representation of the seagulls path?
R √
Q2. Consider the integral s = 01 1 + x5 dx = 1.0746691888481043107276360....
Define Υ(ŝ) ≡ log10 ( |ŝ − s| ) where ŝ is an approximation to s. Then Υ(ŝ)
gives a measure of the order of magnitude of the error in ŝ. Let Tn , Sn and
Gn be the n-point approximations to s using the trapezoid rule, Simpson’s
rule and Gaussian integration respectively.
(a) Are numerical methods needed to calculate the value of this integral?
(b) Write computer code to produce a graph of Υ(Tn ), Υ(Sn ) and Υ(Gn )
versus n for 5 ≤ n ≤ 13 (submit both the code and the graph).
(c) Comment on the relative convergence rates of the three methods.
Q3. The vertical position of a detergent particle in a washing machine is given by
the function f (t) and governed by the following IVP.
cos t
[1 + f (t)] · f 00 (t) − f 0 (t) = √
,
t+1
f (0) = 0, f 0 (0) = 0
Numerically solve the IVP, using your own finite difference scheme, for t in
the interval [0, 10]. Hand in your computer code and the solution.
Tutorial Exercise 5 - Forces
Due at 5pm on Friday the 22nd of August
Q1. A 25, 000 kg barge is pulled by two tugboats as shown. The barge is accelerated in the horizontal x direction at 1 m · s−2 .
Tugboat
30◦
Barge
x
α
Tugboat
Determine
(a) the tension in each of the ropes if α = 45◦ .
(b) the angle α which minimises the tension in the lower rope.
Q2. A movable bin and its contents have a mass of 300 kg.
C
A
0.7 m
B
Jeremy’s
Bins Inc.
1.2 m
Determine the shortest chain sling ACB which may be used to lift the loaded
bin if the tension in the chain is not to exceed 6250 N.
Q3. A machine applies three forces to steady a steel plate while it is being drilled,
as shown in the figure below. Luke, the operator, must apply an equivalent
force when the machine breaks due to his clumsy lever pulling. Determine the
force which Luke must use and its point of application.
40 N
20 N
30 N
y
2m
O
x
3m
Lab Exercise 5 - Forces and Equilibrium
Due at 5pm on Friday the 22nd of August
Q1. Consider three forces F~1 , F~2 and F~3 applied vertically downwards on a steel
plate. Let (x1 , y1 ), (x2 , y2 ) and (x3 , y3 ) be their points of application.
(a) Write a function that accepts the six parameters (|F1 |, x1 , y1 , |F2 |, x2 , y2 ,
|F3 |, x3 , y3 ) and outputs an equivalent system consisting of the single
force F~R applied at (xR , yR ).
(b) Test your function with the situation described in Q3 of Tut Exercise 5.
Q2. Consider the following situation.
5m
Next bird lands here!
0.1 m
1.5 m
Point A
Bird Weight = w
Panda Weight = W
A panda falls off of a branch, but manages to grab and hang on by one paw.
However this weakens the branch, which is almost ready to break at point
A. Some birds notice the situation and amuse themselves by landing one at
a time on the branch, which emits creaking and cracking noises under the
strain. The first bird lands 5 m from A, and the rest land successively 0.1 m
further along from A. The panda has a mass of 20 kg and each bird has a
mass of 0.4 kg.
(a) Write a function that, given n (the number of birds), calculates the
moment about A due to the weight of the panda and the birds..
(b) Let ~n = [1, 2, 3, . . . , 20]. Use your function to calculate m
~ where each
element mi of m
~ is the moment about A due to the panda plus ni birds.
(c) Plot the moment versus the number of birds using your vectors from (b).
(d) Use Fit or polyfit to fit a quadratic m(n) = an2 + bn + c to the data.
(e) Analytically prove that this quadratic represents the exact answer (∀n).
(f) The branch can take a moment of 500N · m before breaking. How many
birds can safely land?
(g) If the birds were to land one atop another, all 5 m from A, how many
could safely land?