1 / 23

MA/CS 375

MA/CS 375. Fall 2002 Lecture 23. Class Exercise. Part 1: Build a function called vandermonde.m which accepts a vector of x values and a polynomial order P In the function find N=length of x Function returns a matrix V which is Nx(P+1) and whose entries are:

jeslyn
Download Presentation

MA/CS 375

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. MA/CS 375 Fall 2002 Lecture 23 MA/CS 375 Fall 2002

  2. Class Exercise • Part 1: • Build a function called vandermonde.m which accepts a vector of x values and a polynomial order P • In the function find N=length of x • Function returns a matrix V which is Nx(P+1) and whose entries are: V(n,m) = (xn)(m-1) • Part 2: • Translate this pseudo-code to a Matlab script: • for N=1:5:20 • build x = set of N points in [-1,1] • build f = exp(x) • build xfine = set of 10N points in [-1,1] • build Vorig = vandermonde(N-1,x) • build Vfine = vandermonde(N-1,xfine) • build Finterp = Vfine*(Vorig\f); • plot x,f and xfine,Finterp on the same graph • end MA/CS 375 Fall 2002

  3. Runge Phenomenon • Theorem 2 (van Loan page 90) • Suppose If(x) is an N-1’th order interpolating polynomial of the function f at N distinct points x1,x2,..,xN. If f is N times continuously differentiable on an interval I containing the {x1,x2,..,xN} then for any x in I=[a,b]: MA/CS 375 Fall 2002

  4. Runge Phenomenon • If we base the interpolant on the equi-spaced points then after some basic math we can show:where MN bounds the N’th derivative MA/CS 375 Fall 2002

  5. Runge Phenomenon • If we base the interpolant on the equi-spaced points then after some basic math we can show:where MN bounds the N’th derivative • Hence if the N’th derivative is badly behaved this bound suggests the quality of interpolation may decrease with increasing N!!. MA/CS 375 Fall 2002

  6. Example: Runge Phenomenon • Use your Vandermonde routine to interpolate the function:for 10,20,30,40,50,60 points on the interval [-1,1] • Volunteer to describe what happens MA/CS 375 Fall 2002

  7. Interpolating in Two Directions • A picture (e.g. jpeg, tif or gif) is actually an array of pixel values • There are a number of ways to represent color on the pixel. • gif uses a colormap, indexed by an integer • jpeg uses an 8 bit number for each component of red, green and blue MA/CS 375 Fall 2002

  8. Loading an Image in Matlab • % read in the three dimensional array • pic = imread(‘foo.jpg’); • red = pic(:,:,1); • green = pic(:,:,2); • blue = pic(:,:,3); MA/CS 375 Fall 2002

  9. Double The Resolution In Each Direction Using 4th order Interpolation MA/CS 375 Fall 2002

  10. Results From Interpolation Notice 300 pixels Notice 600 pixels MA/CS 375 Fall 2002

  11. Details of Interpolation MA/CS 375 Fall 2002

  12. Details of Interpolation Notice reduced pixellation on new image MA/CS 375 Fall 2002

  13. But Not So Fast MA/CS 375 Fall 2002

  14. Now try 10th order interpolation MA/CS 375 Fall 2002

  15. Not So Good! Note stripes appearing on new image MA/CS 375 Fall 2002

  16. Close Up of 10th Order Interpolation Looks quite bad!!! MA/CS 375 Fall 2002

  17. What’s Going On • We have divided each line of the picture into non-overlapping sections, containing 10 points each. • We have then interpolated the picture values at the 10 points to 20 points on the same section • The equispaced points lead to the Runge phenomenon i.e. highly oscillatory interpolants at the ends of each section • How can we make this better? MA/CS 375 Fall 2002

  18. Team Exercise ( a little tricky – feel free to use loops) • Even for 10+ points the interpolant function is probably going to be ok at the center of the region. • build VDM for N points (N even) • build weights = VDM\(1;0;0;…;0) • load in your jpeg picture • now use these weights to build the interpolating values between each given points MA/CS 375 Fall 2002

  19. Nth Order Mid-point Interpolation MA/CS 375 Fall 2002

  20. Nth Order Mid-point Interpolation MA/CS 375 Fall 2002

  21. Nth Order Mid-point Interpolation MA/CS 375 Fall 2002

  22. Summary • So we have started to invert general matrix systems to obtain interpolating polyomial coefficients • We saw the Runge phenomenon in action when equi-spaced interpolation is used • We improved things somewhat by ignoring the interpolating polynomial away from the center of its range. MA/CS 375 Fall 2002

  23. Next Time • Using Matlab’s built in interpolation routine • Morphing images class project MA/CS 375 Fall 2002

More Related