I am trying to generate a random vector from two other random vectors and a scalar in Matlab. λ* P - Φ.*μ < 0 where P, Φ, μ are vectors and λ is a scalar value. I have written following code in Matlab. But it stuck in while loop many times when I try to use higher value of λ e.g. λ = 30 or 50. I shall appreciate any help.
%generate P from uniform distribution: 0≤ P ≤1 and ∑P =1
a=rand(47,1);
a=[0;a;1];
a=sort(a);
b=zeros(48,1);
for i=1:48
b(i)=abs(a(i)-a(i+1));
end
P=b';
%---------------------------------------------
% Generate μ from uniform distribution: 1≤ μ ≤2
%----------------------------------------------
a=1; b=2; miu = a+(b-a)* rand(48,1);
%-----------------------------------------------------------------------
% Generate from uniform distribution: 0≤ Φ ≤1 such that λ* P - Φ.*μ < 0
%-----------------------------------------------------------------------
count=1; lamda=5;
while(count ~= 49)
tPhi = rand(1,1);
c = lamda* P(count) - tPhi.*miu(count);
if(c<0)
Phi(count,1)= tPhi;
count=count+1;
end
end
disp(Phi);
Aucun commentaire:
Enregistrer un commentaire