MATH2070: LAB 6: Interpolation on Evenly-spaced Points



Introduction Exercise 1
Matlab Tips Exercise 2
The Polynomial through Given Data Exercise 3
Vandermonde's Equation Exercise 4
Lagrange Polynomials Exercise 5
Interpolating functions that are not polynomials Exercise 6
Trigonometric polynomial interpolation Exercise 7
  Exercise 8
  Exercise 9
  Exercise 10


Introduction

This lab will consume three sessions. It covers material from Sections 3.1 and 3.8 of Atkinson on interpolation on evenly-spaced points. If you print this lab, you may prefer to use the pdf version.

This lab is concerned with interpolating data with polynomials and with trigonometric functions. There is a difference between interpolating and approximating. Interpolating means that the function passes through all the given points little regard to the points between them. Approximating means only that the function is close to all the given points. Although it might seem that interpolating is always better than approximating, this is not true.

Polynomials are commonly used to interpolate data. There are several methods for defining, constructing, and evaluating the polynomial of a given degree that passes through data values. One common way is to solve for the coefficients of the polynomial by setting up a linear system called Vandermonde's equation. A second way is to represent the polynomial as the sum of simple Lagrange polynomials. Other ways are available and are discussed in Atkinson. In addition, we will discuss interpolation using trigonometric polynomials.

We will examine these two ways of finding the interpolating polynomial and a way of finding the interpolating trigonometric polynomial. We will see that interpolation does not necessarily mean good approximation and that polynomial interpolation can break down with a fatal case of ``the wiggles.'' Trigonometric polynomial interpolation does better, but can also break down.

Notation

This lab is focussed on finding functions that pass through certain specified points. In customary notation, you are given a set of points $ \{(x_k,y_k)\vert k=1,2,\ldots,n\}$ and you want to find a function $ f(x)$ that passes through each point ( $ f(x_k)=y_k$ for $ k=1,2,\ldots,n$). The given points are variously called the ``given'' points, the ``specified'' points, the ``data'' points, etc. In this lab, we will use the term ``data points.''

Written in the customary notation, it is easy to see that the quantities $ x$ and $ x_k$ are essentially different. In Matlab, without kerning and font differentiation, it can be difficult to keep the various quantities straight. In this lab, we will use the name xval to denote the values of $ x$ and the names xdata and ydata to denote the data $ x_k$ and $ y_k$. The variable names fval or yval are used for the value $ f(x)$ to emphasize that it is the value of the function approximating $ y$.


Matlab Tips

At some point in this lab, you will need to determine if a quantity A is not equal to a quantity B. The Matlab syntax for this is

  if A ~= B
Sometimes it is convenient to enclose the logical expression in parentheses, but this is not required.

If you have a (square) linear system of equations, of the form

  A * x = b
where A is an N by N matrix, and b and x are column vectors, then Matlab can solve the linear system either by using the expression:
  x = inv(A)*b
or, better, via the ``backslash'' command:
  x = A \ b
The backslash command is strange looking. You might remember it by noting that the matrix A appears underneath the backslash. The difference between the two commands is merely that the backslash command is about three times faster because it solves the equation without constructing the inverse matrix. You will not notice a difference in this lab, but you might see one later if you use Matlab for more complicated projects.

The backslash command is actually more general than just multiplication by the inverse. It can find solutions when the matrix A is singular or when it is not a square matrix! We will discuss how it does these things later in the course, but for now, be very careful when you use the backslash operator because it can find ``solutions'' when you do not expect a solution.

Matlab has several commands for dealing with polynomials:

poly(r)
Finds the coefficients of the polynomial whose roots are given by the vector r.
roots(c)
Finds the roots of the polynomial whose coefficients are given by the vector c.
polyfit( xdata, ydata, n)
Finds the coefficients of the polynomial of degree n passing through the points xdata(k),ydata(k), for $ \texttt{k}=1,2,\dots,K$, where $ K$ need not be near to n.
polyval( c, xvals)
Evaluates a polynomial with coefficients given by the vector c at the values xvals(k) for $ k=1,2,\dots,K$ for $ K\ge 1$.

