<<

Outlines

Curve Fitting,

Mike Renfro

October 14, 2004

Mike Renfro Fitting, Interpolation Part I: Review of Previous Lecture Outlines Part II: Curve Fitting, Interpolation

Review of Previous Lecture

Mike Renfro Curve Fitting, Interpolation Part I: Review of Previous Lecture Outlines Part II: Curve Fitting, Interpolation

Curve Fitting and Interpolation

Introduction Relevance of Curve Fitting Relevance of Interpolation

Spline Interpolation Step Linear Spline Quadratic Spline

Homework

Mike Renfro Curve Fitting, Interpolation Part I

Review of Previous Lecture

Mike Renfro Curve Fitting, Interpolation Review of Previous Lecture

Standard Matrix Eigenvalue Problem General Eigenvalue Problem Eigenvalue Solutions in MATLAB

Mike Renfro Curve Fitting, Interpolation Introduction Homework

Part II

Curve Fitting, Interpolation

Mike Renfro Curve Fitting, Interpolation Introduction Relevance of Curve Fitting Spline Interpolation Relevance of Interpolation Homework Relevance of Curve Fitting

Extracting parameters from experimental data: A standard tensile test involves pulling on opposite ends of a material specimen and recording the amount of stretch (strain) in the specimen as the load and stress on the specimen is gradually increased. The initial portion of the stress-strain graph is theoretically a straight line, and its represents the modulus of elasticity of the specimen material.

Mike Renfro Curve Fitting, Interpolation Introduction Relevance of Curve Fitting Spline Interpolation Relevance of Interpolation Homework Relevance of Curve Fitting Realistically, finite amounts of experimental error will be introduced into both stress and strain measurements, causing the data to not fall along a single straight line.

Mike Renfro Curve Fitting, Interpolation Introduction Relevance of Curve Fitting Spline Interpolation Relevance of Interpolation Homework Relevance of Curve Fitting

One method of curve fitting attempts to find a single “best-fit” slope and intercept on a line that will minimize the overall amount of error between the line and the data points. The slope of that line is then used as a best estimate of the specimen’s elastic modulus.

Mike Renfro Curve Fitting, Interpolation Introduction Relevance of Curve Fitting Spline Interpolation Relevance of Interpolation Homework Relevance of Interpolation

The behavior of many engineering systems is very complex and difficult or impossible to describe analytically. Experiments can be run for a large set of test cases, but not an infinite set. Interpolation provides a method to estimate the results of untested cases based off the results of known cases.

Mike Renfro Curve Fitting, Interpolation Introduction Relevance of Curve Fitting Spline Interpolation Relevance of Interpolation Homework Relevance of Interpolation

For example, the specific heat property of a given material can be found via calorimetry experiments, but is not a constant for all possible temperatures.

Mike Renfro Curve Fitting, Interpolation Introduction Relevance of Curve Fitting Spline Interpolation Relevance of Interpolation Homework Relevance of Interpolation Interpolation provides a way for us to make close estimates of the material’s specific heat at other temperatures, in this case, by fitting a series of simple compatible to each segment of the original data.

Mike Renfro Curve Fitting, Interpolation Introduction Step Function Spline Spline Interpolation Linear Spline Homework Quadratic Spline Piecewise Spline Interpolation

Some interpolation methods shown early in Chapter 5 attempt to fit a single function (normally a ) to a wide selection of data points. This can cause several problems shown in Figure 5.8.

Mike Renfro Curve Fitting, Interpolation Introduction Step Function Spline Spline Interpolation Linear Spline Homework Quadratic Spline Problem 1

Some functions simply aren’t accurately described with a single polynomial function.

Mike Renfro Curve Fitting, Interpolation Introduction Step Function Spline Spline Interpolation Linear Spline Homework Quadratic Spline Problem 2

Most such yield an nth order polynomial when given n + 1 points — the result is a function with large oscillations not confirmed by further experiments. Even if the theoretical function is a close match for a single polynomial, small errors in the fit points can drastically throw off the calculations.

