Professional Documents
Culture Documents
Universiti Tunku Abdul Rahman Faculty of Science: Lim Xue Qi 16ADB03823 Loo Xin Yi 16ADB04027
Universiti Tunku Abdul Rahman Faculty of Science: Lim Xue Qi 16ADB03823 Loo Xin Yi 16ADB04027
FACULTY OF SCIENCE
Assignment
1
{
f ( x )= b−a
,a≤ x≤b
0 ,otherwise
x
1
F ( x )=∫ dy
a b−a
y x
¿ [ ]
b−a a
x −a
¿
b−a
0 , x <a
F ( x )= x
{
−a
b−a
,a ≤ x ≤ b
1 , x >b
u=F ( x )
x −a
¿
b−a
x=a+ ( b−a ) u
a=2 ; b=8
SAS code:
Data Q1a;
a=2;
b=8;
Do i=1 to 1000;
u=ranuni(55555);
x=a+(b-a)*u;
output;
End;
run;
proc means;
var x;
run;
Analysis Variable : x
N Mean Std Dev Minimum Maximum
1000 5.0038915 1.7299146 2.0003241 7.9972109
( b−a )2
Var ( X )=
12
( 8−2 )2
¿
12
¿ 3.0000
∴ The simulated mean and variance are almost the same as the exact answer.
b) Exponential distribution with mean 0.5.
f ( x )= λ e−λx , x>0
x
F ( x )=∫ λ e−λy dy
0
x
¿ [ −e− λy ] 0
¿ 1−e−λx , x >0
u=F ( x )
¿ 1−e−λx
1
x=−
λ()ln ( 1−u )
SAS code:
Data Q1b;
lamda=2;
Do i=1 to 1000;
u=ranuni(55555);
x=-(1/lamda)*log(u);
output;
End;
run;
proc means;
var x;
run;
Analysis Variable: x
N Mean Std Dev Minimum Maximum
1000 0.5000478 0.5052911 0.000232481 4.9130612
Simulated mean and variance:
E ( X ) =0.5000478
2
Var ( X )=( 0.5052911 ) =0.255319096
∴ The simulated mean and variance are almost the same as the exact answer.
Question 2
π π
4 4
2 2
g ( xy )=x y sin ( x+ y ) ln ( x + y )
x−0 4 x π
Let a= = → x= a
π π 4
−0
4
da 4 π
= → dx= da
dx π 4
y−0 4 y π
Let b= = → y= b
π π 4
−0
4
db 4 π
= → dy= db
dy π 4
1 1
π π π 2
¿ ∫ ∫ g((
0 0 4
a)( b))
4 4() dadb
1 1
π π π 2
∴ θ=∫ ∫ g
0 0
( a∙ b
4 4 4 )( )
dadb
π 2 π π
¿∑
k () [
4
∙ g a∙ b
4 4 ]
i=1 k
SAS code:
Data Q2;
k=2000;
Pi=constant("pi");
Do i=1 to k;
a=ranuni(55555);
b=ranuni(55555);
x=Pi/4*a;
y=Pi/4*b;
ans=((Pi/4)**2)*((x**2)*(y**2)*sin(x+y)*log (x+y));
output;
End;
run;
proc means;
var ans;
run;
E ( X ) =0.0042366
f ( x )= 2 x , 0≤ x ≤ 1
{0 , otherwise
g ( x )=1 ,0 ≤ x ≤ 1
f (x)
2 .0
1 .5
g( x )
1 .0
0 .5
0 .2 0 .4 0 .6 0 .8 1 .0
f (x )
=2 x
g (x)
f ( x)
Since is a straight line, based on the graph, we can see that it does not consist of any
g(x)
inflation point. Thus, differentiation is not necessary to find the maximum point. By taking
x=1, it gives the highest possible c which is c=2. Note that c is a scalar greater than 1. cg(x) is
proposal distribution and f(x) is target distribution.
2 .0
cg (x)
f (x)
1 .5
1 .0
0 .5
0 .2 0 .4 0 .6 0 .8 1 .0
f x
c=max ( (( )) )
gx
¿ max ( 21x ) ,0 ≤ x ≤ 1
f ( x)
=x
c g( x )
Data bootsamp;
Do sampnum=1 to 200;
Do i=1 to nobs;
x=round(ranuni(55555)*nobs);
set original
nobs=nobs
point=x;
output;
End;
End;
stop;
run;
Data msecalc;
no=200;
xbar=41.4;
msesum=0;
Do i=1 to no;
set mean_output;
if _n_=1 then xbarest=number_Mean;
msesum=msesum+(xbarest-xbar)**2;
End;
mse=msesum/no;
run;
proc print data=msecalc;
var mse;
run;
proc sort
data=mean_output;
by number_Mean;
run;
Data ci_perc;
Obs mse
1 22.3426