3. Numerical Methods I

Curve Fitting

Curve Fitting in Numerical Methods I

students, imagine you have a set of real-world data points from an experiment, such as the voltage output of a sensor at different temperatures 📈. The points do not lie perfectly on a straight line or any simple formula, but you still want a mathematical model that describes the trend. That is the central idea of curve fitting.

In this lesson, you will learn how curve fitting helps engineers turn scattered data into useful equations. By the end, you should be able to explain the main terminology, apply basic curve-fitting reasoning, and see how this topic connects to root-finding and interpolation in Numerical Methods I.

What Curve Fitting Means

Curve fitting is the process of finding a function that best matches a set of data points. Suppose you have measurements $\left(x_1,y_1\right),\left(x_2,y_2\right),\dots,\left(x_n,y_n\right)$. You want a model $y=f\left(x\right)$ that represents the data well.

A key idea is that the fitted curve usually does not pass through every point exactly. That is different from interpolation. In curve fitting, small differences between the data and the model are expected because real measurements often contain noise, rounding error, or natural variation.

Engineers use curve fitting for many tasks:

  • estimating material behavior from test data,
  • predicting future values from trends,
  • designing control systems,
  • calibrating sensors,
  • and simplifying complex data into a usable equation.

A common example is a load test on a bridge component. If the measured strain values do not form a perfect line, a fitted curve can still give a reliable relationship between load and strain.

The main goal is to choose a model that captures the pattern without becoming too complicated. A model that is too simple may miss important behavior, while one that is too complicated may fit random noise instead of the real trend.

Common Curve-Fitting Terms and Ideas

To understand curve fitting, students, it helps to know several important terms.

Data points are the measured values. If $x$ is the input and $y$ is the output, each pair $\left(x_i,y_i\right)$ is one observation.

Model means the type of function you choose. Common models include:

  • linear models such as $y=mx+b$,
  • polynomial models such as $y=a_0+a_1x+a_2x^2$,
  • exponential models such as $y=ae^{bx}$,
  • logarithmic models such as $y=a+b\ln\left(x\right)$.

Parameters are the unknown constants in the model. For $y=mx+b$, the parameters are $m$ and $b$.

Residual is the difference between a measured value and the model prediction. For one data point, the residual is

$$r_i=y_i-f\left(x_i\right)$$

A positive residual means the data point is above the curve; a negative residual means it is below the curve.

Error measures how far the model is from the data overall. A common choice is the sum of squared residuals:

$$S=\sum_{i=1}^{n}\left(y_i-f\left(x_i\right)\right)^2$$

This formula is important because squaring the residuals makes all terms positive and gives larger penalties to bigger mistakes.

Least Squares Fitting

The most common curve-fitting method in Numerical Methods I is least squares fitting. The idea is simple: choose the model parameters so that the sum of squared residuals is as small as possible.

For a linear model $y=mx+b$, the objective is to minimize

$$S\left(m,b\right)=\sum_{i=1}^{n}\left(y_i-\left(mx_i+b\right)\right)^2$$

The best values of $m$ and $b$ are the ones that make $S\left(m,b\right)$ as small as possible.

Why use squared residuals? There are several reasons:

  • large errors are penalized more strongly,
  • positive and negative errors do not cancel each other out,
  • the math becomes manageable for many important models.

In engineering, least squares is useful when measurements are imperfect. For example, if a thermometer gives slightly different readings each time, least squares fitting can still produce a dependable trend line.

For linear fitting, the result is often called the best-fit line. If the data show a curved pattern, a higher-degree polynomial or another model may fit better.

Fitting a Straight Line

A straight-line fit is often the first step in curve fitting because it is easy to understand and compute. The model is

$$y=mx+b$$

where $m$ is the slope and $b$ is the $y$-intercept.

Suppose students has temperature and resistance data from a sensor. If the values increase nearly linearly, a straight line may be a good model. The fitted line gives an equation that can be used for prediction, calibration, and analysis.

In a least squares line fit, the slope and intercept can be found from formulas based on the data. A useful interpretation is that the line balances the points so that the vertical distances from the points to the line are overall as small as possible.

Example: if a lab measures force and extension for a spring and the graph looks roughly straight, then a linear fit can estimate the spring constant. This connects directly to engineering work because many systems are approximated by simple linear models near a working range.

A straight line is not always the best choice, though. If the data curve upward or downward clearly, a linear model may leave large residuals and give poor predictions.

Polynomial and Other Models

When data are not close to a straight line, engineers often use polynomial fitting. A polynomial model has the form

$$y=a_0+a_1x+a_2x^2+\cdots+a_kx^k$$

