MATH 375 Assignment 2¶
By Brenton LeMesurier
Due Friday February 5
Drafts encouraged by Friday January 29, for Python code in particular.
Objectives¶
A test case¶
As a first test case you can use the familiar example \(x - \cos(x) = 0\), which we have seen to have a unique root that lies in the interval \([-1, 1]\).
Here is a definition for the test function \(f\).
Note that I get the cosine function from the module numpy
rather than the standard Python module math
, because numpy
will be far more useful for us, and so I encourage you to avoid module math
as much as possible!
from numpy import cos
def f(x):
return x - cos(x)
Exercise 1¶
The equation \(x^3 -2x + 1 = 0\) can be written as a fixed point equation in many ways, including
\(\displaystyle x = \frac{x^3 + 1}{2}\)
and\(x = \sqrt[3]{2x-1}\)
For each of these options:
(a) Verify that its fixed points do in fact solve the above cubic equation.
(b) Determine whether fixed point iteration with it will converge to the solution \(r=1\). (assuming a “good enough” initial approximation).
Note: computational experiments can be a useful start, but prove your answers mathematically!
Exercise 2¶
a) Show that Newton’s method applied to
leads to fixed point iteration with function
b) Then verify mathematically that the iteration \(x_{k+1} = g(x_k)\) has super-linear convergence.
Exercise 3¶
a) Create a Python function for Newton’s method, with usage
(root, errorEstimate, iterations, functionEvaluations) = newton(f, Df, x_0, errorTolerance, maxIterations)
(The last input parameter maxIterations
could be optional, with a default like maxIterations=100
.)
b) based on your function bisection2
create a third (and final!) version with usage
(root, errorBound, iterations, functionEvaluations) = bisection(f, a, b, errorTolerance, maxIterations)
c) Use both of these to solve the equation
i) with [estimated] absolute error of no more than \(10^{-6}\), and then
ii) with [estimated] absolute error of no more than \(10^{-15}\).
Note in particular how many iterations and how many function evaluations are needed.
Graph the function, which will help to find a good starting interval \([a, b]\) and initial approximation \(x_0\).
d) Repeat, this time finding the unique real root of
Again graph the function, to find a good starting interval \([a, b]\) and initial approximation \(x_0\).
e) This second case will behave differently than for \(f_1\) in part (c): describe the difference. (We will discuss the reasons in class.)
This work is licensed under Creative Commons Attribution-ShareAlike 4.0 International