Docsity

5 Problems on Numerical Computations - Homework 4 | MATH 451, Assignments of Mathematics

Toggle sidebar
bg1
CSE/MATH 451: Numerical Computations, section 2,
spring 2005
Home work 4
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.
1 Trapezoid and Simpson’s methods
Given function f(x) = e−xat the points 0.0,0.2,0.4,0.6,0.8, we would like to study
different numerical approximations to the integral
Z0.8
0.0
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 h2f00(ξ), 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 h4f(4)(ξ0), h =b−a
2n,
for some ξ0∈(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?
1
pf3
pf4

Partial preview of the text

Download 5 Problems on Numerical Computations - Homework 4 | MATH 451 and more Assignments Mathematics in PDF only on Docsity!

CSE/MATH 451: Numerical Computations, section 2,

spring 2005

Home work 4

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.

1 Trapezoid and Simpson’s methods

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

  1. 0

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?

2 Matlab problem: Trapezoid rule

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.

3 Matlab problem: Simpson’s rule

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.

4 Romberg algorithm

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).