## Description

Question 1 50 marks

Consider the nonlinear equation

f(x) = sin(πx) − x

2 = 0

(a) Can you “solve the equation by hand”, i.e. express the solution x

∗

explicitly in terms of

elementary functions and the constant π?

(b) Show that the equation f(x) = 0 has the same solution(s) as g(x) = x if

g(x) = 1

2π

sin(πx) −

1

2π

x

2 + x

In fact, we can show that for any initial point in (0, 2] the sequence xk = g(xk−1) converges to a

unique solution x

∗

.

(c) Write a function that computes this sequence. Your function should:

– Take for input the an initial point, a maximal number of iterations and a tolerance for

|xk − xk−1| (the estimated error) and for |f(xk)| (the residual).

– Print to the commend window the list of iterates, stopping when either the maximal

number of iterations is reached or the estimated error and the residual are below their

respective tolerance.

– Output the approximate solution, its estimated error and its residual.

(d) If you used a for or while loop in (c), program a function with the same functionality using

recursion (i.e. no explicit loops). If you used recursion in (c) then program a function with

the same functionality using loops (i.e. no recursion).

Name your functions iteration.m for the version with a loop and recursion.m for the version

without.

(e) What happens if you take x0 = 0? What happens if you take x0 < 0?

Question 2 50 marks

(a) Write a function that implements the following pseudo-code:

Input: f, f

0

, x, , N.

Output: x

∗

.

1. Repeat N times:

(a) Set y1 = x.

(b) Take one Newton step, starting from y1. Call the result y2.

(c) Take one Newton step, starting from y2. Call the result y3.

(d) Set

x = y1 −

(y2 − y1)

2

y3 − 2y2 + y1

(e) Display |f(x)|.

(f) If |f(x)| < print “converged!”, break.

2. Output x

∗ = x.

This algorithm is called Steffensen’s iteration.

(b) Write a sctipt to test your function on the problem

exp(−x

2 + x) −

1

2

x = 1.0836 (with initial guess x = 1)

Show that Newton iteration does not converge quadratically, but your new iterative algorithm

does.