Interpolation and Curve Fitting of Experimental Data
Summary
Interpolation and curve fitting are fundamental numerical techniques used to approximate unknown values and establish mathematical models for experimental data. Curve fitting provides a function that best represents the overall trend of the data, without necessarily passing through all the points, and allowing for measurement noise and uncertainty. However, interpolation provides a function that passes through all the given data. In this project, students will apply polynomial interpolation, spline interpolation, and least-squares curve fitting (linear, polynomial, and nonlinear) to a given dataset using MATLAB.
Learning Goals
In this activity, students will implement polynomial and spline interpolation on a given dataset, for example, the US population. In addition, they will perform linear, quadratic, cubic, or nonlinear curve fitting on the same dataset. Students will compare interpolation and curve fitting methods in terms of accuracy and smoothness, visualize, and interpret the results.
Context for Use
The educational level of the project is college first-year students and sophomores, with a class size of 50 or fewer. It could be a laboratory activity or a homework project. Students are expected to have basic knowledge of MATLAB programming and Calculus I or its equivalent. This project is for a lower level in numerical analysis and can be assigned to the students around the middle of the semester. The learning objectives include:
- Students will be able to create predictive models for experimental data.
- Students will be able to apply polynomial interpolation, spline interpolation, and least-squares curve fitting (linear, polynomial, and nonlinear) to a given dataset using MATLAB.
- Students will develop problem-solving and communication skills.
- Students will be able to apply machine learning techniques to develop predictive models.
Description and Teaching Materials
Students will explore interpolation and curve-fitting methods that best approximate a curve for a given set of data points. Students will use splines of order 4 or less and compare their accuracy. They will implement curve-fitting methods and compare them in terms of accuracy and smoothness. Students will use visualization to explore the accuracy of methods.
Teaching Notes and Tips
This project can be individual or group-based. It is a classroom-based activity that can be extended to Lagrange interpolation, higher-order splines, and nonlinear curve fitting. It is assumed that students have been introduced to these topics earlier in the semester. They will be given three different datasets. Students will construct a polynomial of degree n-1 and cubic splines of piecewise polynomials to ensure smoothness at knots. They will be asked to find curves that best represent the points using Linear, Quadratic, Cubic, or Non-Linear regression. For example, the exponential function y = a*exp(bx) using MATLAB's fit() function.
Students will use MATLAB functions: polyfit, polyval, spline, fit, plot, and determine the Goodness of fit, the coefficient of determination (R²), and residual error between test and reference data for analysis and validation of predictive models.
Tools to be used:
- MATLAB functions: polyfit, polyval, spline, fit, plot.
- Goodness of fit, the coefficient of determination (R²), and residual error.
Assignment: Students will be provided three data sets to use for the project.
Assessment
The rubric for the project will have the following criteria:
A scoring scale of 1–5, where 5 means exemplary, 4 means proficient, 3 means average, 2 means developing, and 1 means major improvement needed. Students will be expected to provide a MATLAB code at the end of the project and their observations of the results. The instructor will run the code or use MATLAB Grader to look for code errors and the correctness of calculations. The following will be assessed: code organization, code correctness/figures, and final report documentation.
Code organization: Here, exemplary means the code is highly organized and readable. The code has descriptive variables and organized logical sections. Needs major improvement if the code lacks all the properties of an exemplary code.
Correctness and plots: Here, exemplary means the code produces expected, accurate results and is robust to unexpected errors. The code needs major improvement if it lacks all the properties of an exemplary code.
Final report documentation: Here, exemplary means having a clear and well-written report with explanations of figures and an interpretation of results. Needs major improvement if the documentation lacks all the properties of an exemplary score.
--------------------------------------------------------------------------------------
The results should show the following:
Interpolation
- Polynomial interpolation produces an exact fit but oscillations for higher degrees.
- Cubic spline interpolation produced smoother curves without oscillations.
Curve Fitting
- Linear fit captured the overall trend but underestimated curvature.
- Quadratic and cubic fits improved accuracy significantly.
- Nonlinear exponential fit provided the best match, with the best R², Goodness of fit, or residual scores.
Graphical Comparison
Figures generated in MATLAB, for example, for the US Population
- Plot 1: Polynomial interpolation
- Plot 2: Cubic spline interpolation
- Plot 3: Linear, quadratic, cubic curve fitting
- Plot 4: Nonlinear exponential fitting
MatlabMinProject1.pdf (Acrobat (PDF) 155kB Oct31 25)
MatlabMinProject.pdf (Acrobat (PDF) 685kB Oct28 25)
References and Resources
1. Chapra, S. C., & Canale, R. P. Numerical Methods for Engineers. McGraw-Hill.
2. MathWorks Documentation: Interpolation (https://www.mathworks.com/help/matlab/ref/interp1.html), Curve Fitting Toolbox (https://www.mathworks.com/help/curvefit/).
3. Burden, R. L., & Faires, J. D. Numerical Analysis. Brooks Cole.