Anda di halaman 1dari 10

TUGAS TEKNIK SIMULASI

Program Simulasi Buffon Needle

Oleh : FERRY ISWONO NRP. 1209 100 059

Jurusan Matematika Fakultas Matematika dan Ilmu Pengetahuan Alam Institut Teknologi Sepuluh Nopember Surabaya 2012

DEKSRIPSI BUFFON NEEDLE Dalam percobaan Buffon Needle, jarum dengan panjang (l), di jatuhkan secara acak pada sebuah papan bidang datar bergaris sejajar dengan jarak (d). Untuk pemecahan secara teoritis panjang jarum (l), dibatasi lebih kecil atau sama dengan jarak (d). Jika percobaan ini dilakukan berulang-ulang, maka perkiraan peluang jarum menyentuh sebuah garis yaitu P, dapat diperoleh dari perbandingan jumlah percobaan dimana sebuah garis tersentuh, dengan jumlah total percobaan :

Selain itu, posisi jarum juga harus bisa diletakkan secara acak, relative terhadap garis sejajar pada papan. Untuk itu ditetapkan posisi jarum adalah unik, yaitu titik tengah jarum (m) dan sudut yang terbentuk antara jarum dengan garis (). Supaya jarum mempunyai posisi yang acak maka variabel m dan harus berupa variabel acak uniform. Untuk menyederhanakan bentuk model maka hanya akan ditinjau dari dua garis sejajar seperti pada gambar diatas. Lokasi m ditetapkan dan dicari garis mana yang

mempunyai jarak terpendek dengan m. Karena posisi acak adalah simetri maka hanya ditinjau dari setengah jarak dua garis tersebut ( ). Sehingga jarak dari m ke garis terdekat (a) adalah variabel acak juga. Karena simetris maka adalah sebuah variabel acak uniform pada variabel 0 sampai radian.

MULAI

MASUKKAN I, d, dan N

INISIALISASI NI = 0; NT = 0

BANGKITKAN r1 HITUNG a = ( d/2 ). r1

BANGKITKAN r2 HITUNG = . r2
NO

YES

A<= ( l/2 ) sin

NO

NI = NI + 1

NT = NT + 1

NT > N

YES

HITUNG P = NI / N

CETAK P

BERHENTI

Model Flowchart dari Percobaan Buffon Needle

Listing Program Simulasi Buffon Needle dengan Matlab


function varargout = AlgBuffonNeedle(varargin) % ALGBUFFONNEEDLE M-file for AlgBuffonNeedle.fig % ALGBUFFONNEEDLE, by itself, creates a new ALGBUFFONNEEDLE or raises the existing % singleton*. % % H = ALGBUFFONNEEDLE returns the handle to a new ALGBUFFONNEEDLE or the handle to % the existing singleton*. % % ALGBUFFONNEEDLE('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in ALGBUFFONNEEDLE.M with the given input arguments. % % ALGBUFFONNEEDLE('Property','Value',...) creates a new ALGBUFFONNEEDLE or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before AlgBuffonNeedle_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to AlgBuffonNeedle_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help AlgBuffonNeedle % Last Modified by GUIDE v2.5 06-Mar-2012 14:07:00 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @AlgBuffonNeedle_OpeningFcn, ... 'gui_OutputFcn', @AlgBuffonNeedle_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT

% --- Executes just before AlgBuffonNeedle is made visible. function AlgBuffonNeedle_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn.

% % % %

hObject eventdata handles varargin

handle to figure reserved - to be defined in a future version of MATLAB structure with handles and user data (see GUIDATA) command line arguments to AlgBuffonNeedle (see VARARGIN)

% Choose default command line output for AlgBuffonNeedle handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes AlgBuffonNeedle wait for user response (see UIRESUME) % uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line. function varargout = AlgBuffonNeedle_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output;

function TxtL_Callback(hObject, eventdata, handles) % hObject handle to TxtL (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of TxtL as text % str2double(get(hObject,'String')) returns contents of TxtL as a double

% --- Executes during object creation, after setting all properties. function TxtL_CreateFcn(hObject, eventdata, handles) % hObject handle to TxtL (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function TxtNt_Callback(hObject, eventdata, handles) % hObject handle to TxtNt (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of TxtNt as text

% double

str2double(get(hObject,'String')) returns contents of TxtNt as a

% --- Executes during object creation, after setting all properties. function TxtNt_CreateFcn(hObject, eventdata, handles) % hObject handle to TxtNt (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function TxtD_Callback(hObject, eventdata, handles) % hObject handle to TxtNt (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of TxtNt as text % str2double(get(hObject,'String')) returns contents of TxtNt as a double

% --- Executes during object creation, after setting all properties. function TxtD_CreateFcn(hObject, eventdata, handles) % hObject handle to TxtNt (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function TxtP_Callback(hObject, eventdata, handles) % hObject handle to TxtP (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of TxtP as text % str2double(get(hObject,'String')) returns contents of TxtP as a double

% --- Executes during object creation, after setting all properties. function TxtP_CreateFcn(hObject, eventdata, handles) % hObject handle to TxtP (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB

% handles

empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

% --- Executes on button press in BtnRun. function BtnRun_Callback(hObject, eventdata, handles) % hObject handle to BtnRun (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) ferry = guidata(gcbo) l = str2num(get(ferry.TxtL, 'String')); d = str2num(get(ferry.TxtD, 'String')); Nt = str2num(get(ferry.TxtNt, 'String')); Ni = 0; for i=0:Nt r1=rand; a=(d/2)*r1; r2=rand; t=pi*r2; if a<=((l/2)*sin(t)) Ni=Ni+1; end end P=Ni/Nt; set(ferry.TxtP,'String',P);

% --- Executes on button press in BtnSelesai. function BtnSelesai_Callback(hObject, eventdata, handles) % hObject handle to BtnSelesai (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close();

HASIL PROGRAM Untuk N=5000 , dgn l = 10 dan d = 20 Dengan menggunakan program simulasi Buffon Needle diatas, diperoleh: masukkan nilai l = 10 masukkan nilai d = 20 masukkan nilai N = 5000 P = 0.3206

Untuk N=1000, dgn l = 10 dan d = 20 Dengan menggunakan program simulasi Buffon Needle, diperoleh: masukkan nilai l = 10 masukkan nilai d = 20 masukkan nilai N = 1000 P= 0.3450

Untuk N=1500, dgn l = 10 dan d = 20 Dengan menggunakan program simulasi Buffon Needle, diperoleh: masukkan nilai l = 10 masukkan nilai d = 20 masukkan nilai N = 1500 P= 0.3147

Untuk N=2000, dgn l = 10 dan d = 20 Dengan menggunakan program simulasi Buffon Needle, diperoleh: masukkan nilai l = 10 masukkan nilai d = 20 masukkan nilai N = 2000 P= 0.2975

KESIMPULAN: Walaupun nilai N yang diinputkan besar atau kecil, tetapi tidak terjadi perbedaan nilai yang besar di P. karena nilai yang di ambil oleh distribusi seragam antara 0 1 untuk menghitung r1 dan r2.