{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

hw9_solutions

hw9_solutions - Due November 6 2008 CS 257(Luke Olson...

This preview shows pages 1–2. Sign up to view the full content.

Due: November 6, 2008 CS 257 (Luke Olson): Homework #9 Problem 1 Problem 1 We are coding for a particle physics team and asked to compute the mass of a region with density ρ = ln ( x ) x - 1 . That is, compute m = Z 1 0 ρ ( x ) dx. We convince the team use n -point Gauss Quadrature, praising its ability to achieve spectral convergence as n increases. Is this a good idea in this situation? Why not Newton-Cotes? Use int gauss.m and hand in a plot (with code) of n versus error along with comments on the outcome . ( hint: the integral should be π 2 / 6 . See dilog and polylogarithm in Wikipedia for more information ). Solution We test the accuracy of Gauss Quadrature with the following script (a reference case of f ( x ) = cos ( πx ) is commented out): 1 clear ; 2 f=inline( ’log(x)./(x-1)’ ); 3 exact= pi ˆ2 / 6; 4 5 %f=inline(’cos(pi * x/2)’); 6 %exact=2/pi; 7 8 nlist=2:100; 9 err= length (nlist); 10 err2= length (nlist); 11 12 for k=1: length (nlist) 13 n=nlist(k); 14 err(k) = abs (exact - int_gauss(f,0,1,1,n)); 15 end 16 17 figure ; 18 semilogy (nlist,err); xlabel ( ’points in quadrature’ ); ylabel (

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}