Carl Love

Carl Love

28070 Reputation

25 Badges

13 years, 28 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

I can't understand what you want, and you can't understand what I've given you. Please get someone to help you with your English before posting.

You wrote:

The Maxwell-Boltzmann distribution sampling times are 2002. But you just list five sequences. I don't know why.

Five was just a convenient number that fit on one line on the screen. The way that you are using the word "sampling" is not standard mathematical English. The entire population of possible distributions of 9 quanta among 6 particles has size 2002. But that is neither a sample nor a time.

I am very confuced about the sampling. How can you set sampling times are 2002?

I have no idea why you would want a sample of size 2002. The idea seems crazy to me. But you can change the five to any number that you want. That should be obvious!

'R()' $ 2002;

Now, if you want the whole population, that's another matter. Now (in the worksheet posted below) I have included an option to return the whole population: ouput= population.

You said the computation is exact---not based on random sampling. But latter you said that does either the exact computation or provides a random sampler depending on an input option.

If you say output= exact then the computation is exact! If you say output= sampler then the output is a random sample! Why can't you understand that? Please get someone to help you read the code. The computation where I compared the numbers with those on the website were the exact computations.

What's the difference from random sampling and random sampler?

I am using "sampler" to mean a procedure that generates a random sample. When you call my procedure with the option output= sampler then the object returned is itself a procedure---a procedure which draws one item from the population each time it is called.


QuantumDistribution:= proc(
     n::nonnegint, #Number of quanta of energy
     k::posint,    #Number of particles
     {model::identical("Bose-Einstein","Maxwell-Boltzmann","Fermi-Dirac"):= NULL},
     {output::identical(exact, sampler, population):= exact}
)
local C, Population, sz, Rand;
     if model = "Maxwell-Boltzmann" then
          Population:= combinat:-composition(n+k, k)
     else
          # Bose-Einstein:
          Population:= select(p-> nops(p)=k, combinat:-partition(n+k, n+1));
          if model = "Fermi-Dirac" then
               Population:= select(C-> ListTools:-FindRepetitions(C,2) = [], Population)
          end if
     end if;
     sz:= nops(Population);
     userinfo(1, QuantumDistribution, NoName, "Population size = ", sz);
     Population:= [seq(C-~1, C= Population)];
     if output = 'exact' then

          (lhs=rhs/sz)~([{Statistics:-Tally(op~(Population))[]}[]])
     elif output = 'sampler' then
          Rand:= rand(1..sz);
          ()-> Population[Rand()]
     else
          # output = 'population'
          Population
     end if
end proc:

infolevel[QuantumDistribution]:= 1:

T:= QuantumDistribution(9, 6, model= "Maxwell-Boltzmann", output= exact);

Population size =  2002

 

[0 = 15/7, 1 = 135/91, 2 = 90/91, 3 = 90/143, 4 = 54/143, 5 = 30/143, 6 = 15/143, 7 = 45/1001, 8 = 15/1001, 9 = 3/1001]

(1)

evalf(%);

[0. = 2.142857143, 1. = 1.483516484, 2. = .9890109890, 3. = .6293706294, 4. = .3776223776, 5. = .2097902098, 6. = .1048951049, 7. = 0.4495504496e-1, 8. = 0.1498501499e-1, 9. = 0.2997002997e-2]

(2)

R:= QuantumDistribution(9, 6, model= "Maxwell-Boltzmann", output= sampler):

Population size =  2002

 

'R()' $ 5;

 

[1, 0, 1, 0, 2, 5], [1, 5, 1, 0, 0, 2], [2, 0, 3, 0, 2, 2], [1, 6, 1, 1, 0, 0], [0, 1, 2, 1, 3, 2]

(3)

P:= QuantumDistribution(9, 6, model= "Maxwell-Boltzmann", output= population):

Population size =  2002

 

#Above population too lengthy to display.

T:= QuantumDistribution(9, 6, model= "Bose-Einstein", output= exact);

Population size =  26

 

