02.05.2014 Views

PENELOPE 2003 - OECD Nuclear Energy Agency

PENELOPE 2003 - OECD Nuclear Energy Agency

PENELOPE 2003 - OECD Nuclear Energy Agency

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

220 Appendix B. Numerical tools<br />

When accurate values of f ′′ (x) are known, the best strategy is to set σ 1 = f ′′ (x 1 ) and<br />

σ N = f ′′ (x N ), since this will minimize the spline interpolation errors near the endpoints<br />

x 1 and x N . Unfortunately, the exact values f ′′ (x 1 ) and f ′′ (x N ) are not always available.<br />

The so-called natural spline corresponds to taking σ 1 = σ N = 0. It results in<br />

a y = ϕ(x) curve with the shape that would be taken by a flexible rod (such as a<br />

draughtman’s spline) if it were bent around pegs at the knots but allowed to maintain its<br />

natural (straight) shape outside the interval [x 1 , x N ]. Since σ 1 = σ N = 0, extrapolation<br />

of ϕ(x) outside the interval [x 1 , x N ] by straight segments gives a continuous function<br />

with continuous first and second derivatives [i.e. a cubic spline in (−∞, ∞)].<br />

The accuracy of the spline interpolation is mainly determined by the density of knots<br />

in the regions where f(x) has strong variations. For constant, linear, quadratic and cubic<br />

functions the interpolation errors can be reduced to zero by using the exact values of<br />

σ 1 and σ N (in these cases, however, the natural spline may introduce appreciable errors<br />

near the endpoints). It is important to keep in mind that a cubic polynomial has, at<br />

most, one inflexion point. As a consequence, we should have at least a knot between<br />

each pair of inflexion points of f(x) to ensure proper interpolation. Special care must<br />

be taken when interpolating functions that have a practically constant value in a partial<br />

interval, since the spline tends to wiggle instead of staying constant. In this particular<br />

case, it may be more convenient to use linear interpolation.<br />

Obviously, the interpolating cubic spline ϕ(x) can be used not only to obtain interpolated<br />

values of f(x) between the knots, but also to calculate integrals such as<br />

∫ b<br />

a<br />

f(x) dx ≃<br />

∫ b<br />

a<br />

ϕ(x) dx, x 1 ≤ a and b ≤ x N , (B.21)<br />

analytically. It is worth noting that derivatives of ϕ(x) other than the first one may<br />

differ significantly from those of f(x).<br />

To obtain the interpolated value ϕ(x c ) —see eq. (B.3)— of f(x) at the point x c , we<br />

must first determine the interval (x i , x i+1 ] that contains the point x c . To reduce the<br />

effort to locate the point, we use the following binary search algorithm:<br />

(i) Set i = 1 and j = N.<br />

(ii) Set k = [(i + j)/2].<br />

(iii) If x k < x c , set i = k; otherwise set j = k.<br />

(iv) If j − i > 1, go to step (ii).<br />

(v) Deliver i.<br />

Notice that the maximum delivered value of i is N − 1.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!