Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rejection method

Status
Not open for further replies.

Hibru

Bioengineer
Joined
Nov 17, 2004
Messages
3
Location
BE
I wanted to have a exponential distribution from uniform distribution between 0 and 1.while I implement some methods in matlab I failed to solve the problem of rejecting points out of range.As a result I get fewer points between 0 and 1 in exponential distribution than uniform distribution.

I used the following program.

function [x,y,vx,vy]=exponential(n)

rand('state',sum(100*clock))
%exponential distribution from uniform distribution
u =rand(1,n);
v= rand(1,n);
for i=1:n
x = -2*log(u);
y = -2*log(v);

end
[vx,vy]=voronoi(x,y);
plot(x,y,'b*',vx,vy,'r')
axis([0 1 0 1])

can any body help me?

Regards,


 
Are you aware of that your for-loop is useless? The loop variable [tt]i[/tt] is never used. Could this be the problem?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top