komputasi sistem fisis 6
TRANSCRIPT
-
8/19/2019 Komputasi Sistem Fisis 6
1/5
1
Assignment 6
Name : Nadya Amalia
Student ID : 20213042
Subject : Computation of Physical Systems (FI5005)
Lecturer : Dr.rer.nat. Linus Ampang Pasasa
NUMERICAL INTEGRATIONUSINGMONTE CARLOMETHOD
1. Evaluate:
(ݔ
) = 4ඥ 1 − ଶݔfor ݔ = ( , ). Use = 0, = 1 and = 1000.
2. Evaluate:
(ݔ
) = 6 −ݔ
ଶ௬
for ݔ = (0, 2) and ݕ = (0, 1). Use ݖ = 2, ௫ݖ = 6, and = 10000.
Solution
Consider 1-dimensional definite integral:
ܫ = න ݀ݔ ∙ (ݔ)
This can be approximated by pulling N random number ݔ , = 1, 2, 3, … , , from a distributionwhich is constant in the interval ≤ ݔ ≤ :
ܫ ≈− (ݔ)
ୀଵ
The result becomes exact when → ∞.
Fig, 1. The integral equals the area under the curve (ݔ)
-
8/19/2019 Komputasi Sistem Fisis 6
2/5
2
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. ) = 4√ 1ݔ) − ଶ, forݔ ݔ = ( , ). = 0, = 1 and = 1000.
MATLAB Source Code
clc, clear all;
% Author: Nadya Amalia (20213042)
% Department of Physics
% Bandung Institute of Technology, Bandung
% Numerical Integration using Monte Carlo Method
% f(x) = 4*sqrt(1 - x^2)
N = 1000; % amount of pseudo-random numbers
% Range of integration
a = 0 ;b = 1 ;
-
8/19/2019 Komputasi Sistem Fisis 6
3/5
3
area = 1;
% Generate N pseudo-random numbers in the interval [a,b]:
x = r a n d ( N , 1 ) ;
% Uniformly randomly sample points x
s x = a + ( b - a ) . * x ;
% Calculate the maximum value of the function f(x) in the range of
% integration
fx = 4 . *sqrt(1 - s x .^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 >
2. ) = 6ݔ) − ଶ௬, forݔ ݔ = (0, 2) and ݕ = (0, 1). ݖ = 2, ௦ݖ = 6, and = 10000.
-
8/19/2019 Komputasi Sistem Fisis 6
4/5
4
MATLAB Source Code
clc, clear all;
% Author: Nadya Amalia (20213042)
% Department of Physics
% Bandung Institute of Technology, Bandung
% Numerical Integration using Monte Carlo Method
% f(x) = 6 - x ^(2 *y)
N = 10000; % amount of pseudo-random numbers
% Range of integration
xo = 0; xn = 2;
yo = 0; yn = 1;
zmin = 2; zmax = 6;
area = ( xn - xo )*( yn - yo ); % the are of rectangle
% Generate N pseudo-random numbers in the interval [xo, xn] and [yo,
yn]:
x = r a n d ( N , 1 ) ;
y = r a n d ( N , 1 ) ;
% Uniformly randomly sample points (x,y)
s x = x o + ( x n - x o ) . * x ;
s y = y o + ( y n - y o ) . * y ;
subplot 121
scatter(sx,sy,'o');
xlabel('x'); ylabel('y');
title('Uniformly randomly sample points (x,y)')
% Restrict the value of x and y by considering the value of z^2 = x^2 +
y^2
i = find ( zmin^2
-
8/19/2019 Komputasi Sistem Fisis 6
5/5
5
Fig. 4. Left: scattering of random ݔ and ݕ. Plotting of ݔ ) as a function ofݔ) and ݕ
Amount of the accepted value of x and y : 10000
I =
9.8841
>>