?? ch4_6_2.htm
字號:
<! Made by Html Translation Ver 1.0>
<HTML>
<HEAD>
<TITLE> 常態亂數 </TITLE>
</HEAD>
<BODY BACKGROUND="bg0000.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img/bg0000.gif">
<FONT COLOR="#0000FF">
<H1>4.6.2 常態亂數</H1>
</FONT>
<HR>
<P>
用 MATLAB 函數 <FONT COLOR=#FF0000>randn</FONT>產生常態亂數,它是以高斯分布在亂數出現的上下限區間。常態亂數其值分布于一區間的特性可以從
其統計密度函數(PDF) 說明。從其 PDF 分布可以看出其每一個亂數值出現的機率皆不相同,靠近中間的亂
數值出現的機率比起兩端的值要高,這是一般不規則現象較可能出現的情形,所以它被稱為常態亂數。由
于常態亂數并非以上下限來定義,它是用數據的平均值和變異數定義之。因此在產生一常態亂數時,需設
定平均值和變異數的大小。<FONT COLOR=#FF0000>randn(n)</FONT>和<FONT COLOR=#FF0000>randn(n,m)</FONT> 是分別產生一矩陣含 <FONT COLOR=#FF0000>n</FONT>x<FONT COLOR=#FF0000>n</FONT>個亂數和一矩陣含<FONT COLOR=#FF0000>m</FONT>x<FONT COLOR=#FF0000>n</FONT>的常態亂數,
其平均值為0變異數為1。
<BR>
<P>
見以下的例子:
<P>
<FONT COLOR=#FF0000>>> x=-2.9:0.2:2.9; % 這個例子用到 hist
函數來畫出二種亂數的分布圖</FONT>
<P>
<FONT COLOR=#FF0000>>> y=randn(1,5000);</FONT>
<P>
<FONT COLOR=#FF0000>>> hist(y,x)</FONT>
<P>
<FONT COLOR=#FF0000>>> title('Histogram of Normal Random
Data')</FONT>
<P>
<FONT COLOR=#FF0000>>> y1=rand(1,5000);</FONT>
<P>
<FONT COLOR=#FF0000>>> hist(y1,x)</FONT>
<P>
<FONT COLOR=#FF0000>>> title('Histogram of Uniform Random
Data')<BR>
</FONT>
<P>
如果需要產生常態亂數值的平均值和變異數并非0和1,可以采用以下步驟將平均值和變異數做轉換。假設要
得到一組常態亂數值的平均值為<I>b</I>和變異數為<I>a</I>,我們先產生一組亂數<I>r</I>,再將其值乘以變異數<I>a</I>。接著再加平
均值<I>b</I>。算式如下
<P>
<I>x</I>=<I>a</I>*<I>r</I> + <I>b</I>
<P>
其中<I>x</I>代表轉換后的亂數值的陣列。請看下列示范:
<P>
<FONT COLOR=#FF0000>>>data_2 = randn(1,500)+3 %原亂數值有500個</FONT>
<P>
<FONT COLOR=#FF0000>>>plot(data_2) %這個圖是否看來眼熟?</FONT>
<P>
<FONT COLOR=#FF0000>>>axis([1 500 0 6])</FONT>
<P>
<FONT COLOR=#FF0000>>>hist(data_2) %看看其長條圖</FONT><HR>
<A HREF="ch4_6_1.htm" tppabs="http://166.111.167.223/computer/cai/matlabjc/ch4_6_1.htm"><IMG SRC="lastpage.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img/lastpage.gif" BORDER=0></A>
<A HREF="ch4_7.htm" tppabs="http://166.111.167.223/computer/cai/matlabjc/ch4_7.htm"><IMG SRC="nextpage-1.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img/nextpage.gif" BORDER=0 HSPACE=10></A>
<A HREF="index.html" tppabs="http://166.111.167.223/computer/cai/matlabjc/index.html"><IMG SRC="outline-1.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img/outline.gif" BORDER=0 HSPACE=6></A><BR>
<FONT SIZE=2 COLOR=#AA55FF> 上一頁 下一頁 講義大綱 </FONT>
</BODY>
</HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -