Problem1: Newtonβsmethodin1dimension 30points
(a) Newtonβs method for solving a scalar nonlinear equation π (π₯) = 0 requires computation of the derivative of π at each iteration. Suppose that we instead replace the true derivative with a constant value π, that is, we use the iteration scheme:
π₯π+1 =π₯π βπ(π₯π)/π.
i) Under what conditions on the value of π will this scheme be locally convergent? ii) What will be the convergence rate in general?
iii) Is there any value of π that would still yield quadratic convergence?
(b) Write a Python function to implement Newtonβs method in 1d. Your function should take as inputs the 1d function, its derivative, an initial guess and a tolerance for checking con- vergence. Use this function to find the roots of the following functions using Newtonβs method with the provided initial guess.
i) π₯2 β 1 = 0, π₯0 = 106. ii) (π₯β1)4 =0,π₯0 =10. iii) π₯ β cos π₯ = 0, π₯0 = 1.
What is the observed convergence rate of Newtonβs method for each problem? Why does each problem exhibit this convergence rate?
You can compute the rate by using the fact that the error at each iteration ππ = π₯β β π₯π satisfies |ππ+1| / |ππ|π = πΆ. Thus, |ππ+1| / |ππ|π = |ππ| / |ππβ1|π from which you should derive an equation for obtaining π for each iteration. You can use the computed solution in the last iteration as the true solution π₯β and the last of these computed rates to be the rate of convergence.
Problem2: Newtonβsmethodforasystem
Consider the conversion formula from spherical to Cartesian coordinates:
π₯ = π sin π cos π π¦ = π sin π sin π
30points
π§ = π cos π
(a) Writeafunctionnewton(f,J,x0,tol=1e-12,maxit=500)thatimplementsNewtonβs
method generically, with a starting guess of x0.
f is a function that accepts a numpy array π₯ of the current state and returns the function
value π (π₯) as another numpy array. Write f so that π (π₯) = 0 at the sought solution.
J is the Jacobian of f, so given a numpy array x, it returns a Jacobian matrix of the appropriate
2/6
dimensions.
Terminate the iteration once either the residual is smaller than tol or maxit iterations have been performed.
- (b) Β Write a function that, given π₯, π¦, and π§, finds π, π and π, using the Newton implementation from part (a). Do not reimplement Newtonβs method, simply pass in appropriate functions f and J to newton from part (a).
Find a starting guess that leads to convergence in your experiments.
The routine should accept π₯, π¦, π§ in one input vector and return π, π and π in one output vector.
- (c) Β Test your work from (a) and (b) by drawing 10 random vectors from π₯β β R3 usingnp.random.randn and finding their spherical coordinates.
For each case, print the final relative residual βπ₯ β π₯ββ2 / βπ₯ββ2, where π₯ are the Cartesian coordinates corresponding to the spherical coordinates returned by your routine.
Also compare the polar coordinates π€Μ = [πΜ πΜ πΜ]π output by your routine with the true values computed using the formulas:
π = βπ₯2 + π¦2 + π§2 π = a r c c o s ( π§π )
π = a r c t a n ( π₯π¦ )
Let π€ = [π π π]π . For each example, print the relative error βπ€ β π€Μβ2 / βπ€ β2 in your com-puted values. Is this small whenever the residual is small? Why/why not?
H ints:
- Read the documentation for and use np.arctan2 in implementing the formulas to find π, π, and π.
- It is instructive to watch the conditioning of the Jacobian. A singular Jacobian will cause the method to break down or compute inaccurate results. Some starting guesses are more prone to this than others.
Problem3: Chebyshevpolynomials,Vandermondematrices50points
(a) A function πΉπ(π‘) is known to satisfy the Chebyshev three-term recurrence if the following prop- erties hold:
πΉ0(π‘) = 1
πΉ1(π‘) = π‘
πΉπ+1(π‘) = 2π‘πΉπ(π‘) β πΉπβ1(π‘)
3/6
Show that the function
satisfies the Chebyshev three-term recurrence.
H int: Remember the addition formula for cosines:
cos(πΌ + π½) = cos(πΌ) cos(π½) β sin(πΌ) sin(π½).
How would this apply to cos((π + 1) arccos(π‘))?
- (b) Β Deduce that πΉπ(π‘) is a polynomial. This is called the Chebyshev polynomial.
- (c) Β The generalized Vandermonde matrix π for a set of points π₯1,…,π₯π with a set of functions π1,…,ππ is given by
πππ = ππ(π₯π).
Notice that this matrix captures an essential bit of interpolation: it maps coefficients with respect to the functions (ππ) to point values at the points (π₯π):
βπΌπππ(π₯π) = βππππΌπ = (ππΌ)π.
π=1 π=1
Clearly, π β1 describes the reverse process, and the conditioning of π can tell us quite a bit about how well-behaved of an operation interpolation is with respect to the given sets of functions and nodes.
Perform the following steps:
i) Construct π Γ π generalized Vandermonde matrices for π = 5, 10, 15, … , 100.
ii) Plottheconditionnumberofthematrixwithrespecttoπ.foreachofthecasesbelow: i. Equispaced nodes π₯π in the interval [β1, 1] (endpoints included), with the mono-
mials ππ(π₯) = π₯π.
ii. Chebyshev nodes in the range [β1, 1] are given by
π₯π =cos(2π+1π), 2π
with the monomials.
iii. Equispaced nodes π₯π in the interval [β1,1] (again, endpoint included), with the
Chebyshev polynomials πΉπ .
iv. Chebyshev nodes in the interval [β1, 1] (see equation above) with the Chebyshev
polynomials πΉπ .
Your output should include one (clearly labeled) plot as described above showing (and com-
paring) the behavior of the condition number for all four cases.
H int: Use matplotlib.pyplot.semilogy() to plot the values with a linear scale in π on
the π₯ axis and a logarithmic scale for the condition number on the π¦ axis. 4/6
πΉπ(π‘) = cos(π arccos(π‘))
(d) Which of the combinations performs best?
Problem4: Interpolation,NewtonandCubicSpline 40 points (a) Thefollowingformulaiscalledthedivideddifferencesapproachtocomputingthecoefficients
of an interpolating polynomial using Newtonβs polynomials as a basis:
π[π‘1,π‘2,…,π‘π] β π[π‘2,π‘3,…,π‘π] β π[π‘1,π‘2,…,π‘πβ1] π‘π β π‘1
π[π‘π] β π(π‘π)
Prove that, using mathematical induction, that indeed this approach gives the coefficient of the πth basis function using the Newton interpolation polynomial.
- (b) Β Given the three data points (β1, 1), (0, 0), (1, 1), determine the interpolating polynomial of degree 2 (using hand calculations alone and showing all necessary steps) using:
i) Using the monomial basis. ii) Using the Lagrange basis.
iii) Using the Newton basis.
iv) Show that all three representations give the same polynomial. - (c) Β Considerinterpolatingagivensetofdatapoints(π₯π,π¦π),π=1,…,πusingnaturalcubicsplines. Write a code to set up and solve the linear system that performs this interpolation. Plot the resulting cubic spline along with the data. For the data, pick π = 6 random points (π₯π)ππ=1 on [0, 1) with values (π¦π)ππ=1 in [0, 1).
H int: Make sure you sort the π₯πβs after you draw the random numbers and before you start constructing the spline, to avoid confusing your spline construction code.
5/6
Submission Notes
- Theanswertoalltheoreticalproblems,outputofPythoncodeforcomputationalproblems including figures, tables and accompanying analyses should be provided in a single PDF file along with all your code files.
- Youcantypeset(pleaseconsiderusingLATEXifyouchoosetodoso),orwritebyhandand scan/take photographs of solutions for theoretical questions. For scanning or photography, please put in the extra effort and provide a single PDF file of your submission.
- For Problem 2, submit your code in one file: problem_2.py. You can use the Python file provided as a boilerplate.
- For Problem 3, submit your code in one file again: problem_3.py. You will of course, copy- paste the functions written in problem_2.py for Gaussian elimination without and with partial pivoting into this file.
6/6




