Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

updata

  • Loading branch information...
commit 2af6fa5a88198e340b073d44a2dbfbd258fc99ca 1 parent 3e07d01
liuzheng authored

Showing 2 changed files with 32 additions and 14 deletions. Show diff stats Hide diff stats

  1. +29 13 Buffon_needle.m
  2. +3 1 setmap.m
42 Buffon_needle.m
... ... @@ -1,44 +1,56 @@
1   -
2 1 % Monte Carlo test for Buffon's needle
3   -clc;clear;figure(1);clf;
  2 +clc;clear;
  3 +%figure('color',[1 1 1],'name','Buffon needles','numbertitle','off','menubar','none');
  4 +clf;
  5 +htexttitle = uicontrol(gcf,'style','text','string','Buffon needles','fontsize',26,'position',[120 380 300 40]);
4 6
5 7 % D is each line distance , default is 5
6 8 D = 5 ;
7   -heditD = uicontrol(gcf,'style','edit','string','5','position',[20 300 100 25]);
8   -
  9 +heditD = uicontrol(gcf,'style','edit','string','5','position',[20 300 100 20]);
  10 +htextD = uicontrol(gcf,'style','text','string','D is each line distance','position',[5 322 130 16]);
9 11
10 12 % d is line length
11 13 d = 10 ;
12   -heditd = uicontrol(gcf,'style','edit','string','10','position',[20 270 100 25]);
  14 +heditd = uicontrol(gcf,'style','edit','string','10','position',[20 260 100 20]);
  15 +htextd = uicontrol(gcf,'style','text','string','d is line length','position',[5 282 130 16]);
13 16
14 17 % L is each needle's length
15 18 L = 1 ;
16   -heditL = uicontrol(gcf,'style','edit','string','1','position',[20 240 100 25]);
  19 +heditL = uicontrol(gcf,'style','edit','string','1','position',[20 220 100 20]);
  20 +htextL = uicontrol(gcf,'style','text','string','L is each needle''s length','position',[5 242 130 16]);
17 21
18 22 % n is line number
19 23 n = 5 ;
20   -heditn = uicontrol(gcf,'style','edit','string','5','position',[20 210 100 25]);
  24 +heditn = uicontrol(gcf,'style','edit','string','5','position',[20 180 100 20]);
  25 +htextn = uicontrol(gcf,'style','text','string','n is line number','position',[5 202 130 16]);
21 26
22 27 % N is the time to run
23 28 N = 500 ;
24   -heditN = uicontrol(gcf,'style','edit','string','500','position',[20 180 100 25]);
  29 +heditN = uicontrol(gcf,'style','edit','string','500','position',[20 140 100 20]);
  30 +htextN = uicontrol(gcf,'style','text','string','N is the time to run','position',[5 162 130 16]);
25 31
26 32 val = 1;
27 33 tt = 0;
  34 +
  35 +% close the menubar
  36 +%set(gcf,'menubar','none');
  37 +
  38 +
  39 +% popip
28 40 hpop = uicontrol('style','popup',...
29 41 'string','Rand|Betarnd|Binornd|Chi2rnd|Exprnd|Frnd|Gamrnd|Geornd|Hygernd|Lognrnd|Nbinrnd|Ncfrnd|Nctrnd|Ncx2rnd|Normrnd|Poissrnd|Raylrnd|Trnd|Unidrnd|Unifrnd|Weibrnd',...
30 42 'position',[20 320 100 50]);
31 43
32 44 button1 = uicontrol('style','pushbutton',...
33 45 'string','ok',...
34   - 'position',[20 140 100 30],...
  46 + 'position',[20 100 100 30],...
35 47 'callback',[...
36 48 'setmap;',...
37 49 'tic;',...
38 50 'needles;',...
39 51 'tt=toc;',...
40   -'heditans = uicontrol(gcf,''style'',''edit'',''string'',[''Elapsed time is '',num2str(tt),'' seconds.''],''position'',[280 30 200 60]);',...
41   -'a/N'...
  52 +'heditans = uicontrol(gcf,''style'',''text'',''string'',[''Elapsed time is '',num2str(tt),'' seconds.'',10,''Probability '',num2str(a/N)],''position'',[280 45 200 40]);',...
  53 +
42 54 ]);
43 55
44 56 % set the show square
@@ -46,8 +58,12 @@
46 58 % close the xtick and ytick
47 59 set(gca,'xtick',[],'ytick',[]);
48 60
  61 +% slider
49 62 hslider = uicontrol('style','slider',...
50 63 'min',0,'max',100,'value',50,...
51   - 'position',[20 70 200 30]);
  64 + 'position',[20 50 200 30]);
  65 +
  66 +heditans = uicontrol(gcf,'style','text','string',['Elapsed time is ',num2str(tt),' seconds.',10,'Probability ','0'],'position',[280 45 200 40]);
52 67
53   -heditans = uicontrol(gcf,'style','edit','string',['Elapsed time is ',num2str(tt),' seconds.'],'position',[280 30 200 60]);
  68 +line([1 1],[0 1],'Color','k');
  69 +line([0 1],[1 1],'Color','k');
4 setmap.m
@@ -11,4 +11,6 @@
11 11 for i = 0:n-1
12 12 line([0 d],[i i]*D,'Color','r','LineWidth',4);
13 13 end
14   -axis([-0.1*d 1.1*d -0.1*D*n 1.1*D*(n-1)]);
  14 +axis([-0.1*d 1.1*d -0.1*D*n 1.1*D*(n-1)]);
  15 +line([1.1*d 1.1*d],[-0.1*D*n 1.1*D*(n-1)],'Color','k');
  16 +line([-0.1*d 1.1*d],[1.1*D*(n-1) 1.1*D*(n-1)],'Color','k');

0 comments on commit 2af6fa5

Please sign in to comment.
Something went wrong with that request. Please try again.