How to generate samples from a modified exponential density?

조회 수: 2 (최근 30일)
Cuong
Cuong 2014년 6월 9일
댓글: Star Strider 2014년 6월 9일
Hi everyone, The standard form of an exponential density is f(x|lambda)= lambda*exp(-x/lambda) if x>=0 and f(x|lambda)=0 if x<0.
I want to generate samples from the following density f(x|lambda, b)= lambda*exp(-(x-b)/lambda) if x>b and f(x|lambda,b)=0 if x<=b. Where b is a user-specified parameter.
Can anyone here suggest me how to do this ?
Best regards,

채택된 답변

Star Strider
Star Strider 2014년 6월 9일
This works:
lambda = 0.1;
m = 1;
n = 100;
expshft = @(b,lambda,x) (x>=b) .* lambda.*exp(-max(0, (x-b))./(b+lambda));
x = 25*rand(m,n);
R2 = expshft(10,lambda,x);
figure(1)
plot(x, R2,'*b')
grid
The actual function is ‘expshift’. The rest is demonstration code to show how it works.
  댓글 수: 2
Cuong
Cuong 2014년 6월 9일
Thank you so much,
Your answer is very useful.
Best,
Star Strider
Star Strider 2014년 6월 9일
My pleasure!
That was an interesting problem!

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

추가 답변 (1개)

Shashank Prasanna
Shashank Prasanna 2014년 6월 9일
편집: Shashank Prasanna 2014년 6월 9일
You can generate uniform random numbers using the rand function and apply it to your modified density function.

Community Treasure Hunt

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

Start Hunting!

Translated by