An M-file function to implement the natural spline can be written as a The not-a-knot fit can be set up in MATLAB as

165

15.6 An M-file function to implement the natural spline can be written as

function yy = natsplinex,y,xx natsplinex,y,xx: uses a natural cubic spline interpolation to find yy, the values of the underlying function y at the points in the vector xx. The vector x specifies the points at which the data y is given. n = lengthx; m = lengthxx; aa1,1 = 1; aan,n = 1; bb1 = 0; bbn = 0; for i = 2:n-1 aai,i-1 = hx, i - 1; aai,i = 2 hx, i - 1 + hx, i; aai,i+1 = hx, i; bbi = 3 fdi + 1, i, x, y - fdi, i - 1, x, y; end c = aa\bb; for i = 1:n - 1 ai = yi; bi = fdi + 1, i, x, y - hx, i 3 2 ci + ci + 1; di = ci + 1 - ci 3 hx, i; end for i = 1:m yyi = SplineInterpx, n, a, b, c, d, xxi; end function hh = hx, i hh = xi + 1 - xi; function fdd = fdi, j, x, y fdd = yi - yj xi - xj; function yyy = SplineInterpx, n, a, b, c, d, xi for ii = 1:n - 1 if xi = xii - 0.000001 xi = xii + 1 + 0.000001 yyy=aii+biixi-xii+ciixi-xii2+diixi-xii3; break end end 166 The program can be used to duplicate Example 15.3: x = [3 4.5 7 9]; y = [2.5 1 2.5 .5]; xx = linspace3,9; yy = natsplinex,y,xx; plotx,y,o,xx,yy

15.7 a The not-a-knot fit can be set up in MATLAB as

x = [1 3 5 6 7 9]; y = 0.0185x.5-0.444x.4+3.9125x.3-15.456x.2+27.069x-14.1; xx = linspace1,9; yy = splinex,y,xx; yc = 0.0185xx.5-0.444xx.4+3.9125xx.3-15.456xx.2+27.069xx-14.1; plotx,y,o,xx,yy,xx,yc,-- b The function can be differentiated to give 069 . 27 912 . 30 7375 . 11 776 . 1 0925 . 2 3 4 + − + − = x x x x x f This function can be evaluated at the end nodes to give f1 = 6.211 and f9 = 11.787. These values can then be added to the y vector and the spline function invoked to develop the clamped fit: 167 yd = [6.211 y 11.787]; yy = splinex,yd,xx; plotx,y,o,xx,yy,xx,yc,-- 168 CHAPTER 16 16.1 A table of integrals can be consulted to determine ax a dx cosh ln 1 tanh = ∫ Therefore, t d d d t d d t m gc gc m c gm dt t m gc c gm cosh ln tanh ⎥ ⎥ ⎦ ⎤ ⎢ ⎢ ⎣ ⎡ ⎟ ⎟ ⎠ ⎞ ⎜ ⎜ ⎝ ⎛ = ⎟ ⎟ ⎠ ⎞ ⎜ ⎜ ⎝ ⎛ ∫ ⎥ ⎥ ⎦ ⎤ ⎢ ⎢ ⎣ ⎡ − ⎟ ⎟ ⎠ ⎞ ⎜ ⎜ ⎝ ⎛ cosh0 ln cosh ln 2 2 t m gc gc gm d d Since cosh0 = 1 and ln1 = 0, this reduces to ⎟ ⎟ ⎠ ⎞ ⎜ ⎜ ⎝ ⎛ t m gc c m d d cosh ln

16.2 a The analytical solution can be evaluated as