Description
β
π(πΌ,π₯) = π₯3 β πΌπ₯ + 2
by using fixed-point iterations.
1. Define a Julia function for π and draw it; make an interactive visualization as πΌ changes. [Make sure to fix the plot limits so as to be able to see whatβs going on.]
2. When πΌ varies, the number of real roots can change. For which approximate value of πΌ does the number of real roots change? How many real roots are there?
3. When πΌ = 2.5, approximately where are the roots? From now on fix πΌ to this value.
The simplest thing we can try is π(π₯) = π₯ + π(πΌ,π₯), since then a fixed point of π is a root of π.
4. Plot the function π(π₯) and the function π¦ = π₯. Taking into account the results stated in the slides, which root do you expect to be able to calculate by iterating π? Fix an initial condition and show that it does converge there.
5. What is the rate of convergence to that root?
6. What happens with the initial condition π₯ = 1.1? Why?
7. Draw a cobweb diagram to illustrate this behaviour.
8. By using algebraic transformations, find fixed-point iterations π that converge to the other two roots.
There are two alternative approaches you can take here. The first is to find other iteration schemes, π₯ = β(π₯) by algebraically rearranging π(πΌ,π₯) = 0 to isolate an π₯ on one side. The second is to introduce the generalized function π(π,π₯) βΆ= π₯+ππ(π₯). Make an interactive plot of π(π,π₯) and π¦ = π₯ as π varies. What do you notice about the slope of π(π,π₯) at the fixed points as π changes? Can you use this to change the stabilities of the fixed points in the iteration scheme?
9. (Extra credit) Call πΌπ the critical value of πΌ at which the number of roots changes. [This is called a bifurcation point.] Find πΌπ numerically.
Exercise 2: Defining a type for Polynomials Although we have already used polynomials, we havenβt had a way to say βthis object is a polynomialβ. For this we need to define a new type!
1. Define a type Polynomial to represent a polynomial. It should have fields degree and coefficients.
2. Write a constructor function with the same name (Polynomial) that accepts a vector of coefficients and builds a Polynomial object whose degree it automatically calculates.
3. Write a show method to display the polynomial nicely.
4. Write a function to evaluate the polynomial at a point x, as follows:
function (p::Polynomial)(x)
# fill in end
Then if you have an object p of type polynomial, writing e.g. p(3) will evaluate that polynomial at the value 3.
5. Write a function derivative that takes a polynomial and returns a new polynomial that is its derivative.
6. Julia contains a module Test (in the standard library β no installation required) for testing that code is correct.
Write a few tests of the functionality you have defined using tests of the form
@test a == b
E.g. to test the sum of two Polynomials you can write
@test Polynomial([1, 2]) + Polynomial([3, 4]) == Polynomial([4, 6]) When you run these tests, you should see the message Test passed.
To create the tests, do the calculations by hand.
Exercise 3: Newton method
1. Write a function newton to implement the Newton method. It should take a function π, its derivative πβ² and an initial guess π₯0. It should terminate when the residual is less than some tolerance, or when the number of iterations is too large.
2. Write a specialised method of newton for polynomials that accepts an object of type Polynomial, written p::Polynomial and calculates its derivative automatically.
3. Taking the same polynomial as in exercise 1, confirm that the Newton method has quadratic convergence by verifying numerically the defining limit.
4. Can you find different roots by taking different initial conditions π₯0? How will you know if/when you have found all of the roots like this?
The Newton method works fantastically well when the starting point is close enough to a root, but can also behave very badly, as follows.
5. How many roots does the function π(π§) = π§3 β 1 have in the complex plane β? Where are they?
6. Calculate those roots using the Newton method with complex starting points π + ππ forming a square grid in the complex plane. Store the imaginary part of the resulting root (or final value, if no root is reached) in a matrix.
7. Plot the matrix with the heatmap function and plot the true roots as points. What kind of object are you seeing? What does this imply for the Newton method? What happens close to the roots?
Exercise 4: Aberth method Newtonβs method only finds one root at a time. The Aberth method calculates them all at once! Given estimates (π§π) for all roots of a polynomial it calculates a new estimate via π§π = π§π β π€π, where
π
π€π =.
β² π πβ π π§πβπ§π In order to guarantee convergence the initial guess must be chosen in a special way. Cauchyβs bound tells us that all the roots of a polynomial π(π₯) = π0 + π1π₯ + β― + πππ₯π must have absolute value less than
ππβ1β£,β£ππβ2β£,β¦,β£π0β£)
π = 1 + max (β£
ππ ππ ππ
and a lower bound of
πΏ =
The starting points should be chosen so that their absolute value lies in between these bounds.
1. Implement a function poly_bounds that takes in a Polynomial and returns πΏ and π.
2. Use poly_bounds to write a function initialize_points that finds a suitable starting group of points. Do this by choosing πs sampled from a uniform distribution over [πΏ,π] and πs sampled from a uniform distribution over [0,2π]. Then calculate π§ = ππππ.
[Hint: The rand() function generates uniform random numbers between
0 and 1. Use rand to write a function uniform(a, b) to generate uniform numbers between π and π.]
3. Implement the Aberth method for a polynomial π which takes in values from initialize_points and terminates either after a certain number of iterations or when a certain tolerance is met. Test your function for the polynomials we have considered so far.
4. Make an interactive visualization of the progress over time on some random polynomials of degree 10 or 20.
5. Find numerically the order of convergence of the method.
6. Try polynomials with multiple roots, such as (π₯2 + 1)3. What happens?
Reviews
There are no reviews yet.