12
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. ax 2 + bx + c =0 (b) Prove that the following formula also gives both roots of the quadratic. x 1,2 = 2c -b ± b 2 - 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 formula 1 a better choice than the two above for calculating the roots of a quadratic? x 1 = q a ,x 2 = c q , where q = - 1 2 h b + sgn(b) b 2 - 4ac i Q2. Which of the following expressions is best to use for evaluation of a fourth or- der polynomial on computer? Justify your answer by counting the operations used for each. (a) axxxx + bxxx + cxx + dx + e (b) ax 4 + bx 3 + cx 2 + dx + e (c) e + x(d + x(c + x(b + xa))) Q3. Consider quantities ˆ x and ˆ y 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|≤ y . (a) Determine the propagated error under the multiplication operation (i.e. find a bound for |x · y - ˆ x · ˆ y|). (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, ˆ y =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.

Tutorial Exercise 0 - Introductionjenlow/files/como201_exercises.pdf · Tutorial Exercise 0 - Introduction ... She de nes CT as the total distribution cost. ... Derive an equation

  • Upload
    buikiet

  • View
    220

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Tutorial Exercise 0 - Introductionjenlow/files/como201_exercises.pdf · Tutorial Exercise 0 - Introduction ... She de nes CT as the total distribution cost. ... Derive an equation

Tutorial Exercise 0 - IntroductionDue 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 followingquadratic 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 subtractivecancellation in the two formulas.

(d) Why is the following formula1 a better choice than the two above forcalculating the roots of a quadratic?

x1 =q

a, x2 =

c

q, where q = −1

2

[

b + sgn(b)√

b2 − 4ac]

Q2. Which of the following expressions is best to use for evaluation of a fourth or-der polynomial on computer? Justify your answer by counting the operationsused 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 y that approximate x and y. Let εx and εy bebounds on the magnitudes of the absolute errors in these approximations, sothat

|x− x| ≤ εx, |y − y| ≤ εy.

(a) Determine the propagated error under the multiplication operation (i.e.find a bound for |x · y − x · y|).

(b) Simplify your answer to the previous question by assuming that εxεy issmall enough to be neglected.

(c) Calculate the values of both your expression from part (a) and yourexpression from part (b) for the particular case where

x = 1.538, y = 3.175, εx = 0.001, εy = 0.005.

1Note that sgn(b) is the sign of b, i.e. +1 if b ≥ 0, -1 if b < 0.

Page 2: Tutorial Exercise 0 - Introductionjenlow/files/como201_exercises.pdf · Tutorial Exercise 0 - Introduction ... She de nes CT as the total distribution cost. ... Derive an equation

Lab Exercise 0 - IntroductionDue 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 quadraticbeing represented is ax2 + bx + c). Your code should use a formula that isdesigned to avoid subtractive cancellation.

Q2. The bisection method is designed to find roots of a function. It solves thefollowing problem:

Given a continuous function f and points a and b, suchthat f(a) and f(b) are of opposite sign, we wish to find avalue of x between a and b where f(x) = 0.

The method is very simple - at each step calculate f( a+b2

). If this is the samesign as f(a) then a← 1

2(a+ b), otherwise b← 1

2(a+ b). The algorithm should

stop when f(a+b2

) is smaller than a given tolerance.

(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 equationx = 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

2)| < 10−4.

iii. Enter and execute your function on computer, then write down theapproximate solution generated.

Page 3: Tutorial Exercise 0 - Introductionjenlow/files/como201_exercises.pdf · Tutorial Exercise 0 - Introduction ... She de nes CT as the total distribution cost. ... Derive an equation

Tutorial Exercise 1 - Iterative MethodsDue at 5pm on Friday the 25th of July

Q1. Using

f ′(s) ≈ xc − xb

xb − xa

