CS314 Numerical Analysis

Homework 4

1. Do the following problems. Write your solutions on paper and turn them in during class on Wednesday July 24th

Page 259 Problem 1
Page 275 Problem 1
Page 276 Problem 5
Page 295 Problem 4

2. Write a program in matlab that asks for a function f(x), and an interval a, b, and plots the graph. You may take this part from homework 2. Name the program hw4.m

2. After ploting the graph, the progam will ask

1) Do you want to plot another function?,
or approximate the function using
2) Newthon approximation
3) Polynomila fitting
4) Splines
5) Exit
3. If you choose to approximate using Newthon method, the program will ask you for the number N of points the interval a,b will be subdivided, so there will be N+1 points: a, a+(b-a)/N, a+2(b-a)/N..,, a+N(b-a)/N. Then the program will plot f(x), the Newthon polynomial of degree 1, 2, ...N using lines of different colors. It will also plot crosses at each of the points and it will print the polynomial coefficients. The program will also display in another window the error f(x)-PN(x) for each polynomial.

4. If you choose the polynomial fitting option, the program will ask the degree M of the polynomial that will be used to fit the polynomial. The program will also ask you for the number N of points the interval a,b will be subdivided, so there will be N+1 points: a, a+(b-a)/N, a+2(b-a)/N..,, a+N(b-a)/N. The program will fit the function into the polynomial and it will plot f(x) and the polynomial P(X). It will also plot crosses at each point. Additionally, it will also plot in another window the error f(x)-P(x) and print the coefficients of the polynomial.

5. If you choose to approximate using Splines, the program will ask you for the number N of points the interval a,b will be subdivided, so there will be N+1 points: a, a+(b-a)/N, a+2(b-a)/N..,, a+N(b-a)/N. Then the program will plot f(x), the Spline, and it will plot crosses at each of the points.Also print the polynomial coefficients for each of the splines. Use the Natural Spline as the end-point constraint. Additionally, also plot in another window the error f(x)-P(x). Also print the coefficients of the polynomial.

Turn in

To turnin please e-mail your files to cs314-ta@cs.purdue.edu.

The deadline for the program is Sunday July 28th at 11:59pm.
E-mail your questions to cs314-ta