메트랩 과제중 막히는 부분이 있어서 난감해서 ㅜㅜ
과제는 부폰의 바늘실험을 메트렙으로 하는건데
clear all; close all; format long; clc;
hold on %holds plots so it can graph all values
trials = 1000;
exp = 1000;
tolerance=0.1
결과를 내고자 하는데 자꾸 오류가 나 .. ㅜㅜ 선생님 힌트로는 while 루프랑 if 루프를 같이 사용하면 된데..
% While PIE<pi+tolerance && PIE<pi+tolerance
%end
for counter = 1:trials;
%end
for counter = 1:trials;
x = rand(1,exp); %generates an array of
이 while 루프 부분에서 문제잘 안되네.. PIE 가 pi+tolerance 와 pi+tolerance 사이에 값이 들어가게되면 루프를 멈추고
x values for the experiments
y = rand(1,exp); %generates an array of y values for the experiments
theta = (0.5*pi*rand(1,exp)*180)/pi; %generates angles for all the experiements
hits = x <= sind(theta); lculates how many experiments landed on the line
total_hits = sum(hits); % sum of all of the needles that cross the line
PIE(counter) = 2/(total_hits/(exp)); %generates a value of pi based on the # of experiments
%plot(x,y,'.')
end
mean(PIE)
hist(PIE)
계속 머리를 싸메고 생각해 보았는데 잘 모르넹 .. ㅜㅜ 부탁드립니다
설마 중간에 주석처리 안한거 저거는 아니겠지