使用mathematica 4.0生成排列

发布于 2024-10-15 06:50:10 字数 204 浏览 2 评论 0原文

您好,我正在使用 Mathematica 4.0。我试图找到所有排列,例如,假设有两个数字 0 和 0。 1. 我试图在 3 个(比如说)位置重复使用这两个数字来生成所有排列,例如 {1,1,1},{1,1,0},{1,0,1},{1, 0,0}...我还尝试将每个排列放入一个数组中。 Mathematica 4.0 中是否有任何代码或命令可以让我完成所有这些事情。请帮助我完成这项任务...

Hi I am using Mathematica 4.0. I am trying to find all the permutations, for example, say there are two numbers 0 & 1. I am trying to generate all permutations using these two numbers in 3(say) places with repetition i.e. like {1,1,1},{1,1,0},{1,0,1},{1,0,0}... Also I am trying to put each of the permutation in an array. Is there any code or command in Mathematica 4.0 by which I can do all these things. Please help me in this task...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

荒芜了季节 2024-10-22 06:50:10

在 Mathematica 5.1 及更高版本中,有一个函数 Tuples 可以完成您想要的操作。你可以尝试

getTuples[elements_List, length_Integer] :=
  Flatten[Outer[List, Sequence @@ Table[elements, {length}]], length - 1]

例如:

In[6]:= getTuples[{0, 1}, 3]

Out[6]= {{0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {0, 1, 1}, {1, 0, 0}, {1, 0, 1}, {1, 1, 0}, {1, 1, 1}}

但我不知道这是否适用于M4.0。我想应该是这样,但我无法检查。一般来说,使用4.0这样的过时版本,你会遇到各种各样的困难,包括缺乏功能、性能和界面(前端)较差、某些在后续版本中修复的错误、与后续编写的代码不兼容等。版本,并获取帮助。对于 Mathematica 来说尤其如此,因为自 4.0 以来,Mathematica 在各个方面都取得了巨大的进步。因此,如果您打算定期使用它,我强烈建议升级。

In Mathematica 5.1 and higher, there is a function Tuples which does what you want. You may try

getTuples[elements_List, length_Integer] :=
  Flatten[Outer[List, Sequence @@ Table[elements, {length}]], length - 1]

For example:

In[6]:= getTuples[{0, 1}, 3]

Out[6]= {{0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {0, 1, 1}, {1, 0, 0}, {1, 0, 1}, {1, 1, 0}, {1, 1, 1}}

But I don't know if this works in M4.0. It should, I guess, but I can not check. Generally, you will face tons of difficulties of various kinds working with such an obsolete version as 4.0, including lacking the functionality, inferior performance and interface (front-end), certain bugs that were fixed in later versions, incompatibility with code written in later versions, and getting help. This is especially true for Mathematica given huge advances in all sorts of directions introduced since 4.0. So, if you plan to use it regularly, I'd strongly suggest to upgrade.

旧时模样 2024-10-22 06:50:10

一种考古问题:D。版本 4 已经很老了!

<<DiscreteMath`Combinatorica`

perm1[l_,n_]:=Union[KSubsets[Flatten[Table[l,{n}]],n]]  

In[70]:= perm1[{1,2,1},4]
Out[70]= {{1,1,1,1},{1,1,1,2},{1,1,2,1},{1,1,2,2},{1,2,1,1},
          {1,2,1,2},{1,2,2,1},{1,2,2,2},{2,1,1,1},{2,1,1,2},
          {2,1,2,1},{2,1,2,2},{2,2,1,1},{2,2,1,2},{2,2,2,1},{2,2,2,2}}  

In[73]:= perm1[{1,0},3]
Out[73]= {{0,0,0},{0,0,1},{0,1,0},{0,1,1},{1,0,0},{1,0,1},{1,1,0},{1,1,1}}

Kind of archeological question :D. Version 4 is pretty old!

<<DiscreteMath`Combinatorica`

perm1[l_,n_]:=Union[KSubsets[Flatten[Table[l,{n}]],n]]  

In[70]:= perm1[{1,2,1},4]
Out[70]= {{1,1,1,1},{1,1,1,2},{1,1,2,1},{1,1,2,2},{1,2,1,1},
          {1,2,1,2},{1,2,2,1},{1,2,2,2},{2,1,1,1},{2,1,1,2},
          {2,1,2,1},{2,1,2,2},{2,2,1,1},{2,2,1,2},{2,2,2,1},{2,2,2,2}}  

In[73]:= perm1[{1,0},3]
Out[73]= {{0,0,0},{0,0,1},{0,1,0},{0,1,1},{1,0,0},{1,0,1},{1,1,0},{1,1,1}}
心的位置 2024-10-22 06:50:10

顺便说一句 - 请注意,所有先前版本的 Mathematica 文档都可以在 http://reference.wolfram 上免费在线获取。 com/legacy - 专门针对版本 4,请参阅 http://reference.wolfram.com/legacy /v4

您可以通过 google 搜索 v4 文档:

permutations site:reference.wolfram.com/legacy/v4

,它会显示 v4 函数 Permutations http://reference.wolfram.com/legacy/v4/RefGuide/Permutations.html 其中包含示例和旧 Mathematica 书籍其他部分的一些链接。

Just an aside - please note that documentation for all previous versions of Mathematica is freely available online at http://reference.wolfram.com/legacy - specifically for version 4, see http://reference.wolfram.com/legacy/v4.

You can search the v4 docs via google:

permutations site:reference.wolfram.com/legacy/v4

which turns up the v4 function Permutations http://reference.wolfram.com/legacy/v4/RefGuide/Permutations.html which has examples and a few links to other parts of the old Mathematica Book.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文