The number $k$ is the degree of the polynomial.

Polynomials are popular because they are flexible and easy to compute with. A quadratic model,

$$y=a_0+a_1x+a_2x^2$$

can represent simple curved behavior. Higher-degree polynomials can match more complex shapes, but too high a degree may produce unrealistic oscillations between data points.

Other common models are also important:

  • Exponential models for growth or decay, such as population change or capacitor discharge,
  • Logarithmic models for processes that rise quickly at first and then level off,
  • Power models for relationships like area and scaling.

Choosing the right model depends on both the data and the physical meaning of the problem. For example, radioactive decay is often modeled with an exponential function because the process naturally decreases by a fixed proportion over time.

Curve Fitting Versus Interpolation

Curve fitting is closely related to interpolation, but they are not the same.

In interpolation, the goal is to build a function that passes exactly through the given data points. If the data are $\left(x_1,y_1\right),\dots,\left(x_n,y_n\right)$, then the interpolating function satisfies

$$f\left(x_i\right)=y_i \quad \text{for all } i$$

In curve fitting, the fitted function may not pass through every point. Instead, it aims to represent the overall trend.

This difference matters in engineering. Interpolation is useful when the data are exact values from a table, such as a physics formula sampled at specific points. Curve fitting is better when measurements contain noise, which is common in experiments.

Think of a GPS altitude reading taken every second while driving over a hill. The measurements may bounce slightly because of sensor error. Interpolation would try to hit every noisy point exactly, while curve fitting would produce a smoother and often more realistic trend.

So, students, interpolation is about exact matching of known data, while curve fitting is about approximation and prediction.

How Curve Fitting Fits into Numerical Methods I

Curve fitting belongs to Numerical Methods I because it uses numerical reasoning to solve practical problems with data. This topic connects with the rest of the course in several ways.

First, curve fitting often leads to formulas that must be analyzed numerically. For example, if the fitted model is nonlinear, finding the best parameters may require iterative computation.

Second, the idea of approximation is central to numerical methods. Just as root-finding estimates solutions to equations and interpolation estimates unknown values between data points, curve fitting estimates an underlying relationship from noisy data.

Third, many fitting methods use algebraic systems or optimization ideas. In advanced cases, the best-fit parameters are found by solving equations derived from minimizing

$$S\left(\theta\right)=\sum_{i=1}^{n}\left(y_i-f\left(x_i;\theta\right)\right)^2$$

where $\theta$ represents the unknown parameters.

This shows a strong link to engineering computation: the computer is used not just to calculate numbers, but to build useful mathematical models from information collected in the real world.

Worked Example: Fitting a Trend

Suppose an engineer records the following data for a machine’s output:

$$\left(1,2.1\right),\left(2,4.0\right),\left(3,6.2\right),\left(4,8.1\right)$$

The points look close to a straight line. A reasonable model is

$$y=mx+b$$

If the line fit gives a slope near $2$ and an intercept near $0$, then the model is approximately

$$y\approx 2x$$

This means that when $x$ increases by $1$, $y$ increases by about $2$. In practice, that kind of model can help predict future output, compare performance, or identify whether a machine is behaving as expected.

Now suppose the data were curved instead, such as growth data that accelerates over time. Then a polynomial or exponential model might be more appropriate. The choice of model depends on the pattern in the data and the purpose of the analysis.

Conclusion

Curve fitting is a core numerical method for building useful equations from real data. It helps students transform measurements into models that can be analyzed, predicted, and applied in engineering tasks 🔧. The main idea is to choose a function whose residuals are small overall, often using least squares.

This lesson also showed how curve fitting differs from interpolation. Interpolation matches all points exactly, while curve fitting aims for the best overall approximation. Together with root-finding and interpolation, curve fitting forms an important part of Numerical Methods I because it teaches how numerical tools help engineers make sense of real-world data.

Study Notes

  • Curve fitting finds a function that best represents a set of data points.
  • Real data usually contain noise, so the fitted curve does not need to pass through every point.
  • The residual is $r_i=y_i-f\left(x_i\right)$.
  • Least squares fitting minimizes $S=\sum_{i=1}^{n}\left(y_i-f\left(x_i\right)\right)^2$.
  • A linear model has the form $y=mx+b$.
  • Polynomial, exponential, logarithmic, and power models are common in engineering.
  • Interpolation passes exactly through the data points, while curve fitting focuses on overall trend.
  • Curve fitting is useful for prediction, calibration, modeling, and analysis in engineering computation.

Practice Quiz

5 questions to test your understanding

Curve Fitting — Engineering Computation | A-Warded