[0 = 59/26, 1 = 20/13, 2 = 23/26, 3 = 7/13, 4 = 4/13, 5 = 5/26, 6 = 3/26, 7 = 1/13, 8 = 1/26, 9 = 1/26]

(4)

evalf(%);

[0. = 2.269230769, 1. = 1.538461538, 2. = .8846153846, 3. = .5384615385, 4. = .3076923077, 5. = .1923076923, 6. = .1153846154, 7. = 0.7692307692e-1, 8. = 0.3846153846e-1, 9. = 0.3846153846e-1]

(5)

#Verify correctness of above values.

`+`((lhs*rhs)~(T)[]);

9

(6)

R:= QuantumDistribution(9, 6, model= "Bose-Einstein", output= sampler):

Population size =  26

 

'R()' $ 5;

[0, 1, 1, 1, 3, 3], [0, 1, 2, 2, 2, 2], [0, 0, 1, 1, 3, 4], [0, 1, 1, 2, 2, 3], [0, 1, 1, 1, 3, 3]

(7)

P:= QuantumDistribution(9, 6, model= "Bose-Einstein", output= population);

Population size =  26

 

[[1, 1, 1, 2, 2, 2], [0, 1, 2, 2, 2, 2], [1, 1, 1, 1, 2, 3], [0, 1, 1, 2, 2, 3], [0, 0, 2, 2, 2, 3], [0, 1, 1, 1, 3, 3], [0, 0, 1, 2, 3, 3], [0, 0, 0, 3, 3, 3], [1, 1, 1, 1, 1, 4], [0, 1, 1, 1, 2, 4], [0, 0, 1, 2, 2, 4], [0, 0, 1, 1, 3, 4], [0, 0, 0, 2, 3, 4], [0, 0, 0, 1, 4, 4], [0, 1, 1, 1, 1, 5], [0, 0, 1, 1, 2, 5], [0, 0, 0, 2, 2, 5], [0, 0, 0, 1, 3, 5], [0, 0, 0, 0, 4, 5], [0, 0, 1, 1, 1, 6], [0, 0, 0, 1, 2, 6], [0, 0, 0, 0, 3, 6], [0, 0, 0, 1, 1, 7], [0, 0, 0, 0, 2, 7], [0, 0, 0, 0, 1, 8], [0, 0, 0, 0, 0, 9]]

(8)

T:= QuantumDistribution(9, 6, model= "Fermi-Dirac", output= exact);

Population size =  5

 

[0 = 9/5, 1 = 8/5, 2 = 6/5, 3 = 4/5, 4 = 2/5, 5 = 1/5]

(9)

R:= QuantumDistribution(9, 6, model= "Fermi-Dirac", output= sampler):

Population size =  5

 

'R()' $ 5;

[0, 0, 1, 2, 2, 4], [0, 0, 1, 2, 2, 4], [0, 1, 1, 2, 2, 3], [0, 0, 1, 2, 3, 3], [0, 0, 1, 1, 2, 5]

(10)

P:= QuantumDistribution(9, 6, model= "Fermi-Dirac", output= population);

Population size =  5

 

[[0, 1, 1, 2, 2, 3], [0, 0, 1, 2, 3, 3], [0, 0, 1, 2, 2, 4], [0, 0, 1, 1, 3, 4], [0, 0, 1, 1, 2, 5]]

(11)

 


Download QuantumDistribution.mw

 

@H-R It is usually easier to specify a unique characterization of the component that you want to extract than it is to fix its operand number. For your situation, could I characterize the part that you want to extract as "the factor in the sum that has a sinh in it"? Would that be general enough to cover every situation where you would use this and yet precise enough to uniquely specify the part that you want?

For the case at hand, the following extracts the subexpression that you want:

select(hastype, op(1, indets(BC4, specfunc(anything, sum))[]), sinh(algebraic));

This assumes that BC4 has only one sum.

m:= 1:  N:= 2:
Z:= Matrix(m+1, m+1):
Id:= Matrix([1$m+1], scan= band[0]):
A:= Matrix([[Z$N], [Id$N-1]], scan= band[0,1]);

See ?scan (unfortunately there are no examples on this help page).

