How to create a 2D random vector in MATLAB?

I have a non-negative function fdefined on a unit square S = [0,1] x [0,1]such that enter image description here

My question is: how can I use MATLAB to create a two-dimensional random vector from Saccording to the probability density function f?

+4
source share
2 answers

Sampling Deviation

Luis Mendo's proposal is very well done because it applies to all distribution functions. Based on this answer, I wrote code for m.

, PDF- . , . , !

, .

pdf=@(x).5.*x(:,1)+3./2.*x(:,2);
maximum=2; %Right maximum for THIS EXAMPLE. 
%If you are unable to determine the maximum of your 
%function within the [0,1]x[0,1] range, please give an example.
result=[];
n=10;
while (size(result,1)<n)
    %1. sample random point:
    val=rand(1,2);
    %2. Accept with probability pdf(val)/maximum
    if rand<pdf(val)/maximum
        %append to solution
        result(end+1,:)=val;
    end
end

, , , , .

+1

ICDF

, , . ICDF ( ), ICDF(rand(n,1)) .

, PDF ICDF1 (ICDF ) ICDF2 (ICDF ) matlab.

ICDF1 unifrom .

ICDF2 , ICDF1 .

matlab, , ICDF1 ICDF2

samples=ICDF1(rand(n,1));
samples(:,2)=ICDF2(samples,rand(n,1));

, , .

+1

Source: https://habr.com/ru/post/1627614/


All Articles