Anda di halaman 1dari 5

Matrix Computing

This practical introduces the following:

 LU decomposition for the solution of a set of linear equations


 Comparison of 32 bit, 64 bit and 80 bit calculations of the Hilbert matrix
 Solution of eigenvalue problems using the method of Jacobi rotation

Introduction

Many problems in computational physics can be reduced to linear algebra problems.


In this laboratory you will use several fundamental techniques of computational linear
algebra to solve physics problems common in many different areas of science. In
order to solve the problem with some variations you will need to solve a system of
linear equations by Gauss-Jordan Elimination, ‘LU decomposition plus back
substitution’, matrix inversion and matrix diagonalisation.

Solving a set of linear equations

A common problem in physics is the task of solving a set of linear equations

a11 x1 + a12 x2 + a13 x3 + a14 x4 + a15 x5 = b1


a21 x1 + a22 x2 + a23 x3 + a24 x4 + a25 x5 = b2
a31 x1 + a32 x2 + a33 x3 + a34 x4 + a35 x5 = b3
a41 x1 + a42 x2 + a43 x3 + a44 x4 + a45 x5 = b4
a51 x1 + a52 x2 + a53 x3 + a54 x4 + a55 x5 = b5

In matrix form this becomes A . x = b with A, b and x given by

a11 a12 a13 a14 a15 b1 x1


a21 a22 a23 a24 a25 b2 x1
a31 a32 a33 a34 a35 b3 x1
a41 a42 a43 a44 a45 b4 x1
a51 a52 a53 a54 a55 b5 x1

The standard method for solving for the vector x is Gaussian elimination. A
particularly useful formulation in terms of numerical treatment is called LU
decomposition. Here the matrix A is written as the product of a lower triangular
matrix L and an upper triangular matrix U, A = L . U. Note that the vector b does not
enter here. This means that once the decomposition has been performed, it can be
applied to solve A . x = b for any value of b. The determinant of A is simply given by
the product of the diagonal elements of L. For a detailed discussion of both Gaussian
Elimination and LU decomposition see DeVries pp 119-131 and your lecture notes
from course 342, Numerical Methods. The function lu_solver.c (Appendix A) takes
as input the matrix A and the vector b (and specification of the array sizes). It returns
the solution x and the determinant. In the course of the decomposition A is
overwritten by L and U (note that the rows become interchanged).
Exercise 1 Solution of Linear Equations by LU Decomposition
Write a programme that solves the equation A . x = b for

3 1 1  2
   
A  3 2 1 b   3 (1)
1 1 1  1
  

using LU decomposition and solve the problem yourself on paper. Compare results of
each method of solution. The main() function (here called lin_eq.c) contains the value
of the matrix elements and the vector b. It should call the external function
lu_solver.c. Thus use as header:

#include "lu_solver.h"
#include <math.h>

extern void lu_solve(double a[][],double x[],double b[], double det, int ndim, int n);

Exercise 2 Hilbert Matrices

The nxn Hilbert matrix is the square matrix with elements

1
H ij 
i  j -1
(2)

For example, the 3x3 Hilbert matrix is

 1 1/ 2 1/ 3 
 
H  1 / 2 1/ 3 1/ 4  (3)
1 / 3 1/ 4 1 / 5 

The Hilbert matrix has the property that its determinant decreases rapidly with
increasing matrix dimension. Using your LU decomposition program, solve the
equation H . x = b with bi = i, e.g. for the 3x3 matrix b = (1,2,3) and compute the
determinant of H. The numerical accuracy of your program may be checked by
setting

n
bi  H
j 1
ij (4)

which has the solution x = (1,1,1). Up to what values of n do your computations


agree with this? How does it change when you define the Hilbert matrix as a) float b)
double c) long double. Using long double compute the determinant as a function of
n (for a reasonable range of n) and plot the data. The format statements in the fprintf
command should be %f, %lf and %Lf, respectively.

Eigenvalue problems

The eigenvalue problem is defined by the equation


A . xn  λ n xn (5)

where A is a matrix of constants and xn and n are the nth eigenvector and eigenvalue
solutions of the problem. In all, if A is an NXN matrix, there are N eigenvectors and
eigenvalues. The problem may be solved by computing the following determinant

det A - I  0
(6)

where I is the unit matrix of the same dimension as A. Evaluation of this determinant
for an NxN matrix A results in an Nth order polynomial in . This is called the
characteristic equation or secular equation for the matrix A. Its N roots give the
eigenvalues of A, n. Obviously this is challenging for n > 2, so one generally adopts
a numerical solution for larger matrices. A square matrix A can be diagonalised by a
unitary transformation (see lecture notes from course Numerical Simulations of
Physical Systems MA 342 or Linear Algebra and its Applications, G. Strang S-LEN
512.5 L6*2).

A' = S-1 . A . S (7)