andxb − s ≈ (xa − s) f ′(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 byevaluating e−0.567143 on your calculator.

(b) Again using your calculator, find xb and xc using the S.I.M., startingwith xa = 0.5.

(c) Calculate x∗ using the above expression.

(d) Calculate xd = f(xc) using the standard iteration method. Is xd a betteror worse approximation to the solution than x∗?

Q3. It can be shown that

limn→∞

x∗

n − s

xn − s= 0,

where x∗

n is the nth approximate solution calculated by Aitken’s method. Whatdoes 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 formf(x) = x? Explain how. What circumstances could prevent your schemefrom being applied?

(b) Could the S.I.M. and Aitken’s ∆2 method be used to solve equationsof the form f(x) = 0? Explain how. When might your scheme fail toproduce the correct answer?

Page 4: Tutorial Exercise 0 - Introductionjenlow/files/como201_exercises.pdf · Tutorial Exercise 0 - Introduction ... She de nes CT as the total distribution cost. ... Derive an equation

Lab Exercise 1 - Iterative MethodsDue 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 afterthe decimal place.

(b) Write down the first two approximations using Aitken’s Method, alsoshowing six digits after the decimal place.

(c) Write down the number of iterations and the number of evaluations of thefunction f that each method requires to converge to six figure accuracyin x.

(d) How many iterations and evaluations of f does the bisection methodrequire to converge to six figure accuracy for this problem?

Q2. Consider the functiong(x) = x− x1/3 − 2.

We wish to find the root of g(x) that is near to x = 3 using the standarditerative method. Clearly g(x) = 0 needs to be rearranged to be in the formf(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 thefollowing 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 threef(x) functions.

(d) Briefly comment on the three choices of f(x) based on the results of theprevious question.

Page 5: Tutorial Exercise 0 - Introductionjenlow/files/como201_exercises.pdf · Tutorial Exercise 0 - Introduction ... She de nes CT as the total distribution cost. ... Derive an equation

Tutorial Exercise 2 - Newton’s MethodDue 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∗ = xa −(∆xa)

2

∆2xa.

Q2. Show that Newton’s Method gives the following iterative equation for findingroots of the function g(x) = x− x1/3 − 2:

xn+1 =6 + 2 xn

(1/3)

3− x(−2/3)n

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’smethod and the bisection method for the equation x = e−x on the interval0.5 ≤ x ≤ 0.7.

(a) Write down the iterative step of Newton’s method for this problem (sub-stituting an appropriate f(x) into the standard expression and simplify-ing where possible).

(b) Calculate two iterations of Newton’s method using this equation, startingwith 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).

Page 6: Tutorial Exercise 0 - Introductionjenlow/files/como201_exercises.pdf · Tutorial Exercise 0 - Introduction ... She de nes CT as the total distribution cost. ... Derive an equation

Lab Exercise 2 - Newton’s MethodDue at 5pm on Friday the 1st August

Q1. Write a function, together with supporting functions, that implements thealgorithm for Newton’s method from Q4 of Tutorial Exercise 2. Design yourcode for easy modification of f(x) and f ′(x).

Q2. A manufacturer of green plastic lamp shades collects data on distributioncosts. 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 andwhere 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 tocalculate 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

f(x) = sin(x) e−x2 − 1

10.

(a) Use your answer to Q1 to solve f(x) = 0, with x0 = 1.5 and the otherparameters 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) (withthe aid of computer) and use it to explain this behaviour.

Q4. We can approximate f ′(x) in Newton’s method with the expression

f ′(x) ≈ f(x + ζ)− f(x)

ζ,

where |ζ| is small. This may reduce the convergence rate and could causestability 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, tofind an approximate solution to

f(x) = sin(x) e−x2 − 1

10.

Leave the other parameters as they were in Q2 and Q3.

Page 7: Tutorial Exercise 0 - Introductionjenlow/files/como201_exercises.pdf · Tutorial Exercise 0 - Introduction ... She de nes CT as the total distribution cost. ... Derive an equation

Tutorial Exercise 3 - Newton’s MethodDue 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 inpreparation 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)

1bk

(8eαk − 2e2αk + bkαk)

.

The following matrix inverse may help:

1 −e−α be−α

−1 2e−α −2be−α

0 e−2α −2be−2α

−1

=

2 1 02eα 2eα −e2α

1beα 1

beα −1

be2α

.

(c) Using the first two equations, a − b e−α = 5 and −a + 2b e−α = 3, showthat 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 theproblem?

(e) Using your answer to (b), perform one iteration of Newton’s methodstarting at

a0

b0

α0

=

10301.3

.

Q2. Use Lagrange Interpolation to find the polynomial of degree two which passesthrough the points (a, 0), (b, 0) and (c, yc). Check that your polynomial sat-isfies p2(a) = 0, p2(b) = 0 and p2(c) = yc.

Page 8: Tutorial Exercise 0 - Introductionjenlow/files/como201_exercises.pdf · Tutorial Exercise 0 - Introduction ... She de nes CT as the total distribution cost. ... Derive an equation

Lab Exercise 3 - Newton’s MethodDue 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 andbe−2α = 2. In Mathematica we can draw the contours f = 0 and g = 0of 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 ;

30 31 32 33 34 35

1.325

1.35

1.375

1.4

1.425

1.45

1.475

What does the crossing point of the two lines represent?

(b) Solve, with 10 iterations of Newton’s method, the system in the firstquestion of tutorial exercise 3.

Q2. A satellite travels in two dimensional circular motion, with position given by

~p =

