smith_alpha

150 Reputation

6 Badges

7 years, 210 days

MaplePrimes Activity


These are questions asked by smith_alpha

Hi,

 

  I think similar question has been asked by several people, but I did not find a suitable thread. My question is, suppose I have a probablity distirubtion function like

  p(x,y) = exp(-alpha (x+y) ) x^2 y^2 / |x-y|  , alpha>0

 x,y goes from - \infty to + \infty. This function is normalizable but unbounded, which makes the rejection algorithm a bit difficult(?).

 

  How to generate samping points from this type of probability distribution function?

 

Thank you very much!

 

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

 

 

Suppose I have a table of variables

 

f[1]:=a;

f[2]:=b;

 

numelems(f); gives 2.

 

In case I have not assign f, 

unassign(f);
numelems(f); gives error message.

 

Is there any simple way let maple detect that if it is unassined, numelems(f), can provide zero?

 

Thank you very much

 

 

  If I use

 

f:=(a+b)^2;
expand(f);

 

I got 

a^2+2ab+b^2

 

This result holds if ab=ba. Otherwise the result is a^2 + ab + ba + b^2

 

Is there any simpler way to obtain  a^2 + ab + ba + b^2? I looked up http://www.maplesoft.com/support/help/maple/view.aspx?path=dot

but did not find a solution :(

 

Thank you very much!

 

 

 

The member function can provide the position of x in table/list s for the first variable

 

e.g.

f:=[a,b,c,a,a];
member(a,f,'p');

will provide p=1

 

If I would like to know the position of all a, [1,4,5], is there any simple way to obtain them? I can do something like

 

n:=0;

for i from 1 to 5 do

 if f[i]='a' then

  n:=n+1;

  p[n]:=i;

 end if;

end do;

 

something like that

Thank you very much

1 2 3 4 5 6 7 Last Page 1 of 10