Exam_4_Solutions - function Exam4Prob1 % % % % % %...

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

View Full Document Right Arrow Icon
function Exam4Prob1 % Numerical integration of functions problem % Concepts covered: % 1) Trapezoidal rule % 2) Simpson's 1/3 rule % 3) Romberg integration % Use homework problem 17.6 as the foundation % Solve the two-dimensional integral below using Simpson's 1/3 rule % as many times as possible and the trapezoidal rule elsewhere. % First define sample points to provide to the students % z = f(x,y) % = [0 3 9; % 4 0 8] % with an interval of 1 in the x direction and 2 in the y direction. % Assume x = 0, 1, and 2, while y = 0 and 2 % Next integrate across x for fixed y using Simpson's 1/3 rule: % I = h/3*(f(x0)+4*f(x1)+f(x2)) % % For y = 0, h = 1, and % I1 = 1/3*(4+4*0+8) = 4 % % For y = 2, h = 1, and % I2 = 1/3*(0+4*3+9) = 7 % Then integrate across y using trapezoidal rule % I = h*(f(x0)+f(x1))/2 % I3 = 2*((4+7)/2) = 11 % Now repeat the problem using ONLY trapezoidal rule but implementing % Romberg integration as many times as possible to improve the accuracy % of the result. % First apply Romberg integration across x for fixed values of y: % Iromb = 4/3*Ibetter-1/3*Iworse % % For y = 0, h = 1, and % Ibetter = 1*((4+0)/2)+1*((0+8)/2) = 6 % Iworse = 2*((4+8)/2) = 12 % Iromb = 4/3*6-1/3*12 = 4 % % For y = 2, h = 1, and % Ibetter = 1*((0+3)/2)+1*((3+9)/2) = 1.5 + 6 = 7.5 % Iworse = 2*((0+9)/2) = 9 % Iromb = 4/3*7.5-1/3*9 = 7
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

Exam_4_Solutions - function Exam4Prob1 % % % % % %...

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

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