230 likes | 338 Views
This lecture covers the construction of the Vandermonde matrix and its applications in polynomial interpolation. It first introduces a MATLAB function that accepts a vector of x values and a polynomial order to create the Vandermonde matrix. It then discusses the Runge phenomenon, highlighting the issues of equidistant interpolation points leading to oscillations. Examples of interpolation with increasing points are provided. Finally, the session emphasizes the significance of using interpolation techniques effectively to avoid issues in graphical representations.
E N D
MA/CS 375 Fall 2002 Lecture 23 MA/CS 375 Fall 2002
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
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
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
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
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
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
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
Double The Resolution In Each Direction Using 4th order Interpolation MA/CS 375 Fall 2002
Results From Interpolation Notice 300 pixels Notice 600 pixels MA/CS 375 Fall 2002
Details of Interpolation MA/CS 375 Fall 2002
Details of Interpolation Notice reduced pixellation on new image MA/CS 375 Fall 2002
But Not So Fast MA/CS 375 Fall 2002
Now try 10th order interpolation MA/CS 375 Fall 2002
Not So Good! Note stripes appearing on new image MA/CS 375 Fall 2002
Close Up of 10th Order Interpolation Looks quite bad!!! MA/CS 375 Fall 2002
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
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
Nth Order Mid-point Interpolation MA/CS 375 Fall 2002
Nth Order Mid-point Interpolation MA/CS 375 Fall 2002
Nth Order Mid-point Interpolation MA/CS 375 Fall 2002
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
Next Time • Using Matlab’s built in interpolation routine • Morphing images class project MA/CS 375 Fall 2002