Norm and condition number of a matrix If A.x = b then A(x+x) = b+b. Since we are dealing with a set of linear equations, A. x = b. If b is an error term then the corresponding error in x, x, is given by x = A-1.b. The magnitude and direction of this error obviously depend on the inverse of A and will be large (for some b) when A is nearly singular. Suppose that A is symmetric with positive eigenvalues then it is possible to expand the inverse of A in terms of the eigenvectors and eigenvalues of A as follows: A.xi = i xi A -1 c i x i x iT i ci are coefficients to be determined. A.A -1 c i A.x i x iT 1 i c i i x i x iT 1 xx i i 1 T i i The last equation holds provided the vectors xi are complete and orthonormal and so ci i =1 for all i and ci =1/i. A -1 1 x i x iT i Now consider x = A-1.b. Rewrite this as i δx 1 x i x iT .δb and we see that the error term, b, is projected onto xi with i coefficient 1/i xiT.b. The largest contribution to x will come from eigenvectors with the smallest eigenvalues and those for which b and xi are nearly parallel. Nearly singular matrices will be most sensitive since they have the smallest eigenvalues. i Relative error The error x will depend on both the direction and magnitude of b. It makes more sense therefore to compare the relative change ||b||/||b|| with the relative error ||x ||/||x||. For a positive definite matrix (all eigenvalues positive) the solution vector and error term always satisfy: ||x|| ≥ ||b||/max and ||x|| ≤ ||b||/min Therefore the relative error is bounded by ||x||/||x|| ≤ ||b||/||b|| (max/min) The ratio (max/min) is known as the condition number of A. Norm of A For a symmetric matrix the condition number can be expressed in terms of its maximum and minimum eigenvalues. When A is not symmetric then we make use of the norm of the matrix defined by: ||A|| = max (x≠0) ||A.x||/||x||. This is a measure of the amplifying power of A and replaces ||x||/||x|| when A is not symmetric. In this case the condition number is c = ||A|| ||A-1|| To see why this is an appropriate definition for the condition number, replace A-1 by its expansion in eigenvectors and eigenvalues above. The relative error satisfies ||x||/||x|| ≤ c ||b||/||b|| as before. If we consider the effect of an error in the elements of A instead of the vector b then we find, perhaps surprisingly, that the same definition of condition number satisfies ||x||/||x|| ≤ c ||A||/||A|| (A+A).(x+x) = b A.x+A.x+A.x = 0 x = -A-1.A.(x+.x) = 0 Multiplying by A amplifies a vector by no more than the norm, ||A||, and multiplying by A-1amplifies by no more than ||A-1||. Therefore ||x|| = ||A-1||.||A||.||(x+.x)|| ||x||/||x+x || ≤ ||A-1||.||A|| = c ||A||/||A|| Round off error therefore comes from: natural sensitivity, c, and the actual errors in A and b. For the case of an eigenvalue problem the relevant condition number is that of the eigenvector matrix, S, not A. For the eigenvalue problem A.S = S. with an error A in A (A+A).S = S.(+ ) A.S = S. = S-1.A.S |||| = ||S-1||.||A||.||S|| = c ||A|| NB When S is an orthogonal matrix (A real symmetric, unitary if A Hermitian) then c = 1 since there is no amplification by an orthogonal matrix. IX Special Functions Special functions such as the gamma function, Legendre polynomials or Bessel functions appear in many aspects of computational physics. For example, the incomplete gamma function arises in methods for rapidly and absolutely converging lattice sums in crystal physics. They are available in many scientific computing libraries such as the Gnu Scientific library (GSL) www.gnu.org/software/gsl/ Gamma function See any text in mathematical physics, e.g. Mathematical methods for physicists, Arfken and Weber. Euler definition (Infinite limit) lim 1.2.3. n n z z 0, - 1, - 2 , - 3 n z(z 1)(z 2) (z n) lim 1.2.3. n (z 1) n z 1 z - 1, - 2 , - 3 n (z 1)(z 2)(z 3) (z 1 n) lim nz 1.2.3. n n z z 0, - 1, - 2 , - 3 n z n 1 z(z 1)(z 2) (z n) (z+1) = z (z) (1) = 1.(0) = 1 (z) (2) = 1.(1) = 1 (3) = 2.(2) = 2.1 = 2 (4) = 3.(3) = 3.2.1 = 6 (5) = 4.(4) = 4.3.2.1 = 24 (n+1) = n.(n) = (n-1)! Euler definition (Definite Integral) (z) = e -t t z-1 dt Re(z) > 0 0 With the change of variable = t1/2 this becomes (z) = 2 e -t t 2z-1 dt Re(z) > 0 2 0 (1/2) = 2 e -t dt 2 erf( ) 2 0 erf(x) is known as the error function. Incomplete gamma function The incomplete gamma function is defined by generalising the Euler definite integral definition of the gamma function to x (z, x) = e - t t z-1 dt Re(z) > 0 0 (z, x) = e - t t z -1 dt Re(z) > 0 x (z) (z, x) (z, x) (z, x) (z, x) 1 (z) (z) The utility of the incomplete gamma function lies in the fact that multiplying an expression by ((z,x)+(z,x))/(z) leaves it unchanged and the two parts generated in this way may be, rapidly convergent, e.g., when the original expression is not. Functions such as the gamma functions are generally computed numerically using either asymptotic series (which may converge rapidly for large or small arguments of the function) and recursion relations. By expanding the exponential in the incomplete gamma function and integrating term by term we obtain x (z, x) = e - t t z-1 dt Re(z) > 0 0 z 1 (z 1)!(1 e x ) s 0 xs s! (z, x) = e - t t z -1 dt Re(z) > 0 x z 1 (z 1)!e x s 0 xs s! For the particular case z=1/2 x (1/2, x) = 2 e -t dt Re(z) > 0 2 0 erf(x) erfc(x) 2 2 x e - t dt 2 0 x e -t dt 2 1 (1/2, x 2 ) 1 (1/2, x 2 ) erfc(x) is known as the complementary error function and for all arguments erf(x) + erfc(x) = 1 2 1.5 1 0.5 -4 -2 2 4 -0.5 -1 Plot of erf(x) (rising from -1 to 1), erfc(x) (falling from 2 to zero) and erf(x) + erfc(x) (constant value of 1). The series expansions for erf(x) and erfc(x) are erf(x) 2 x3 x5 x 2n 1 n x ... 1 ... 3 5.2! (2n 1)n! π 2 e -x 1 1.3 1.3.5 n (2n - 1)!! erf(x) 1 ... 1 2 2 4 3 6 ... 1 n 2n 2 x 2 x 2 x π x 2x The first expansion is obtained simply by expanding e-t^2 and integrating erf(x) term by term. The second is obtained by writing 2 1 2 1 d 1 -t 2 e - t te - t - e t t dt 2 and integrating by parts. The first expansion is good for small x and the second for large x. Recurrence relations for the incomplete gamma function The incomplete gamma functions satisfy the following upwards and downwards recursion relations (z, x) (z 1)(z 1, x) e x x z 1 (z, x) (z 1) (z 1, x) e x x z 1 Γ(z 1, x) e x x z z (z 1, x) e x x z (z, x) z Γ(z, x) The first two are upwards and the last two downwards and the relations can be obtained using integration by parts. The starting points for the downwards recurrences are e x γ(1 z, x) for z 0 (1) m x 1 z m m! (1 z m) for 0 z 1 m 0 for z 0 1 e x (1 z, x) (1 z, x) - (1 z, x) for 0 z 1 See paper by Guseinov and Mamedov for further details. Use of gamma incomplete functions for calculating lattice sums The Madelung constant is a familiar concept from crystal physics. A real space lattice is defined by r i a1 j a 2 k a 3 denotes ijk and the corresponding reciprocal lattice is defined by G h b1 k b 2 b 3 denotes hk The Madelung constant is defined by (1) ' i j k r where the primed sum indicates that the self term i = j = k = 0 is omitted. Write this formally as an integral over all space. Define w(r ) (1) i j k (r r ) ' 1 (b1 , b 2 , b 3 ) 2 using a i .b j 2 ij (definitio n of reciprocal lattice) w(r ) e ' ik 1/2 .r (r r ) k 1/2 1 (b1 .a1 ) e i - 1 2 w(r )dr w(r )erf( r) dr w(r )erfc( r) dr r r r (1,0,0) k 1/2 .r w(r )dr w(r )erf( r) dr w(r )erfc( r) dr r r r F(h)G Parseval' s Relation * - choose f( r ) w(r ) g( r ) (h)dh f(x)g * (x)dx - F(h) erf( r) r w(r )erf( r) dr 1 r G(h) h 2 e - h ( h h k ) 1 dh 1/2 h 2 - h k 1/2 1 e h k 1/2 i j k erfc( r ) (-1) ' r ' ' 1 ' (h h k 1/2 ) - 1 2 e - h 2 2 2 e ' 1 2 - h k 1/2 h k 1/2 2 is the unit cell volume h is a vector in reciprocal space 2 2 Sturm-Liouville theory and orthogonal functions The Sturm-Liouville equation is a second order ordinary differential equation (ode) of the form d du p(x) q(x)u(x) w(x)u(x) dx dx w(x) is a weight (or density) function. Many physical problems described by an eigenvalue equation belong to the class of Sturm-Liouville equations. Some examples are equation Legendre Bessel Hermite SHO p(x) 1-x2 x e-x2 1 q(x) 0 -n2/x 0 0 ℓ(ℓ+1) a2 2a n2 w(x) 1 x e-x2 1 We will look at Bessel’s equation illustrated by vibration of a drumhead and Legendre’s equation illustrated by Laplace’s equation in 3-D. In particular we will look at recursive methods for calculating Bessel functions and Legendre polynomials. For further details on the Sturm-Liouville equation and properties its solutions see e.g. Arfken and Weber. Bessel’s equation and the wave equation in 2-D 2 1 2 2 2 Ψ(r, , t) 0 c t 1 1 2 Ψ(r, , t) R(r) ( )T(t) r r r r r 2 2 1 1 1 R(r) ( )T' ' (t) R' ' (r) ( )T(t) R' (r) ( )T(t) 2 R(r) ' ' ( )T(t) 2 r c r 1 T' ' (t) R' ' (r) 1 R' (r) 1 ' ' ( ) -2 2 2 c T(t) R(r) r R(r) r ( ) 2 T' ' (t) 2 c 2 T(t) 0 R' ' (r) R' (r) ' ' ( ) r2 r 2 r 2 n 2 R(r) R(r) ( ) ' ' ( ) n 2 ( ) 0 r 2 R' ' (r) r R' (r) 2 r 2 n 2 R(r) 0 or d r r R' (r) 2 r 2 n 2 R(r) 0 Bessel' s equation dr R(r) A J n (r) B Yn (r) Recurrence relations and zeroes of Bessel functions Jn and Yn are Bessel functions of the first and second kinds, respectively. Jn is finite at the origin (Jn(0) = 1) while Yn is divergent. For a vibrating drumhead, we impose the boundary conditions, R(0) = finite, R(1) = 0 (assume drumhead has unit radius). Then B = 0 and the solution to the ode is a linear combination of Bessel functions of the first kind. The allowed solutions will have Bessel function zeroes at r = 1. Let the mth zero of the nth Bessel function be denoted kmn. The first three Bessel functions of the first kind are plotted below. The function which takes the value one at the origin is J0[x]. J1(x) and J2(x) have value zero at the origin and J1 is more tightly curved than J2. Bessel Jn x 1 0.8 0.6 0.4 0.2 x 2.5 5 7.5 10 12.5 15 -0.2 -0.4 Zeroes of the first two Bessel functions of the first kind m/n 1 2 3 0 2.4048 5.5201 8.6537 1 3.8318 7.0516 10.1735 Radial and angular nodes for modes tabulated above. n=0 n=1 Radial nodal positions for corresponding modes on drumhead m/n 1 2 3 0 1.0000 0.4356 0.2778, 0.6378 1 1.0000 0.5461 0.3766, 0.6895 The generating function for Bessel functions of the first kind is x 1 (h ) h m J (x)h m e2 m m set h 1 and obtain e0 1 m m J m (x) From the property t hat J -m (x) (-1) m J m (x) for integral m J 0 (x) 2m 1 J m (x) 1 m Differenti ating the generating function w rt h results in a recurrence relation x 1 d 2 (h h ) x 1 e 1 2 dh 2 h x 1 (h ) 2 h d m J (x)h m m J (x)mh m-1 e m m dh m m m x 1 m J m (x)h m J m (x)mh m-1 1 2 2 h m m Everything is an infinite sum so rearrange and collect coefficent s of h m 2m m 1 m J m (x)h m-1 1 2 J m (x)h m x h m m 2m 1 J m (x)h m-1 1 2 J m (x)h m J m (x)h m J m (x)h m-2 x h 2m J m (x) J m 1 (x) J m-1 (x) x 2m J m-1 (x) J m (x) J m 1 (x) Downwards recurrence relation x 1 ex lim m 2m 2m To obtain zeroes of Bessel functions use Newton - Raphson Initialise recursive process with J m (x) x n 1 x n - J m (x n ) J 'm (x n ) J 'm (x n ) m for m x m d J m (x) - J m 1 (x) also from generating function x dx 2m J m (x) J m 1 (x) Downwards recurrence relation x m J 'm (x n ) J m (x) - J m 1 (x) For calculatin g zeroes from Newton - Raphson x J m-1 (x) Legendre polynomials and Laplace’s equation in spherical polar coordinates The Laplacian operator in spherical polar coordinates is 1 2 1 1 2 (r, , ) 0 r sin 2 r 2 sin 2 2 r 2 sin r r For an azimuthall y symmetric problem this reduces to 1 2 1 R(r) ( ) 0 r 2 sin 2 r sin r r 2 R(r) ( ) ( )r 2 rR(r) sin 0 sin r 2 1 ( ) r 2 rR(r) sin r n(n 1) sin R(r) ( ) 2 r 2 rR(r) - n(n 1)R(r) 0 soln. R(r) c1 r n c 2 r -(n 1) r 1 ( ) sin n(n 1)( ) 0 sin Let x cos sin 1 - x 2 equation in becomes d d (1 x 2 ) P n (x) n(n 1)P n (x) 0 in the standard Sturm - Liouville form dx dx Solutions are the Legendre polynomial s given by Rodrigues formula n 1 d P n (x) n ( x 2 1) n 2 n! dx Recurrence relations for Legendre polynomials The generating function for Legendre polynomials is (1 2xt t 2 ) -1/2 n 0 Pn (x)t n n A recurrence relation for Pn (x) may be obtained by differenti ating wrt t d (x t) n (1 2xt t 2 ) -1/2 n 0 Pn (x)nt n -1 2 3/2 dt (1 2xt t ) (x t) n n ( x t ) n 0 Pn (x)t n (1 2xt t 2 )n 0 Pn (x)nt n -1 2 1/2 (1 2xt t ) x Pn (x)t n - Pn (x)t n 1 Pn (x)nt n -1 2xPn (x)nt n Pn (x)nt n 1 Collect coefficien ts of t n x Pn (x) - Pn -1 (x) (n 1)Pn 1 (x) - 2nxP n (x) (n - 1)Pn -1 (x) Pn 1 (x) (2n 1)x n Pn (x) P (x) n 1 n -1 (n 1) A recurrence relation for Pn' (x) may be obtained by differenti ating wrt x d t n (1 2xt t 2 ) -1/2 n 0 Pn' (x)t n 2 3/2 dx (1 2xt t ) t n n n 0 Pn (x)t n 1 (1 2xt t 2 )n 0 Pn' (x)t n 2 1/2 (1 2xt t ) Pn (x)t n 1 Pn' (x)t n 2xPn' (x)t n 1 Pn' (x)t n 2 Collect coefficien ts of t n Pn -1 (x) Pn' (x) - 2xPn' -1 (x) Pn' -2 (x) Pn' 1 (x) Pn' -1 (x) 2xPn' (x) Pn (x) (index has been shifted up by 1) Pn 1 (x) (2n 1)x n Pn (x) P (x) n 1 n -1 (n 1) Pn' 1 (x) Pn' -1 (x) 2xPn' (x) Pn (x) The first two Legendre polynomials are P0(x) = 1 and P1(x) =x so these may be used to calculate higher Legendre polynomials using the recurrence relation. Example of a recursive function double ftuvn(int t, int u, int v, int n, double *f, VECTOR_DOUBLE x) { double result ; if (t < 0 || u < 0 || v < 0 ) return 0.0 ; if (t >= u && t >= v) { if (t == 0 && u == 0 && v == 0) return f[n] ; result = (t > 0) ? x.comp1*ftuvn(t-1,u,v,n+1,f,x) + (t-1)*ftuvn(t-2,u,v,n+1,f,x) : 0.0 ; } else if (u > t && u >= v) { result = (u > 0) ? x.comp2*ftuvn(t,u-1,v,n+1,f,x) + (u-1)*ftuvn(t,u-2,v,n+1,f,x) : 0.0 ; } else { result = (v > 0) ? x.comp3*ftuvn(t,u,v-1,n+1,f,x) + (v-1)*ftuvn(t,u,v-2,n+1,f,x) : 0.0 ; } return result ; }