AMSC/CMSC 460 HW3: Approximating Integrals with Undetermined Coefficients & Gauss-Leguerre, Assignments of Computer Science

Solutions to problem 3 of the amsc/cmsc 460 homework, which involves using the method of undetermined coefficients to derive the 'half simp' formula and approximating integrals using gauss-leguerre quadrature. Matlab scripts to solve the linear systems and find the abscissas and weights for the quadrature formula.

Typology: Assignments

Pre 2010

Uploaded on 02/13/2009

koofers-user-t9g-1
koofers-user-t9g-1 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
AMSC/CMSC 460 Homework 3 Due 3/13
Show work for all three problems. If you used Matlab, hand in scripts
showing what you did. The following are useful fodder for the Matlab’s help
command: horzcat,vertcat,mldivide,roots.
1. Use the method of undetermined coefficients to derive the “half simp” formula
Z1
1/2
f(x)dx
=A0f(0) + A1f(1/2) + A2f(1);
[Hint: Use Matlab to solve the linear system.]
Answer: We have the three equations
R1
1/21dx =1
2=A0+A1+A2
R1
1/2x dx =3
8=1
2A1+A2
R1
1/2x2dx =7
24 =1
4A1+A2
the solution is
format long
C = [1 1 1; 0, 1/2, 1; 0, 1/4, 1];
b = [1/2; 3/8; 7/24];
A = C\b;
A =
-0.04166666666667
0.33333333333333
0.20833333333333
2. We wish to approximate
Z
0
f(x)exdx =A0f(0) + A1f(3) + A2f(5).
Use the method of undetermined coefficients to determine the weights Ai. Apply your
quadrature rule to approximate
Z
0
sechx dx =π
2= 1.5707 . . . . ()
[Hints: First find a formula for R
0xnexdx. It will then be easy to set up a 3×3 for
the Ai.]
Answer: The system is determined as in the first problem. Using the fact that R
0xn=n!, we get
the following Matlab script.
1
pf3

Partial preview of the text

Download AMSC/CMSC 460 HW3: Approximating Integrals with Undetermined Coefficients & Gauss-Leguerre and more Assignments Computer Science in PDF only on Docsity!

Show work for all three problems. If you used Matlab, hand in scripts showing what you did. The following are useful fodder for the Matlab’s help command: horzcat, vertcat, mldivide, roots.

  1. Use the method of undetermined coefficients to derive the “half simp” formula ∫ (^1)

1 / 2

f (x) dx ∼= A 0 f (0) + A 1 f (1/2) + A 2 f (1);

[Hint: Use Matlab to solve the linear system.]

Answer: We have the three equations

∫ (^1) 1 / 2 1 dx^ =^

1 ∫ 2 =^ A^0 +^ A^1 +^ A^2 1 1 / 2 x dx^ =^

3 8 =^

1 ∫ 2 A^1 +^ A^2 1 1 / 2 x

(^2) dx = 7 24 =^

1 4 A^1 +^ A^2

the solution is

format long C = [1 1 1; 0, 1/2, 1; 0, 1/4, 1]; b = [1/2; 3/8; 7/24]; A = C\b; A = -0.

  1. We wish to approximate ∫ (^) ∞

0

f (x)e−x^ dx = A 0 f (0) + A 1 f (3) + A 2 f (5).

Use the method of undetermined coefficients to determine the weights Ai. Apply your quadrature rule to approximate

∫ (^) ∞

0

sechx dx =

π 2

[Hints: First find a formula for

0 x

ne−x (^) dx. It will then be easy to set up a 3×3 for

the Ai.]

Answer: The system is determined as in the first problem. Using the fact that

∫ (^) ∞ 0 x

n (^) = n!, we get

the following Matlab script.

C = [1, 1, 1; 0, 3, 5; 0, 9, 25]; b = [1, 1, 2]’; A = C\b;

A =

-0.

The evaluation of the integral (∗) goes as follows.

absc = [0, 3, 5]; f = sech(absc).exp(absc); apprx = fA

apprx =

  1. Compute the abscissas and weights for the Gauss–Leguerre quadrature formula ∫ (^) ∞

0

f (x)e−x^ dx = A 0 f (x 0 ) + A 1 f (x 1 ) + A 2 f (x 2 );

Use it to approximate the integral (∗). Compare your results with those of Problem 2. [Hints: This involves three steps. First, you must find the coefficients of the cubic Laguerre polynomial p(x) = x^3 − ax^2 − bx − c satisfying

0 x

ip(x)e−x (^) = 0 (i = 0, 1 , 2).

Then you must find the roots of this polynomial. Finally, you must determine the weights as usual. A three line Matlab script will do all of this.]

Answer: Here is the matlab script that evaluates the abscissas and weights.

coef = [1;-([2,1,1;6,2,1;24,6,2][6;24;120])] absc = sort(roots(coef)) wgt = [1 1 1;... absc(1), absc(2), absc(3);... absc(1)^2, absc(2)^2, absc(3)^2][1;1;2]

coef =

-9.

-6. absc =