curve fitting, interpolation · 2012. 4. 23. · relevance of curve fitting relevance of...
TRANSCRIPT
Curve Fitting, Interpolation
Mike Renfro
February 27, 2008
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Part I
Curve Fitting, Interpolation
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Relevance of Curve FittingRelevance of Interpolation
Relevance of Curve Fitting
Extracting parameters from experimental data:
A standard tensile test involves pulling on opposite ends of amaterial specimen and recording the amount of stretch(strain) in the specimen as the load and stress on thespecimen is gradually increased.
The initial portion of the stress-strain graph is theoretically astraight line, and its slope represents the modulus of elasticityof the specimen material.
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Relevance of Curve FittingRelevance of Interpolation
Relevance of Curve Fitting
Realistically, finite amounts of experimental error will beintroduced into both stress and strain measurements, causing thedata to not fall along a single straight line.
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Relevance of Curve FittingRelevance of Interpolation
Relevance of Curve Fitting
One method of curvefitting attempts to find asingle “best-fit” slope andintercept on a line thatwill minimize the overallamount of error betweenthe line and the datapoints. The slope of thatline is then used as a bestestimate of the specimen’selastic modulus.
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Relevance of Curve FittingRelevance of Interpolation
Relevance of Interpolation
The behavior of many engineering systems is very complex anddifficult or impossible to describe analytically. Experiments can berun for a large set of test cases, but not an infinite set.Interpolation provides a method to estimate the results of untestedcases based off the results of known cases.
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Relevance of Curve FittingRelevance of Interpolation
Relevance of Interpolation
For example, the specific heat property of a given material can befound via calorimetry experiments, but is not a constant for allpossible temperatures.
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Relevance of Curve FittingRelevance of Interpolation
Relevance of Interpolation
Interpolation provides a way for us to make close estimates of thematerial’s specific heat at other temperatures, in this case, byfitting a series of simple compatible curves to each segment of theoriginal data.
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Step Function SplineLinear SplineQuadratic Spline
Piecewise Spline Interpolation
Some interpolation methods shown early in Chapter 5 attempt tofit a single function (normally a polynomial) to a wide selection ofdata points. This can cause several problems shown in Figure 5.8.
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Step Function SplineLinear SplineQuadratic Spline
Problem 1
Some functions simply aren’t accurately described with a singlepolynomial function.
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Step Function SplineLinear SplineQuadratic Spline
Problem 2
Most such interpolations yield an nth order polynomial when givenn + 1 points — the result is a function with large oscillations notconfirmed by further experiments. Even if the theoretical functionis a close match for a single polynomial, small errors in the fitpoints can drastically throw off the calculations.
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Step Function SplineLinear SplineQuadratic Spline
Terminology
Spline: a piecewise polynomial of low order (normally linear,quadratic, or cubic).
Piecewise: the particular function is defined only on a smallrange of x values, not across the entire function domain.
Knots: the data points that the splines must pass through.
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Step Function SplineLinear SplineQuadratic Spline
Trivial Case: Step Function Spline
The step function spline is the simplest case. The interpolatedfunction value is identical to the function value at the previousknot. Since this has the potential to display large discontinuities, itis almost never used.
fi (x) = f (xi−1)
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Step Function SplineLinear SplineQuadratic Spline
Linear Spline
A linear spline connects adjacent knots with straight lines.
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Step Function SplineLinear SplineQuadratic Spline
Development of Linear Spline
For example, the first two knots in a set of data points are(x0, f (x0)) and (x1, f (x1)). The equation of the line connectingthem is
f1(x) = f (x0) +
(f (x1)− f (x0)
x1 − x0
)(x − x0)
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Step Function SplineLinear SplineQuadratic Spline
Development of Linear Spline
For the general case of knots i − 1 and i , the equation would be
fi (x) = f (xi−1) +
(f (xi )− f (xi−1)
xi − xi−1
)(x − xi−1)
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Step Function SplineLinear SplineQuadratic Spline
Linear Spline Procedure
Given: a table of xi and f (xi ) data, and a value x to interpolate af (x) value for.
Locate the interval of xi points that contains the required x .
Plug the appropriate values of xi−1, xi , f (xi−1), f (xi ), and xinto the previous formula and calculate the correspondingf (x).
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Step Function SplineLinear SplineQuadratic Spline
Linear Spline Example
(5.10) Find a linear spline to fit the following data:
i 0 1 2 3 4
xi 2.0 3.0 6.5 8.0 12.0
f (xi ) 14.0 20.0 17.0 16.0 23.0
Use the results to estimate the value of f at x = 7.0.
x = 7.0 lies on the interval [6.5, 8.0].
Use i = 3, xi−1 = 6.5, xi = 8.0, f (xi−1) = 17.0, andf (xi ) = 16.0.
The spline equation becomes
f3(x) = f (x2) +
(f (x3)− f (x2)
x3 − x2
)(x − x2)
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Step Function SplineLinear SplineQuadratic Spline
Linear Spline Example (continued)
Substitute the values for i , xi , xi−1, f (xi ), and f (xi−1):
f3(x) = 17.0 +
(16.0− 17.0
8.0− 6.5
)(x − 6.5)
Collect the terms:
f3(x) = 21.3333− 0.6667x
Substitute x = 7.0 into the equation:
f (7.0) = 21.3333− 0.6667(7.0) = 16.6664
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Step Function SplineLinear SplineQuadratic Spline
Quadratic Spline
One drawback to the linear spline is that even though it is acontinuous function (unlike the step function spline), it does notexhibit a continuous first derivative. To overcome this limitation,we use higher-order polynomials instead of straight lines.
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Step Function SplineLinear SplineQuadratic Spline
Quadratic Spline Development
Assuming we have n + 1 knot coordinates (xi ,f (xi )),i = 0, 1, 2, · · · , n, we’ll need to calculate the equations for ndifferent quadratic functions that connect them. Each of thesefunctions can be expressed in the form
fi (x) = ai + bix + cix2, i = 1, 2, · · · , n
where ai , bi , and ci are unknown constants. Since we have 3nunknowns, we can solve for them if we can find 3n independentequations concerning them.
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Step Function SplineLinear SplineQuadratic Spline
Quadratic Spline Development
First, the quadratic functions must be continuous at the knots.That is, the function value at an interior knot xi must be the sameregardless of whether it is calculated using piecewise function fi (x)or fi+1(x):
fi (x = xi ) = ai + bixi + cix2i = f (xi ), i = 1, 2, · · · , n − 1
fi+1(x = xi ) = ai+1 + bi+1xi + ci+1x2i = f (xi ), i = 1, 2, · · · , n− 1
The above equations provide 2n − 2 conditions, out of a 3n totalrequired.
Warning: the x values are known here, the a, b, and c values arethe unknowns!
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Step Function SplineLinear SplineQuadratic Spline
Quadratic Spline Development
Second, the first and last quadratic functions must pass throughthe endpoints x0 and xn, respectively:
f1(x = x0) = a1 + b1x0 + c1x20 = f (x0)
fn(x = xn) = an + bnxn + cnx2n = f (xn)
The above equations provide 2 conditions, making the total so far2n.
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Step Function SplineLinear SplineQuadratic Spline
Quadratic Spline Development
Third, we need continuous first derivatives. The quadraticfunctions themselves have continuous first derivatives, but we haveto ensure that the function slopes are continuous at each interiorknot:
f ′i (x) = bi + 2cix , i = 1, 2, · · · , n
f ′i (x = xi ) = f ′i+1(x = xi )
which yields
bi + 2cixi = bi+1 + 2ci+1xi , i = 1, 2, · · · , n − 1
The above equations provide n − 1 conditions, making the total sofar 3n − 1.
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Step Function SplineLinear SplineQuadratic Spline
Quadratic Spline Development
Finally, we need one more condition, and have some leeway in thecondition we can select. One common condition is to specify thatthe second derivative (curvature) of the last quadratic function iszero at xn:
f ′′n (x = xn) = 2cn = 0
cn = 0
We now have a 3n set of equations, with 3n unknowns. Use any ofthe methods from Chapter 3 to solve them.
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Step Function SplineLinear SplineQuadratic Spline
Quadratic Spline Example
(5.11) Find a quadratic spline to fit the data given in Example5.10. Use the results to estimate the value of f at x = 7.0.
i 0 1 2 3 4
xi 2.0 3.0 6.5 8.0 12.0
f (xi ) 14.0 20.0 17.0 16.0 23.0
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Step Function SplineLinear SplineQuadratic Spline
Quadratic Spline Example: Step 1
The quadratic functions must be continuous
fi (x = xi ) = ai + bixi + cix2i = f (xi ), i = 1, 2, · · · , n − 1
fi+1(x = xi ) = ai+1 + bi+1xi + ci+1x2i = f (xi ), i = 1, 2, · · · , n− 1
f1(x1) = a1 + 3b1 + 9c1 = 20
f2(x2) = a2 + 6.5b2 + 42.25c2 = 17
f3(x3) = a3 + 8b3 + 64c3 = 16
f2(x1) = a2 + 3b2 + 9c2 = 20
f3(x2) = a3 + 6.5b3 + 42.25c3 = 17
f4(x3) = a4 + 8b4 + 64c4 = 16
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Step Function SplineLinear SplineQuadratic Spline
Quadratic Spline Example: Step 2
The first and last functions must pass through the endpoints x0
and xn
f1(x0) = a1 + 2b1 + 4c1 = 14
f4(x4) = a4 + 12b4 + 144c4 = 23
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Step Function SplineLinear SplineQuadratic Spline
Quadratic Spline Example: Steps 3 and 4
The first derivatives must match at each interior knot
b1 + 6c1 − b2 − 6c2 = 0
b2 + 13c2 − b3 − 13c3 = 0
b3 + 16c3 − b4 − 16c4 = 0
Finally, set the second derivative at x4 to 0
c4 = 0
and we have 12 equations and 12 unknowns.
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Step Function SplineLinear SplineQuadratic Spline
Quadratic Spline Example: Matrix Form
1 3 9 0 0 0 0 0 0 0 0 00 0 0 1 6.5 42.25 0 0 0 0 0 00 0 0 0 0 0 1 8 64 0 0 00 0 0 1 3 9 0 0 0 0 0 00 0 0 0 0 0 1 6.5 42.25 0 0 00 0 0 0 0 0 0 0 0 1 8 641 2 4 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 1 12 1440 1 6 0 −1 −6 0 0 0 0 0 00 0 0 0 1 13 0 −1 −13 0 0 00 0 0 0 0 0 0 1 16 0 −1 −160 0 0 0 0 0 0 0 0 0 0 1
a1b1c1a2b2c2a3b3c3a4b4c4
=
20171620171614230000
Which can be solved for the unknown a, b, and c values:a1 = −25.7858, a2 = 10.1683, a3 = 105.1112, a4 = 2.0000,b1 = 29.1548, b2 = 5.1854, b3 = −24.0278, b4 = 1.7500,c1 = −4.6309, c2 = −0.6361, c3 = 1.6111, c4 = 0.0000.
Mike Renfro Curve Fitting, Interpolation
IntroductionSpline Interpolation
Step Function SplineLinear SplineQuadratic Spline
Quadratic Spline Example: Conclusion
The quadratic spline functions can then be written as:
f1(x) = −25.7858 + 29.1548x − 4.6309x2; 2.0 ≤ x ≤ 3.0
f2(x) = 10.1683 + 5.1854x − 0.6361x2; 3.0 ≤ x ≤ 6.5
f3(x) = 105.1112− 24.0278x + 1.6111x2; 6.5 ≤ x ≤ 8.0
f4(x) = 2.0000 + 1.7500x ; 8.0 ≤ x ≤ 12.0
and the value of f at x = 7.0 is then
f3(7.0) = 105.1112− 24.0278(7.0) + 1.6111(7.0)2 = 15.8605
Mike Renfro Curve Fitting, Interpolation