17.9 KB · commit a9602da
Let the set of data points be (xi,yi),i=1,2,…,m, and let the curve given by Y=f(x) be fitted to this data. At x=xi, the given ordinate is yi and the
corresponding value on the fitting curve is f(xi). If ei is the error of approximation at x=xi, then we have ei=yi−f(xi)(4.1) If we write
S=[y1−f(x1)]2+[y2−f(x2)]2+⋯+[ym−f(xm)]2=e12+e22+⋯+em2,(4.2)then the method of least squares consists in minimizing S, i.e., the sum of the squares of the errors. In the following sections, we shall study the linear and nonlinear least squares fitting to given data (xi,yi),i=1,2,…,m.
Let Y=a0+a1x be the straight line to be fitted to the given data, viz. (xi,yi),i=1,2,…,m. Then, corresponding to Eq. (4.2), we have
S=[y1−(a0+a1x1)]2+[y2−(a0+a1x2)]2+⋯+[ym−(a0+a1xm)]2(4.3)For S to be minimum, we have ∂a0∂S=0=−2[y1−(a0+a1x1)]−2[y2−(a0+a1x2)]−⋯−2[ym−(a0+a1xm)](4.4a) and ∂a1∂S=0=−2x1[y1−(a0+a1x1)]−2x2[y2−(a0+a1x2)]−⋯−2xm[ym−(a0+a1xm)](4.4b) The above equations simplify to ma0+a1(x1+x2+⋯+xm)=y1+y2+⋯+ym(4.5a) and a0(x1+x2+⋯+xm)+a1(x12+x22+⋯+xm2)=x1y1+x2y2+⋯+xmym(4.5b) or more compactly to ma0+a1i=1∑mxi=i=1∑myi(4.6a) and a0i=1∑mxi+a1i=1∑mxi2=i=1∑mxiyi(4.6b)
Equations (4.6) are called the normal equations, and can be solved for a0 and a1, since xi and yi are known quantities.
We can obtain easily a1=mi=1∑mxi2−(i=1∑mxi)2mi=1∑mxiyi−i=1∑mxi⋅i=1∑myi(4.7) and then a0=yˉ−a1xˉ.(4.8) Since ∂a02∂2S and ∂a12∂2S are both positive at the points a0 and a1, it follows that these values provide a minimum of S. In Eq. (4.8), xˉ and yˉ are the means of x and y, respectively. From Eq. (4.8), we have yˉ=a0+a1xˉ, which shows that the fitted straight line passes through the centroid of the data points.
Sometimes, a goodness of fit is adopted. The correlation coefficient (cc) is defined as cc=SySy−S,(4.9) where Sy=i=1∑m(yi−yˉ)2(4.10) and S defined by Eq. (4.3).
If cc is close to 1, then the fit is considered to be good, although this is not always true.
| xi | yi | xi2 | xiyi | (yi−yˉ)2 | (yi−a0−a1xi)2 |
|---|---|---|---|---|---|
| 1 | 0.6 | 1 | 0.6 | 7.84 | 0.0784 |
| 2 | 2.4 | 4 | 4.8 | 1.00 | 0.0676 |
| 3 | 3.5 | 9 | 10.5 | 0.01 | 0.0100 |
| 4 | 4.8 | 16 | 19.2 | 1.96 | 0.0196 |
| 5 | 5.7 | 25 | 28.5 | 5.29 | 0.0484 |
| 15 | 17.0 | 55 | 63.6 | 16.10 | 0.2240 |
The correlation coefficient =16.1016.10−0.2240=0.9930. ◀
Suppose that z is a linear function of two variables x and y. If the function z=a0+a1x+a2y is fitted to the data (z1,x1,y1),(z2,x2,y2),…(zm,xm,ym), then the sum S=i=1∑m(zi−a0−a1xi−a2yi)2
should be minimum. For this, we have
∂a0∂S∂a1∂S=−2∑(zi−a0−a1xi−a2yi)=0,=−2xi∑(zi−a0−a1xi−a2yi)=0,and ∂a2∂S=−2yi∑(zi−a0−a1xi−a2yi)=0. These equations simplify to
ma0+a1∑xi+a2∑yia0∑xi+a1∑xi2+a2∑xiyia0∑yi+a1∑yixi+a2∑yi2=∑zi=∑zixi=∑ziyi⎭⎬⎫(4.11)from which a0, a1 and a2 can be determined.
The given data may not always follow a linear relationship. This can be ascertained from a plot of the given data. If a nonlinear model is to be fitted, it can be conveniently transformed to a linear relationship. Some nonlinear laws and their transformations are given as follows.
(a) y=ax+xb
This can be written as
xy=ax2+b
Put xy=Y, x2=X. With these transformations, it becomes a linear model.
(b) xya=b
Taking logarithms of both sides, we get
log10x+alog10y=log10b.
In this case, we put
log10y=Y,log10x=X,
a1log10b=A0and−a1=A1,
so that
Y=A0+A1X.
(c) y=abx
Taking logarithms of both sides, we obtain
log10y=log10a+xlog10b
⇒Y=A0+A1X,
where
Y=log10y,A0=log10a,
X=x,andA1=log10b
(d) y=axb
We have
log10y=log10a+blog10x
⇒Y=A0+A1X,
where
Y=log10y,A0=log10a,A1=b
and
X=log10x.
(e) y=aebx
In this case, we write
lny=lna+bx
⇒Y=A0+A1X,
where
Y=lny,A0=lna,A1=b
and
X=x.
Solution: We have y=aebx Therefore, lny=lna+bx ⇒Y=A0+A1X, where Y=lny,A0=lna,A1=bandX=x. The table of values is given below
X Y=lny X2 XY 1 0.905 1 0.905 3 1.905 9 5.715 5 2.905 25 14.525 7 3.905 49 27.335 9 4.905 81 44.145 25 14.525 165 92.625 We obtain Xˉ=5,Yˉ=2.905 A1=5(165)−6255(92.625)−25(14.525)=0.5=b. Then A0=Yˉ−A1Xˉ=2.905−0.5(5)=0.405. Hence, a=eA0=e0.405=1.499. It follows that the required curve is of the form y=1.499e0.5x ◀
The table of values is
X Y X2 XY 0.333 0.140 0.111 0.047 0.200 0.098 0.040 0.020 0.125 0.074 0.016 0.009 0.083 0.061 0.007 0.005 0.741 0.373 0.174 0.081 We obtain A1=a=4(0.174)−(0.741)24(0.081)−0.741(0.373)=0.324,Xˉ=0.185,Yˉ=0.093 and A0=b=Yˉ−aXˉ=0.0331. Hence the required fit is Y=0.0331+0.324(X), which simplifies to y=0.324+0.0331(x)x.
[Note: The given data is obtained from the relation y=0.3162+0.0345xx] ◀
Let the polynomial of the nth degree, Y=a0+a1x+a2x2+⋯+anxn(4.12) be fitted to the data points (xi,yi),i=1,2,…,m. We then have
S=[y1−(a0+a1x1+a2x12+⋯+anx1n)]2+[y2−(a0+a1x2+a2x22+⋯+anx2n)]2+⋯+[ym−(a0+a1xm+a2xm2+⋯+anxmn)]2(4.13)Equating to zero the first partial derivatives and simplifying, we obtain the normal equations:
ma0+a1∑xi+a2∑xi2+⋯+an∑xina0∑xi+a1∑xi2+⋯+an∑xin+1a0∑xin+a1∑xin+1+⋯+an∑xi2n=∑yi,=∑xiyi, ⋮=∑xinyi⎭⎬⎫(4.14)where the summations are performed from i=1 to i=m.
The system (4.14) constitutes (n+1) equations in (n+1) unknowns, and hence can be solved for a0,a1,…,an. Equation (4.12) then gives the required polynomial of the nth degree.
For larger values of n, system (4.14) becomes unstable with the result that round off errors in the data may cause large changes in the solution. Such systems occur quite often in practical problems and are called ill-conditioned systems. Orthogonal polynomials are most suited to solve such systems and one particular form of these polynomials, the Chebyshev polynomials, will be discussed later in this chapter.
The normal equations are
4a0+14a1+62a214a0+62a1+308a262a0+308a1+1634a2=17.54=87.78=472.44,from which we obtain a0=1.24,a1=−1.05anda2=0.44 ◀
A frequently encountered problem in engineering and physics is that of fitting a sum of exponentials of the form y=f(x)=A1eλ1x+A2eλ2x+⋯+Aneλnx(4.15) to a set of data points (xi,yi),i=1,2,…,m, where m is much greater than 2n.
We describe here a computational technique due to Moore [1974]. For easy of presentation, we assume n=2.
Then the function y=A1eλ1x+A2eλ2x(4.16) is to be fitted to the data (xi,yi),i=1,2,…,m, and m≫4. It is known that y(x) satisfies a differential equation of the form dx2d2y=a1dxdy+a2y(4.17) where the constants a1 and a2 have to be determined. Integrating Eq. (4.17), we obtain y′(x)−y′(x0)=a1[y(x)−y(0)]+a2∫x0xy(x)dx,(4.18) where x0 is the initial value of x and y′(x)=dxdy. Integrating Eq. (4.18), we get
y(x)−y(0)−(x−x0)y′(x0)=a1∫x0xy(x)dx−a1(x−x0)y(x0)+a2∫x0x∫x0xy(x)dxdx(4.19)Now, ∫x0x∫x0xy(x)dxdx=∫x0x(x−t)y(t)dt Hence, Eq. (4.19) becomes
y(x)−y(0)−(x−x0)y′(x0)=a1∫x0xy(x)dx−a1(x−x0)y(x0)+a2∫x0x(x−t)y(t)dt(4.20)In Eq. (4.20), y′(x0) is eliminated in the following way. Let x1 and x2 be two data points such that x0−x1=x2−x0(4.21) Then Eq. (4.20) gives
y(x1)−y(x0)−(x1−x0)y′(x0)=a1∫x0x1y(x)dx−a1(x1−x0)y(x0)+a2∫x0x1(x1−t)y(t)dt(4.22)and
y(x2)−y(x0)−(x2−x0)y′(x0)=a1∫x0x2y(x)dx−a1(x2−x0)y(x0)+a2∫x0x2(x2−t)y(t)dt(4.23)Adding Eqs. (4.22) and (4.23) and using Eq. (4.21), we obtain
y(x1)+y(x2)−2y(x0)=a1[∫x0x1y(x)dx+∫x0x2y(x)dx]+a2[∫x0x1(x1−t)y(t)dt+∫x0x2(x2−t)y(t)dt](4.24)Equation (4.24) can now be used to set up a linear system of equations for a1 and a2, and then we obtain λ1 and λ2 from the characteristic equation
λ2=a1λ+a2(4.25) Finally, A1 and A2 can be obtained by the method of least squares or by the method of averages.
*See Section 6.4.2.