Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Interpolation and Curve Fitting - Assignment 4 | CS 340, Assignments of Computer Science

Material Type: Assignment; Professor: McNelis; Class: Intro Scientific Comp; Subject: Computer Science; University: Western Carolina University; Term: Spring 2004;

Typology: Assignments

Pre 2010

Uploaded on 08/19/2009

koofers-user-1xi-1
koofers-user-1xi-1 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 340 - Introduction to Scientific Computing
Homework Assignment # 4
Interpolation and Curve Fitting
Due: Wednesday, March 24, 2004
Note: You are to use MS Word (or your favorite document preparation system) in producing your write-up
for this assignment. You are welcome to work together, discussing ideas with each other, but for clarification
purposes the following work must be your own:
Your write-ups (discussions, illustrations, etc.), and
Your code
These will illustrate your own understanding of the topics covered and are not to be shared. You are welcome
to come to me if you have any questions regarding the project, the instructions, or my expectations.
1. Consider the function
f(x) = 1
1 + x2on [5,5]
(a) [15 points] Plot P10(x) and P16(x), the tenth and sixteenth degree Lagrange interpolating poly-
nomials, on the same axes with f(x) where x= [x0, x1,· · · , xn] are the (n+ 1) equi-spaced
points on [5,5] with x0=5 and xn= 5.
Comments:
If you choose to use MATLAB for this, download the M-files DivDiff.m and LagrangePoly.m
along with some instructions on how to use them from the course website.
If you choose to use Maple for this, first look up the help on interp (the one with the lower
case “i”).
Please use different colors and line styles in plotting the different functions.
Turn in your commands, and a copy of your graph with an appropriate title, a legend, and
labels on the axes.
(b) [15 points] Repeat the process above, except let x0, x1,· · · , xnbe the (n+ 1) Chebyshev nodes
on [5,5]. You will need to download the appropriate file (Cheby.m or Cheby.mws) from the
course website, and use it to generate the list of x-values, x0, x1,· · · , xn, you’ll need to start.
Again, turn in your commands, and a copy of your graph with an appropriate title, legend and
labels on the axes.
(c) [10 points] Repeat the process above, this time using your software’s built-in function, spline,
and the 11 equi-spaced points x= [x0,· · · , x10] on [5,5] from 1a, to graph f(x) along with the
interpolating cubic spine. Turn in your commands, and a copy of your graph with an appropriate
title, legend and labels on the axes.
(d) [10 points] Comment on the interpolating polynomials you found above: the difference the
selected points made; the difference the degrees made; the difference between the types of
interpolating polynomials; which polynomials should be regarded as the most accurate for ap-
proximating other values of f(x), etc.
pf3

Partial preview of the text

Download Interpolation and Curve Fitting - Assignment 4 | CS 340 and more Assignments Computer Science in PDF only on Docsity!

CS 340 - Introduction to Scientific Computing Homework Assignment # 4 Interpolation and Curve Fitting Due: Wednesday, March 24, 2004

Note: You are to use MS Word (or your favorite document preparation system) in producing your write-up for this assignment. You are welcome to work together, discussing ideas with each other, but for clarification purposes the following work must be your own:

  • Your write-ups (discussions, illustrations, etc.), and
  • Your code

These will illustrate your own understanding of the topics covered and are not to be shared. You are welcome to come to me if you have any questions regarding the project, the instructions, or my expectations.

  1. Consider the function f (x) =

1 + x^2 on [− 5 , 5]

(a) [15 points] Plot P 10 (x) and P 16 (x), the tenth and sixteenth degree Lagrange interpolating poly- nomials, on the same axes with f (x) where x = [x 0 , x 1 , · · · , xn] are the (n + 1) equi-spaced points on [− 5 , 5] with x 0 = −5 and xn = 5.

Comments:

  • If you choose to use MATLAB for this, download the M-files DivDiff.m and LagrangePoly.m along with some instructions on how to use them from the course website.
  • If you choose to use Maple for this, first look up the help on interp (the one with the lower case “i”).
  • Please use different colors and line styles in plotting the different functions.
  • Turn in your commands, and a copy of your graph with an appropriate title, a legend, and labels on the axes. (b) [15 points] Repeat the process above, except let x 0 , x 1 , · · · , xn be the (n + 1) Chebyshev nodes on [− 5 , 5]. You will need to download the appropriate file (Cheby.m or Cheby.mws) from the course website, and use it to generate the list of x-values, x 0 , x 1 , · · · , xn, you’ll need to start. Again, turn in your commands, and a copy of your graph with an appropriate title, legend and labels on the axes. (c) [10 points] Repeat the process above, this time using your software’s built-in function, spline, and the 11 equi-spaced points x = [x 0 , · · · , x 10 ] on [− 5 , 5] from 1a, to graph f (x) along with the interpolating cubic spine. Turn in your commands, and a copy of your graph with an appropriate title, legend and labels on the axes. (d) [10 points] Comment on the interpolating polynomials you found above: the difference the selected points made; the difference the degrees made; the difference between the types of interpolating polynomials; which polynomials should be regarded as the most accurate for ap- proximating other values of f (x), etc.
  1. Sleeping Snoopy (or is it Spike?)

Consider the picture of Snoopy shown below.

The data below gives the (xi, yi) values of points that form the upper curve of Snoopy.

xi 1 2 5 6 7 8 10 13 17 20 23 24 25 27 27.7 28 29 30 yi 3.0 3.7 3.9 4.2 5.7 6.6 7.1 6.7 4.5 7.0 6.1 5.6 5.8 5.2 4.1 4.3 4.1 3.

(a) [10 points] Use either MATLAB or Maple’s spline function to interpolate this data. Graph your results. Turn in your commands, and a copy of your graph with an appropriate title and labels on the axes. Your plot will look better (if you’re using MATLAB) if you use the command axis equal which gives equal tic-mark spacing in the x and y axes. (b) [15 points] Now break up the data into three pieces, as follows:

Piece 1: xi 1 2 5 6 7 8 10 13 17 yi 3.0 3.7 3.9 4.2 5.7 6.6 7.1 6.7 4.

Piece 2: xi 17 20 23 24 25 27 27. yi 4.5 7.0 6.1 5.6 5.8 5.2 4.

Piece 3: xi 27.7 28 29 30 yi 4.1 4.3 4.1 3. Create a cubic spline for each piece. Plot these three on the same graph. Turn in your commands, and a copy of your graph with an appropriate title and labels on the axes.