Computational Physics - Department of Physics

(Axel Boer) #1

2.6 Exercises 41


Using Eq. (2.4) we obtain the final result


F(x) =b 0 −b 1 cos(x), (2.7)

andb 0 andb 1 are determined from Eq. (2.3). The latter relation is after Chensaw. This method
of evaluating finite series of orthogonal functions that areconnected by a linear recurrence
is a technique generally available for all standard specialfunctions in mathematical physics,
like Legendre polynomials, Bessel functions etc. They all involve two or three terms in the
recurrence relations. The general relation can then be written as


Fn+ 1 (x) =αn(x)Fn(x)+βn(x)Fn− 1 (x).

Evaluate the functionF(x) =∑Nn= 0 ancos(nx)in two ways: first by computing the series of
Eq. (reffour-1) and then using the equation given in Eq. (2.5). Assume thatan= (n+ 2 )/(n+ 1 ),
set e.g.,N= 1000 and try with differentx-values as input.


2.9.Often, especially when one encounters singular behaviors,one may need to rewrite the
function to be evaluated in terms of a taylor expansion. Another possibility is to used so-called
continued fractions, which may be viewed as generalizations of a Taylor expansion. When
dealing with continued fractions, one possible approach isthat of successive substitutions.
Let us illustrate this by a simple example, namely the solution of a second order equation


x^2 − 4 x− 1 = 0 , (2.8)

which we rewrite as
x=


1

4 +x,
which in turn could be represented through an iterative substitution process


xn+ 1 =^1
4 +xn

,

withx 0 = 0. This means that we have


x 1 =^1
4

,

x 2 =

1

4 +^14

,

x 3 =

1

4 + 4 +^11

4

,

and so forth. This is often rewritten in a compact way as


xn=x 0 +
a 1
x 1 +x 2 +a^2 a 3
x 3 +x 4 a+^4 ...

,

or as
xn=x 0 +
a 1
x 1 +


a 2
x 2 +

a 3
x 3 +

...

Write a program which implements this continued fraction algorithm and solve iteratively
Eq. (2.8). The exact solution isx= 0. 23607 while already after three iterations you should
obtainx 3 = 0. 236111.

Free download pdf