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
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,yy15.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 ln16.2 a The analytical solution can be evaluated as
Parts
» Solutions Manual Applied Numerical Met
» a The first two steps are 2.3 The first two steps yield a a
» The true value is ln3 = 1.098612
» function root = bisectnewfunc,xl,xu,Ead function root = falseposfunc,xl,xu,es,maxit
» a The graph can be generated with MATLAB
» a The function can be set up for fixed-point iteration by solving it for x in two different
» a a Solutions Manual Applied Numerical Met
» a The formula for Newton-Raphson is
» a The formula for Newton-Raphson is a The formula for Newton-Raphson is
» a Terms can be combined to yield The mass balances can be written as
» The problem can be written in matrix form as The problem can be written in matrix form as a
» a Prob. 8.3: a The equations can be expressed in a format that is compatible with graphing x
» Equation 9.6 is The matrix to be evaluated is The LU decomposition can be computed as
» The system can be written in matrix form as The following solution is generated with MATLAB.
» a The first iteration can be implemented as
» The first iteration can be implemented as The first iteration can be implemented as
» a 2 Solutions Manual Applied Numerical Met
» 2 2 a 7.2 a Solutions Manual Applied Numerical Met
» 2.8 3 3.2 4 1.92 2.1 2.2 2.3 Solutions Manual Applied Numerical Met
» 1.2 1.8 Solutions Manual Applied Numerical Met
» a a a Solutions Manual Applied Numerical Met
» a The simultaneous equations for the clamped spline with zero end slopes can be set up as
» 8.4 8.8 Solutions Manual Applied Numerical Met
» a The analytical solution can be used to compute values at times over the range. For
» Note that students can take two approaches to developing this M-file. The first program
» a Solutions Manual Applied Numerical Met
» a a The explicit Euler can be written for this problem as
Show more