Matrix sort

V

vijayendramunikoti

Hi
I have a matrix of numbers representing the nodal points as follows:

Element No. Nodes

1 1 2 3 4
2 5 6 7 8
3 2 3 9 10
............................
............................
x 9 10 11 12
............................

so this is a matrix of numbers 4 x n
Elements 1 and 3 are neighbours (as they share nodes 2 3). Similarly elements 3 and x are neighbours (they share nodes 9 and 10). I want to sort the matrix in such a way all the elements are sequentially arranged. How could Iscript it? can any one help me?
Thanks!
Vijayendra
 
O

Oscar Benjamin

Hi
I have a matrix of numbers representing the nodal points as follows:

Element No. Nodes

1 1 2 3 4
2 5 6 7 8
3 2 3 9 10
...........................
...........................
x 9 10 11 12
...........................

so this is a matrix of numbers 4 x n
Elements 1 and 3 are neighbours (as they share nodes 2 3). Similarly elements 3 and x are neighbours (they share nodes 9 and 10). I want to sort thematrix in such a way all the elements are sequentially arranged. How couldI script it? can any one help me?

I think you want a topological sort algorithm. See here:
http://en.wikipedia.org/wiki/Topological_sorting

Before that though you'll want to preprocess your matrix into a data
structure that allows you to easily find the elements adjacent to any
given element. A list of lists is one approach:

graph = [
[3], # nodes adjacent to element 1
[], # element 2
[1, x], # element 3
...
[3] # element x
]


Oscar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top