Encerrado

Matlab Problems

Project is using MatLab to solve two Monte Carlo simulation questions and one acceptance/rejection method question.

## Deliverables

Question 6.

Consider the two probability distribution functions f and g de ned by

f(x) =

1

p

2

e??

1

2 x2

; x 2 R; (1)

g(x) =

1

2

e??jxj; x 2 R: (2)

Note that the distribution function for the two-sided exponential probability

distribution is

G(x) =

1

Z x

??1

g(y) dy =

(

1

2 ex; x < 0;

1 ?? 1

2

??x

; x 0:

Then its inverse satis es

G??1(y) =

(

log(2y); 0 < y < 1=2;

??log[2(1 ?? y)]; 1=2 y < 1:

For f and g de ned by (1) and (2), the inequality

f(x) Kg(x); x 2 R; (3)

holds with

K =

r

2e

1:315:::

Write MATLAB code which implements the following. Choose a suitable

value for N.

(a) Generate a sequence v1; : : : ; vN according to U(0; 1).

(b) Use the inverse method to generate a sequence of variates x1; : : : ; xN which

corresponds to the probability distribution function g.

(c) Put the elements x1; : : : ; xN into a suitable number of bins, and plot the

histogram, superimposing on it the graph of the probability density function

g de ned in (2).

(d) Use the generalised rejection method to generate a subsequence 1; : : : ; M

which corresponds to the standard normal N(0; 1) (where M N because

not every xj might be accepted).

(e) Calculate the sample mean

^M =

1

M

MX

j=1

j ;

and the sample variance

^sM =

1

M ?? 1

MX

j=1

(j ?? ^M)2

1=2

:

(f) Put the elements 1; : : : ; M into a suitable number of bins, and plot the

histogram, superimposing on it the graph of the standard normal probability

density function f de ned in (1).

The next two questions suggests two methods of calculating using

Monte Carlo integration.

Question 7.

This question is based on fact that

4

=

ZZ

IQ(x; y) dx dy;

where IQ is indicator function of region

Q = f(x; y) : x2 + y2 1; x 0; y 0g:

(a) Generate a sequence u1; : : : ; uN of random vectors according to U(0; 1)

U(0; 1), so that

uj =

uj

1

uj

2

; 1 j M;

where (uj

1)1jN and (uj

2)1jN are sequences of U(0; 1) variates.

(b) Accept uj if (uj

1)2 + (uj

2)2 1; otherwise reject. Let M be number of

random vectors accepted, and calculate

^N =

4M

N

(c) Investigate how close ^N is to for large values of N. You might generate

table like following.

N j ?? ^Nj

? ?

...

...

Question 8.

The second method is based on

4

=

Z 1

1

1 + x2 dx:

Remember that

Z b

a

h(x) dx = (b ?? a)

Z n

a

h(x)

1

b ?? a

dx = (b ?? a)E[h(X)];

where X is uniformly distributed on (a; b). A crude Monte Carlo estimator for

this is

MN =

b ?? a

N

XN

j=1

h(a + (b ?? a)Uj);

where U1;U2; : : : ;UN is a sequence of random variables in U(0; 1).

Write MATLAB code which implements the following. Choose a suitable

value for N.

(a) Generate a sequence v1; : : : ; vN according to U(0; 1).

(b) Calculate

~N =

4

N

XN

j=1

h(vj); (4)

where

h(x) =

1

1 + x2 ; x 2 R:

Investigate how close ~N is to for large values of N. You might generate

table like following.

N j ?? ~Nj sample variance

? ? ?

...

...

...

(c) Using an antithetic variable, calculate

N =

2

N

XN

j=1

[h(vj) + h(1 ?? vj )]:

Investigate how close

N is to for large values of N. Theory shows that

the variance should be reduced by at least a half, and that therefore only

a quarter of number simulations are needed to get the same accuracy as

the crude Monte Carlo estimate (4).

3

Habilidades: Redação técnica

Ver mais: writing functions matlab, writing functions, writing exponential functions, writing inequality, writing function matlab, uj, solve graph problems, sample problems, sample probability questions, region 13, probability sample problems, probability solve, solve probability questions, solve probability question, solve probability problems, solve probability, graph theory problems, es log, code theory, least probability questions, zz, xn, writing matlab, write matlab, vj

Acerca do Empregador:
( 0 comentários ) Ireland

ID do Projeto: #3058206

4 freelancers estão ofertando em média $96 para este trabalho

themazeeu

See private message.

$68 USD in 14 dias
(10 Comentários)
4.8
manybodycoder

See private message.

$42.5 USD in 14 dias
(7 Comentários)
3.7
renardpaul

See private message.

$170 USD in 14 dias
(10 Comentários)
3.4
Hadia788

See private message.

$102 USD in 14 dias
(3 Comentários)
0.3