Carl Love

Carl Love

28025 Reputation

25 Badges

12 years, 308 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

Maple can communicate via sockets. See ?Sockets .

Use $include instead of read. Note that the $ must be in the first column. See ?$include . The problem with read is that the code is read and executed.

You simply need to give a domain restriction to fsolve.

fsolve({F,Fw,Fk,Ft}, {w,k,ki,T} =~ 0..infinity);

Here's a recursive procedure for it, using option remember, though I wouldn't say that it's any more efficient than your loop.

inc1:= ex-> subsindets[flat](ex, indexed, x-> op(0,x)[op(1,x)+1]):
mytest:= proc(C::posint)
local k;
option remember;
     (inc1(thisproc(C-1)) + w[2]*mul(s[k], k= 3..C))*s[1]
end proc:
mytest(2):= s[1]*w[2]+w[1]*s[2]:
mytest(3):= inc1(mytest(2))*s[1]:
mytest(6);

Use the divide command to explicitly check whether the polynomial is divisible by (Px-Py) (over the rational numbers). If you are looking for factorizations over more complicated fields than the rationals, that is also possible, but you need to specify the field extension(s) (if they're not implied by the coefficients). Let me know.

Update: Your polynomial contains terms that have neither a p1 nor a p2. So p1-p2 couldn't possibly be a factor.

You can use a userinfo statement or a print statement to print any infomation about an ongoing computation. That includes plots. If you put a plot inside a userinfo, it needs to be inside print also, like

userinfo(1, mytest, print(plot(...)));

To "activate" the above statement, before you run the procedure do

infolevel[mytest]:= 1:

It is supported: I've uploaded animated GIF files to MaplePrimes many times. I do not use the image->include tool. I always upload files using the green uparrow (Upload File), which is the last thing on the second row of the toolbar. The animation will automatically "play" in the editor and in the post.

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

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