1 / 25

Scientific Computing

Scientific Computing. Linear and Quadratic Splines. Splines Overview. We have looked at two methods of finding interpolating polynomials for a set of data points – Lagrange polynomials and Newton’s method .

igor-hester
Télécharger la présentation

Scientific Computing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Scientific Computing Linear and Quadratic Splines

  2. Splines Overview We have looked at two methods of finding interpolating polynomials for a set of data points – Lagrange polynomials and Newton’s method. While these methods are fairly simple to program, they have a serious drawback – for a large number of data points, the interpolating polynomial can be quite unstable.

  3. Splines Overview Here is a set of 11 data points and the computer interpolating polynomial. Note the high degree of oscillation near the ends. This is an unfortunate property of interpolating polynomials of high degree!

  4. Splines Overview Here is a picture of the same data, but with spline curves interpolating the data. Note how this interpolation is so much more smooth and stable than the previous example.

  5. What is a Spline Curve? A spline curve is a curve that is made of a set of simple curves (lines, quadratics, cubics) that are joined together. A spline is piece-wise defined. That is, it is defined over a set of sub-intervals of a given interval. This set is called a partition. Definition: A partition of an interval [a,b] is a sequence of points between a and b such that a = t0 < t1 < … < tn = b The numbers ti (i = 1 to n-1) are called knots

  6. Linear Spline Definition: A function S is a linear spline on [a,b] if The domain of S is [a,b] S is continuous on [a,b] There is a partition of points on [a,b] such that S is a linear function on each sub-interval [ti , ti+1 ]

  7. Linear Spline A linear spline is defined by its values at the set of knots. Given the table of values there is a unique linear spline with those values. On each sub-interval, [ti , ti+1 ] , the linear spline is defined by a linear function: Then, S(ti)= yi and S(ti+1) = yi+1 (verify this)

  8. Linear Spline Example:

  9. Linear Spline Piece-Wise Linear Formula for Spline: Note: The fractions here are just the first divided differences for the data.

  10. Matlab Linear Spline Function function v = piecelin2(x,y,u) %Piecewise linear interpolation. (Slightly modified from Moler text) % v = piecelin2(x,y,u) finds the piecewise linear value of S(x) % with S(x(j)) = y(j) and returns v = S(u). % First divided difference – “diff” is a built-in Matlab command delta = diff(y)./diff(x); % Find subinterval index k so that x(k) <= u < x(k+1) n = length(x); k = 1; for j = 2:n-1 if x(j) <= u; k = j; end end % Evaluate spline at u s = u - x(k); v = y(k) + s*delta(k);

  11. Matlab Linear Spline Example % x,y data in vector form x = 1:6; y = [16 18 21 17 15 12]; % A series of values along the x-axis u = 1.0:.05:6.0; [m n] = size(u); % polyvals stores the linear spline values for the u-values splinevals = zeros(n); for i = 1:n % Compute each polynomial value splinevals(i) = piecelin2(x,y,u(i)); end % Plot the x-y data as circles ('o') and the polynomial data as '-' plot(x,y,'o',u,splinevals,'-')

  12. Matlab Linear Spline Example

  13. Quadratic Spline Definition: A function Q is a quadratic spline on [a,b] if The domain of Q is [a,b] Q is continuous on [a,b] Q’ is continuous on [a,b] There is a partition of points on [a,b] such that Q is a polynomial of degree <= 2 on each sub-interval [ti , ti+1 ]

  14. Quadratic Spline Example: Class Exercise: Verify that Q satisfies all parts of the definition of a quadratic spline.

  15. Formula for Quadratic Spline Need to find constants ai, bi, ci, such that

  16. Formula for Quadratic Spline

  17. Formula for Quadratic Spline Need to find constants ai, bi, ci, such that Thus, we need to determine 3n different constants.

  18. Formula for Quadratic Spline We know that: Qi (ti ) = yi Qi (ti+1 ) = yi+1 Qi’ (ti+1 ) = Qi+1’ (ti+1 )(Q’ is continuous at knots) This gives n + n + (n-1) =3n -1 equations for 3n unknowns! Need one more condition on Q. Could use one of these a0 = 0 (Q0 is a line) Q’(t0 ) = z0 (slope at start) Q’’(t0 ) = w0 (curvature at start) We will use the second condition.

  19. Formula for Quadratic Spline Let zi = Qi’ (ti) Recall: Qi(x) = ai (x-ti)2 + bi (x-ti) + ci Then, Qi (ti ) = yi -> ci = yi Also, Qi’ (ti ) = zi -> bi = zi So, Qi(x) = ai (x-ti)2 + zi (x-ti) + yi Since Qi’(ti+1 ) = zi+1 we get 2ai(ti+1-ti) + zi = zi+1 Thus, ai = (zi+1-zi)/2(ti+1-ti)

  20. Formula for Quadratic Spline We then get a formula for Qi(x) in terms of data points ti and yi and the derivative values zi Now, z0 is given as data. How do we get other zi ?

  21. Formula for Quadratic Spline

  22. Formula for Quadratic Spline Algorithm: Given data (ti , yi) and z0 = derivative at Q(a), compute 1) for i = 1, 2, …,n 2)

  23. Quadratic Spline Example: Data x = [0 1 4], y = [1 -2 1] Create Matlab Program piecequad. This is one of your homework problems. We add another input variable z0, so we have piecequad(x,y,z0,u) Output is Qi(u) for i = interval in which u lies. Our example, get Q0 (x)= -3x2 + 1 Q1 (x) = 7/3 (x-1)2 – 7 (x-1) -2 (Verify this is correct!)

  24. Quadratic Spline Example: Plot this using Matlab: x = [0 1 4]; y = [1 -2 1]; % A series of values along the x-axis u = 0.0:.05:4.0; [m n] = size(u); % polyvals stores the quadratic spline values for the u-values splinevals = zeros(n); for i = 1:n splinevals(i) = piecequad(x,y,1,u(i)); end % Plot the x-y data as circles ('o') and the polynomial data as '-' plot(x,y,'o',u,splinevals,'-')

  25. Quadratic Spline Example:

More Related