Hi,

I have the following input

***

restart;

with( Statistics ):

a:=2;c:=0.3;

g:= exp(-a*x) + c*a*exp(-a*x);

#f := x -> piecewise( x < 0, 0, x>0, g );

f :=x -> piecewise( x < 0, 0, x>0, exp(-a*x) + c*a*exp(-a*x));

norm_factor:=int( f(x), x=0..infinity );

print(norm_factor);

randomize():

F := Distribution( PDF = 1/norm_factor*f ):

X := RandomVariable( F ):

N := 20;

S := convert( Sample(X,N), list );

print(`cc`,S[1]);

***

The code works. However, if I comment out

f :=x -> piecewise( x < 0, 0, x>0, exp(-a*x) + c*a*exp(-a*x));

, then use

f := x -> piecewise( x < 0, 0, x>0, g );

i.e.

f := x -> piecewise( x < 0, 0, x>0, g );

#f :=x -> piecewise( x < 0, 0, x>0, exp(-a*x) + c*a*exp(-a*x));

It is said "

Error, (in Statistics:-Sample) unable to construct the envelopes for _R, try to specify the initial range"

The norm_factors are actually the same for both inputs. What is the reason for the error message? Suppose I still want to use something like

f := x -> piecewise( x < 0, 0, x>0, g );

,how to fix the problem?

Thank you very much