generating random numbers respect to a certain constraint

hello everybody, I want to generate two numbers ( x1 and x2 ) which have a normal distribution which always respect an equality ( x1+x2=0.5 ).
Appreciate your kind comments.

답변 (2개)

John D'Errico
John D'Errico 2017년 6월 12일
Trivial? Although really, you have not provided sufficient information.
What are the parameters of that distribution along the constraint line? Just saying the distribution is normal is not sufficient. Regardless, normal distributions are so easy to work with that the answer is easy.
V = [1 1];V = V/norm(V);
xy = randn(10000,2);
xy = xy - xy*V'*V + [0.25 0.25];
min(sum(xy,2))
ans =
0.5
max(sum(xy,2))
ans =
0.5
As I said, normal distributions are so easy to work with, that this is trivial. The rows of xy represent points along the constraint line, normally distributed. The variance of those points along the constraint line is 1.
Or, I could have done it by creating a singular covariance matrix. You need to be careful there, because the standard methods to create normal random variables can fail, if the covariance matrix is just slightly not positive definite. I have posted a tool called nearestSPD on the file exchange though.

댓글 수: 2

Appreciate in advance for your answer, would you mind please send me the mathematics logic behind this method, or any reference for this method?
Basic linear algebra. Its just a projection into a subspace.

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

Walter Roberson
Walter Roberson 2017년 6월 14일
x1 = randn();
x2 = 0.5 - x1;

댓글 수: 1

Thanks Walter, but the problem is generating random numbers such that they follow a certain constraints, moreover the numbers should have a normal distribution also. each number(set of numbers) should have its own mean and standard deviation.

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

카테고리

도움말 센터File Exchange에서 Random Number Generation에 대해 자세히 알아보기

질문:

2017년 6월 12일

댓글:

2017년 6월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by