Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 8

Numerical Integration

Find

Numerical integration may be used when

is difficult to integrate

is known only through discretely sampled data points


Methods of Numerical Integration: Trapezoidal Rule

Approximate the area under the curve as a trapezoid and calculate its area

𝒇 (𝒙)
𝑏
( 𝑓 ( 𝑏 )+ 𝑓 ( 𝑎 ) )( 𝑏− 𝑎)
∫ 𝑓 ( 𝑥 ) 𝑑𝑥 ≅ 2
𝑎

The area under is approximated by the area under the red line
Methods of Numerical Integration: Trapezoidal Rule

The integral is better approximated if you

(i)
• Partition the integral interval [a,b] to (i+1)
()
sub-intervals of equal width,

• Apply the trapezoidal rule to each sub-interval


a i i+1

• Sum the results ∆𝒙

¿
Application

Approximating the distance travelled


Moving in a straight line, record your speed every 30 second intervals and use this information to
find the distance travelled

Time interval number Speed in km/hr Distance travelled=


0 0
1 22
2 39 is known only through discretely
3 11 sampled data points
4 5
5 4
6 15
7 19
8 20
Application

Approximating the distance travelled

Suppose that the velocity of an object at time is given by ), find the position at time
=2

Difficult integration
Demo..
• Open Octave
• Type math_session5a.m
• Interpret the output
Using Octave..
% Calculate the integral of y=x^2 on the interval [0,10] using trapezoidal rule
%% Exact value
% Define the function that needs to be integrated
fun = @(x) x.^2;
a=0;
b=10;
% Find exact value of integration from 0 to 10 using builtin function integral
ExactValue= integral(fun,a,b);
%% Approximated value using trapezoidal rule using n equal subintervals
n=5 % number of subintervals

x = linspace(a, b, n) % x coordinates of samples


y =fun(x); % y coordinates of samples
sum_y = sum(y) - (y(1) + y(end)) ./ 2 % sum y coordinates, taking just half of endpoints
dx = (b - a) / (n - 1) % width of each trapezoid
area = sum_y * dx
ApproxValue=area
Assessment
• Using the trapezoidal rule, find the approximated value of the
distance travelled by an object, if its velocity is given by Find the
error if n=5, 10, and 40.

You might also like