Write three separate MATLAB programs to approximate the sine curve between 0 and 2Π using
(a) Curve fitting by a polynomial curve of power 4;
(b) Newton's interpolating polynomial;
(c) Lagrange's interpolating polynomial.
You may refer to the textbook (Numerical Methods for Engineers by Chapra and Canale) for the algorithms, but I expect that you can work that out yourself given the lecture materials.
For each of the three cases, you should generate points on the sine curve at regular intervals and use these points as your data points for the curve fitting. Use the same set for each of the curves.
1. For each case, investigate the quality of the fitting with varying number of data points. You can study that qualitatively by plotting the original sine curve on top of the fitted curves, together with the curve of the difference between the two. Compare the three results and comment on your observations. Use at least three different numbers of data points. You can choose your own numbers, but be sensible.
2. For each case, for one specific number of data points only (you decide that number) investigate the behaviour of the fitted curves if there are some errors in the data. You can manufacture the errors artificially by changing some (or all) of the sine values slightly for the given angles. This error should be random, and therefore different for different points. Your investigation should be systematic, by studying different errors progressively; this means varying the bounds of the error magnitudes In each study. Again, study the variations qualitatively by graphical means. Comment on the results. (This can be an endless investigation if you are to vary the data many times. So let's keep It to three.)
3. What conclusion can you draw from the comparison between Newton's and Lagrange interpolation polynomials? Explain your findings.
You should produce a report showing your results and commenting on the above investigations, supported by graphical outputs. Of course, your report should show the data you use for every case. Include printouts of your MATLAB programs in the report. (If I need to test your program, I will ask you for a softcopy separately.)
The above are all that you have to submit. But for those of you who fancy an extra challenge, fit a cubic spline to the curve, and perform the same analysis as above. You can obtain the tangent directions at the start and the end points of the spline from the tangent directions of the sine curve at the corresponding points.