Homework/Programming 4. (Due Feb 18.)

advertisement
Homework/Programming 4. (Due Feb 18.)
Math. 417
Problem 1. (MATLAB) The first problem involves the approximation of
the “ruddy duck” (See, p.158-160). Figure 3.14 is another illustration that
the use of higher order polynomials may not work well in general. This
exercise shows that piecewise quadratic approximation does a pretty good job
on this problem. The data points in Table 3.18 provide 20 intervals which
we group together in pairs, i.e., the first two, the third and the fourth, the
fifth and sixth, etc. Each pair of intervals provide 3 data points which you
are to use to define the quadratic approximation (on that pair of intervals).
For example, the first two intervals provide {x0 , x1 , x2 } = {.9, 1.3, 1.9} with
corresponding y-values {y0 , y1 , y2 } = {1.3, 1.5, 1.85}.
You will have to write a routine which first defines all of the data. Next, you
need to loop through the interval pairs, fitting a quadratic to the x − y pair
and subsequently plotting the fit. This is done with the aid of a plot routine
quadp.m. This routine has the following interface:
function quadp(a,b,c,xs,xe,np)
Here the quadratic is given by P (x) = a + bx + cx2 and is valid over the
interval [xs,xe]. np is the number of intermediate plot points (use np=10).
You must call quadp for each of the 10 intervals. After looping through all
10 intervals, you will have a plot resembling those of Figures 3.12-3.13.
Problem 2. (BY HAND) Use undetermined coefficients to derive the second
order finite difference approximation to the derivative of f at x based on the
points x − h, x and x + h, i.e.,
f ′ (x) ≈ af (x − h) + bf (x) + cf (x + h)
Problem 3. (MATLAB) In this problem, we compare three finite difference
approximations applied to computing the derivative of ex at 0. The three
approximations are as follows:
(a) The forward difference approximation
f ′ (x) ≈
f (x + h) − f (x)
.
h
1
2
(b) The three term backward difference approximation
3/2f (x) − 2f (x − h) + 1/2f (x − 2h)
.
h
(c) The finite difference approximation of the previous problem.
f ′ (x) ≈
Compute the above three difference approximations and report the results and
error as a function of h with h = .1, .01, .001, . . . , 10−16 . Make sure that you
print you results in scientific notation. You will have a table with 16 lines,
each containing
h, r1 , e1 , r2 , e2 , r3 , e3
with ri and ei being, respectively, the result and error for the i’th approximation. The effect of computer round-off error should be apparent.
Hand in the results for the above problems and a copy of any
matlab code that you created to do the assignment.
Download