Mathematica 函数变红,不起作用
我正在尝试使用 Mathematica 找到最小生成树,并且我想使用 Combinatorica 中的 MinimumSpanningTree 函数。我正在使用以下代码。
Needs["Combinatorica`"]
MinimumSpanningTree[GraphPlot[m]]
其中 m 是矩阵。然而,MinimumSpanningTree 变成红色并且不起作用。输出给出了
out = MinimumSpanningTree[<maximum spanned tree>] //can't show the tree here
How can I make the MinimumSpanningTree work?为什么会变红?
I'm trying to find the minimum spanned tree using Mathematica and I want to use the MinimumSpanningTree function from Combinatorica. I'm using the following code.
Needs["Combinatorica`"]
MinimumSpanningTree[GraphPlot[m]]
where m is a matrix. However, MinimumSpanningTree turns red and does not work. The output gives
out = MinimumSpanningTree[<maximum spanned tree>] //can't show the tree here
How can I make the MinimumSpanningTree work? Why does it turn red?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当遇到所谓的阴影问题时,这些函数会变成红色。您可以在文档中阅读更多相关信息。这个问题在很多地方都有讨论,特别是在 Roman Maeder 的《Mathematica 编程》一书中。 David Wagner 在 Mathematica Journal 上发表的一篇关于阴影的非常精彩且详细的文章,可参见 此处为 pdf 文件。要理解这个问题,您需要对上下文和包有一些基本的了解。以下过去的 SO 讨论也可能会有所帮助:
制作 Mathematica 包
mathematica 中的包导入问题
基本上,一些
Combinatorica`
函数与版本 8 的新系统图相关函数具有相同的名称,因此 Mathematica 不知道要调用哪些函数。如果您确实想使用Combinatorica`
函数,那么您首先需要“静默”加载Combinatorica`
,而不将其放在$ContextPath
上之后,这可能是最容易完成的,因为然后,您必须通过长名称来引用
Combinatorica`
的函数,例如Combinatorica`MinimumSpanningTree
。另一件需要记住的事情是,Combinatorica`
中的图形表示与内置 v.8 功能中的图形表示不同,因此如果您想混合,可能需要将一种转换为另一种那些。The functions turn red when you run into the so-called shadowing problem. You can read more about it in the documentation. This problem is discussed in many places, in particular in the book by Roman Maeder "Programming in Mathematica". A very nice and detailed account on shadowing is the article by David Wagner in Mathematica Journal, available here as pdf. To understand this issue, you will need some basic understanding of contexts and pacakges. The following past SO discussions may also be helpful:
Making Mathematica packages
Package import problem in mathematica
Basically, some of the
Combinatorica`
functions have the same name as the new system graph-related functions of version 8, so Mathematica does not know which ones to call. If you really want to useCombinatorica`
functions, then you will first need to "silently" loadCombinatorica`
without having it on the$ContextPath
afterwards, which is probably most easily accomplished asThen, you will have to refer to the functions of
Combinatorica`
by their long names, such asCombinatorica`MinimumSpanningTree
. One more thing to keep in mind is that a graph representation inCombinatorica`
is different from that in the built-in v.8 functionality, so you may need to transform one into another if you want to mix those.我想您会想要转换为如下图表。
也可能感兴趣:
http://demonstrations.wolfram.com/ConnectingTownsUsingKruskalsAlgorithm/
I think you'll want to convert to a graph as below.
Also possibly of interest:
http://demonstrations.wolfram.com/ConnectingTownsUsingKruskalsAlgorithm/