Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Problem 2:

Using Numerical Integration methods, we were able to find the area of enclosed space
bounded by parabolic equations 𝑔(𝑥) above and 𝑓(𝑥) below.
Given:
𝑓(𝑥) = 𝑥 2 − 4𝑥 + 5
𝑔(𝑥) = −𝑥 2 + 2𝑥 + 5
Final Answer:
a. Area = 9.0000 (By solving analytically)
b. Area = 9.0000 (Adaptive Quadrature via Trapezoidal Rule)
c. Area = 9.0000; N = 301 (Using Midpoint Rule)
Solution:

Graphing the functions 𝑔(𝑥) & 𝑓(𝑥):


Script:
f = @(x) -x.^2 + 2*x + 5 - (x.^2 -4*x + 5); % Declare the function

a = 0; b = 3; tol = 1e-8; % Limits of integration


N = 301; h = (b-a)/N; % # of pts and step size
x = linspace (a,b,N+1); % Create vector x
% Midpoint Rule
i = 1:N;
S = h*sum(f(0.5*(x(i )+x(i+1))));
fprintf('Area: %.4f (Midpoint Rule)\n',S)
% Adaptive Quadrature
fprintf('Area: %.4f (Adaptive Quadrature via Trapezoidal Rule)\n',
AdaptQuad(f,a,b,tol));
function S1 = AdaptQuad(f,a,b,tol)
S1 = 0.5*(b-a)*(f(a)+f(b)); % Area from a to b
m = 0.5*(a+b); % Midpoint of a and b
S2 = 0.5*(m-a)*(f(a)+f(m))+... % (Area from a to m) +
0.5*(b-m)*(f(m)+f(b)); % (Area from m to b)
if abs(S2 - S1) > tol % If S and S2 are dissimilar
S1 = AdaptQuad(f,a,m,tol)+... % Do AdaptQuad from a to m
AdaptQuad(f,m,b,tol); % Do AdaptQuad from m to b
end
end

Result:
Area: 9.0000 (Midpoint Rule)
Area: 9.0000 (Adaptive Quadrature via Trapezoidal Rule)

You might also like