Documente Academic
Documente Profesional
Documente Cultură
Name
: Nadya Amalia
Student ID
: 20213042
Subject
Lecturer
2. Evaluate:
( = )6
= )(
()
In most cases, the exact value of the definite integral can not be found because an
antiderivative of the integrand can not be found. There are several methods to approximate the
value of a definite integral. One of these methods is Monte Carlo Integration.
The idea of Monte Carlo integration is to evaluate the integral F using random sampling.
Imagine a rectangle of height h, width , and area = ( ) such that the function ()
is within the boundaries of the rectangle (see Fig. 2). Compute N pairs of random numbers
with . The fraction of point that satisfy the condition () is an estimate of
the ratio of the integral of ( )to the area of the rectangle. Hence, the estimate in the hit or
miss method is given by:
Where is the number of splashes or points below the curve, and N is the total number of
points.
Fig. 2. The function ( )is in the domain determined by the ractangle of height h and width ( )
Computer is carrying out some well defined procedure, one that can be predicted or
repeated. What comes out of a computer program is called a stream of pseudorandom numbers.
1. ( = )41 , for ( = , ). = 0, = 1 and = 1000.
MATLAB Source Code
area = 1;
% Generate N pseudo-random numbers in the interval [a,b]:
x = rand ( N, 1 );
% Uniformly randomly sample points x
sx = a + ( b - a ) .* x;
% Calculate the maximum value of the function f(x) in the range of
% integration
fx
= 4 .*sqrt(1 - sx .^2);
% function of x
plot(x,fx,'ro');
xlabel('x'); ylabel('y'); title('fx = 4*sqrt(1 - x^2)');
fmax = max(fx);
% maximum value of fx
% Restrict the value of x
i = find ( sx <= 4.*sqrt(1 - sx.^2));
p = numel(i);
% amount of the accepted x
q = N - p;
% amount of the rejected x
prob = [p q];
% Approximately evaluate the integral
fprintf('Amount of the accepted value of x : \t%d', p);
I = p * fmax * b / N
Result
970
3.8800
>>
Result
10000