Coursework 2: Numerical Solution of equations
Submission: All solutions should be submitted on Moodle only and submitted to the Group Folder
for your Workshop Group. Submissions should include:
R script. le (XXX.R) { This should include all R code used in the coursework and the marker
should be able to open and run your R le without any other les.
pdf of solutions (XXX.pdf) { Typed solutions to the coursework questions. You may use the package
of your choice to produce the solutions (for example, LATEX or Word) but solutions must be typed
up.
For questions which state "Write a function :::", you are expected to provide R code to implement the
function and these should be provided in the R script. le. I have denoted the questions with [R].
For all other questions, you may make use of R functions but are not required to produce R code. However,
answers should be provided in the pdf of solutions with mathematical workings included if appropriate.
Only two les should be submitted and the le names must be of the form. XX YYYYYYYY ZZZZ.R
and XX YYYYYYYY ZZZZ.pdf, where XX denotes workshop group number (not lab group),
YYYYYYYY denotes your student number and ZZZZ denotes your name. For example, if you are John
Smith with student number 38009152 and in workshop W3, then your lenames should be:
W3 38009152 JohnSmith.R and W3 38009152 JohnSmith.pdf
Failure to follow the above procedures will lead to mark deductions.
Deadline: 17.00 on Friday 16 February (Week 15)
Consider the equation
f(x) = sin(x3) exp( x):
1. [R] Write an R function f to compute f(x) given input x. [1 mark]
2. Plot the function f with suitable axes labels on the interval [0; ], include the plot in your solutions.
[2 marks]
3. Use the Golden Section function provided in golden.R to estimate the minimum of f(x) on the
interval [0; ].
Note an appropriate initial interval of width at least 0.2 needs to be chosen based upon the plot of
f to initiate the Golden Section search for the minimum. [2 marks]
4. [R] Adapt the Golden Section function to estimate the maximum of f(x) on the interval [0; ] and
call the function Golden maxima. Provide the R code. [2 marks]
5. Use the your function to estimate the maximum of f(x) on the interval [0; ].
Note an appropriate initial interval of width at least 0.2 needs to be chosen based upon the plot of
f to initiate the Golden Section search for the maximum. [2 marks]
Let h(x) = f0(x). Note that maxima and minima of the function f correspond to turning points and
solve h(x) = 0.
6. [R] Compute h(x) and write an R function h to compute h(x) given input x. [3 marks]
7. [R] Write an R function, called secant to compute solutions of h(x) = 0. [6 marks]
The function should return as output, (xn;h(xn)) (n = 0;1;:::) used in the estimation of x which
solves h(x ) = 0.
8. Using x0 = 1:9 and x1 = 1:95, estimate the local maxima of the function f( ) in the vicinity of
x = 2. [2 marks]