Problem with generating random numbers from a 2D distribution

I used the following function
to generate random numbers, but i get wrong results. I wonder if i can use this function, if my distribution function(with dependent variables) is in this form:
where
theta = linspace(0, 2*pi, 10);
phi = linspace(0, pi, 10);
After posting the question: I think this function generates random numbers under the assumption that the variables of the 2D function is independent.

답변 (1개)

David Hill
David Hill 2022년 2월 6일
Why not something like this? I might not be understanding you.
r=randi(10,1,2);
f(theta(r(1)),phi(r(2)));

댓글 수: 1

"randi" is generating random numbers based on a uniform distribution. In my case (and i suppose what the mentioned code does), the random numbers are generated based on a given density function (which is not uniform)

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2022년 2월 6일

편집:

2022년 2월 7일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by