


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Due: Friday March 4, 2005, in class. The problems will be graded selectively. Problems marked with (*) are more challanging, extra points will be awarded for them.
Given function f (x) = e−x^ at the points 0. 0 , 0. 2 , 0. 4 , 0. 6 , 0 .8, we would like to study different numerical approximations to the integral
∫ (^0). 8
f (x) dx.
a). Write out the trapezoid rule and compute the numerical integration with 8 digits.
b). Write out the Simpson’s rule and compute the numerical integration with 8 digits.
c). What is the exact value of the integral? What is the absolute error by using trapezoid and Simpson’s rule? Which method is better?
d). The error for trapezoid rule with (n+1) points is
ET (f ; h) = − b − a 12
h^2 f ′′(ξ), h = b − a n
for some ξ ∈ (a, b). The error for Simpson’s rule with (2n+1) points is
ES (f ; h) = − b − a 180
h^4 f (4)(ξ′), h = b − a 2 n
for some ξ′^ ∈ (a, b). If we wish the absolute value of the error to be smaller than 10 −^4 , how many points would be needed for each method?
Preparation: Use the help in Matlab to learn how to use the function feval. Write a Matlab function which computes the integral by trapezoid rule. Your function should be used by the following command in Matlab command window:
v=trapezoid(’funItg’,a,b,n)
where funItg.m is the name of the file of the function f (x), and a,b is the interval, and n is the number of sub-intervals (i.e., n+1 will be the number of points.) Test your function on problem 1. Write a script that computes for n = 4, 8 , 16 , 32 , 64 , 128. Compute also the absolute error for each n, and make a plot of the absolute error against n. (Use loglog to plot. ) How does the error change when n is doubled?
What to hand in? Print out your function in the file trapezoid.m, your script file, the plot of error, and your comments.
Write a Matlab function which computes the integral by Simpson’s rule. Your function should be used by the following command in Matlab command window:
v=simpson(’funItg’,a,b,n)
where funItg.m is the name of the file of the function f (x), and a, b is the interval, and n is the number of sub-intervals (i.e., 2n+1 will be the number of points.) Test your function on problem 1. Write a script that computes for n = 2, 4 , 8 , 16 , 32 , 128, the absolute error for each n, and a plot (with loglog) of the absolute error against n. How does the error change when n doubled? Compare the results with trapezoid rule and comment.
What to hand in? Your function in simpson.m, your script file, the plot of error, and your comments.
Preparation: Use helpdesk in Matlab to learn how to use the functions feval and quad.
a) Write a Matlab function that computes the Romberg intergration. One should be able to call the function by:
R=romberg(’f’,a,b,n)
d)* (extra 5 points) Estimate the error of the approximation to J in c)(ignore the error in computing f (x) and the round off error).