Question: How can I prevent the creation of random variables or destroy them?

Hi, 

Suppose you have to do some sequence of operations on a random variable (RV), and that you need to repeat this for several RV of the same family (e.g. exponential RV), differing only in the values of their parameters.

Here are two examples do code this.
1/ probably the most natural way to proceed (?)
restart:
with(Statistics):
X := a -> RandomVariable(Exponential(a)):
for n from 1 to 100 do
  S := X(n);
  # here are some operations to do
end do:
anames(alluser);

The last instruction indicates that 103 user variables have been created (X, n, S and 100 random variables).
Note that adding one of the commands S := 'S'; or unassign('S') before the end of the loop just unassigns S but not remove the variables named _ProbabilityDistribution, ..., _ProbabilityDistribution98.


2/ To prevent this inflation of random variables I thought to use the procedure Specialize:
restart:
with(Statistics):
X := RandomVariable(Exponential(a)):
for n from 1 to 100 do
  S := Specialize(X, [a=n]):

  # here are some operations to do
end do:
anames(alluser);

This doesn't change the situation.

So my (multiple) question: 

  • How can I prevent the creation of the objects _ProbabilityDistribution, ..., _ProbabilityDistribution98 given only one of them is used for a given value of the loop counter (once the operations have been done I pass to another random variable) ?
  • How can I unassign a random variable ?
    Maybe it is not possible as suggested by the help page about "_": "Any symbol beginning with an underscore (_) is effectively reserved for use only by library code. It is not available to users." ?

Thanks in advance

Please Wait...