Here's another solution completely in polar coordinates. Unlike Kitonum's solution (which I don't mean to disparage), I derive the polar form of the necessary formulae for slope and tangent line from first principles.

restart:
R:= theta-> 3 - 3*cos(theta):
theta0:= 3*Pi/4:
polar:= (r,theta)-> {x = r(theta)*cos(theta), y(x) = r(theta)*sin(theta)}:
dy_dx:= PDEtools:-dchange(polar(r,theta), diff(y(x),x)):
line:= PDEtools:-dchange(polar(r,theta), y(x) - eval(y(x), polar(R,theta0)) =
     m*(x - eval(x, polar(R,theta0)))):
line_polar:= solve(line, r(theta)):
m:= eval(dy_dx, [r= R, theta= theta0]):
P1:= plots:-polarplot(R(theta), theta= 0..2*Pi):
P2:= plots:-polarplot(line_polar, theta= Pi/4..Pi):
plots:-display([P1,P2]);

Here's a procedure for it:

Pbar:= proc(P::Matrix(square), k::posint)
local
     m:= op([1,1], P),
     km:= k*m,
     M:= Matrix(km, km, (i,j)-> `if`(i < j, 1/m, 0)),
     n
;
     for n to k do M[(n-1)*m+1..n*m, (n-1)*m+1..m*n]:= P end do;
     M/k
end proc:

Example of use:

Pbar(< 1,2 ; 3,4 >, 3);

One way is by declaring the parameter as type evaln:

mysum:= (data::evaln(list))-> printf("The sum of %a is %3.3f.", data, `+`(eval(data)[])):

listA:= [1,2,3]:  listB:= [4,5,6]:
mysum(listA);
The sum of listA is 6.000.

Note that the parameter itself refers to the assigned name and that the contents of the name are accessed by using eval.

You are missing a left square bracket before b1, and Gamma should be GAMMA.

If that doesn't solve your problem, then I need to know what version of Maple you are using.

When you receive a "lost connection to kernel" error, you need to

  1. save your worksheet
  2. close your worksheet
  3. open it again

Okay, here is one procedure that does either the exact computation or provides a random sampler depending on an input option.

THe result for Bose-Einstein energy level 4 given on that website must be wrong. If you multiply the energy levels times their average values and add them up, you must get 9, right? If you do that for the numbers in the Bose-Einstein column on that website, you will see that you don't get 9. My results come from exact computation on the entire population of possible states.


interface(prompt=``);

"> "

(1)

QuantumDistribution:= proc(
     n::nonnegint, #Number of quanta of energy
     k::posint,    #Number of particles
     {model::identical("Bose-Einstein","Maxwell-Boltzmann","Fermi-Dirac"):= NULL},
     {output::identical(exact, sampler):= exact}
)
local C, Population, sz, Rand;
     if model = "Maxwell-Boltzmann" then
          Population:= combinat:-composition(n+k, k)
     else
          # Bose-Einstein:
          Population:= select(p-> nops(p)=k, combinat:-partition(n+k, n+1));
          if model = "Fermi-Dirac" then
               Population:= select(C-> ListTools:-FindRepetitions(C,2) = [], Population)
          end if
     end if;
     sz:= nops(Population);
     userinfo(1, QuantumDistribution, NoName, "Population size = ", sz);
     Population:= [seq(C-~1, C= Population)];
     if output = 'exact' then

          (lhs=rhs/sz)~([{Statistics:-Tally(op~(Population))[]}[]])
     else
          # output = sampler
          Rand:= rand(1..sz);
          ()-> Population[Rand()]
     end if
end proc:

infolevel[QuantumDistribution]:= 1:

T:= QuantumDistribution(9, 6, model= "Maxwell-Boltzmann");

Population size =  2002

 

[0 = 15/7, 1 = 135/91, 2 = 90/91, 3 = 90/143, 4 = 54/143, 5 = 30/143, 6 = 15/143, 7 = 45/1001, 8 = 15/1001, 9 = 3/1001]

(2)

evalf(%);

[0. = 2.142857143, 1. = 1.483516484, 2. = .9890109890, 3. = .6293706294, 4. = .3776223776, 5. = .2097902098, 6. = .1048951049, 7. = 0.4495504496e-1, 8. = 0.1498501499e-1, 9. = 0.2997002997e-2]

(3)

R:= QuantumDistribution(9, 6, model= "Maxwell-Boltzmann", output= sampler):

Population size =  2002

 

'R()' $ 5;

 

[1, 0, 5, 0, 0, 3], [4, 0, 1, 2, 2, 0], [1, 0, 0, 5, 0, 3], [5, 1, 0, 0, 2, 1], [2, 0, 5, 1, 1, 0]

(4)

T:= QuantumDistribution(9, 6, model= "Bose-Einstein");

Population size =  26

 

[0 = 59/26, 1 = 20/13, 2 = 23/26, 3 = 7/13, 4 = 4/13, 5 = 5/26, 6 = 3/26, 7 = 1/13, 8 = 1/26, 9 = 1/26]

(5)

evalf(%);

[0. = 2.269230769, 1. = 1.538461538, 2. = .8846153846, 3. = .5384615385, 4. = .3076923077, 5. = .1923076923, 6. = .1153846154, 7. = 0.7692307692e-1, 8. = 0.3846153846e-1, 9. = 0.3846153846e-1]

(6)

#Verify correctness of above values.

`+`((lhs*rhs)~(T)[]);

9

(7)

R:= QuantumDistribution(9, 6, model= "Bose-Einstein", output= sampler):

Population size =  26

 

'R()' $ 5;

[0, 1, 1, 1, 3, 3], [0, 1, 2, 2, 2, 2], [0, 0, 1, 1, 3, 4], [0, 1, 1, 2, 2, 3], [0, 1, 1, 1, 3, 3]

(8)

T:= QuantumDistribution(9, 6, model= "Fermi-Dirac");

Population size =  5

 

[0 = 9/5, 1 = 8/5, 2 = 6/5, 3 = 4/5, 4 = 2/5, 5 = 1/5]

(9)

R:= QuantumDistribution(9, 6, model= "Fermi-Dirac", output= sampler):

Population size =  5

 

'R()' $ 5;

[0, 0, 1, 1, 2, 5], [0, 0, 1, 2, 2, 4], [0, 1, 1, 2, 2, 3], [0, 0, 1, 1, 2, 5], [0, 0, 1, 2, 3, 3]

(10)

 


Download QuantumDistribution.mw

The symbol has no mathematical meaning in Maple, but for typing in mathematical text mode, the ordinary vertical bar works fine |. On my keyboard, it's the shifted version of the backslash key.

P1:= PlanePlot(-3*x+ 2*y + 3*z = 0, [x,y,z], normaloptions= [shape= harpoon], showbasis):
P2:= PlanePlot(
     2*y+3*z = 0, [x,y,z], normaloptions= [shape= harpoon], showbasis,
     planeoptions= [color= red]
):
plots:-display([P1,P2], caption= "");

Here are two ways to accomplish the task with rtable_scanblock. This first one is in the spirit of the examples given at ?rtable_scanblock :

ind:= rtable_scanblock(A, [], (val,ind,res)-> `if`(val >= 3, [ind,res[]], res), []):

That's pretty good timewise and has the benefit of being a one-liner. Timewise it's about midway between Preben's Matrix solution and Pagan's seq solution. But it suffers a bit from the res being constantly appended and passed back and forth. The following is 3 to 4 times faster on the 2000x2000 Matrix that I used for testing. Instead of using res for the results, I store the results in a table.

Ind:= table():
rtable_scanblock(A, [], (val,ind)-> if val >= 3 then :-Ind[ind]:= 0 fi):
ind:= [indices(Ind, nolist)]:

Note that the value 0 that I assign is insignificant; it could be any value. All that matters are the indices of the table that are assigned.

Update: The following variation of Joe Riel's dynamic Array solution (given in a subsequent Answer) fares about the same timewise as my table-based solution:

Ind:= Vector():  k:= 0:
rtable_scanblock(A, [], (val,ind)-> if val >= 3 then :-k:= k+1; :-Ind(k):= ind fi):

The commands diff and convert are not thread safe. See ?index,threadsafe .

The following procedure computes all three distributions. The computation is exact---not based on random sampling. The numbers match perfectly with those on the web site that you linked to.


QuantumDistribution:= proc(
     n::nonnegint, #Number of quanta of energy
     k::posint,    #Number of particles
     model::identical("Bose-Einstein","Maxwell-Boltzmann","Fermi-Dirac")
)
local C, Population, sz;
     if model = "Maxwell-Boltzmann" then
          Population:= combinat:-composition(n+k, k)
     else
          Population:= select(p-> nops(p)=k, combinat:-partition(n+k, n+1));
          if model = "Fermi-Dirac" then
               Population:= select(C-> ListTools:-FindRepetitions(C,2) = [], Population)
          end if
     end if;
     sz:= nops(Population);
     userinfo(1, QuantumDistribution, NoName, "Population size = ", sz);

     (lhs=rhs/sz)~([{Statistics:-Tally(op~([seq(C-~1, C= Population)]))[]}[]])
end proc:

infolevel[QuantumDistribution]:= 1:

T:= QuantumDistribution(9, 6, "Fermi-Dirac");

Population size =  5

[0 = 9/5, 1 = 8/5, 2 = 6/5, 3 = 4/5, 4 = 2/5, 5 = 1/5]

T:= QuantumDistribution(9, 6, "Bose-Einstein");

Population size =  26

[0 = 59/26, 1 = 20/13, 2 = 23/26, 3 = 7/13, 4 = 4/13, 5 = 5/26, 6 = 3/26, 7 = 1/13, 8 = 1/26, 9 = 1/26]

evalf(%);

[0. = 2.26923076923077, 1. = 1.53846153846154, 2. = .884615384615385, 3. = .538461538461538, 4. = .307692307692308, 5. = .192307692307692, 6. = .115384615384615, 7. = 0.769230769230769e-1, 8. = 0.384615384615385e-1, 9. = 0.384615384615385e-1]

T:= QuantumDistribution(9, 6, "Maxwell-Boltzmann");

Population size =  2002

[0 = 15/7, 1 = 135/91, 2 = 90/91, 3 = 90/143, 4 = 54/143, 5 = 30/143, 6 = 15/143, 7 = 45/1001, 8 = 15/1001, 9 = 3/1001]

evalf(%);

[0. = 2.14285714285714, 1. = 1.48351648351648, 2. = .989010989010989, 3. = .629370629370629, 4. = .377622377622378, 5. = .209790209790210, 6. = .104895104895105, 7. = 0.449550449550450e-1, 8. = 0.149850149850150e-1, 9. = 0.299700299700300e-2]

 


Download QuantumDistribution.mw

Although I strongly prefer Markiyan's use of display(..., insequence= true) to my use of delay-evaluation quotes below, I wanted to point out what was wrong with the original animate command since the problem is quite subtle. Once the call to P(n) is made, defining the parameterized random variable, it is impossible to substitute a numeric value for n. This is a limitation, severe in my opinion, of the Statistics package. But you can work around it by using delayed evaluation in the animate command like this:

animate(DensityPlot, ['P(n)', range= 0..10], n= 1..5, frames= 5);

The reason that P(n) does not cause a problem in Markiyan's version is that the special evaluation rules of seq act like delayed evaluation.

On the line where you define o[1,6], you have an angle of 270. That should be 3*Pi/2.

The mathematical constant Pi is spelled in Maple with an uppercase P and lowercase i. A variable spelled pi is just another variable.

Do not use a decimal when you know the exact value of a constant. In other words, use 1/2 instead of 0.5.

After the line defining Ldq:= Tmatrix.L6.Tmatrixinv, put the following:

convert(%, rational): #Correct decimals
subs(pi= Pi, %): #Correct pi
map(expand, %):
map(combine, %);

The resulting 3x3 matrix takes 6 lines on my screen. Let me know if you think that is simplified enough.

First 292 293 294 295 296 297 298 Last Page 294 of 395