Carl Love

Carl Love

28055 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

@nm It is perfectly fine to create a list via

L:= [seq(i, i= 1..N)];

That creates only one list and only one sequence. That's not assigning to a list; it's assigning a list to a name. The following code is bad (O(N^2)), although it is allowed and is very frequently seen:

L:= [];
for i to N do L:= [op(L), i] end do
;

Assuming that a for loop is necessary (i.e., that seq won't work), which is frequently the case, the above should be replaced with either of the following:

V:= Vector();
for i to N do V(i):= i end do;
L:= convert(V, list)
;

or

T:= table();
for i to N do T[i]:= i end do;
L:= convert(T, list);

Table lookup and storage is essentially O(1) in Maple.

When you see code written by Joe or me, pay attention to how lists are created. Note the differences between the two methods presented in both Joe's and my Answers to your earlier Question from today, "How to obtain positions in matrix that meet some condition?"

Mathematica must suffer some performance penalty for allowing lists to be mutable objects. For example, I'd wager that comparing two lists for equality is O(n), whereas it's instantaneous in Maple.

@nm 

{parse(cat(convert(M^%T,list)[]))};

@tomleslie All that's needed to create your sequence is

outp:= convert(M^%T, list)[];

So you want the answer to be a set containing a single integer whose digits come from the Matrix entries? That's what {111222333} is. But that's not a sequence. So I need clarification.

@nm If you want to save typing, as often seems to be your goal, note that the else NULL in Preben's code is superfluous. All if statements without an else clause have else NULL as default. Also, end if can be changed to fi. The 2,3 can be replaced with op(1,A) to increase the generality of the code. Finally, the two statements can be combined. So, it becomes

ind:= convert(Matrix(op(1,A), (i,j)-> if A[i,j] >= 3 then [i,j] fi), list):

That code involves a user arrow procedure iterated over every element, so Pagan's seq solution is faster:

(n,m):= op(1,A):
ind:= [seq(seq(`if`(A[i,j] >= 3, [i,j], NULL), i= 1..n), j= 1..m)]:

I don't yet know how to make rtable_scanblock work.

Update: I figured out rtable_scanblock, and I give two solutions in an Answer below.

@Stephen Forrest Could you explain your Answer, please? Especially the RegSplit and RegSubs?

@k20057 5 Why can't you plot? I gave you the plotting command before:

plot([lhs,rhs]~(T), style= point);

In the link that you give for the Bose-Einstein statistics, there is a table for 9 quanta of energy distributed among 6 particles. The table gives the expected number of particles with each amount of energy from 0 to 9. The expected numbers for 6 through 9 is small but greater than zero. I don't understand how they cannot be zero. For example, the only way to have a single particle receive all 9 units is for the other 5 particles to receive 0. But that means that there are more than 2 particles with 0 units of energy. How can that be?

Update: I have found the problem. You are confusing Bose-Einstein statistics with Fermi-Dirac statistics. It is the Fermi-Dirac where there can be at most two particles with the same energy. This also explains the problem with my Answer to your last question: You were expecting the Fermi-Dirac numbers, but you gave me the instructions for constructing a Bose-Einstein sample.

@nilssson It is perhaps counterintuitive, but expand is often an important early step in a simplification. Although it tends to make expressions longer, the components tend to be made simpler, which means that subsequent simplifiers such as combine are more likely to be able to do something useful with them.

@Stavros So, do you need me to implement this trivial change in the code?

@gourmelens 

You need to create the animation with the display(..., insequence) command, assign that to A, and then use display again in display([A,fish]);

@gourmelens 

Assign the animation to a variable, say A, then

display([fish, A]);

@Kitonum 

You point is made. At some point the proviso that I mentioned was added. It is clearly stated at ?sort in Maple 18.

Liu,

I split off your Reply as a separate Question entitled "Counting occurences of strings in a file."

The ODE is missing from your Question.

First 530 531 532 533 534 535 536 Last Page 532 of 709