KKKA10, Computer Lab 8 Splines and tabular differentiation Publish your code and results as an HTML file using MATLAB’s Cell Mode. Be sure to write down your answers to all questions in the tasks, including text-only (non-numerical) answers. Goal: Smooth given data for the purpose of differentiating. Interpolate given data with a cubic spline. Differentiate splines. Numerical methods and MATLAB: Spline interpolation. Use of the interp1 and unmkpp built-in functions. Preparation before attending the lab: 1. When we express a function as y = f (x), we call x the independent variable and y the dependent variable. In the differential equation dT J = −k , where J and k are constants, should z be considered the dz dependent or the independent variable? 2. What is the definition of the derivative dy/dx? What is its geometrical definition? 3. What is the definition of the second derivative d2 y/dx2 ? What is its geometrical definition? 4. What is meant by the curvature of a function curve? What is an inflection point? How do you find the inflection points of y = f (x)? 5. The derivative of a polynomial of degree n is also a polynomial. What is its degree? 6. What is the degree of the piecewise polynomial produced by the MATLAB built-in function interp1 with method ’spline’? 7. What is the degree of the second derivative of a cubic spline? 8. How can we solve an equation of the type f (x) = 0 in MATLAB? 9. How do you plot a spline in MATLAB? 1 Problem statement: A reactor is warmer on the surface and gets cooler with depth, as in the following table: Depth (m) Temperature (C) 0 70 0.5 68 1.0 55 1.5 22 2.0 13 2.5 11 3.0 10 As shown in the plot above, the tank can be idealized as two zones separated by a thermocline. The location of the thermocline can be defined as the point of the temperature-depth curve at which d2 T /dy 2 = 0. This also corresponds to the inflection point of the curve. At this depth, the heat flux from the surface layer to the bottom layer can be computed with Fourier’s law, J = −k dT dy Tasks: 1. Find the polynomial that interpolates the given points. Which variable should be the independent variable and why? Plot the polynomial and the data points. Is this polynomial suited to find the thermocline and the heat flux? Why? 2. Interpolate the given data with a cubic spline. 3. Plot the spline curve. 4. Note the section of the spline at which the inflection point is located. Use the Matlab function unmkpp to find the coefficients of the cubic polynomial that defines the spline for that interval. 2 5. Write down the equation of the cubic polynomial for the interval. Make sure to use the correct form of the cubic spline piece, which is centered about the left endpoint of the interval (see Lecture Notes). 6. Construct anonymous functions that calculate the first and second derivatives of the spline for that interval. 7. Determine the thermocline depth. (The correct value is approximately 1.23 m below the surface.) 8. Plot the thermocline together with the spline. 9. If k=2 cal/(s · m · C), compute the flux across the thermocline. (The correct value is approximately 146.44 cal/(s · m2 ).) Carmen Arévalo 3
© Copyright 2026 Paperzz