You are on page 1of 8

Computational Mathematics

List of Projects
There are two categories of projects, one for homework, each has 5 points.
The other one is a final project. It has 30 points
1

Homework

Due Date: Oct. 10, 2015


1. Write a program to solve the Wilkinson problem:
f (x) :=

20
Y

(x i) + x20

i=1

Input: , output, the largest-in-magnitude 6 roots.


2. Solve the problem of the rod system (QSG pp. 74, Ex. 2.9)

Homework: Deep Diving in the Mandelbrots Fractal

Due Date: Oct. 10, 2015


In this problem, you will draw a fractal.
Speaking of iterative algorithm, it is an important question to ask whether the iteration is convergent. For a linear iteration like
zn+1 = a zn + b
(a, b, {zn } are complex) it is easy to answer that the
sequence is convergent if |a| < 1 and divergent if
|a| > 1. One may draw the convergence region for
a in the complex plane that collects all choices of a
that makes the iteration convergent, and one get a
unit disk.
However, when the iteration involves nonlinear
term, the region of convergence can become extremely complicated. Consider one of the simplest
nonlinear iterations
z0 = 0
zn+1 = zn 2 + c.

Fig. 1: The first visualization of the Mandelbrot set


(1978).

For what c C does the sequence generated from


the iteration stay bounded? Such collection of c is
the Mandelbrot set M , which is a fractal. Here are some observations: for small c (|c| < 14 ) the iteration is
convergent; for |c| > 2, the iteration sends {zn } to infinity; for intermediate c, the sequence will also blow to

