Re: A newbee to Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg97521] Re: A newbee to Mathematica
- From: Dana DeLouis <dana01 at me.com>
- Date: Sat, 14 Mar 2009 18:13:47 -0500 (EST)
>> showing the weights of each edge as is provided in FromAdjacencyMatrix[g,Edgeweight] Hi. I may be wrong, but I believe you have a "Directed" graph. Meaning that from 1-7 the weight is 2, but from 7-1 the weight is 1. I'm am not sure how you want to label this when you have different weights in different directions. Again, I may be wrong. am // MatrixForm {1,0,1,2,0,1,2} {0,0,0,0,1,1,1} {1,0,0,1,1,1,1} {0,3,1,4,1,0,1} {0,1,1,1,0,1,0} {1,1,1,0,1,0,0} {1,1,5,1,0,0,0} When you do.. g = FromAdjacencyMatrix[am, EdgeWeight]; GraphPlot3D[g, VertexLabeling -> True]; The graph does not show a link between 2 & 4. Although there is a '0 between 2 & 4, there is a '3 between 4 & 2. This shows the link between 2 & 4. (no double call to "FromAdjacencyMatrix". I think help is a little unclear in 7.0) GraphPlot3D[am, VertexLabeling -> True] Just throwing out some additional options: g = FromAdjacencyMatrix[am /. 0 -> \[Infinity], EdgeWeight]; g = SetEdgeLabels[g, GetEdgeWeights[g]]; ops = {VertexColor -> Red, VertexLabelColor -> Blue, VertexLabel -> True, EdgeLabel -> True, ImageSize -> 600}; ShowGraph[g, Sequence @@ ops] Note that because this is undirected, the label from 3-7 is "1", but the label from 7-3 of "5" was discarded. I'm not sure how you want to really label these edges. If you want, remove self-loops... ShowGraph[MakeSimple[g], Sequence @@ ops] One can see the one-way relationships between 1&4, and 2&4 with something like this... g = FromAdjacencyMatrix[am /. 0 -> \[Infinity], EdgeWeight, Type -> Directed]; ShowGraph[g, VertexLabel -> True] Again, just some additional ideas. = = = = = HTH :>) Dana DeLouis Nishant wrote: > Hi I have just started using mathematica,and therefore have a very silly question that needs an answer. > I am trying to run this: > Needs["GraphUtilities`"] > Needs["Combinatorica`"] > am = {{1, 0, 1, 2, 0, 1, 2}, {0, 0, 0, 0, 1, 1, 1}, {1, 0, 0, 1, 1, 1, > 1}, {0, 3, 1, 4, 1, 0, 1}, {0, 1, 1, 1, 0, 1, 0}, {1, 1, 1, 0, 1, > 0, 0}, {1, 1, 5, 1, 0, 0, 0}}; > > MatrixForm[am] > g[FromAdjacencyMatrix[am, EdgeWeight], VertexLabeling -> True, > EdgeLabeling -> True] > GraphPlot3D[g] > I am getting this error message: > GraphPlot3D::grph:Graph:<11,7,Undirected> is not a valid graph. > > BASICALLY what I want to do is to generate a 3d graph from a given adjacency matrix,with the elements of the matrix showing the weights of each edge as is provided in FromAdjacencyMatrix[g,Edgeweight] > > Thank you for helping me out