关键词 > Python代写

Homework 3: Root finding

发布时间:2021-02-24

Homework 3: Root finding

Due February 23.


1. Write a program to find the roots of one-dimensional equations using

a) Bisection method and b) Newton-Raphson method.

Test your implementations on the following equations:

(a) A simple test case: x2 = a (choose an a, say 2.0, and solve for (positive) x).

(b) Kepler’s equation, used for determining Solar System orbits:

M = E  - e sin(E).

Here M is the “mean anomoly”, an angle that increases linearly in time; E is the “eccentric anomoly”, the position of the body from the center (not the focus) of the ellipse, and e is the eccentricity of the ellipse. Choose M = 1.5 and e = 0.5 and solve for E in the interval 0 ≤ E < 2π. Try it again for M = 1.5 and e = 0.9, but be careful where you start the Newton-Raphson.

For each attempt, demonstrate how quickly the method converges by plotting the error (i.e., the difference between the current guess and the true answer) as a function of iteration number. I suggest using a logarithmic axis for the error.


2. It is frequently required that the Kepler problem be solved to the max-imum precision available (i.e. to round-off) as quickly as possible. At-tempt to do this with your Kepler solver. Which method, Bisection or Newton-Raphson, is better? Use your solver to plot sin(E) vs. cos(E) for 20 equally spaced values of M between 0 and 2π for an e = 0.9 orbit.