Introduction to Scientific Computing

Assignment 1

Note: Please use Matlab, or Octave for this assignment. The code must compile on one of the lab

machines with your instructions. Document your code. The aim of the assignment is to give you

familiarity with using Matlab and with the strengths and weaknesses of different kind of polynomial

interpolants. Understanding how to apply the course material here is an important part of this

assignment. Note that the programs need not be long most can be less than 50 lines.

Instructions

1. Write programs to plot the exponential function and the “Hubbard” equation function in the

file hubbard.m on the interval [0,1]. In the Hubbard case use different values of time to show

and describe how the solution evolves in time.

2. Write a simple calling program to use the Matlab routine polyinterp that uses Lagrange

polynomial interpolation ( as described in the text book and given in the Matlab function

polyinterp) based on evenly spaced points to interpolate the Hubbard function on the interval

[0,1]. Use polynomials of degree 28, 36, 44, 52, and 60 and using the L1 L2 and L infinity

norms with 1001 sample points, (as defined in the slides). Comment on how the accuracy

varies in the present case. Change the points used to define the polynomial to the

Chebyshev points of degree N defined on the interval [0,1] denoted by i x where

(1 ) / 2, cos( / ), 0,…, i ii x y y i Ni N =− = = π and comment on the how the accuracy varies in

this case . Use graphs of the errors to illustrate your points and to connect the results back to

the Runge Example used in class.

3. Modify your program that uses the Matlab routine polyinterp that uses Lagrange

polynomial interpolation ( as described in the text book) based on evenly spaced points to

interpolate the GelbTanner function on the interval [-1,1]. Calculate the L2 and Linf (infinity)

error norms and provide a table showing how this error behaves as the polynomial degree is

28, 36, 44,52 and 60 .Again change the points to the Chebyshev points defined on [-1,1] and

comment on the how the accuracy varies in this case . Use graphs of the different solutions

and errors to illustrate your points.

4. Using Matlab’s Cubic Spline Routines . Further modify your codes for both functions to use

the matlab cubic spline routine spline. Compare the performance of the PCHIP interpolant

with the standard spline interpolant both visually and by computing the error norm as

described above what is the accuracy of the two methods and which would you use?

2

For these assignments, we expect both SOURCE CODE(s) and a written REPORT be uploaded

as a zip or tarball file to Canvas.

• Source code for all programs that you write, thoroughly documented.

o Include a README file describing how to compile and run your code.

• Your report should be in PDF format and should stand on its own.

o It should describe the methods used, explain your results and contain figures.

o It should also answer any questions asked above.

o It should cite any sources used for information, including source code and collaborators.

This homework is due on February 2rd 11:59 pm. If you don’t understand these directions, please send

questions to the TAs or come see one of the TAs or the instructor during office hours well in advance

of the due date.

Sale!