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.