Math 449 - Homework 10 - Solutions The integral of f(x) over the interval [a,b] will be denoted I_[a,b]f(x)dx. 1) Exercise 1 (b), section 7.3, page 389. Construct by hand a Romberg table with three rows for the integral I_[0, 3] sin(4x) e^(-2x) dx = 0.1997146621. The first column is R(0,0) = T(0) = (3/2)(f(0) + f(3)) = -0.00199505 R(1,0) = T(1) = T(0)/2 + (3/2)f(3/2) = -0.02186444 R(2.0) = T(2) = T(1)/2 + (3/4)(f(3/4) + f(9/4)) = 0.01611754 The second column is R(1,1) = (4R(1,0) - R(0,0))/3 = -0.02848757 R(2,1) = (4R(2,0) - R(1,0))/3 = 0.02877821 The third column is R(2,2) = (16R(2,1) - R(1,1))/15 = 0.03259592 So we have the table: -0.00199505 -0.02186444 -0.02848757 0.01611754 0.02877821 0.03259592 ************************************************************************** 2) Exercise 4, section 7.3, page 390. Derive Boole's rule (M = 1, h = 1) by using the method of undetermined coefficients: Find the constants w_0, w_1, w_2, w_3, w_4 so that I_[0,4] g(t) dt = w_0g(0) + w_1g(1) + w_2g(2) + w_3g(3) + w_4g(4) is exact for the five functions g(t) = 1, t, t^2, t^3, t^4. The values of I_[0,4] g(t) dt are: I_[0,4] 1 dt = 4 I_[0,4] t dt = 8 I_[0,4] t^2 dt = 64/3 I_[0,4] t^3 dt = 64 I_[0,4] t^4 dt = 1024/5 Thus we obtain the linear system: w_0 + w_1 + w_2 + w_3 + w_4 = 4 w_1 + 2w_2 + 3w_3 + 4w_4 = 8 w_1 + 4w_2 + 9w_3 + 16w_4 = 64/3 w_1 + 8w_2 + 27w_3 + 64w_4 = 64 w_1 + 16w_2 + 81w_3 + 256w_4 = 1024/5 The solution to this system is: w_0 = 14/45, w_1 = 64/45, w_2 = 8/15, w_3 = 64/45, w_4 = 14/45. Therefore, the quadrature formula is: I_[0,4] g(t) dt = (2/45)[7g(0) + 32g(1) + 12g(2) + 32g(3) + 7g(4)] ************************************************************************** 3) Algorithms and Programs 3, section 7.3, page 392. The normal probability density function is f(t) = (1/sqrt(2pi))exp(-t^2/2) and the cumulative distribution is a function defined by F(t) = (1/2) + (1/sqrt(2pi)) I_[0,x]exp(-t^2/2) dt. Compute values for F(0.5), F(1.0), F(1.5), F(2.0), F(2.5), F(3.0), F(3.5), F(4.0) with 8 digits of accuracy. I used program 7.4 with parameters: n=10, a=0, b=0.5, 1.0, etc., tol=10^(-9). The function file for f(x) (written g.m below) is %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function y=g(x) y=1/2 + (1/sqrt(2*pi))*exp(-x^2/2); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% The program is shown below. To find F(0.5), for example, I used the command: format long [R,quad,err,h]=romber('g',0,0.5,10,10^(-9)); quad I obtained the following: F(0.5) = 0.691462461 F(1.0) = 0.841344746 F(1.5) = 0.933192799 F(2.0) = 0.977249868 F(2.5) = 0.993790335 F(3.0) = 0.998650102 F(3.5) = 0.999767371 F(4.0) = 0.999968329 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [R,quad,err,h]=romber(f,a,b,n,tol) %Input - f is the integrand input as a string 'f' % - a and b are upper and lower limits of integration % - n is the maximum number of rows in the table % - tol is the tolerance %Output - R is the Romberg table % - quad is the quadrature value % - err is the error estimate % - h is the smallest step size used M=1; h=b-a; err=1; J=0; R=zeros(4,4); R(1,1)=h*(feval(f,a)+feval(f,b))/2; while((err>tol)&(J