Mike Renfro Curve Fitting, Interpolation Introduction Step Function Spline Spline Interpolation Linear Spline Homework Quadratic Spline Terminology

Spline: a piecewise polynomial of low order (normally linear, quadratic, or cubic). Piecewise: the particular function is defined only on a small of x values, not across the entire function domain. Knots: the data points that the splines must pass through.

Mike Renfro Curve Fitting, Interpolation Introduction Step Function Spline Spline Interpolation Linear Spline Homework Quadratic Spline Trivial Case: Step Function Spline The step function spline is the simplest case. The interpolated function value is identical to the function value at the previous knot. Since this has the potential to display large discontinuities, it is almost never used.

fi (x) = f (xi−1)

Mike Renfro Curve Fitting, Interpolation Introduction Step Function Spline Spline Interpolation Linear Spline Homework Quadratic Spline Linear Spline

A linear spline connects adjacent knots with straight lines.

Mike Renfro Curve Fitting, Interpolation Introduction Step Function Spline Spline Interpolation Linear Spline Homework Quadratic 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 connecting them is   f (x1) − f (x0) f1(x) = f (x0) + (x − x0) x1 − x0

Mike Renfro Curve Fitting, Interpolation Introduction Step Function Spline Spline Interpolation Linear Spline Homework Quadratic Spline Development of Linear Spline

For the general case of knots i − 1 and i, the equation would be   f (xi ) − f (xi−1) fi (x) = f (xi−1) + (x − xi−1) xi − xi−1

Mike Renfro Curve Fitting, Interpolation Introduction Step Function Spline Spline Interpolation Linear Spline Homework Quadratic Spline Linear Spline Procedure

