Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross 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
Nov 17, 2004
3
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,


 
Replies continue below

Recommended for you

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