Question: Please help with this problem, and show your work please. This is all the information that I was given for this assignment. A test case
Please help with this problem, and show your work please. This is all the information that I was given for this assignment.
A test case
As a first test case you can use the familiar example cos()=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 . 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 32+1=0 can be written as a fixed point equation in many ways, including
- =(^3+1)/2 and
- =cube root(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 =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
()=^k-a
leads to fixed point iteration with function
()=((1)+(a/x^(k-1)))/k.
b) Then verify mathematically that the iteration +1=()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
1()=102+sin()=0
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 [,] and initial approximation 0.
d) Repeat, this time finding the unique real root of
2()=^33.3^2+3.631.331=0
Again graph the function, to find a good starting interval [,] and initial approximation 0.
e) This second case will behave differently than for 1 in part (c): describe the difference. (We will discuss the reasons in class.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
