Mathematica 函数变红,不起作用

发布于 2024-12-20 17:16:31 字数 404 浏览 0 评论 0原文

我正在尝试使用 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 技术交流群。

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

发布评论

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

评论(2

稀香 2024-12-27 17:16:31

当遇到所谓的阴影问题时,这些函数会变成红色。您可以在文档中阅读更多相关信息。这个问题在很多地方都有讨论,特别是在 Roman Maeder 的《Mathematica 编程》一书中。 David Wagner 在 Mathematica Journal 上发表的一篇关于阴影的非常精彩且详细的文章,可参见 此处为 pdf 文件。要理解这个问题,您需要对上下文和包有一些基本的了解。以下过去的 SO 讨论也可能会有所帮助:

制作 Mathematica 包

mathematica 中的包导入问题

基本上,一些Combinatorica` 函数与版本 8 的新系统图相关函数具有相同的名称,因此 Mathematica 不知道要调用哪些函数。如果您确实想使用 Combinatorica` 函数,那么您首先需要“静默”加载 Combinatorica`,而不将其放在 $ContextPath 上之后,这可能是最容易完成的,因为

Block[{$ContextPath}, Needs["Combinatorica`"]]

然后,您必须通过长名称来引用 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 use Combinatorica` functions, then you will first need to "silently" load Combinatorica` without having it on the $ContextPath afterwards, which is probably most easily accomplished as

Block[{$ContextPath}, Needs["Combinatorica`"]]

Then, you will have to refer to the functions of Combinatorica` by their long names, such as Combinatorica`MinimumSpanningTree. One more thing to keep in mind is that a graph representation in Combinatorica` 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.

回眸一笑 2024-12-27 17:16:31

我想您会想要转换为如下图表。

MinimumSpanningTree[FromAdjacencyMatrix[m]]

也可能感兴趣:

http://demonstrations.wolfram.com/ConnectingTownsUsingKruskalsAlgorithm/

I think you'll want to convert to a graph as below.

MinimumSpanningTree[FromAdjacencyMatrix[m]]

Also possibly of interest:

http://demonstrations.wolfram.com/ConnectingTownsUsingKruskalsAlgorithm/

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