MATLAB: How to generate samples from a modified exponential density

exponential densityMATLABsamplingStatistics and Machine Learning Toolbox

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,

Best Answer

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.