Lab 3: Fitting, Interpolation, and Residuals
Goal
Compare a fitted model with measured data and decide whether the model is credible.
Setup
Work in a folder called week03. Start scripts from a clean workspace:
clear; clc; close all;Part A: Run And Explain
Open week03_curve_fitting_validation.m.
Run the script and answer:
- What are the independent and dependent variables?
- Which polynomial degrees are compared?
- Which degree has the smallest RMSE?
- Which degree would you trust most for this data set?
- What does the residual plot show that the fitted-curve plot hides?
Part B: Change The Candidate Models
Modify the script so it compares:
degrees = [1 2 3 5];Then answer:
- Did the RMSE decrease for every added degree?
- Did the residual plot become easier or harder to interpret?
- Which degree would you report to someone who cares about the underlying trend?
Part C: Interpolation Versus Fit
Open week03_interpolation_vs_fit.m.
Run the script and compare the estimates at the query points.
| Question | Answer |
|---|---|
| Which method passes through the measured data? | |
| Which method smooths noisy measurements? | |
| Which method would you use to estimate between trusted measurements? | |
| Which method would you use to describe an approximate trend? |
Part D: Polynomial Tool Check
Open week03_polynomial_tools.m.
Run the script and answer:
- What roots are used to build the polynomial?
- What coefficient vector does
polyreturn? - How does the script check the polynomial built with
conv? - What does
polydercompute?
Part E: Interpolation Input Check
Before using interp1, add checks that:
- the
xvalues are sorted; - every query point is inside the measured range.
Explain what should happen if either check fails.
Part F: Residual Notes
For your selected polynomial degree, write 4-6 sentences:
- Describe the residuals near the start of the data.
- Describe the residuals near the middle.
- Describe the residuals near the end.
- State whether the residuals show a pattern.
- Decide whether the model is adequate for the question.
Part G: Stress Test
For one selected degree, add this line after computing its coefficient vector p:
prediction = polyval(p, 12);Answer:
- Is
x = 12inside or outside the measured range? - Is this interpolation, fitting, or extrapolation?
- Would you report this number? Why or why not?
Deliverable
Submit a short note containing:
- the selected model degree;
- one plot of the data and fitted curve;
- one residual plot;
- the RMSE values you compared;
- a justification based on the residuals, not only visual appearance.
AI Use
Ask an LLM: “How do I decide whether a polynomial fit is overfitting?” Then evaluate whether the answer mentions residuals, extrapolation, and model complexity.
Include the prompt and the part of the answer that changed or challenged your model choice.