看板 NTUfin98 關於我們 聯絡資訊
大家好 我今天花了一些時間把高統作業的程式碼寫了 希望大家可以一起討論一下,若要討論,請隨時發站內信給我,謝謝。 1.normdistribution 的 contour (100圈版) clear all mx=input('Input mean of x = '); my=input('Input mean of y = '); sx=input('Input standard variance of x = '); sy=input('Input standard variance of y = '); rho=input('Input correlation coefficient rho = '); n=input('Input bound of x and y = '); x=linspace(-n,n); y=x; [x,y]=meshgrid(x,y); z=exp((-0.5/(1-rho^2))*(((x-mx)/sx).^2-2*rho*((x-mx)/sx).*((y-my)/sy)+((y-my)/sy).^2)); contour(x,y,z,100)//括號最後一項可控制圈數 2.p112 x marginal clear all l=input('Input lunda '); n=input('Input upperbound of x '); x=linspace(0,n); z=l*exp(-l*x); plot(x,z) 3.p112 y margianl clear all l=input('Input lunda '); n=input('Input upperbound of y '); y=linspace(0,n); z=(y*l*l).*exp(-l*y);//注意前面刮弧後有一個頓號,這是為了確保兩刮弧是同秩的 //linespace plot(y,z) 4.p112 joint pdf 這題我遇到一些困難,附上我的兩個版本,第一個版本是不考慮y>=x的情況 clear all xlabel('x') ylabel('y') l=input('Input lunda '); n=input('Input upperbound of '); x=linspace(0,n); y=linspace(0,n); [x,y]=meshgrid(x,y); z=l*l*exp(-l*y); meshz(x,y,z) xlabel('X') ylabel('Y') 第二個版本,我利用描點的方式:把x,y點放入由0到range n,以 d 為每行列間距的 矩陣裡,之所以用離散的表達是希望把每一點拿出來比大小,之後我再把 y 矩陣中的 每一個點換成 x 矩陣中的對應點減去 d,如此保證 y>=x,然後再畫出來就好了。 (其中d代表每行列間距,要訂為小於一,但如果訂得太小電腦會跑不動,我自己測試的時 候,訂為0.03可以得到近乎平滑的表面) 缺點:本程式的精確性不夠,尤其是在邊界值,因為我所用的演算法是把y 矩陣中的 每一個點換成 x 矩陣中的對應點減去 d,所以在 y=0 還有 x=n(boundary) 會有奇怪 的圖形,希望大家跟我討論,一起修正。 clear all l=input('Input lunda '); n=input('Input upperbound of y '); d=input('Input desity '); [x,y]=meshgrid([0:d:n]); for i=1:fix(1/d*(n)); for j=1:fix(1/d*(n)); y(i,j)=x(i,j)-d; end end z=l*l*exp(-l*y); meshz(x,y,z) xlabel('X') ylabel('Y') -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.7.59
Avle:推 泳者鬥餓龍~ 下週六 一起來龍門游吧~ 12/01 12:40
yu0101:XD 12/01 22:19