Assigned: Thursday Nov. 7, 2013 Due Date: Thursday Nov. 14, 2013 MATH 373: Homework 7 “Interpolation III” Fall 2013 NOTE: For each homework assignment observe the following guidelines: • Include a cover page. • Always clearly label all plots (title, x-label, y-label, and legend). • Use the subplot command from MATLAB when comparing 2 or more plots to make comparisons easier and to save paper. 1. Explicitly find all the uknown coefficients in the following expression to make it a cubic spline that satisfies the not-a-knot condition: 16 + b1 (x + 2) + c1 (x + 2)2 + d1 (x + 2)3 −2 ≤ x ≤ −1, 1 + b (x + 1) + c (x + 1)2 + d (x + 1)3 −1 ≤ x ≤ 0, 2 2 2 s(x) = 2 3 c3 x + d3 x 0 ≤ x ≤ 1, 1 + b (x − 1) + c (x − 1)2 + d (x − 1)3 1 ≤ x ≤ 2. 4 4 4 2. SOURCE CODE: Write the following functions: • x = trisolver(u,v,w,rhs) Tridiagonal solver, where u is the main diagonal, v is the lower diagonal, and w is the upper diagonal of the coefficient matrix. rhs is the right-hand side in the linear system. x is the solution to the linear system. • [a,b,c,d] = cubic spline(x,f) Function to construct the coefficients a, b, c, and d in the cubic spline approximation. • sbar = eval cubic spline(x,a,b,c,d,xbar) Function to evaluate the cubic spline at the points xbar. In order to debug your code. Let me suggest the following test for each of the functions: • x = trisolver(u,v,w,rhs): Use your tri-diagonal solver to solve the following 6 × 6 linear system: 1.2857142857142856 x1 7 x1 6 −1 x2 0.7142857142857142 −2 5 0 x2 1 x3 1.3571428571428572 5 x −1 4 1 3 = =⇒ = x4 0.2857142857142857 . 0 3 2 x4 1 x5 0.0714285714285715 1 2 3 x5 3 2 1 x6 1 1 x6 0.8571428571428571 Assigned: Thursday Nov. 7, 2013 Due Date: Thursday Nov. 14, 2013 • [a,b,c,d] = cubic spline(x,f): Consider the following data: x = [−2; −1; 0; 1; 2]; f = [0; −1; 2; −3; 4]; Your results should be 0 −9.666666666666666 −1 4.333333333333333 a = 2 , b = −1.666666666666667 , −3 −3.666666666666666 4 0.000000000000000 12 2 c= −8 , 6 20 −3.333333333333333 −3.333333333333333 d= 4.666666666666667 . 4.666666666666667 0.000000000000000 • sbar = eval cubic spline(x,a,b,c,d,xbar): Use the above values of x, a, b, c, and d to evaluate the cubic spline at the points: xbar = transpose(linspace(−2, 2, 21)); Your results should be 0.000000000000000 −1.480000000000000 −2.160000000000000 −2.200000000000000 −1.759999999999999 −1.000000000000000 −0.079999999999999 0.840000000000001 1.600000000000000 2.040000000000000 sbar = 2.000000000000000 1.383999999999999 0.351999999999998 −0.872000000000000 −2.064000000000001 −3.000000000000000 −3.456000000000000 −3.207999999999998 −2.031999999999999 0.296000000000005 4.000000000000001 3. The following table gives the viscosity, in mili-Pascal-seconds (centipoises) of sulfuric acid as a function of concentration, in mass percent. Concentration Viscosity 0 0.89 20 1.40 40 2.51 60 5.37 80 17.4 100 24.2 (a) Use your code to construct the cubic spline interpolant for this data. (b) Plot the cubic spline interpolant (also add the data points from the table on this plot). (c) The viscosity of sulfuric acid with a 5% concentration is 1.01 and with a 10% concentration is 1.12 Use these values to asses the accuracy of the cubic spline interpolant. 4. Consider the following values for the sound speed, a (meters/second), in water as a function of temperature T (Celcius). T (Celcius) a (meters/second) 0 1402 10 1447 20 1482 2 30 1509 40 1529 50 1542 60 1551 70 1553 80 1554 90 1550 100 1543 Assigned: Thursday Nov. 7, 2013 Due Date: Thursday Nov. 14, 2013 (a) Use your code to construct the cubic spline interpolant for this data. (b) Plot the cubic spline interpolant (also add the data points from the table on this plot). (c) Use your interpolant to determine the sound speed in water when T = 34, T = 68, T = 86, and T = 91. 3