This homework is due the day before Thanksgiving, although we do not have class Nov 23. You can leave it under my office door any time. If it is difficult for you to bring the homework to NYU, let me know by email and we'll make some other arrangement.
Write a function that takes as input a set of points such as the S points, and plots 3 different interpolating curves in 3 different graphics windows: (1) using polynomial interpolation, (2) using piecewise cubic Hermite interpolation, and (3) using cubic splines. You can use any method you want to compute these. For (1) I suggest either setting up a Vandermond matrix and solving it, or using polyinterp, which uses the Lagrange formulation. For (2), use pchip or pchiptx. For (3), use spline or splinetx. Recall that the polyinterp, pchiptx and splinetx routines, along other related files and the accompanying text book, are available at Moler's website. All these routines have similar interfaces: the first argument specifies the independent variable at the interpolation points, which here is called t (the integers 1 through 21 in the case of the S points), the second provides the dependent variable values, which here are either x or y, at the interpolation points, and the third provides additional independent variable values at which the interpolating function is supposed to be evaluated, for example, 1: 0.1: 21 or equivalently linspace(1,21,201). Your plots should be plots in the x-y plane, not of x as a function of t or y as a function of t. Plot the interpolation points with the symbol '*' and the interpolating (in-between) points, with '.' or '-', but be aware that if you use '-', the plotter does additional linear interpolation between the points. The function should be written to handle any set of points. In addition to the results for the S points, print results for another set of points that you make up yourself (try to think of something with an interesting smooth shape).
Modify tridisolve (available here) so that it is suitable for solving any tridiagonal system, by introducing partial pivoting (row interchanges). As discussed in class, that means one more array is needed to store the second superdiagonal of the matrix, to store the fill-in (nonzeros that are introduced by the elimination). Be sure you include comments in the program, which may as well document the original code as well as the new lines. Test the program on some tridiagonal systems with some zeros or small numbers on the diagonal. How much CPU time is needed to solve a tridiagonal system with size one million? Does the row pivoting increase the running time substantially? Compare the accuracy and speed with using Matlab's sparse matrix system i.e. x = T\d where T = spdiags([[a; 0] b [0; c]],[-1 0 1],n,n), as suggested in the comments of tridisolve. Here the [-1 0 1] refers to the first subdiagonal, diagonal, and superdiagonal of T; with this approach, the fill-in is taken care of automatically so you don't have to allocate space for the second superdiagonal.