mmcdara

7891 Reputation

22 Badges

9 years, 54 days

MaplePrimes Activity


These are questions asked by mmcdara

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

Hi, 
How can I load a .m file with the big green arrow ?

TIA

Hi, 

Here is an example where evalf ( Int(....) ) fails to compute an in integral.
The function to integrate is very smooth and, except method=_Gquad, all the others seem to fail (even method=_MonteCarlo fails, which is probably the most surprising thing!)

Is it a weakness of evalf+Int or a misusse of my own ?

restart:

interface(version)

`Standard Worksheet Interface, Maple 2015.2, Mac OS X, December 21 2015 Build ID 1097895`

(1)

plot3d(cos(x*y), x=-1..3, y=-1..-0.2)

 

int(cos(x*y), [x=-1..3, y=-1..-1/5]);
evalf[15](%);

Si(3)+Si(1)-Si(3/5)-Si(1/5)

 

2.00705070023234

(2)

CodeTools:-Usage( evalf[10](Int(cos(x*y), [x=-1..3, y=-1..-0.2], method=_Gquad)) );

memory used=1.24KiB, alloc change=0 bytes, cpu time=0ns, real time=0ns, gc time=0ns

 

2.007050700

(3)

CodeTools:-Usage( evalf[10](Int(cos(x*y), [x=-1..3, y=-1..-0.2], method=_CubaVegas)) );

memory used=22.14KiB, alloc change=0 bytes, cpu time=16.99s, real time=17.01s, gc time=0ns

 

Int(Int(cos(x*y), x = -1. .. 3.), y = -1. .. -.2)

(4)

CodeTools:-Usage( evalf[10](Int(cos(x*y), [x=-1..3, y=-1..-0.2], method=_MonteCarlo)) );

memory used=12.79KiB, alloc change=0 bytes, cpu time=1000.00us, real time=0ns, gc time=0ns

 

Int(Int(cos(x*y), x = -1. .. 3.), y = -1. .. -.2)

(5)

N := 10^6:
X := Statistics:-Sample(Uniform(-1, 3), N):
Y := Statistics:-Sample(Uniform(-1, -0.2), N):
Z := cos~(X*~Y):
add(Z) / N * (4*0.8);

HFloat(2.0076470771803545)

(6)

 


 

Download evalf_Int.mw

 

Hi, 

Here is the minimal situation that reveals which that could be a (little) bug in the MAPLE 2015 version of Explore.

In the attached file y is a list of numbers and val(r) a procedure that just print the value the rth element of y.
Changing the value of r is done with Explore (of course of no interest at all).
If I define the parameter r as a list ( r=[1..numelems(y)] ), only the value of y[1] is displayed: changing the value of r generates an error.
This doesn(t happen if r is defined as a slider ( r=1..numelems(r) ).

I discovered than the initial instance of Explore defines r as an integer while all the others (due to a change of r) define r as a string.
In the last command of the attached file you will see hjow I have circumvent this problem.

Is it a bug in Explore or does it exist some way to force the values of r to the implicit type they have in r=[$1..numelems(y)] ?

TIA

Download explore.mw

 

Hi, 

I have a list of integers (>1) and for all of them I define an alias (in the attached file I've tried two different names for them : a[n] or a||n) wich represents the nth roots of the unity.
When I apply the procedure allvalues to a specific alias it returns the algebraic values of the corresponding roots of the unity.
But when aplied to the list of aliases it gives me back only the name of the alias, not the algebraic values.

How can I fix this ?

TIA

restart:

interface(version)

`Standard Worksheet Interface, Maple 2015.2, Mac OS X, December 21 2015 Build ID 1097895`

(1)

for n from 2 to 3 do
  alias(a[n]=RootOf(z^n-1)):
end do:

alias();

a[2], a[3]

(2)

allvalues(a[2]);
allvalues(a[3]);

seq(allvalues(a[n]), n=2..3)

1, -1

 

1, -1/2+((1/2)*I)*3^(1/2), -1/2-((1/2)*I)*3^(1/2)

 

a[2], a[3]

(3)

for n from 2 to 3 do
  alias(a||n=RootOf(z^n-1)):
end do:

alias();

allvalues(a2);
allvalues(a3);

seq(allvalues(a||n), n=2..3)

a[2], a[3], a2, a3

 

1, -1

 

1, -1/2+((1/2)*I)*3^(1/2), -1/2-((1/2)*I)*3^(1/2)

 

a2, a3

(4)

A := [alias()]:
map(allvalues, A);

[a[2], a[3], a2, a3]

(5)

 


 

Download allvalues.mw

 

First 32 33 34 35 36 37 38 Last Page 34 of 48