隨機過程上機實驗報告_第1頁
隨機過程上機實驗報告_第2頁
隨機過程上機實驗報告_第3頁
隨機過程上機實驗報告_第4頁
隨機過程上機實驗報告_第5頁
已閱讀5頁,還剩26頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、2015-2016第一學期隨機過程第二次上機實驗報告實驗目的:通過隨機過程上機實驗,熟悉Monte Carlo計算機隨機模擬方法,熟悉Matlab的運行環(huán)境,了解隨機模擬的原理,熟悉隨機過程的編碼規(guī)律即各種隨機過程的實現(xiàn)方法,加深對隨機過程的理解。上機內(nèi)容:(1)模擬隨機游走。(2)模擬Brown運動的樣本軌道。(3)模擬Markov過程。實驗步驟:(1)給出隨機游走的樣本軌道模擬結果,并附帶模擬程序。 一維情形%一維簡單隨機游走%“從0開始,向前跳一步的概率為p,向后跳一步的概率為1p” n=50;p=0.5; y=0 cumsum(2.*(rand(1,n-1)<=p)-1); %

2、n步。 plot(0:n-1,y); %畫出折線圖如下。%一維隨機步長的隨機游動 %選取任一零均值的分布為步長, 比如,均勻分布。 n=50;x=rand(1,n)-1/2; y=0 (cumsum(x)-1); plot(0:n,y);二維情形%在(u, v)坐標平面上畫出點(u(k), v(k), k=1:n, 其中(u(k)和(v(k) 是一維隨機游動。例%子程序是用四種不同顏色畫了同一隨機游動的四條軌道。n=100000; colorstr='b' 'r' 'g' 'y' for k=1:4 z=2.*(rand(2,n)

3、<0.5)-1; x=zeros(1,2); cumsum(z'); col=colorstr(k); plot(x(:,1),x(:,2),col); hold on end grid %三維隨機游走 ranwalk3d p=0.5; n=10000; colorstr='b' 'r' 'g' 'y' for k=1:4 z=2.*(rand(3,n)<=p)-1; x=zeros(1,3); cumsum(z'); col=colorstr(k); plot3(x(:,1),x(:,2),x(:,3

4、),col); hold on end grid(2) 給出一維,二維Brown運動和Poisson過程的模擬結果,并附帶模擬程序,沒有結果的也要把程序記錄下來。一維Brown% 這是連續(xù)情形的對稱隨機游動,每個增量W(s+t)-W(s)是高斯分布N(0, t),不相交區(qū)間上的增量是獨立的。典型的模擬它方法是用離散時間的隨機游動來逼近。 n=1000; dt=1; y=0 cumsum(dt0.5.*randn(1,n); % 標準布朗運動。 plot(0:n,y);二維Brownnpoints = 5000; dt = 1; bm = cumsum(zeros(1, 3); dt0.5*ra

5、ndn(npoints-1, 3); figure(1); plot(bm(:, 1), bm(:, 2), 'k'); pcol = (bm-repmat(min(bm), npoints, 1)./ . repmat(max(bm)-min(bm), npoints, 1); hold on; scatter(bm(:, 1), bm(:, 2), . 10, pcol, 'filled'); grid on; hold off;三維Brown npoints = 5000; dt = 1; bm = cumsum(zeros(1, 3); dt0.5*ra

6、ndn(npoints-1, 3); figure(1); plot3(bm(:, 1), bm(:, 2), bm(:, 3), 'k'); pcol = (bm-repmat(min(bm), npoints, 1)./ . repmat(max(bm)-min(bm), npoints, 1); hold on; scatter3(bm(:, 1), bm(:, 2), bm(:, 3), . 10, pcol, 'filled'); grid on; hold off;%泊松過程的模擬、檢驗及參數(shù)估計syms Un X S;n=10;%生成n*n個隨機數(shù)

7、r=1;%參數(shù)temp=0;tem=0;Un=rand(n,1);%共產(chǎn)生n*n個隨機數(shù)for i=1:1:n X(i)=-log(Un(i)/r;endX=subs(X);for i=1:1:n for j=1:1:i temp=temp+X(j); end S(i)=temp; temp=0;endS=subs(S);%檢驗泊松過程使用第四條for i=1:1:n tem=tem+S(i);endsigmaN=tem;T=S(n);alpha=0.05;%置信水平p=sigmaN/T;p1=(1/2)*(n-1.96*(n/3)(1/2);p2=(1/2)*(n+1.96*(n/3)(1/

8、2);c1=subs(p-p1)c2=subs(p-p2)if (c1<=0&c2>=0)|(c1>=0&c2<=0) disp('這是一個泊松過程!') %參數(shù)估計使用極大似然估計 r_=subs(n/T); if abs(subs(r_-r)<0.1 disp('參數(shù)估計正確!') disp('參數(shù)估計值為:') r_ end %繪制軌跡 y=0; x=0:0.001:subs(S(1); plot(x,y) for k=1:1:n y=k; x=subs(S(k):0.001:subs(S(k+

9、1); hold on plot(x,y) endelse disp('這不是一個泊松過程!')end%二維poisson2d lambda=100; nmb=poissrnd(lambda) x=rand(1,nmb); y=rand(1,nmb); grid scatter(x,y,5,5.*rand(1,nmb);%三維poisson3d%單位體積的泊松點數(shù)強度為lambda lambda=100; nmb=poissrnd(lambda) x=rand(1,nmb); y=rand(1,nmb); z=rand(1,nmb); grid scatter3(x,y,z,5

10、,5.*rand(1,nmb);(3)Markov過程的模擬結果。離散服務系統(tǒng)中的緩沖動力學%離散服務系統(tǒng)中的緩沖動力學m=200; p=0.2; N=zeros(1,m); %初始化緩沖區(qū) A=geornd(1-p,1,m); %生成到達序列模型, 比如,幾何分布 for n=2:m N(n)=N(n-1)+A(n)-(N(n-1)+A(n)>=1); end stairs(0:m-1),N);M/M/1模型% tjump, systsize = simmm1(n, lambda, mu) % Inputs: n - number of jumps % lambda - arrival

11、 intensity % mu - intensity of the service times % Outputs: tjump - cumulative jump times % systsize - system size % set default parameter values if ommited :nargin=0nargin=0; if (nargin=0) n=500; lambda=0.8; mu=1; end i=0; %initial value, start on level i tjump(1)=0; %start at time 0 systsize(1)=i;

12、 %at time 0: level i for k=2:n if i=0 mutemp=0; else mutemp=mu; end time=-log(rand)/(lambda+mutemp); % Inter-step times: % Exp(lambda+mu)-distributed if rand<lambda/(lambda+mutemp) i=i+1; %jump up: a customer arrives else i=i-1; %jump down: a customer is departing end %if systsize(k)=i; %system s

13、ize at time i tjump(k)=time; end %for i tjump=cumsum(tjump); %cumulative jump times stairs(tjump,systsize); :nargin不為0時nargin=2; if (nargin=0) n=500; lambda=0.8; mu=1; end i=0; %initial value, start on level i tjump(1)=0; %start at time 0 systsize(1)=i; %at time 0: level i for k=2:n if i=0 mutemp=0;

14、 else mutemp=mu; end time=-log(rand)/(lambda+mutemp); % Inter-step times: % Exp(lambda+mu)-distributed if rand<lambda/(lambda+mutemp) i=i+1; %jump up: a customer arrives else i=i-1; %jump down: a customer is departing end %if systsize(k)=i; %system size at time i tjump(k)=time; end %for i tjump=c

15、umsum(tjump); %cumulative jump times stairs(tjump,systsize); M/D/1系統(tǒng)% function jumptimes, systsize = simmd1(tmax, lambda) % SIMMD1 simulate a M/D/1 queueing system. Poisson arrivals % of intensity lambda, deterministic service times S=1. % jumptimes, systsize = simmd1(tmax, lambda) % Inputs: tmax -

16、simulation interval % lambda - arrival intensity % Outputs: jumptimes - time points of arrivals or departures % systsize - system size in M/D/1 queue % systtime - system times % Authors: % v1.2 07-Oct-02 % set default parameter values if ommited :nargin=0nargin=0;if (nargin=0) tmax=1500; lambda=0.95

17、; end arrtime=-log(rand)/lambda; % Poisson arrivals i=1; while (min(arrtime(i,:)<=tmax) arrtime = arrtime; arrtime(i, :)-log(rand)/lambda; i=i+1; end n=length(arrtime); % arrival times t_1,.t_n arrsubtr=arrtime-(0:n-1)' % t_k-(k-1) arrmatrix=arrsubtr*ones(1,n); deptime=(1:n)+max(triu(arrmatri

18、x); % departure times %u_k=k+max(t_1,.,t_k-k+1) B=ones(n,1) arrtime ; -ones(n,1) deptime' Bsort=sortrows(B,2); % sort jumps in order jumps=Bsort(:,1); jumptimes=0;Bsort(:,2); systsize=0;cumsum(jumps); % M/D/1 process systtime=deptime-arrtime' % system times % plot a histogram of system times

19、 hist(systtime,30); :nargin不為0% function jumptimes, systsize = simmd1(tmax, lambda) % SIMMD1 simulate a M/D/1 queueing system. Poisson arrivals % of intensity lambda, deterministic service times S=1. % % jumptimes, systsize = simmd1(tmax, lambda) % % Inputs: tmax - simulation interval % lambda - arr

20、ival intensity % Outputs: jumptimes - time points of arrivals or departures % systsize - system size in M/D/1 queue % systtime - system times % Authors: % v1.2 07-Oct-02 % set default parameter values if ommited nargin=2;if (nargin=0) tmax=1500; lambda=0.95; end arrtime=-log(rand)/lambda; % Poisson

21、arrivals i=1; while (min(arrtime(i,:)<=tmax) arrtime = arrtime; arrtime(i, :)-log(rand)/lambda; i=i+1; end n=length(arrtime); % arrival times t_1,.t_n arrsubtr=arrtime-(0:n-1)' % t_k-(k-1) arrmatrix=arrsubtr*ones(1,n); deptime=(1:n)+max(triu(arrmatrix); % departure times %u_k=k+max(t_1,.,t_k-

22、k+1) B=ones(n,1) arrtime ; -ones(n,1) deptime' Bsort=sortrows(B,2); % sort jumps in order jumps=Bsort(:,1); jumptimes=0;Bsort(:,2); systsize=0;cumsum(jumps); % M/D/1 process systtime=deptime-arrtime' % system times % plot a histogram of system times hist(systtime,30); M/G/infinity系統(tǒng)%function

23、 jumptimes, systsize = simmginfty(tmax, lambda) % SIMMGINFTY simulate a M/G/infinity queueing system. Arrivals are % a homogeneous Poisson process of intensity lambda. Service times % Pareto distributed (can be modified). % jumptimes, systsize = simmginfty(tmax, lambda) % % Inputs: tmax - simulation

24、 interval % lambda - arrival intensity % Outputs: jumptimes - times of state changes in the system % systsize - number of customers in system % See SIMSTMGINFTY, SIMGEOD1, SIMMM1, SIMMD1, SIMMG1. % set default parameter values if ommited : nargin=0nargin=0; if (nargin=0) tmax=1500; lambda=1; end % g

25、enerate Poisson arrivals % the number of points is Poisson-distributed npoints = poissrnd(lambda*tmax); % conditioned that number of points is N, % the points are uniformly distributed if (npoints>0) arrt = sort(rand(npoints, 1)*tmax); else arrt = ; end % uncomment if not available POISSONRND % g

26、enerate Poisson arrivals % arrt=-log(rand)/lambda; % i=1; % while (min(arrt(i,:)<=tmax) % arrt = arrt; arrt(i, :)-log(rand)/lambda; % i=i+1; % end % npoints=length(arrt); % arrival times t_1,.,t_n % servt=50.*rand(n,1); % uniform service times s_1,.,s_k alpha = 1.5; % Pareto service times servt =

27、 rand(-1/(alpha-1)-1; % stationary renewal process servt = servt; rand(npoints-1,1).(-1/alpha)-1; servt = 10.*servt; % arbitrary choice of mean dept = arrt+servt; % departure times % Output is system size process N. B = ones(npoints, 1) arrt; -ones(npoints, 1) dept; Bsort = sortrows(B, 2); % sort ju

28、mps in order jumps = Bsort(:, 1); jumptimes = 0; Bsort(:, 2); systsize = 0; cumsum(jumps); % M/G/infinity system size % process stairs(jumptimes, systsize); xmax = max(systsize)+5; axis(0 tmax 0 xmax); grid : nargin不為0時%function jumptimes, systsize = simmginfty(tmax, lambda) % SIMMGINFTY simulate a

29、M/G/infinity queueing system. Arrivals are % a homogeneous Poisson process of intensity lambda. Service times % Pareto distributed (can be modified). % jumptimes, systsize = simmginfty(tmax, lambda) % % Inputs: tmax - simulation interval % lambda - arrival intensity % Outputs: jumptimes - times of s

30、tate changes in the system % systsize - number of customers in system % See SIMSTMGINFTY, SIMGEOD1, SIMMM1, SIMMD1, SIMMG1. % set default parameter values if ommited nargin=2; if (nargin=0) tmax=1500; lambda=1; end % generate Poisson arrivals % the number of points is Poisson-distributed npoints = poissrnd(lambda*tmax); % conditioned that number of points is N, % the points are uniformly distributed if

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論