hw17_solutions

Hw17_solutions - Section 4.10 1 4 Section5.2 6a section 5.2 prob 6a 0-2 log10(Error-4-6-8-10-12-14 0 0.5 1 1.5 2 log10(n 2.5 3 3.5 The slope is

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Section 4.10 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
4
Background image of page 2
Section5.2 6a The slope is roughly 4, which matches the fact that the corrected trapezoid rule is O(h^4) accurate. Matlab code is as below a = 0; b = 2; h = (b-a)*(1/2).^(1:11); n = (b-a)./h; I = 2 - 10*exp(-2); % actual integration value Err = zeros(1,11); for k = 1:11 x = a:h(k):b; fx = x.^2.*exp(-x); % f(x) Tn = 0.5*h(k)*(sum(fx)+sum(fx(2:end-1))); % trapezoid Tnc = Tn - h(k)/24*(3*fx(end)-4*fx(end-1)+fx(end-2)+3*fx(1)-4*fx(2)+fx(3)); % improved trapezoid Err(k) = abs(I - Tnc); % error end figure(1) plot(log10(n),log10(Err)); grid on xlabel( 'log10(n)' ) ylabel( 'log10(Error)' ) title( 'section 5.2 prob 6a' ) 0 0.5 1 1.5 2 2.5 3 3.5 -14 -12 -10 -8 -6 -4 -2 0 log10(n) log10(Error) section 5.2 prob 6a
Background image of page 3

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

View Full DocumentRight Arrow Icon
6d The slope is also roughly 4, which matches the fact that the corrected trapezoid rule is O(h^4) accurate. Matlab code is as below a = 0; b = pi; h = (b-a)*(1/2).^(1:11); n = (b-a)./h; I = 4/17*(1-exp(-pi)); % actual integration value Err = zeros(1,11); for k = 1:11 x = a:h(k):b; fx = exp(-x).*sin(4*x); % f(x) Tn = 0.5*h(k)*(sum(fx)+sum(fx(2:end-1))); % trapezoid Tnc = Tn - h(k)/24*(3*fx(end)-4*fx(end-1)+fx(end-2)+3*fx(1)-4*fx(2)+fx(3)); % improved trapezoid Err(k) = abs(I - Tnc); % error end figure(2)
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/15/2012 for the course MAE 107 taught by Professor Rottman during the Spring '08 term at UCSD.

Page1 / 12

Hw17_solutions - Section 4.10 1 4 Section5.2 6a section 5.2 prob 6a 0-2 log10(Error-4-6-8-10-12-14 0 0.5 1 1.5 2 log10(n 2.5 3 3.5 The slope is

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online