Given: a table of xi and f (xi ) data, and a value x to interpolate a f (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 x into the previous formula and calculate the corresponding f (x).

Mike Renfro Curve Fitting, Interpolation Introduction Step Function Spline Spline Interpolation Linear Spline Homework Quadratic 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, and f (xi ) = 16.0. The spline equation becomes   f (x3) − f (x2) f3(x) = f (x2) + (x − x2) x3 − x2

Mike Renfro Curve Fitting, Interpolation Introduction Step Function Spline Spline Interpolation Linear Spline Homework Quadratic Spline Linear Spline Example (continued)

Substitute the values for i, xi , xi−1, f (xi ), and f (xi−1):

16.0 − 17.0 f (x) = 17.0 + (x − 6.5) 3 8.0 − 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 Introduction Step Function Spline Spline Interpolation Linear Spline Homework Quadratic Spline Quadratic Spline

One drawback to the linear spline is that even though it is a continuous function (unlike the step function spline), it does not exhibit a continuous first derivative. To overcome this limitation, we use higher-order instead of straight lines.

Mike Renfro Curve Fitting, Interpolation Introduction Step Function Spline Spline Interpolation Linear Spline Homework Quadratic 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 n different quadratic functions that connect them. Each of these functions can be expressed in the form

2 fi (x) = ai + bi x + ci x , i = 1, 2, ··· , n

where ai , bi , and ci are unknown constants. Since we have 3n unknowns, we can solve for them if we can find 3n independent equations concerning them.

Mike Renfro Curve Fitting, Interpolation Introduction Step Function Spline Spline Interpolation Linear Spline Homework Quadratic 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 same regardless of whether it is calculated using piecewise function fi (x) or fi+1(x):

2 fi (x = xi ) = ai + bi xi + ci xi = f (xi ), i = 1, 2, ··· , n − 1

2 fi+1(x = xi ) = ai+1 + bi+1xi + ci+1xi = f (xi ), i = 1, 2, ··· , n − 1 The above equations provide 2n − 2 conditions, out of a 3n total required.

Warning: the x values are known here, the a, b, and c values are the unknowns!

Mike Renfro Curve Fitting, Interpolation Introduction Step Function Spline Spline Interpolation Linear Spline Homework Quadratic Spline Quadratic Spline Development

Second, the first and last quadratic functions must pass through the endpoints x0 and xn, respectively:

2 f1(x = x0) = a1 + b1x0 + c1x0 = f (x0)

2 fn(x = xn) = an + bnxn + cnxn = f (xn) The above equations provide 2 conditions, making the total so far 2n.

Mike Renfro Curve Fitting, Interpolation Introduction Step Function Spline Spline Interpolation Linear Spline Homework Quadratic Spline Quadratic Spline Development

Third, we need continuous first derivatives. The quadratic functions themselves have continuous first derivatives, but we have to ensure that the function are continuous at each interior knot: 0 fi (x) = bi + 2ci x, i = 1, 2, ··· , n 0 0 fi (x = xi ) = fi+1(x = xi ) which yields

bi + 2ci xi = bi+1 + 2ci+1xi , i = 1, 2, ··· , n − 1

The above equations provide n − 1 conditions, making the total so far 3n − 1.

Mike Renfro Curve Fitting, Interpolation Introduction Step Function Spline Spline Interpolation Linear Spline Homework Quadratic Spline Quadratic Spline Development

Finally, we need one more condition, and have some leeway in the condition we can select. One common condition is to specify that the second derivative () of the last quadratic function is zero at xn: 00 fn (x = xn) = 2cn = 0

cn = 0

We now have a 3n set of equations, with 3n unknowns. Use any of the methods from Chapter 3 to solve them.

Mike Renfro Curve Fitting, Interpolation Introduction Step Function Spline Spline Interpolation Linear Spline Homework Quadratic Spline Quadratic Spline Example

(5.11) Find a quadratic spline to fit the data given in Example 5.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 Introduction Step Function Spline Spline Interpolation Linear Spline Homework Quadratic Spline Quadratic Spline Example: Step 1 The quadratic functions must be continuous

2 fi (x = xi ) = ai + bi xi + ci xi = f (xi ), i = 1, 2, ··· , n − 1 2 fi+1(x = xi ) = ai+1 + bi+1xi + ci+1xi = 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 Introduction Step Function Spline Spline Interpolation Linear Spline Homework Quadratic 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 Introduction Step Function Spline Spline Interpolation Linear Spline Homework Quadratic 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 Introduction Step Function Spline Spline Interpolation Linear Spline Homework Quadratic Spline Quadratic Spline Example: Matrix Form

 13900 000 000 0   a1   20  0 0 0 1 6.5 42.25 0 0 0 0 0 0  b   17     1     00000 018 6400 0   c   16     1     00013 900 000 0   a   20     2     0 0 0 0 0 0 1 6.5 42.25 0 0 0   b   17     2     00000 000 01864   c2   16    =  12400 000 000 0   a3   14   0 0 0 0 0 0 0 0 0 1 12 144   b   23     3     0 1 6 0 −1 −6 0 0 0 0 0 0   c   0     3     0 0 0 0 1 13 0 −1 −13 0 0 0   a   0     4     0 0 0 0 0 0 0 1 16 0 −1 −16   b   0   4    00000 000 000 1 c4 0 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 Introduction Step Function Spline Spline Interpolation Linear Spline Homework Quadratic Spline Quadratic Spline Example: Conclusion

The quadratic spline functions can then be written as:

2 f1(x) = −25.7858 + 29.1548x − 4.6309x ; 2.0 ≤ x ≤ 3.0 2 f2(x) = 10.1683 + 5.1854x − 0.6361x ; 3.0 ≤ x ≤ 6.5 2 f3(x) = 105.1112 − 24.0278x + 1.6111x ; 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

2 f3(7.0) = 105.1112 − 24.0278(7.0) + 1.6111(7.0) = 15.8605

Mike Renfro Curve Fitting, Interpolation Introduction Spline Interpolation Homework Homework

Problem 5.15, 5.17. Use MATLAB to solve any systems of equations required.

Mike Renfro Curve Fitting, Interpolation