Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Strange behavior with comment
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Virgil Stokes

Posts: 77
Registered: 3/16/06
Strange behavior with comment
Posted: May 6, 2011 6:34 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

The following gives an error,

m = 4;
k = 3;
IntegerPartitions[ m, {k}]; (* Get all integer partitions that are exactly of
length k *)
Permutations /@ %; (* Get all permutations of the integer partitions *)
Flatten[%, 1] (* Flatten the list *)
Apply[Multinomial, %, {1}] (* Apply Multinomial to each element of the list % *)
ns = Plus @@ %

Flatten::normal: Nonatomic expression expected at position 1 in Flatten[3,1]. >>

Flatten[3, 1]

However, if I remove the comment from the entry in the line before Flatten, then
it gives the correct results,

m = 4;
k = 3;
IntegerPartitions[m, {k}]; (* Get all integer partitions that are exactly of
length k *)
Permutations /@ %;
Flatten[%, 1] (* Flatten the list *)
Apply[Multinomial, %, {1}] (* Apply Multinomial to each element of the list % *)
ns = Plus @@ %

{{2, 1, 1}, {1, 2, 1}, {1, 1, 2}}

{12, 12, 12}

36

Why does this happen?







Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.