(

xτ − r + r cos

[

2π(t− τ)

T

]

, yτ + r sin

[

2π(t− τ)

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τ ).

(b) Show that the velocity vector, d~pdt

, of the satellite at time t = τ is (0, 2πrT

).

(c) Using the above information it is determined that τ = 57. Additionallythe following positional information is known:

t 77 87x −3 −4y −9 −8

i. Write down four scalar equations in terms of the remaining fourunknown paramters.

ii. Solve these equations using Newton’s method in MATLAB. Includeboth your computer code and the output in your assignment. Usereasonable 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.

Page 9: Tutorial Exercise 0 - Introductionjenlow/files/como201_exercises.pdf · Tutorial Exercise 0 - Introduction ... She de nes CT as the total distribution cost. ... Derive an equation

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 re-gression line y = a∗ + b∗x yields

b∗ =

xiyi −Nxy∑

x2i −Nx2

.

We showed in lecture that the numerator is equivalent to the numeratorin the following representation,

b∗ =

(xi − x)(yi − y)∑

(xi − x)2.

Prove that the denominators are also equivalent.

(b) Prove that with D =N∑

i=1

(a + bxi − yi)2, setting ∂D

∂ato zero leads to

a = y − b x.

Q2. Derive the trapezoid rule for integrating∫ ba 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, bythe four corner points (xk, 0), (xk, f(xk)), (xk+1, f(xk+1)), (xk+1, 0). Includean illustration of the trapezoids to support your derivation.

Q3. [Challenging] Derive the central difference approximation to f ′(x) from theLagrangian interpolating polynomial, as described in lecture.

Page 10: Tutorial Exercise 0 - Introductionjenlow/files/como201_exercises.pdf · Tutorial Exercise 0 - Introduction ... She de nes CT as the total distribution cost. ... Derive an equation

Lab Exercise 4 - Interpolation, NumericalDifferentiation 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 delaybetween its regular transmissions an estimate of the distance d betweenthe probe and Earth can be made, giving the following data, where t isthe number of days since the probe exited the solar system.

t, [days] 0 1 2 3 4 5d, [1010km ] 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 thisdata. 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 aroundany shiny object. A tugboat captain hopes to find a missing shiny buoyby tracking a dizzy-seagull’s flight path. He collects the following seagullpositional data:

x 1.74 1.29 0.43 −0.19 −0.11 0.62 1.44

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?

Q2. Consider the integral s =∫ 10

√1 + x5 dx = 1.0746691888481043107276360....

Define Υ(s) ≡ log10( |s − s| ) where s is an approximation to s. Then Υ(s)gives a measure of the order of magnitude of the error in s. Let Tn, Sn andGn be the n-point approximations to s using the trapezoid rule, Simpson’srule 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 bythe function f(t) and governed by the following IVP.

[1 + f(t)] · f ′′(t)− f ′(t) =cos t√t + 1

, f(0) = 0, f ′(0) = 0

Numerically solve the IVP, using your own finite difference scheme, for t inthe interval [0, 10]. Hand in your computer code and the solution.

Page 11: Tutorial Exercise 0 - Introductionjenlow/files/como201_exercises.pdf · Tutorial Exercise 0 - Introduction ... She de nes CT as the total distribution cost. ... Derive an equation

Tutorial Exercise 5 - ForcesDue at 5pm on Friday the 22nd of August

Q1. A 25, 000 kg barge is pulled by two tugboats as shown. The barge is acceler-ated in the horizontal x direction at 1 m · s−2.

Barge

Tugboat

Tugboat

α

30◦x

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.

Jeremy’sBins Inc.

B

C

1.2 m

A

0.7 m

Determine the shortest chain sling ACB which may be used to lift the loadedbin 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 equivalentforce when the machine breaks due to his clumsy lever pulling. Determine theforce which Luke must use and its point of application.

2 m

40 N

20 N30 N

Ox

y

3 m

Page 12: Tutorial Exercise 0 - Introductionjenlow/files/como201_exercises.pdf · Tutorial Exercise 0 - Introduction ... She de nes CT as the total distribution cost. ... Derive an equation

Lab Exercise 5 - Forces and EquilibriumDue at 5pm on Friday the 22nd of August

Q1. Consider three forces ~F1, ~F2 and ~F3 applied vertically downwards on a steelplate. 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 ~FR applied at (xR, yR).

(b) Test your function with the situation described in Q3 of Tut Exercise 5.

Q2. Consider the following situation.

Point A

1.5 m

Bird Weight = w

Panda Weight = W

5 m0.1 m

Next bird lands here!

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 pointA. Some birds notice the situation and amuse themselves by landing one ata time on the branch, which emits creaking and cracking noises under thestrain. The first bird lands 5 m from A, and the rest land successively 0.1 mfurther along from A. The panda has a mass of 20 kg and each bird has amass of 0.4 kg.

(a) Write a function that, given n (the number of birds), calculates themoment 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 eachelement 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 manybirds can safely land?

(g) If the birds were to land one atop another, all 5 m from A, how manycould safely land?