When there are more data values than the minimum, the polyfit function returns the coefficients of a polynomial that ``best fits'' the given values in the sense of least squares. This polynomial approximates, but does not necessarily interpolate, the data. In this lab, you will be writing m-files with functions similar to polyfit but that generate polynomials of the precise degree determined by the number of data points. (n=length(xdata)-1.

The vector of coefficients c of a polynomial in Matlab are, by convention, defined as

$\displaystyle p(x)=\sum_{k=1}^N c_k x^{N-k}$ (1)

Beware: When a vector of numbers, c, of length N, is regarded as coefficients of a polynomial, the subscripts run backwards! c(1) is the coefficient of the term with degree N-1, and the constant term is c(N).

In this and some later labs, you will be writing m-files with functions analogous to polyfit and polyval, using several different methods. Rather than following the matlab naming convention, functions with the prefix coef_ will generate a vector of coefficients, as by polyfit, and functions with the prefix eval_ will evaluate a polynomial (or other function) at values of xval, as with polyval.

In the this lab and often in later labs we will be using Matlab functions to construct a known polynomial and using it to generate ``data'' values. Then we use our interpolation functions to recover the original, known, polynomial. This strategy is a powerful tool for illustrative and debugging purposes, but practical use of interpolation starts from arbitrary data, not contrived data.


The Polynomial through Given Data

In Lab 4 we discussed Newton's method, which can be derived by determining a linear polynomial (degree 1) that passes through the point $ (a,f_a)$ with derivative $ f'_a$. That is $ p(a)=f_a$ and $ p'(a)=dp/dx(a)=f'_a$. One way of looking at this is that we are constructing an interpolating function, in this case a polynomial, that explains all the data that we have. We may then want to examine the graph of the polynomial, evaluate it at other points, determine its integral or derivative, or do other things with it. This is a reason that polynomial interpolation is important even when the functions we are interested in are not polynomials.


Vandermonde's Equation

Here's one way to see how to organize the computation of the polynomial that passes through a set of data. It's not the best way, but it will give us a good place to start.

Suppose we wanted to determine the linear polynomial $ p(x)=c_1x+c_2$ that passes through the data points $ (x_1,y_1)$ and $ (x_{2},y_{2})$. We simply have to solve a set of linear equations for $ c_1$ and $ c_2$.

$\displaystyle c_1 x_1 + c_2$ $\displaystyle = y_1$    
$\displaystyle c_1 x_2 + c_2$ $\displaystyle = y_2$    

or, equivalently,

$\displaystyle \left[\begin{array}{cc}x_1 & 1 x_2 & 1\end{array}\right]
\left[...
...c_1 c_2\end{array}\right]=
\left[\begin{array}{c}y_1 y_2\end{array}\right]
$

which (usually) has the solution
$\displaystyle c_1$ $\displaystyle =$ $\displaystyle ( y_2 - y_1 ) / ( x_2 - x_1 )$  
$\displaystyle c_2$ $\displaystyle =$ $\displaystyle ( x_2 y_1 - x_1 y_2 ) / ( x_2 - x_1 )$  

Compare that situation with the case where we want to determine the quadratic polynomial $ p(x) = c_1 x^2 + c_2 x + c_3$ that passes through three sets of data values. Then we have to solve the following set of linear equations for the polynomial coefficients c:

$\displaystyle \left[\begin{array}{ccc}x_1^2 & x_1 & 1 x_2^2&x_2 & 1\\
x_3^2&...
...c_3\end{array}\right]=
\left[\begin{array}{c}y_1 y_2 y_3\end{array}\right]
$

This is an example of a third order Vandermonde Equation. It is characterized by the fact that for each row (sometimes column) of the coefficient matrix, the succesive entries are generated by a decreasing (sometimes increasing) set of powers of a set of variables.

You should be able to see that, for any collection of abscissae and ordinates, it is possible to define a linear system that should be satisfied by the (unknown) polynomial coefficients. If we can solve the system, and solve it accurately, then that is one way to determine the interpolating polynomial.

Now, let's see how to construct and solve the Vandermonde equation using Matlab. This involves setting up the coefficient matrix A. As before, we use the Matlab variables xdata and ydata to represent the quantities $ x_k$ and $ y_k$, and we will assume them to have length n.

for j = 1:n
  for k = 1:n
    A(j,k) = xdata(j)^(n-k) ;
  end
end
Then we have to set the right hand side to the ordinates ydata. If we can get all of that set up, then actually solving the linear system is easy. We just write:
c = A \ ydata';
Recall that the backslash symbol means to solve the system with matrix A and right side ydata'. Notice that we are using the transpose of the row vector ydata in this equation. By default, Matlab constructs row vectors unless told to do otherwise.

Exercise 1: The Matlab built-in function polyfit finds the coefficients of a polynomial through a set of points. We will write our own using the Vandermonde matrix. (This is the way that Matlab actually uses.)
  1. Write a Matlab function m-file, coef_vander.m with signature
    function c = coef_vander ( xdata, ydata )
    % c = coef_vander ( xdata, ydata )
    % xdata= ???
    % ydata= ???
    % c= ???
    % other comments
    
    % your name and the date
    
    that accepts a pair of vectors xdata and ydata of arbitrary but equal length, and returns the coefficient vector c of the polynomial that passes through that data.
  2. Test your function by computing the coefficients of the polynomial through the following data points. (This polynomial is $ y=x^2$, so you can check your coefficient vector ``by inspection.'')
    xdata= [  0   1   2 ]
    ydata= [  0   1   4 ]
    
  3. Test your function by computing the coefficients of the polynomial that passes through the following points
    xdata= [ -3   -2  -1   0   1   2   3]
    ydata= [-364 -63  -6  -1   0  21 182]
    
  4. Confirm using polyval that your polynomial passes through these data points.

In the following exercise you will construct a polynomial using coef_vander to interpolate data points and then you will see what happens between the interpolation points.

Exercise 2:
  1. Consider the polynomial whose roots are r=[1 2 3 4 5]. Use the Matlab poly function to find its coefficients. Call these coefficients cTrue.
  2. This polynomial obviously passes through zero at each of these five ``data'' points. We want to see if our coef_vander function can reproduce it. To use our coef_vander function, we need a sixth point. You can ``read off'' the value of the polynomial at x=0 from its coefficients above. What is this value?
  3. Use the coef_vander function to find the coefficients of the polynomial passing through the ``data'' points
      xdata=[0  1 2 3 4 5];
      ydata=[?? 0 0 0 0 0];
    
    Call these coefficients cVander.
  4. What would happen if you had used only the five roots as xdata?
  5. Use the following code to compute and plot the values of the two polynomials on the interval [0,5]. How big is the difference between the curves? (We will be using essentially this same code in several following exercises. You should be sure you understand what it does. You might want to copy it to a script m-file.)
    xval=linspace(0,5,500);  % test abscissae for plotting
    yvalTrue=polyval(cTrue,xval);  % true ordinates
    yvalVander=polyval(cVander,xval);  % our ordinates
    plot(xval,yvalTrue,'b'); % true curve in blue
    hold on
    plot(xval,yvalVander,'r');  % our curve in red
    hold off
    norm(yvalTrue-yvalVander)
    
    Please include a copy of this plot with your summary. (If it appears that there is only one curve, it is possible that the two curves are on top of one another.)


Lagrange Polynomials

Suppose we fix the set of $ n$ distinct abscissæ $ x_k$, $ k=1,\ldots,n$ and think about the problem of constructing a polynomial that has (not yet specified) values $ y_i$ at these points. Now suppose I have a polynomial $ \ell_{7}(x)$ that is zero at each abscissa value, except that at $ x_{7}$, where it is 1. Then the intermediate polynomial $ y_{7} \ell_{7}(x)$ would have the value $ y_{7}$ at $ x_{7}$, and be 0 at all the other $ x_i$. Doing the same for each abscissa and adding the intermediate polynomials together results in the polynomial that interpolates the data!

In fact, the Lagrange polynomials $ \ell_k$ are easily constructed for any set of abscissae. Each Lagrange polynomial will be of degree $ n-1$. There will be $ n$ Lagrange polynomials, one per abscissa, and the $ k^{\mbox{th}}$ polynomial $ \ell_{k}(x)$ will have the special relationship with the abscissa $ x_{k}$, namely, it will be 1 there, and 0 at the other abscissæ.

In terms of Lagrange polynomials, then, the interpolating polynomial has the form:

$\displaystyle p(x)$ $\displaystyle =$ $\displaystyle y_1 \ell_1(x) + y_2 \ell_2(x) +\ldots + y_n \ell_n(x)$ (2)
  $\displaystyle =$ $\displaystyle \sum_{k=1}^n y_k\ell_k(x)$  

Assuming we can determine these magical polynomials, this is a second way to define the interpolating polynomial to a set of data.

Remark: The trick of finding a function that equals 1 at a distinguished point and zero at all other points in a set is very powerful. One of the places you will meet it again is when you study the construction of finite elements for solving partial differential equations.

Exercise 3: In this exercise and the following one, we will construct the polynomials passing through the same data points as in the previous exercise, but we will use the Lagrange polynomials. This exercise will concentrate on construction of the Lagrange polynomials and the following exercise will concentrate on fitting polynomials. Recall the data set for $ y=x^2$:
   k :    1   2   3
xdata= [  0   1   2   ]
ydata= [  0   1   4   ]
(Actually, ydata is immaterial for construction of $ \ell_k(x)$.) In general, the formula for $ \ell_{k}(x)$ can be written as:

$\displaystyle \ell_k(x)= (f_{1}(x)) (f_2(x)) \cdots (f_{k-1}(x)) (f_{k+1}(x)) \cdots (f_{n}(x) )$ (3)

(skipping the $ k^{\mbox{th}}$ factor), where each factor has the form

$\displaystyle f_{j}(x) = \frac{( x - x_{j} ) }{ ( x_{k} - x_{j})}.
$

  1. Write a Matlab function m-file called lagrange.m that computes the Lagrange polynomials (3) for any k. The signature should be
    function pval = lagrange( k , xdata, xval )
    % pval = lagrange( k , xdata, xval )
    % comments
    % k= ???
    % xdata= ???
    % xval= ???
    % pval= ???
    
    % your name and the date
    
    and the function should evaluate the k-th Lagrange polynomial for the abscissas xdata at the point xval. Hint, you can implement the general formula using code like the following.
    pval = 1;
    for j = 1 : n
      if j ~= k
        pval = pval .* ???
      end
    end
    
    Note 1: You will need to decide what to use for n.

    Note 2: If xval is a vector of values, then pval will be the vector of corresponding values, so that an elementwise multiplication (.*) is being performed.

  2. Check that lagrange gives the correct values (ones and zeros) at the data points xdata for each k. You should be able to use the commands:
      lagrange ( 1, xdata, xdata ) 
      lagrange ( 2, xdata, xdata ) 
      lagrange ( 3, xdata, xdata )
    

Exercise 4: The hard part is done. Now we want to use our lagrange routine as a helper for a second replacement for polyfit-polyval pair, called eval_lag, that implements Equation (2). Unlike coef_vander, the coefficient vector of the polynomial does not need to be generated separately because it is so easy, and that is why eval_lag both fits and evaluates the Lagrange interpolating polynomial.
  1. Write a Matlab function m-file called eval_lag.m with the signature
    function yval = eval_lag ( xdata, ydata, xval )
    % yval = eval_lag ( xdata, ydata, xval )
    %  comments
    
    % your name and the date
    
    This function should take the data values xdata and ydata, and compute the value of the interpolating polynomial at xval according to (2), using the lagrange.m file for the Lagrange polynomials. Be sure to include comments to that effect.
  2. Test eval_lag on the simplest data set we have been using.
         k :    1   2   3
      xdata= [  0   1   2 ]
      ydata= [  0   1   4 ]
    
    by evaluating it at xval=xdata. Of course, you should get ydata back.
  3. Test your function by interpolating the polynomial that passes through the following points, again by evaluating it at xval=xdata.
    xdata= [  -3  -2  -1   0   1   2   3]
    ydata= [-364 -63  -6  -1   0  21 182]
    
  4. Returning to the polynomial constructed in an earlier exercise with roots r=[1 2 3 4 5] and coefficients cTrue, reconstruct (using polyval) or recall the ydata values associated with xdata=[0 1 2 3 4 5] and compute the values of the Lagrange interpolating polynomial at the same 100 test points between 0 and 3. Call these values yvalLag. Plot yvalLag and yvalTrue and compute the error between them using the test plotting approach used above. Include a copy of this plot with your summary.


Interpolating functions that are not polynomials

Interpolating functions that are polynomials and using polynomials to do it is cheating a little bit. It is harder to use polynomials to interpolate functions that are not themselves polynomials. At the interpolation points, the function and its interpolant agree exactly, so we want to examine the behavior between the interpolation points.

Exercise 5:
  1. Construct a function m-file for the Runge function $ y=\frac{1}{1+x^2}$. Name the file runge.m and give it the signature
    function y=runge(x)
    % comments
    
    Use componentwise (vector) division and exponentiation (./ and .^).
  2. We would like to interpolate the Runge function on the interval $ [-\pi,\pi]$, so use the following outline to examine the behavior of the polynomial interpolant to the Runge function for five evenly-spaced points. It would be best if you put these commands into a script m-file named exer5.m.
    % construct n=5 data points
    n=5;
    xdata=linspace(-pi,pi,n);
    ydata=runge(xdata);
    
    % construct many test points
    xval=linspace(??,??,4001);
    % construct the true function, for reference
    yvalTrue=runge(??);
    
    % use Lagrange polynomial interpolation to evaluate 
    % the interpolant at the test points
    yval=eval_lag(??,??,xval);
    
    % plot reference values in blue, interpolant in red
    plot(xval,yvalTrue,'b');
    hold on
    plot(xval,yval,'r');
    hold off
    
    % estimate the approximation error of the interpolant
    approximationError=max(abs(yvalTrue-yval))
    
    Please send me this plot.
  3. Confirm visually that the Runge function and its interpolant agree at the interpolation points, but not necessarily between them.
  4. Using more data points gives higher degree interpolation polynomials. Fill in the following table using Lagrange interpolation with increasing numbers of data points.
      n =  5  Approximation Error = ________
      n = 11  Approximation Error = ________
      n = 21  Approximation Error = ________
    
    You probably are surprised to see that the errors do not decrease.

Most people expect that an interpolating polynomial $ p(x)$ gives a good approximation to the function $ f(x)$ everywhere, no matter what function we choose. If the approximation is not good, we expect it to get better if we increase the number of data points. These expectations hold only when the function does not exhibit some ``essentially non-polynomial'' behavior. You will see why the Runge function cannot be approximated well by polynomials in the following exercise.

Exercise 6: The Runge function has Taylor series

$\displaystyle \frac{1}{1+x^2}=1-x^2+x^4-x^6+\dots$ (4)

as you can easily prove. This series has a radius of convergence in the complex plane of 1. Polynomials, on the other hand, are entire functions, i.e., their Taylor series converges everywhere in the complex plane. No finite sum of polynomials can be anything but entire, but no entire function can approximate the Runge function on a disk with radius larger than one about the origin in the complex plane. If there were one, it would have to agree with the series (4) inside the unit disk, but the series diverges at $ x=i$ and an entire function cannot have an infinite value.
  1. Make a copy of exer5.m called exer6.m that uses coef_vander and polyval to evaluate the interpolating polynomial rather than eval_lag.
  2. Confirm that you get the same results as in Exercise 5 when you use Vandermonde interpolation for the Runge function.
      n =  5  Approximation Error = ________
      n = 11  Approximation Error = ________
      n = 21  Approximation Error = ________
    
  3. Look at the nontrivial coefficients ($ c_k$) of the interpolating polynomials by filling in the following table.
    n=5   c( 5)= _____  c( 3)= _____  c( 1)= _____
    n=11  c(11)= _____  c( 9)= _____  c( 7)= _____  c( 5)= _____
    n=21  c(21)= _____  c(19)= _____  c(17)= _____  c(15)= _____
    
  4. Look at the trivial coefficients ($ c_k$) of the interpolating polynomials by filling in the following table. (Look carefully at what the colon notation does.)
    n=5   max(abs(c(2:2: 5)))= _____
    n=11  max(abs(c(2:2:11)))= _____
    n=21  max(abs(c(2:2:21)))= _____
    
You should see that the interpolating polynomials are ``trying'' to reproduce the Taylor series (4). These polynomials cannot approximate the Runge function at all points, though, because the Taylor series does not converge at all points.


Trigonometric polynomial interpolation

Atkinson discusses interpolation by trigonometric polynomials in Section 3.8. I modify his expressions (3.8.11), (3.8.13), and (3.8.15) here to satisfy the restriction that subscripts in Matlab must be positive integers. Here, $ n$ is chosen so that $ 2n+1$ is the number of interpolation points.

$\displaystyle \ell_j$ $\displaystyle =(j-n-1),$    for $\displaystyle j=1,2,\dots,(2n+1)$    
$\displaystyle t_j$ $\displaystyle =\frac{2\pi\ell_j}{2n+1},$    for $\displaystyle j=1,2,\dots,(2n+1)$    
$\displaystyle a_k$ $\displaystyle =\frac{1}{2n+1}\sum_{j=1}^{2n+1}e^{-i(k-n-1)t_j}f(t_j),$    for $\displaystyle k=1,2,\dots,(2n+1)$ (5)
$\displaystyle f(t_j)$ $\displaystyle =\sum_{k=1}^{2n+1}a_ke^{i(k-n-1)t_j}$ (6)

Note that the interpolation points are required to be evenly-spaced and, in this case, are specific to the interval $ [-\pi,\pi]$.



Remark: The trigonometric coefficients $ a_k$ in (5) play the same role as the polynomial coefficients $ c_k$ in (1).

In the following exercises, we are going to write functions coef_trig to be analogous to polyfit and coef_vander, and also eval_trigl to be analogous to polyval and eval_lag.

Exercise 7:
  1. Construct a function m-file named coef_trig.m with the signature
    function a=coef_trig(f,n)
    % a=coef_trig(f,n)
    % f=???
    % n=???
    % a=???
    % comments
    
    % your name and the date
    
    This function should evaluate the trigonometric coefficients $ a_k$ according to Equation (5). It is more efficient to use vector (componentwise) notation and the Matlab sum function, but if you cannot see how to do that, just use for loops.
  2. Test your function by applying it to the function $ f(t)=e^{it}$, for n=10. (You can either write an m-file for $ e^{it}$ or use Matlab's inline command.) By examining Equation (6), you should be able to see that $ a_k=1$ for $ k=n+2$ and zero otherwise.
  3. Test your function again by applying it to $ f(t)=\sin t$ with n=10. You should see that $ a_k$ is zero for all but two subscripts. What subscripts ($ k$) have non-zero $ a_k$ and what are the values?

Exercise 8:
  1. Construct a function m-file named eval_trig.m with the signature
    function fval=eval_trig(a,tval)
    % fval=eval_trig(a,tval)
    % a=???
    % tval=???
    % fval=???
    % comments
    
    % your name and the date
    
    This function should evaluate Equation (6) at an arbitrary collection of points, tval, not just $ t_\ell$. Again, it is best to use vector (componentwise) notation and the Matlab sum function.
  2. Test your function by first using coef_trig to find the coefficients for the function $ \sin t$ with n=10 (you did this in the previous exercise), and then applying eval_trig to those coefficients at a selection of points in the interval $ [-\pi,\pi]$. Compare the interpolated values versus $ \sin t$. Plot them on the same plot: the lines should overlap. You can modify the m-file exer5.m that you wrote for Exercise 5. Call your modified m-file exer8.m. (Warning: Your interpolated values may appear to Matlab to be complex, and Matlab may not plot them the way you expect. In that case, verify that their imaginary parts (Matlab function imag) are zero and plot only the real (Matlab function real) parts. Please send me the plot.

Trigonometric polynomial interpolation does well even when the functions are not themselves trigonometric polynomials.

Exercise 9:
  1. Modify exer8.m to use the function $ y=e^{\sin t}$, and call the modified file exer9.m. Plot the function and its interpolant for n=2 and n=5. What are the approximation errors? You do not have to send me the plots.
  2. Do the same thing for the Runge function and fill in the following table.
      n = 2  Runge Approximation Error = ________
      n = 4  Runge Approximation Error = ________
      n = 5  Runge Approximation Error = ________
    
    You do not have to send me the plots.

The previous exercise shows that trigonometric polynomial interpolation does well for some functions. It does much less well when the function is not continuous. Consider, for example, the function

$\displaystyle f(x)=\begin{cases}x+\pi & \text{for } x<0\\
x-\pi & \text{for } x\ge0 \end{cases} $

Exercise 10:
  1. Copy the following code into a function m-file named sawtooth.m
    function y=sawtooth(x)
    % y=sawtooth(x)
    % x=???
    % y=???
    % comments
    
    % your name and the date
    
    y=(x+pi)-2*pi*(x>=0);
    
    Be sure to add the usual comments. This code works because of a trick. In Matlab the logical ``true'' is the same as the value 1, and ``false'' is zero. Hence the result of x>=0 is a vector of ones and zeros, with zeros where x<0 and ones where x>=0.
  2. Fill in the following table
      n =   5  Approximation Error = ________
      n =  10  Approximation Error = ________
      n = 100  Approximation Error = ________
    
    You can see that the approximation error is not shrinking, but if you look at the plots you will see that the error really is shrinking everywhere except near zero, where the oscillations get more rapid but do not get smaller. This behavior is typical and is called Gibbs's phenomenon. Please send me only the plot for n=100.



Back to MATH2070 page.





Mike Sussman 2006-09-14