0% found this document useful (0 votes)
8 views2 pages

Assignment 02

The document outlines coursework assessment exercises for the University of Nottingham's Numerical Methods and Numerical Mathematics modules, focusing on implementing numerical methods using Matlab. It includes specific tasks such as creating functions for Newton's and Secant methods, testing convergence, and analyzing results with provided parameters. The assignment is marked out of 100, with detailed requirements for each exercise, including error handling and output formatting.

Uploaded by

sharmasnigdha04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Assignment 02

The document outlines coursework assessment exercises for the University of Nottingham's Numerical Methods and Numerical Mathematics modules, focusing on implementing numerical methods using Matlab. It includes specific tasks such as creating functions for Newton's and Secant methods, testing convergence, and analyzing results with provided parameters. The assignment is marked out of 100, with detailed requirements for each exercise, including error handling and output formatting.

Uploaded by

sharmasnigdha04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

University of Nottingham

School of Mathematical Sciences

Numerical methods/Numerical Mathematics

The following exercises are to be used for coursework assessment in the modules Numerical methods
and Numerical mathematics. Credit will be given for relevant working associated with solving the
problems as well as the answer. The Matlab output and print outs of any M-files used should be
submitted, firmly attached to a completed Coursework Submission Sheet and in accordance with the
instructions given on that sheet. The style and efficiency of your programs is important. A barely-
passing script will include attempts to write programs which include some of the correct elements
of a solution. A borderline first-class script will include working code that neatly and efficiently
implements the relevant algorithms, and that shows evidence of testing. An indication is given of the
approximate weighting of each question by means of a figure enclosed by square brackets, e. g. [2].

This assignment is marked out of 100

1. Write a function M-file called newton.m that implements Newton’s method to find a zero of a
function f , using the following prototype
function [x , res , xvec , resvec ] = newton (f , df , x0 , maxiter , tol )

Your function should have the following arguments:


• A function handle f for the function f .
• A function handle df for the function f 0 .
• An initial guess x0.
• The maximum number of iterations allowed, maxiter.
• The required tolerance tol.
Let {xk } be a sequence generated by Newton’s method and let x∗ be a root of f . Your function
should return
• A variable x containing an approximation to x∗ .
• A variable res containing the residual |f (x)| evaluated at the approximate solution x.
• A vector xvec containing {xk }, including initial guess and final approximation.
• A vector resvec of the same dimension of xvec, containing {|f (xk )|}.
Your function should also satisfy the following requirements:
• At each iteration, the function should print k, xk , |f (xk )| and |xk+1 −xk | (browse the doc-
umentation of Matlab’s in-built command fprintf to print formatted output on screen).
• The iterations should terminate if the number of iterations exceeds maxiter or if the
distance between two successive approximations is less than tol.
• The function should perform error checks on maxiter and tol.
• The function should print an output message stating whether convergence has been
achieved or not.
[25]

2. Use your newton function to compute 10 10 with an error less than or equal to the machine
accuracy m . No analytical proof of convergence is required in this question. Check your ap-
proximation using Matlab’s in-built function nthroot. [5]

3. Show that newton exits with an error if users provide inadmissible values of maxiter or tol. [5]

4. Let f : R → R be defined by

f (x) = cosh x + cos x − γ, γ≥2

and let x∗ be the root of f .


(a) Let γ = 3 and let x∗ be the non-negative root of f . Prove that Newton’s method applied
to f converges quadratically to x∗ for sufficiently close initial guesses x0 . You may use
without proof any theorem in the lecture notes. [15]

(b) Let γ and x∗ be as in part (a). Use your function newton to provide numerical evidence
that Newton’s method applied to f converges quadratically to x∗ . [10]

(c) Use newton to approximate x∗ for γ = 2, using at most 20 iterations with a tolerance
m . Do the iterations converge? Plot, on the same graph, the residuals {|f (xk )|} as a
function of k for γ = 2 and γ = 3, using a logarithmic scale for the y axis. Comment on
your results. [10]

5. Write a function M-file called secant that implements the Secant method to find a zero of a
function f , using the following template
function [x , res , xvec , resvec ] = secant (f , x0 , x1 , maxiter , tol )

where all arguments are as in newton, except for x1, which is the Secant method’s second
guess. [20]
6. Use secant to approximate a root of f (x) = x10 − 10, with initial guesses x0 = 4, x1 = 3,
and tolerance
√ 10−5 , and provide numerical evidence that the method converges to order q =
(1 + 5)/2. [10]

You might also like