The transformation matrix S turns A into a diagonal matrix A'. Once the
transformation matrix S has been found, the eigenvectors of A are contained in the
columns of the transformation matrix on the right in Eq. 7 and in the rows of its
inverse in Eq. 7, S-1. The eigenvalues A are the diagonal elements of A' and the
eigenvalue in the nth diagonal element corresponds to the eigenvector in the nth
column of S. Numerical diagonalisation is achieved by bringing the matrix A
gradually towards diagonal form using a sequence of similarity transformations. For
symmetric matrices a sequence of orthogonal similarity transformations is used. One
such procedure is called Jacobi transformation. The routine jacobi_trans.c performs
just such a transformation. Its input is the matrix A, the outputs are the eigenvalues in
array e[i] and the eigenvectors in matrix v[i][j]. Note that typedef statements have
been used for declaration of scalars, matrices and vectors. (For further details, see
your course JS 3065 Computational Methods).

Exercise 3 3x3 Matrix Diagonalisation

Write a programme which calls jacobi and solves the eigenvalue problem for

 2 1 2
 
A   1 2  2
 2 2 5 

Calculate the eigenvalues and eigenvectors of this matrix by hand and compare your
numerical results with your analytical result.

Exercise 4 Nearly Free Electron Energy Band Structure


The question of what determines whether a material is an electrical conductor,
insulator or semi-conductor is of great importance in solid state physics. The free
electron model, where electrons are treated as an ideal Fermi gas, gives good insight
into heat capacity and thermal conductivity but fails to explain the electrical
conductivity of solids. It is found that the crystal structure is most important in this
problem as Bragg reflections of electron waves within the crystal lead to the
formation of energy band gaps, which in turn determine the electrical conductivity of
the solid. The Schrödinger equation for electrons in a ‘1-D crystal’ is

1 2
  ψ k (x)  V(x)ψ k (x)  ε k ψ k (x)
2
(8)

ψ k (x) is the eigenfunction for wavenumber k, ε k are the allowed energies and V(x)
is a periodic potential energy. A plot of ε k versus k is called the band structure.
Since the potential energy operator and the eigenfunctions both contain periodic
functions they can be expanded in Fourier series. We will use the complex form of
Fourier series to expand the periodic function f(x) = f(x+na) (a = period, n is 0, 1,
2, ..)


f(x)   cn exp[i 2x/a]
n  
(9)

In the nearly free electron problem we choose to limit the expansion for the potential
and wavefunction such that only coefficients with –2  n  2 are nonzero. Solutions
to the Schrödinger equation using such a limited expansion for the wave function are
quite accurate provided the magnitudes of the potential energy Fourier components in
the problem are much less than the kinetic energies of the electrons. The expansions
for the potential energy and wave functions are

2
V(x)   vn exp[i 2x/a]  v0  2v1 cos(2x/a)  2v2 cos(x/a)
n  2
(10a)

2 i 2x
 k (x)   c n exp[
a
 ikx] (10b)
n  2

The right hand equality in Eq. 10a is valid provided v1 = v-1 and v2 = v-2. We also
choose v0 = 0. The factor exp[ikx] multiplying each term in Eq. 10b is necessary to
make k a Bloch eigenfunction. (See lecture notes from course JS 3014 Thermal and
Electronic Properties). When the potential and eigenfunction are substituted into Eq.
8, the resulting set of linear equations is
1 2 
 (k  G  2 )  ε k v1 v2 0 0 
 2 
 v-1
1 2
(k  G 1 )  ε k v1 v2 0  c 2 
 2  c 
 1 2  -1 
 v-2 v-1 k  εk v1 v2  c0   0
 2  c 
 1 2  1 
0 v- 2 v-1 (k  G1)  ε k v1
 2  c 2 
 1 
 0 0 v-2 v-1 (k  G 2 )2  ε k 
 2 
Inspection of the matrix equation above shows that its diagonal elements depend on
wave number k. An energy band calculation using these equations consists of
repeated construction of the matrix and computation of its eigenvalues. The notation
Gn in the equations above means 2n/a. In 1-D the reciprocal lattice consists of points
given by k = Gn with n integer. The equations are given in atomic units in which h bar
= e = me = 1. It will be helpful if you choose units for wavenumbers to be in units of
/a so that k = ±1 correspond to the Brillouin zone boundaries for the problem and G n
=2n.

Exercise 4

Write a programme which contains a function which constructs the 5x5 matrix above
as a function of k. The programme should also call the diagonalisation routine to
obtain the eigenvalues of the matrix.

Use your programme to obtain the bandstructure of a solid where all of the Fourier
components of the potential are weak (v-2 = v-1 = v1 = v2 = 0.1) and for a solid
where some of the Fourier components of the potential are strong (v -2 = 0.3 v-1 = 0.7
v1 = v2 = 0.1). Compare the band gaps calculated in your programme at the
Brillouin zone centre and at its edges with the result from perturbation theory that the
nth band gap is twice the nth Fourier component of the periodic potential, e.g. the first
gap at k = 1 (in units of /a) is equal to 2 v1.

Anda mungkin juga menyukai