Introduction
Curve fitting refers to the process of generating a curve that fits to a set of data points. For example, consider a series of data points that consists of ‘n’ data points [(x1,y1),(x2,y2 )… (xn,yn)]. The variables yi are related to their respective xi through a function f(xi). In this configuration, the residual (Ri) of the ith data pair is defined as the difference between the theoretical value and the observed value (Eqn. 3.1).
The aim of curve fitting is to minimize Ri, i.e., to minimize the difference between expected values and the observed values. From Eqn. 3.1, it is evident that the value of Ri can be positive for some values of ‘i’ and it can be negative for others. Therefore, the objective of ‘least square’ in curve fitting is to minimize the sum of square of all the residuals.
In the following sections, the least square fitting of different types of data sets will be discussed. The curve fitting for a linear and a non-linear data set is described in Sections 3.2 and 3.3 respectively. This is followed by polynomial fitting in Section 3.4. The next section explains the fitting procedure using built-in Scilab function. Applications of these methods have been discussed in Section 3.6.
Fitting of Linear Data
Consider a data set having ‘n’ data points [(x1,y1),(x2,y2),… (xn,yn)]. The linear relation between xi and yi is given by Eqn. 3.2.
Eqn. 3.2 represents a straight line whose slope is ‘m’ and the intercept on y-axis is ‘c’. The residual (Ri) is given by Eqn. 3.3.
Eqn. 3.4 gives the sum of squares of all the residuals.
The objective of least square fitting method is to find the values of m and c, such that they minimize S. The minimum value of S can be determined by differentiating it w.r.t. the slope and the constant and then equating the differential to zero, i.e.
In Eqn, 3.5,
Simultaneous solution of Eqns. 3.7 and 3.9 will give,
Eqns. 3.7 and 3.9 can also be written in the matrix notation, i.e.
Eqn. 3.12 implies that
In Eqn. 3.14, the first element of the matrix C will give the slope of the best fit curve. The second element of this matrix will give the intercept on the y-axis.