Expt 1_Curve Fitting
Expt 1_Curve Fitting
Interpolation: Linear
§ If data is reliable, we can plot it and connect the Interpolation
data dots.
§ Since its really a group of small 𝑓(𝑥)s connecting one point to the
next, it doesn’t work very well for data that has built in random
error (scatter)
Regression or Curve Fitting:
§ capturing the trend in the data by assigning a single
function across the entire range. Curvilinear
Interpolation
𝒓 …(4)
■ Note that if 𝑛 = 𝑚, we have interpolation, not curve fitting. In that case both the numerator and the
denominator in Eq. (4) are zero, so that σ is indeterminate. (Explained on Next Slide with 7 data points)
We Ask:
….(5)
…..(6) (𝑛 + 1) ∑ 𝑥% 𝑦% − ∑ 𝑥% ∑ 𝑦% ….(9)
𝑎" = #
𝑛 + 1 ∑ 𝑥%# − (∑ 𝑥% )
■ Setting the above derivatives equal to zero will result in a
minimum Sr and we get
§ Substituting Eqn. (9) in Eqn. 8(a) we get
….(7) …..(10)
■ Eqns. (7) can be expressed as a set of two simultaneous linear where 𝑦2 & 𝑥̅ are means of 𝑦 and 𝑥 respectively.
equations with two unknowns 𝑎" & 𝑎# .
■ These are called the normal equations. They can be solved which can be easily solved.
simultaneously to give
a) the spread of the data around the mean of the dependent variable § Because the magnitude of this quantity is
b) the spread of the data around the best-fit line. scale-dependent the difference is normalized
§ The reduction in the spread in going from (a) to (b) as indicated by the to 𝑆, to yield
bell-shaped curves at the right, represents the improvement due to ….(13)
linear regression.
§ These concepts can be used to quantify the “goodness” of our fit. This is where 𝑟2 is called the coefficient of
useful for comparison of several regressions as illustrated in Figure (3). determination
§ To do this, we determine the total sum of the squares 𝑺𝒕 around the mean and 𝑟 is the correlation coefficient.
of 𝑦 values of the given data set. This is the magnitude of the residual error § For a perfect fit, 𝑆- = 0 and 𝑟 = 𝑟 $ = 1,
associated with the dependent variable prior to regression. signifying that the line explains 100% variability of
§ After performing the regression, we compute 𝑺𝒓 , the sum of the squares data.
of the residuals around the regression line. § The other extreme is 𝑟 = 𝑟 $ = 0 & 𝑆- = 𝑆,
§ The difference between the two quantities 𝑆, − 𝑆- , the improvement or error when the fit represents no improvement.
reduction due to describing the data in terms of a straight line rather than § r can also be computed using the relation
as an average value.
Dr. Pragati Ashdhir , Professor, Department of Physics, Hindu College@2024-25 ….(14) 12
Practice Problem-1 (Fitting a Straight Line)
a) Fit a straight line to the 𝑥 and 𝑦 values given in the following table.
b) Display the equation of the regression line (fitted line).
c) Plot both the fitted line and the given data points.
2
■ Thus, because 𝑆./0 < 𝑆. , the linear regression model has merit. The extent of the improvement is quantified by
■ These results indicate that 86.8 percent of the original uncertainty has been explained by the linear model or the
model explains 93.2% of variability in the given data.
ii. The 𝑦 values are independent random iii. Since the squares of residuals appear in
variables and all have the same variance. the eqn. (5),therefore, it provides more
Limitation: Using regression analysis, only those values of 𝑦 = 𝑓(𝑥) can be estimated that lie within
the range of the given data set.
The regression curve cannot be used to extrapolate the 𝑦 values.
𝑆 𝑎! , 𝑎" , … , 𝑎$ = ; 𝑤% [𝑦% − 𝑓 𝑥% ]#
0 0 0
%+,
■ This procedure forces the fitting function f(x) closer to
the data points that have higher weights.
■ If all the data have same importance, then the
weights are set to 1. 0 0 0
….(2)
§ It is to be noted that he above three equations are
■ Differentiating Eqn.(2) w.r.t. each of the unknown linear in three unknowns 𝑎" , 𝑎# & 𝑎$.
coefficients of the polynomial, we get § The coefficients of the unknowns can be calculated
directly from the observed data.
§ Thus, the problem of determining a least-squares
second-order polynomial is equivalent to solving a
system of three simultaneous linear equations.
Dr. Pragati Ashdhir , Professor, Department of Physics, Hindu College@2024-25 21
Practice Problem-4 (Quadratic Fitting)
a) Fit a quadratic polynomial to the 𝑥 and 𝑦 values given in the following table.
b) Display the equation of the regression curve. (fitted curve).
c) Plot both the fitted curve and the given data points.
These results indicate that 99.851 percent of the original uncertainty has been explained by the model
Dr. Pragati Ashdhir , Professor, Department of Physics, Hindu College@2024-25 22
Generalizing Polynomial Curve Fitting