infinity whenever |zk | > 2 for some k. (Can you show them?) For the visualization of the Mandelbrot set,
consider the integer-valued function
o
n
(

c
/M
min k |zk (c)| > 2
, where {zk (c)} denotes the sequence generated by
u(c) =
0
cM
(
z0 (c) = 0
zn+1 (c) = (zn (c))2 + c.
That is, u(c) records the iteration number when the sequence escapes the circle of radius 2.
Your assignment Write a MATLAB function m-file mandelbrot.m and a MATLAB script prob2.m.
The mandelbrot function you write takes the form
mandelbrot.m
function mandelbrot(x0,y0,w0)
% Write your code here...
%
end

and the script prob2 will be


prob2.m
% Problem 2 Mandelbrot set
x0 = -1.768607;
y0 = -0.002229;
w0 = 0.000003;
mandelbrot(x0,y0,w0)

Your function mandelbrot(x0,y0,w0) needs to create a figure showing u(c) for c in the square [x0
w0 , x0 + w0 ] [y0 w0 , y0 + w0 ] of the complex plane.
Specifically, partition [x0 w0 , x0 + w0 ] [y0 w0 , y0 + w0 ] into 500 500 pixels and create a complex
matrix C representing the coordinate of each pixel. Initialize an all-zero matrix Z with the same size as C.
Iterate z z 2 + c elementwise (or pixelwise) for a maximal iteration 500 times. Along the iterations, setup
the matrix U such that Uij = u(Cij ). The whole computation shouldnt take more than 10 seconds typically.
There are numbers of way to visualize the matrix U . You may use imagesc command with your own
choice of colormap. You may also use the code written below.
figure;
% pcolor plot
hp = pcolor(U);
% colormap
c summer = colormap(summer);
my cmap = repmat(c summer([1:end,end:-1:1],:),floor(N/64),1);
colormap(my cmap);
caxis([0,N])
colorbar
set(hp,'EdgeColor','none','FaceColor','interp')
set(gcf,'Renderer','zbuffer') % zbuffer renderer interpolates color differently
axis equal
axis off
drawnow

You are encouraged to modify these colormap/plot commands to create even better visualization.
For your own first test, try mandelbrot(-0.5,0,1.5). You can play with viewing in different coordinates
(x0 , y0 , w0 ). You can also share a coordinate with your friends or on Piazza. You can put your favorite
coordinate in your script prob2.m. It is okay if your coordinate is the same as your friends.

Project: Majorana Stars

This project is provided by Albert Chern.


In this problem you will find all complex roots of an arbitrary polynomial.
Using the Newtons method (like the babylonian method)
one can efficiently find a root of a nonlinear function. But it
does not seem immediately obvious how to extend the Newtons
method to find, for example, all complex roots of a high-order
polynomial. But wait, finding numerical values for all complex
roots of a polynomial just amounts to finding all eigenvalues of
a matrix whose characteristic polynomial is the given one. Fortunately, MATLAB has already equipped with powerful eigenvalue solvers. Using MATLAB, finding all 500 complex roots
of a 500-degree polynomial is a piece of cake. The built-in
Fig. 2: Left: n random points sitting unifunction
formly and independently. Right: n
doc roots
random points sitting uniformly and
repelling each other.
finds all n roots for a given (n + 1) polynomial coefficients.
With the power of computation, in this case visualizing roots
of high-order polynomial (which is something you dont have
if you only have bare hands), we can explore something cool.
If I hand you a random polynomial, do you know where the
roots are? More precisely, if a0 , . . . , an are independent normal distributed random complex numbers, where
are the n roots of the polynomial
f (z) = an z n + an1 z n1 + + a1 z + a0 =

n
X

ak z k ?

k=0

Try this out:


>>
>>
>>
>>

a = randn(1,201) + randn(1,201)*1i; % 200 random complex number with normal distributions


z = roots(a); % z are the roots of f(z)
plot(z,'*')
% plot of complex numbers
axis equal

Do you see roots of f tend to sit on the unit circle? An even less obvious example: if a0 , . . . , an are
independent normal distributed random complex numbers, where are the roots of
r
n
X
nk
f (z) =
ak z k ?
k!
k=0

They tend to sit in the unit disk uniformly. And notice that they tend to repel each other, which is what
one wont see if one just throw n points uniformly in the disk independently. The third example: again
a0 , . . . , an are defined as same as the above examples; where are roots of
s 
 
n
X
n
n
n!
k
f (z) =
ak
z ,
=
?
k
k
k!(n k)!
k=0

The roots will scatter over the complex plane. But after one uses the stereographic projection to map the
complex plane to the unit sphere, the roots sit uniformly, repelling each other, on the unit sphere. This last
example is your assignment.
Your assignment Write a MATLAB function m-file named stellar.m taking the form
stellar.m
function stellar(n)
%
%

in which you generate (n + 1) independent normal random complex numbers a0 , . . . , an and find the n roots
z1 , . . . , zn C to
s 
n
X
n
zk .
f (z) =
ak
k
k=0

Your function stellar will need to generate a figure which includes a 3D plot of the stereographic-projection
image of z on the unit sphere.
We will test your function with a few numbers of n less or equal to 500. For example
stellar(20)
stellar(100)
stellar(500)

You may include the following code for 3D plotting. Suppose the vectors x, y, z are the list of x, y, z
coordinates of the 3D points you want to plot,
figure
[sx,sy,sz] = sphere(50); % data of the sphere surface
surf(sx,sy,sz,...
% surface plot a sphere
'FaceColor','w',...
% white sphere
'EdgeColor','none',...
'FaceAlpha',.8,...
% a bit transparent
'FaceLighting','phong') % better light rendering
hold on
plot3(x,y,z,'k*')
% the 3D points
axis equal
axis off
cameratoolbar
% a better 3D nevigation tool than the default one
cameratoolbar('SetMode','orbit')
cameratoolbar('SetCoordSys','none')
camproj perspective
light

Hint For n as large as 500, it might not be a good idea to compute


because

n
k

by dividing n! with k!(n k)!

>> factorial(500)
ans =
Inf

Can you come up with a better way to evaluate

n
k

? You may want to dig into this problem more.

http://en.wikipedia.org/wiki/Stereographic_projection

Homework: Compare performance for classical iterative methods

Many classical iterative methods were aiming to solve the Poisson equation. It is a good project to compare
the performance of classical iterative solvers for solving the Poisson equation in 1D and 2D.

Project: Search Engine: How google works

Google search engine mainly use power method to find the largest eigenvalue of a stochastic matrix. A
stochastic matrix A = (pij )nn is also called transition matrix, which satisfies
pij 0,
P

j pij = 1.
The search engine is modeled by a graph (V, E). The vertices V are those web pages containing key words
in the inquiry sentence. At node j (page j), let Nj denote the number of pages that j is linked to (out-link).
Let pij = 1/Nj if there is a link from j to i. The edges E = {(i, j)} denote those nonzero links from j to i.

Project: Find the map of the locations of cities from their pair distances

This project is provided by Albert Chern.


Multidimensional Scaling (MDS) roots in psychology [YH41] which aims to recover Euclidean coordinates
given pairwise distance metrics or dissimilarities. It is equivalent to principal component analysis (PCA)
when pairwise distances are Euclidean. In the core of theoretical foundation of MDS lies the notion of
positive definite functions [Sch37, Sch38a, Sch38b] (or see the survey [Bav11]) which has been the foundation of the kernel method in statistics [Wah90] and modern machine learning society (http://www.kernelmachines.org/). In this project, we study classical MDS, or metric Multidimensional scaling problem. The
problem of classical MDS or isometric Euclidean embedding: given pairwise distances between data points,
can we find a system of Euclidean coordinates for those points whose pairwise distances meet given constraints? The forward problem: given a set of points x1 , x2 , ..., xn Rp , we can compute the pairwise
distances
d2ij := kxi xj k2 , 1 i, j n
Now we are considering the inverse problem: given {dij }nn , find a {xi }i = 1n in Rp satisfying the relations
above. Clearly the solutions are not unique as any Euclidean transform on {xi } gives another solution. The
dimension p is also not unique. You can always imbed the data in higher dimensions and make a rotation
to get another set of solution in high dimensions. We want to choose smallest dimension p. General ideas of
classic (metric) MDS is: we express X = [x1 , , xn ]pn .
(i) transform squared distance matrix D = [d2ij ] to an inner product form K = X T X;
(ii) perform the eigen-decomposition for this inner product form.
More precisely,
1. Given X = [x1 , ..., xn ]pn given K := X T X  0.
2. Express D = (d2ij )nn in terms of K:
D = k 1T + 1 kT 2K,
where 1 = (1, ..., 1)T Rn , k = diag(Kii ) = (kxi k2 )n1 . This is derived from
d2ij = (xi xj )T (xi xj ) = xTi xi + xTj xj 2xTi xj .
5

3. Express K (with K 1 = 0) in terms of D:


1
K = H D HT
2
where H = I

1
n

1 1T , called centering matrix.

4. Splitting a semi positive definite matrix K = X T X


We can perform eigen-expansion of K: K = V nn V T , where V is orthogonal, i.e. V T V = I
and = diag(1 , ..., n ), i 0.
Split K into
K = X T X, X = 1/2 V T
We summarize the above discussion by the following MDS algorithm.
Algorithm 1 Classical MDS Algorithm
1: Input: (Dij )nn
2: Output: Yk := [y1 , ..., yn ]kn with Yk 1 = 0
1
3: Compute K = 12 H D H T , where H = I n
1 1T
T
4: Decompose K = V V
1/2
5: Choose top k nonzero eigenvalues and define Yk = k V T , where V = [v1 , , vn ]nn , k =
diag(1 , ..., k , 0..., 0).
hp
i
p
YkT =
1 v1 , , k vk , 0, , 0
nn

In the class website you will find a file


dist data.mat, in which two variables is given D
(11-by-11 matrix) and cityname (cell array). The
cell array cityname contains the name of 11 US

cities, and the matrix D is the data where


Dij = distance between city i and city j.
Your Assignment Write a script m-file prob1.m,
which will create a plot of points which are the
computed city locations on the plane. In the code
you will need to load the data file by the command
load('dist data.mat'), where dist data.mat is
in your folder; in particular remember to include
it when you zip the submission file. On the plot
created, label the city names at the plotted points,
which can be done by the command text( ). You might find functions svd, svds useful.
The resulting plot may be different from the US map we are familiar with by a rotation and a reflection
(linear transformations that keep mutual distances unchanged).
Note The result may still exhibit dislocation because we did not assume the earth is spherical. This
algorithm is particularly useful in data visualization such as visualizing clusters of friends from Facebook
data. It is also very useful for compressing data from high to low dimensional subspace without loosing much
information.

Project: Julia Set

In this project, you will draw Julia set on the complex plane. Consider the complex Newtons iterative map
g (z) = z P (z)/P0 (z), where P (z) := z 3 + ( 1)z . Notice that there are three roots of P (z) = 0.
A region is called the basin of a root z0 if each point inside is attracted to z0 through Newtons iteration.
To find the basin region of z0 , you may partition your domain into N N grid points. You may check the
property of each points under Newtons iteration. You then identify each point as (i) in one of the basins, or
(ii) outside the basin (i.e. Newtons iteration does not converge). The complementary of the basins is called
a Julia set. It is a fractal set. Plot this Julia set as a function of for proper range of . You may plot the
orbits for those points on the Julia set. You may also find some reference to figure out how to plot the Julia
set more efficient and more accurately.
Ref. H.-O. Peitgen and P.H. Richter, The beauty of fractals, Springer.

Project: Inverted Pendulum

This project is provided by Albert Chern.


In this problem you will solve an ODE numerically by MATLAB.
Consider the ODE which describes the motion of a pendulum (as
shown in the figure)

00

(t) = (1 + f (t)) sin((t))


(0) = 2/3, 0 (0) = 0

0 t tmax
Here (t) is the angle at time t the pendulum made with the vertical
line, whose acceleration 00 (t) (angular acceleration) is projected from the
gravitational acceleration, assuming that the length of pendulum is 1 and
the gravity is 1 plus an extra vertical force f (t).
For a gravity driven pendulum (f (t) = 0), it swings back and forth
about the central bottom = 0. An interesting fact is that when the
external force f (t) is highly oscillatory, the pendulum may swing back
and forth about the central top = , as if the pendulum is inverted.
Your Assignment Write an m-file prob3.m, which can be a script or a
function with no input argument. In prob3.m you will solve the pendulum
ODE using ode45 with tmax = 20 twice: first with f (t) = 0, next with
f (t) = 500 cos(50t). Create the plots of solutions (t) of both cases, plotted in a single axes. Your figure
should include a clear x-label, y-label and a legend that indicates which curve correspond to which case. The
MATLAB functions xlabel, ylabel, legend, title are useful. You may write auxiliary m-files; remember
to include them when you submit.

Project: Image Compression

10

Project: Image Denoising

11

Project: Image deblurring: I can see clearly now

This problem is quoted from D. OLeary, Scientific Computing with Case Study, 2009.

12

The Direction-of-Arrival Problem

This problem is quoted from D. OLeary, Scientific Computing with Case Study, 2009.

13

Project: How to price a financial derivative

14

Project: Radon transform: Computed Tomography

15

Project: Pattern recognition

You might also like