=================================== CHAPTER 3 PROBLEMS GERALD AND WHEATLEY, 6TH EDITION ==================================== ------------------ 1. (x-0.5)(x-3.1) (x+2.3)(x-3.1) 2.1 -------------------- + (-1.3) ------------------ (-2.3-0.5)(-2.3-3.1) (0.5+2.3)(0.5-3.1) (x+2.3)(x-0.5) + (4.2) ------------------ (3.1+2.3)(3.1-0.5) This reduces to: 0.617x^2 + 0.181x - 1.405 In Matlab: >> x = -5:0.01:5; >> y =0.617*x.^2 + 0.181*x - 1.405; >> plot(x,y) In Mathematica: In[1]:= Plot [ 0.617x^2 + 0.181x - 1.405, {x,-5,5} ] ------------------ 34. See the back of the book. ------------------ 35. From these x_i values, compute the h_i (just the differences between successive x_i): x_i: 0.15 0.27 0.76 0.89 1.07 2.11 to obtain: h_i: 0.12 0.49 0.13 0.18 1.04 Then plug those x_i and h_i into the matrix equation at the bottom of page 243. Remember to chop off the first and last column of the matrix on the LHS of the equation and the top and bottom entry of the vector on the RHS of the equation; since this is a *natural* cubic spline, we know that S_0 and S_5 are zero, so we don't need to compute them. This leaves us with a 4x4 Ax=b equation, where the unknowns (the values in the vector x) are the S_i values. Here is the h_i matrix: In[1]:= A = {{1.22,0.49,0,0}, {0.49,1.24,0.13,0}, {0,0.13,0.62,0.18}, {0,0,0.18,2.44}} The right-hand side is: b = 6 [-.221] [ .857] [-.138] [-.311] That -.221, for example, came from the following first differences: (- (/ (- .7175 .2974) (- .76 .27)) (/ (- .2974 .1680) (- .27 .15))) ...and the .857 came from: (- (/ (- .7918 .7175) (- .89 .76)) (/ (- .7175 .2974) (- .76 .27)) Solving that Ax=b system using Mathematica, I get: S-vals: 0.000 -0.678 -1.018 -0.922 -0.696 0.000 Lastly, plug those S_i into the a/b/c/d equations at the top of page 245 to obtain the coefficients of the cubic spline polynomial g_i(x)=a(x-x_i)^3 + b(x-x_i)^2 + c(x-x_i) + d in each interval: a: -0.9413 -0.1159 0.1240 0.2087 0.1136 b: 0 -0.3389 -0.5092 -0.4609 -0.3482 c: 1.0919 1.0512 0.6356 0.5095 0.3639 d: 0.1680 0.2974 0.7175 0.7918 0.8698 Use Mathematica or Matlab to plot each spline curve in the corresponding interval: g1=-0.9413(x-0.15)x^3 + 1.0919(x-0.15)x + 0.1680 Plot [ g1, {x,0.15,0.27} ] g2=-0.1159(x-0.27)x^3 - 0.3389(x-0.27)x^2 + 1.0512(x-0.27)x + 0.2974 Plot [ g2, {x,0.27,0.76} ] and so on. Note that the probability of making an arithmetic error approaches 1 in problems like this. ------------------ 45. See the back of the book. ------------------ 46. For both Bezier curves and B-spline curves, changing a single point changes the curve only within the intervals where that point enters the equations. Its influence is localized, in contrast to a cubic spline, where changing any one point affects the entire curve. ------------------ 59. See the back of the book.