Numeric Chap 3
Numeric Chap 3
– Introduction
• Functions of Curve Fitting
• Types of Curve Fitting
– Linear Regression
• Quantification of Error of Linear Regression
– Linearization of Non-linear Models
– Polynomial Regression
– Interpolation
• Linear Interpolation
• Quadratic Interpolation
• Cubic Interpolation 1
Functions of Curve Fitting
1. You may require estimates at points b/n the data of
discrete values.
– techniques to fit curves to such data to obtain intermediate
estimates.
2. To make a simplified version of a complicated
function.
– compute values of the function at a number of discrete values
along the range of interest.
– then, a simpler function may be derived to fit these values.
• Both of these applications are known as Curve Fitting.
2
Types of Curve Fitting
• There are two general approaches for curve fitting based
on the amount of error associated with the data.
1. Where the data exhibits a significant error, derive a
single curve that represents the general trend of the
data.
– Because any individual data point may be incorrect, we make
no effort to intersect every point.
– Rather, the curve is designed to follow the pattern of the
points taken as a group.
– One approach of this nature is called least-squares regression
(Fig. 3.1a).
2. Where the data is known to be very precise, fit a curve
that passes directly through each of the points. 3
Types of Curve Fitting
– The estimation of values between well-known discrete points
is called Interpolation (Fig. 3.1b and c).
…. (a)
• This criterion yields a unique line for a given set of data.
• To determine values for a0 and a1, Eq. (a) is differentiated wrt
each coefficient:
… (b)
5
Least-squares Regression
• All summations are from i = 1 to n.
• Setting the derivatives equal to zero will result in a
minimum Sr.
…. (c)
• Since we can express the equations as a set of
two simultaneous linear equations with two unknowns
(a0 & a1):
…. (d)
The equations can be solved simultaneously as,
and … (e, f)
6
Example 3.1: Linear Regression
• Fit a straight-line to the x and y values in the table
below.
x y
1 0.5
2 2.5
3 2.0
4 4.0
5 3.5
6 6.0
7 5.5
7
Example 3.1: Linear Regression
• Soln.
8
Example 3.1: Linear Regression
10
Quantification of Error of Linear Regression
• The analogy can be extended to the determination of “Standard
Deviation” for the regression line as:
11
Improvement Due to Linear Regression
• Improvement
12
Improvement Due to Linear Regression
• Improvement
13
Example 3.2: Estimation of error for the linear least-squares fit
• Compute the total standard deviation, the standard error of the
estimate, and the correlation coefficient for the data in Example
3.1.
14
Example 3.2: Estimation of error for the linear least-squares fit
• Example 3.2
15
Example 3.3: Linear Regression
• Fit a straight line to the x and y values in the table
below. Compute the Total Standard Deviation, Standard
Error of Estimate and the Coefficient of Determination.
x y
10 25
20 70
30 380
40 550
50 610
60 1220
70 830
80 1450 16
Example 3.3: Linear Regression
• Soln.
17
Linearization of Non-linear Relationships
• Linear regression provides a powerful technique for
fitting a best line to data.
• However, it is predicated on the fact that the relationship
b/n the dependent and independent variables is linear.
• This is not always the case, and the first step in any
regression analysis should be to plot and visually inspect
the data to ascertain whether a linear model applies.
• Fig. 3.7 (a) Data ill-suited for linear least-squares regression, (b) Parabola is preferable.
18
Linearization of Non-linear Relationships
• Exponential Model
19
Linearization of Non-linear Relationships
• Power Eqn. and Saturation-growth-rate Eqn.
20
Linearization of Non-linear Relationships
• Exponential Eqn. and Power Eqn. Transformations
21
Linearization of Non-linear Relationships
• Saturation-growth-rate Eqn. Transformations
22
Linearization of Non-linear Relationships
• Exponential Eqn. and Power Eqn. Transformations
23
Linearization of Non-linear Relationships
• Saturation-growth-rate Eqn. Transformations
24
Example 3.4: Linearization of Non-linear Eqns.
• Fit a power equation to the data given below by using
linear transformation
x y
1 0.5
2 1.7
3 3.4
4 5.7
5 8.4
25
Example 3.4: Linearization of Non-linear Eqns.
• Soln
26
Example 3.4: Linearization of Non-linear Eqns.
• Soln
27
Example 3.5: Linearization of Non-linear Eqns.
• A
28
Example 3.5: Linearization of Non-linear Eqns.
• Soln.
29
Example 3.5: Linearization of Non-linear Eqns.
• Soln.
30
Polynomial Regression
• PR
31
Polynomial Regression
• PR
32
Polynomial Regression
• PR
33
Example 3.6: Polynomial Regression
• Fit a 2nd – order polynomial (m = 2) to the data given
below.
x y
0 2.1
1 7.7
2 13.6
3 27.2
4 40.9
5 61.1
34
Example 3.6: Polynomial Regression
• Soln.
35
Example 3.6: Polynomial Regression
• Soln.
36
Interpolation
• Interpolation can be used to:
– estimate intermediate values between precise data points;
– approximate a complicated function by a polynomial function which is
simple to differentiate and integrate
• For n + 1 data points, there is one and only one polynomial of
order n that passes through all the points.
– there is only one straight line that connects two points
– only one parabola connects a set of three points
• Polynomial Interpolation consists of determining a unique nth-
order polynomial that fits n + 1 data points.
• The polynomial then provides a formula to compute intermediate
values.
37
Interpolation
• there are a variety of mathematical formats in which nth-order
polynomial can be expressed;
• two alternatives that are well-suited for computer implementation:
Newton and Lagrange Interpolating Polynomials.
• Newton Interpolating Polynomials: Linear Interpolation
εt = 48.3%.
• Using smaller interval from x0 = 1 to x1 = 4 yields
εt = 33.3%.
40
Quadratic Interpolation
• For more accurate results, introduce some curvature into the line
connecting the points
• For three data points, use a 2nd-order polynomial
• One convenient form for this purpose is
f2(x) = b0 + b1(x − x0) + b2(x − x0)(x − x1)
f2(x) = b0 + b1x − b1x0 + b2x2 + b2x0x1 − b2xx0 − b2xx1
or, collecting terms,
f2(x) = a0 + a1x + a2x2
• a0 = b0 − b1x0 + b2x0x1
• a1 = b1 − b2x0 − b2x1
• a2 = b2
• Recall that the general form of nth-order polynomial is:
f(x) = a0 + a1x + a2x2 +· · ·+anxn 41
Quadratic Interpolation
• A simple procedure can be used to determine the values of the
coefficients, b0 , b1, b2.
• b0 can be computed with x = x0 → b0 = f(x0)
• b1 can be computed with x = x1 →
• b1 still represents the slope of the line connecting points x0 and x1.
• The last term, b2(x − x0)(x − x1), introduces the 2nd -order
curvature into the formula.
42
Example 3.8: Quadratic Interpolation
• Fit a 2nd-order polynomial to the three points used in Example 3.7
• x0 = 1 f(x0) = 0
• x1 = 4 f(x1) = 1.386294
• x2 = 6 f(x2) = 1.791759
• Use the polynomial to evaluate ln 2.
Solution
• b0 = f(x0) = 0
45
Example 3.9: NIP
• In Example 3.8, data points at x0 = 1, x1 = 4, and x2 = 6 were used
to estimate ln 2 with a parabola. Now, adding a fourth point
[x3 = 5; f (x3) = 1.609438], estimate ln 2 with a third-order
Newton’s Interpolating Polynomial.
Solution
• The 3rd-order polynomial with n = 3, is
f3(x) = b0 + b1(x − x0) + b2(x − x0)(x − x1) + b3(x − x0)(x − x1)(x − x2)
• The first divided differences for the problem are
46
Example 3.9 Solution: NIP
• The second divided differences are
• The results for f [x1, x0], f [x2, x1, x0], and f [x3, x2, x1, x0] represent
the coefficients b1, b2, and b3, respectively.
• Along with b0 = f (x0) = 0.0, the cubic Eqn. is
f3(x) = 0 + 0.4620981(x − 1) − 0.05187311(x − 1)(x − 4)
+ 0.007865529(x − 1)(x − 4)(x − 6)
• which can be used to evaluate f3(2) = 0.6287686, εt = 9.3%.
47
Example 3.9 Solution: NIP
• The complete cubic polynomial is shown in Figure below.
48
Lagrange Interpolating Polynomials
• The Lagrange Interpolating Polynomial is simply a reformulation
of the Newton polynomial that avoids the computation of divided
differences. It can be represented concisely as
• where
49
Lagrange Interpolating Polynomials
• Each term Li (x) will be 1 at x = xi and 0 at all other sample points.
• Thus, each product Li(x) f(xi) takes on the value of f(xi) at the
sample point xi.
• Consequently, the summation of all the products designated by
fn(x) is the unique nth order polynomial that passes exactly
through all n + 1 data points.
50
Example 3.10: Lagrange Interpolating Polynomials
• Use a Lagrange interpolating polynomial of the first and second
order to evaluate ln 2, on the basis of the data given in Ex. 3.8:
• x0 = 1 f(x0) = 0
• x1 = 4 f(x1) = 1.386294
• x2 = 6 f(x2) = 1.791760
Solution
• The 1st-order polynomial can be used to estimate at x = 2,