Моделирование физических явлений на ЭВМ. Ч. V. Статистическое моделирование: Методическое пособие

  • Published on
    13-Dec-2016

  • View
    220

  • Download
    5

Embed Size (px)

Transcript

<ul><li><p> - </p><p> V</p></li><li><p> - </p><p> .., .., .., ..,</p><p> .., .., ..</p><p> V</p><p>2000</p></li><li><p>1</p><p> - , - ( - . ..), " ". ( -) , . , . .</p><p>:</p><p> ..</p><p> . , ..-.. ..</p><p> , 2000</p><p> "", " </p><p> -" (. 274)</p></li><li><p>2</p><p> 3</p><p> 4</p><p> 12</p><p> 15</p><p> 17</p><p> 20</p><p> 23</p><p> 30</p><p> 34</p><p> - 39</p><p> 45</p><p> 79</p><p> 80</p></li><li><p>3</p><p> , , -. "-" - , , , . , .</p><p> . , . , , "" .</p><p> - ( , , , , ..). - , ; - . , .</p><p> , , , , , , .., .</p></li><li><p>4</p><p> , , , . X , , . (, ). , ( ), iX , ni ,,2,1= . iX .</p><p> , ( ) ( ).</p><p> X , .. .</p><p> X , 1X , 2X , ..., nX</p><p> 1P , 2P , ..., nP , </p><p>=</p><p>n</p><p>n</p><p>P...PPX...XX</p><p>X21</p><p>21 ,</p><p> 1X , 2X , ..., nX X , 1P , 2P , ..., nP</p><p> , , 11</p><p>==</p><p>n</p><p>iiP .</p><p> ( ) )(xF , x P</p></li><li><p>5</p><p>, X , x :</p><p>)()( xXPxF </p></li><li><p>6</p><p>2) </p><p>= 1)( duuf ;</p><p>3) ( dxxXx + ) .</p><p> , , . , .</p><p> ix X , :</p><p> = =</p><p>===n</p><p>i</p><p>n</p><p>iiiii PxxXPxxX</p><p>1 1</p><p>)(}M{ .</p><p>, x , , .</p><p> , )(XHY = :</p><p> = =</p><p>===n</p><p>i</p><p>n</p><p>iiiii PxHxXPxHXH</p><p>1 1</p><p>)()()()}(M{ .</p><p>= dxxfxxX )(}M{</p><p>= dxxfxHXH )()()}(M{ .</p></li><li><p>7</p><p> , X :</p><p>.})(M{}M{})M{(}})M{M{(</p><p>)(}D{2222</p><p>2</p><p>XXxXXX</p><p>XX</p><p>==</p><p>=</p><p> )(2 X+= *). , X x .</p><p> , .</p><p> N 1N , 2N , 3N ,</p><p>4N , 5N , 6N ,6,5,4,3,2,1 . , - i( 6,5,4,3,2,1=i ) </p><p>NNP ii ,</p><p>.. iP , i , . , N , , , iN . , N :</p><p>NN</p><p>P iNi </p><p>= lim .</p><p> *) .</p></li><li><p>8</p><p> , "", 6,5,4,3,2,1 </p><p>61</p><p>654321 ====== PPPPPP .</p><p> , </p><p> = =</p><p>==6</p><p>1</p><p>6</p><p>1</p><p>11</p><p>i iii PNN</p><p> .</p><p> }M{X }D{X :</p><p>5.3616</p><p>615</p><p>614</p><p>613</p><p>612</p><p>611}M{ =+++++=X ,</p><p>.917.2)5.3(616</p><p>615</p><p>614</p><p>613</p><p>612</p><p>611</p><p>})(M{}M{}D{</p><p>2222222</p><p>22</p><p>=+++++=</p><p>== XXX</p><p> .</p><p> 1. .</p><p> X ( ba, ) , :</p></li><li><p>9</p><p>)(xp ( )ab 1 , bxa , 0 , x [ ]ba, . , , , ( )ba, [ ]ba, , ( )ba, .</p><p> , +==b</p><p>a</p><p>abdxxpxX2</p><p>)(}M{ , </p><p> =</p><p> +==</p><p>b</p><p>a</p><p>abdxxpabxXXX12</p><p>)()(2</p><p>}})M{M{(}D{22</p><p>2 .</p><p> , 0=a 1=b , )1,0( , -. </p><p>21}M{ =X , </p><p>121}D{ =X .</p><p> 2. ( ) .</p><p> ( ) X , ( ) , </p><p>= 2</p><p>2</p><p>2)(exp</p><p>21)( axxp ,</p><p> a . :</p><p>aX =}M{ , 2}D{ =X .</p></li><li><p>10</p><p> a - - X . - X - a .</p><p> -. , .. 21 21 </p><p> (. .). , - a , 2121 2w= , 21w</p><p> . -, = ax </p><p>607.0)( =ap </p><p>=</p><p>21</p><p>maxp .</p><p>, </p><p>= 18.12ln221w </p><p> 36.221 . , )( ap </p><p> ( 18 % ) 21w , </p><p>. </p><p>a0</p><p> p(x)</p><p> x</p><p> = 0.5</p><p> = 1.0</p><p> = 2.0</p><p>1/2</p><p>w1/2</p><p>w1/2</p><p>pmax</p><p>0.5pmax</p><p>p(x)</p><p>0.607pmax</p><p> xa0</p></li><li><p>11</p><p> , 2 21 . , </p><p> .</p><p> , +</p><p>=3</p><p>3</p><p>997.0)(a</p><p>a</p><p>dxxp , , ,</p><p>997.0)33( =+</p></li><li><p>12</p><p> . , , , . , , , .</p><p> , : "" , "" , "" , " " , ...</p><p> , . , , , , .</p><p> . S .</p><p> a N . N , S . , a</p><p> a</p><p>0 x</p><p> y</p><p>S</p></li><li><p>13</p><p> S NNa /'2 . , N , S . , :1. , </p><p> ),0( a . X - .</p><p>2. , ),0( a . Y - .</p><p>3. , ( ), S . , N ( N ).</p><p>4. ( 1,2,3) N .5. .</p><p> . . , , N . </p><p> N1 , .. , .</p><p> , () . , , - ( , , , , ..), " ".</p></li><li><p>14</p><p> : A ? 1A , 2A ,..., kA ? X ? 1X , 2X ,..., kX ? ... , : ( A ) ? ( 1A , 2A ,..., kA ) ? , ( X ) ? ( 1X , 2X ,..., kX ) ? ...</p><p> - ( ), . ( , , ).</p><p> , , ( ) . (, ,, , ..), . , , , 0 1. , , y )(yf , (0,1).</p></li><li><p>15</p><p> , , </p><p> (0,1). : , . . , (), . , "" , , "" "" , , . , , ( , ..). .</p><p> , , "" . ,</p><p> 1+ i i . , , , . , x y xy "".</p></li><li><p>16</p><p> (0,1) :</p><p>}{1 ii = + ,</p><p>1.00 = .</p><p> { } , . : 1.00 = , 415926.01 = , 667.02 = ,</p><p>54422.03 = , 97175.04 = , 28426.05 = ...</p><p> . 1 , 2 ,..., ( ), :</p><p>}{1 ii M = + ,m= 20 ,</p><p> M , , m . M , 0 m ( "") ( , ..).</p><p> Turbo Pascal Random() . , 0 1 . ( n ), 0 n . :</p></li><li><p>17</p><p>x := Random; { 0 &lt; x &lt; 1 }</p><p>m := Random(n); { 0 m &lt; n } .</p><p> , Random </p><p>( 0 ). , . , , , , . , Randomize , ( ) , Random . , Randomize "" .</p><p> , n</p><p> 1X , 2X , ..., nX 1P , 2P ,..., nP . </p><p>=</p><p>n</p><p>n</p><p>PX</p><p>PX</p><p>PX</p><p>...</p><p>...</p><p>2</p><p>2</p><p>1</p><p>1 , =</p><p>=n</p><p>kkP</p><p>1</p><p>1 .</p><p> [0,1] n 1 , 2 ,..., n , </p><p> 1P , 2P ,..., nP . </p></li><li><p>18</p><p> , (0,1), </p><p> kX= , k .</p><p> . ( ) - kS 1S , 2S ,..., nS , . , :</p><p>=</p><p>nPn</p><p>PP ......21</p><p>21 , kP kS .</p><p> , kS , , k .</p><p> )( kPpk ==( ,...2,1,0=k ), </p><p>)(1 krpp kk =+ . . ),( np :</p><p>knkknk ppkPP</p><p>=== )1(C)( , nk ,...,1,0= ,</p><p>pp</p><p>kkn</p><p>ppkr</p><p>k</p><p>k</p><p>+== +</p><p>11)( 1 ,</p><p>!)!(!C</p><p>kknnk</p><p>n = .</p><p> :</p><p>= e!k</p><p>pk</p><p>k , 1)(</p><p>+=</p><p>kkr , ,1,0=k .</p></li><li><p>19</p><p> :</p><p> , :</p><p>Function Puass(Lamda : real) : integer;var ver, p0, P : real; k : integer;</p><p>begin k := 0; p0 := exp(-Lamda); P := p0; ver := random; repeat ver := ver - P; if ver &gt;= 0 then begin</p><p> P := P*Lamda/(k+1); {Lamda/(k+1) = r(k)} k := k + 1; end; until ver &lt; 0; Puass := k;end;</p><p>M = , P = p0 , m = 0</p><p>M = M P</p><p>P = Pr(m) , m = m + 1</p><p> = m</p><p>M 0</p><p>M &lt; 0</p></li><li><p>20</p><p> ,</p><p> ( )ba, ( )xf . , (0,1), .. x )(xf </p><p>=y</p><p>a</p><p>dxxfyF )()(</p><p> (0,1).</p><p> - - )(xf :</p><p>1. , (0,1).</p><p>2. == </p><p>a</p><p>dxxfF )()( .</p><p>3. )(1 = F , .</p><p> .</p><p> ,</p><p> = e)(p , . </p><p> F(y)</p><p>y</p><p>1 2</p><p>3</p><p>1.0</p><p>0</p><p>0.60.40.2</p><p>0.8</p><p>a b</p><p> F() = </p></li><li><p>21</p><p> : , ...</p><p> , </p><p>== </p><p> e1e0</p><p>dxx .</p><p> )</p><p>= 1ln(1 . 1 </p><p> , , </p><p>)</p><p>= ln(1 .</p><p> . , ),( ba :</p><p>abxp</p><p>= 1)( , bxa </p></li><li><p>22</p><p> . .</p><p> ( ) .</p><p> ( ba, ) , Mxf )( . , (0,1) , :</p><p>1. 1 2 </p><p> Q (. ):)(10 aba += , M= 2 .</p><p>2. )( 0&gt; f , ( )21, .1; 0= .</p><p> , ),( 0 Q, )(xf , </p><p> )(1 aba += )(xf . , , .</p><p> ., , </p><p>y</p><p>x</p><p>f(x)</p><p>ba</p><p>0</p><p>Q</p><p>M</p></li><li><p>23</p><p> X . , . </p><p> , =</p><p>=n</p><p>iiX</p><p>1</p><p> 8n </p><p>{ } 2/M nX = 12n= . </p><p> ( ),m += m , (0,1), </p><p> (0,1) :</p><p>= </p><p>=</p><p>nn</p><p>n</p><p>ii 2</p><p>112</p><p>1</p><p>21</p><p> .</p><p> 12=n : =</p><p>=12</p><p>1</p><p>6i</p><p>i .</p><p> , . , ( ) ( ) ().</p><p> , , , </p></li><li><p>24</p><p> n X . n </p><p>nxxx ,,, 21 X :</p><p> : =</p><p>=n</p><p>iin xn</p><p>x1</p><p>1 ,</p><p> : ( )=</p><p>=n</p><p>inin xxn 1</p><p>22</p><p>11</p><p> .</p><p> nx , 2n </p><p> X . nx 2n </p><p> { }XM { }XD</p><p> X , .. { } nxxX M , { } 22D nX . , n . n </p><p> 2n . </p><p> , . , . , , ( </p><p> nx 2n ). </p><p> :</p></li><li><p>25</p><p>( ) </p><p>=</p><p>= ==</p><p>n</p><p>ini</p><p>n</p><p>inin xnxn</p><p>xxn 1</p><p>22</p><p>1</p><p>22</p><p>11</p><p>11</p><p> .</p><p> nx </p><p> X =</p><p>n</p><p>iix</p><p>1</p><p> =</p><p>n</p><p>iix</p><p>1</p><p>2 .</p><p> , , . ( ) , . . . , , . 20 .</p><p> , , , . .</p><p> . nomR . R , </p><p>RRnom RRnom + . </p></li><li><p>26</p><p> izmN , , . :</p><p>uses Gisto,Graph;</p><p>const NGist = 100; { }var Gd, Gm, i : Integer; Nizm : integer; R, Rnom, Rsr, SumR, SumR2, deltaR, Disp : real;</p><p>begin write(' Rnom = '); readln(Rnom); write (' deltaR = '); readln (deltaR); write (' Nizm = '); readln (Nizm); SumR := 0; { } SumR2 := 0; { </p><p>}{ } InitGist(NGist,Rnom-deltaR,Rnom+deltaR);</p><p>{ } Randomize;for i := 1 to Nizm do begin R := Rnom + (2*deltaR*Random-deltaR); { R = Rnom + DR } SumR := SumR + R; { } SumR2 := SumR2 + sqr(R); { } InGist(R); { } end; Rsr := SumR/Nizm; { } Disp := (SumR2 - Nizm*sqr(Rsr))/(Nizm-1); { } writeln (' R = ',Rsr:5:2); writeln (' . R = ',sqrt(Disp):5:2); readln; { } Gd := Detect; InitGraph(Gd, Gm, 'c:\tp\bgi'); { } if GraphResult grOk then begin { } writeln (' Graph error or bgi driver not found '); { }</p></li><li><p>27</p><p> Halt; end; Gistogram(green); { } readln; { } CloseGraph;end.</p><p> Gisto : InitGist ,InGist , Gistogram . Gisto.pas , (). Gisto.pas Alt-F9 , Gisto.tpu , Build Make Compile. :</p><p>{ }{ : gisto.pas }</p><p>UNIT Gisto;</p><p>INTERFACE</p><p>uses Graph;var I, NGist : Integer; { NGist- } OldPattern : FillPatternType; Xstart,Xfin,deltaX : real; MGist : array[1..580] of integer; { }</p><p>procedure InitGist(Ng : integer; Xl,Xh : real);procedure InGist(Value : real);procedure Gistogram(Color : Byte);</p><p>IMPLEMENTATION</p><p>{ }{ Ng - ; Xl,Xh - X }</p></li><li><p>28</p><p>procedure InitGist(Ng:integer; Xl,Xh:real);var i : integer;begin if Ng NGist then i := NGist; { } MGist[i] := MGist[i] + 1; { }end;</p><p>{ }</p><p>procedure Gistogram(Color : Byte); { Color - }const MaxY = 420; { Y } X0 = 50; Y0 = 450; { }var max,x,y,i,shir : integer; mash : real; s : string;</p><p>begin{ Y } max := MGist[1]; for i := 2 to NGist do if MGist[i] &gt; max then max := MGist[i];</p></li><li><p>29</p><p> if max 0 then mash := MaxY / max; if max = 0 then mash:=0;{ } shir := trunc((630-X0) / Ngist); GetFillPattern(OldPattern); { } SetFillPattern(OldPattern,Color);{ } for i := 1 to NGist do begin y := Y0 - round(MGist[i]*mash); x := X0 + round(Shir*(i-1)); bar(x+1, Y0, x + shir-1, y); end;{ } SetColor(white); line(X0-10,Y0,X0+NGist*shir+9,Y0); line(X0,Y0+10,X0,Y0-MaxY-10); line(X0-10,Y0-MaxY,X0+10,Y0-MaxY); line(X0+NGist*shir,Y0+10,X0+NGist*shir,Y0-10);{ , X } Str(0,s); MoveTo(X0-22,Y0-4); OutText(s); Str(max,s); MoveTo(0,Y0-MaxY-4); OutText(s); Str(Xstart:8:2,s); MoveTo(X0,Y0+14); OutText(s); Str(Xfin:8:2,s); MoveTo(X0+NGist*shir-64,Y0+14); OutText(s);end;end.</p></li><li><p>30</p><p> -, , . - , y~</p><p> x , .. y~ x : )(~~ xyy = .</p><p> ix , Ni ,,1= , </p><p> ix </p><p>)(~~ ii xyy = . </p><p> , - iy~ "" )(~~ xyy = ("") (. .).</p><p> , - y~ </p><p>)(~ xy . </p><p> iy~ ,, " " (), iy~ , )(~ xy . , "" -</p><p>x xi</p><p>y~ i</p><p> y=y(x)</p></li><li><p>31</p><p> , </p><p>iy~ . , , </p><p> ),...,,( 1 mppxyy = , </p><p>mpp ,...,1 . ,</p><p> ),...,,( 1 mppxy </p><p>() iy~ . , "</p><p>" ? , ix )(~~ ii xyy = </p><p>),...,,( 1 mii ppxyy = . , </p><p> ( )2~ii yy . iy~ ),...,,( 1 mppxy , , .. </p><p>( )=</p><p>=N</p><p>iii yyS</p><p>1</p><p>2~</p><p> .</p><p> iy ix , </p><p>mpp ,...,1 , S </p><p>mpp ,...,1 :</p><p>( )=</p><p>==N</p><p>iimim yppxyppSS</p><p>1</p><p>211</p><p>~),,,(),,( .</p><p> S , (. ):</p></li><li><p>32</p><p>.,,</p><p>0),,(</p><p>0),,(</p><p>1</p><p>1</p><p>1</p><p>=</p><p>=</p><p>m</p><p>m</p><p>m</p><p>pppS</p><p>pppS</p><p> m m </p><p>mpp ,...,1 . mN , ,</p><p> ),...,,( 1 mppxy . mpp ,...,1 ),...,,( 1 mppxy </p><p> iy~ .</p><p> () , .</p><p> , )(xy </p><p>baxy += ,</p><p> . , </p><p>ap =1 , bp =2 ,</p><p>( )=</p><p>+==N</p><p>iii ybaxbaSS</p><p>1</p><p>2~)(),( ,</p><p>, , :</p><p>( ) ( ) 0~)(2~)(11</p><p>2 =+=+=</p><p>==ii</p><p>N</p><p>ii</p><p>N</p><p>iii ybaxxybaxaa</p><p>S ,</p></li><li><p>33</p><p>( ) ( ) 0~)(2~)(11</p><p>2 =+=+=</p><p>==</p><p>N</p><p>iii</p><p>N</p><p>iii ybaxybaxbb</p><p>S .</p><p> :</p><p>( )22~~</p><p>xx</p><p>yxyxa</p><p>= , xayb = ~ ,</p><p> =</p><p>=N</p><p>iixN</p><p>x1</p><p>1 , </p><p>=</p><p>=N</p><p>iixN</p><p>x1</p><p>22 1 , =</p><p>=N</p><p>iiyN</p><p>y1</p><p>~1~ , =</p><p>=N</p><p>iii yxN</p><p>yx1</p><p>~1~ .</p><p> a b baxy += N ( )ii yx ~, , Ni ,,1= :</p><p>Program MNK ;</p><p>Var a, b, x, y, sum_x, sum_y : Real ; sum_xx, sum_xy : Real ;</p><p> i, N : Integer ;Begin Write(N=? : ) ; { } Readln(N) ; sum_x:=0 ; sum_y:=0 ; sum_xx:=0 ; sum_xy:=0 ; For i:=1 to N do Begin Write(Input x : ) ;</p><p> Readln(x) ; { x } Write(Input y : ) ; Readln(y) ; { y } sum_x:=sum_x + x ; sum_y:=sum_y + y ; sum_xx:=sum_xx + x*x ; sum_xy:=sum_xy + x*y ; End ; a:=( sum_x*sum_y - N*sum_xy )/(sum_x*sum_x - N*sum_xx) ;</p></li><li><p>34</p><p> b:=(sum_y - a*sum_x)/N ; Writeln(a=, a) ; Writeln(b=, b) ; Readln ;End.</p><p> )(xy , , , . , , )(~ xy </p><p>xkxy = e)( , , , q p , :</p><p>xkxy += )ln())(ln( ,)ln(yp = , xq = , kb ln= , =a ,</p><p>baqqp +=)( .</p><p> . a b , , k :</p><p>( )22~ln~ln</p><p>xx</p><p>yxyx</p><p>= , xyk =</p><p>~lne .</p><p> 75=D . </p><p> llp = e)( , 0981.0= -1.</p></li><li><p>35</p><p>141.0=ap , </p><p> 859.0=sp . , .</p><p> .</p><p> , , .</p><p> . : , - ( ) , , . , . , . y , 0 . :</p><p>1. :0=x , 0=y , 0= ( x ).</p><p>2. (). </p><p>n</p><p>0</p><p>y</p><p>x</p><p>D</p></li><li><p>36</p><p> llp = e)( , </p><p> )ln(1 </p><p>=l . </p><p> : += coslxx , += sinlyy ,= .</p><p>3. , ? ( Dx &gt; ) , .1. ( Dx ) , .</p><p>4. . , . </p><p> ap . ap , , , .1 . ap&gt; , 5.</p><p>5. . , = 2 , . , , .2 .</p><p>6. , , .</p><p> :</p></li><li><p>37</p><p>uses Gisto,Graph;</p><p>const MashX = 2; { X } MashY = 1.2; { Y } NGist = 60; { } Mu = 0.0981; { Mu - } Pa = 0.0141; { Pa - } D = 80.; { D - }</p><p>var Gd, Gm, I, N : Integer; Xscr, Yscr, Xscr0, Yscr0 : Integer; OldPattern : FillPatternType; x, y, Lpr, Fi : real;</p><p>label P1, P2, P3, P4, P5, OutGist;</p><p>begin writeln(' N = '); readln(N);{ } Gd := Detect; InitGraph(Gd, Gm, ':\tp\bgi'); if GraphResult grOk then begin writeln (' Graph error or BGI driver not found. '); Halt; end;</p><p>{ } GetFillPattern(OldPattern); SetFillPattern(OldPattern,7); { } Bar(320-round(D*MashX/2), 0, 320+round(D*MashX/2), 479);</p><p> Randomize; { Random } i := 0; { }</p><p> InitGist(NGist,-Pi/2,Pi/2); { -Pi/2 Pi/2 }</p><p> P1:{ } i := i + 1; if (i &gt; N ) then goto OutGist; { } x := 0; y := 0; Fi := 0; Xscr0 := 320-round(D*MashX/2); Yscr0 := 240; MoveTo(Xscr0,Yscr0); { x=0, y=0 } SetColor (i); { }</p></li><li><p>38</p><p> P2:{ } Lpr := - ln(Random)/Mu; { } x := x + Lpr*cos(Fi); { x } y := y + Lpr*sin(Fi); { y }</p><p>{...</p></li></ul>