Is Concatenating Matrices Possible for Different Mesh Sizes?

  • Thread starter qwuasi
  • Start date
  • Tags
    Matrix
Good luck with your thesis.In summary, the conversation discusses creating a matrix of nodes and neighboring nodes for a square grid, with the example of a 2-by-2 mesh. The final solution involves nodes from an element and nodes from neighboring elements that share a common edge. An algorithm was provided to handle a 15-by-15 grid. The individual who provided the algorithm wishes to remain anonymous and wishes the best of luck to the person using it for their thesis.
  • #1
qwuasi
8
0
I have a mesh (2-by-2) which is numbered 1:16.

[URL]http://www.flickr.com/photos/moorekwesi/5454749337[/URL]

A = [1 2 5 6; 3 4 7 8;9 10 13 14;11 12 15 16] ;

i want to create a matrix of the nodes from the element and it's neighbouring nodes.
This is for a 2-by-2 and hope to implement it also for say 15-by-15.
>>
The 2-by-2 results
I2 = [A(1,:) A(2,1) A(2,3) A(3,1) A(3,2) ;
A(2,:) A(1,2) A(1,4) A(4,1) A(4,2) ;
A(3,:) A(4,1) A(4,3) A(1,3) A(1,4) ;
A(4,:) A(3,2) A(3,4) A(2,3) A(2,4)]
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
Is this matlab? Also, all the jargon you're using makes what you want unclear to me. What do you consider a node and what do you consider a neighboring node? Is A your "2 by 2 mesh," whatever that is?
 
  • #3


Homework Statement


Given a square grid ( n-by-n) with numbering 1:4n2 from the figure attached
(eg. n=2), the matrix: A = [1 2 5 6; 3 4 7 8;9 10 13 14;11 12 15 16] which corresponds
to the elements,ie row 1 corresponds to element 1,etc. is generated.i
want to create a new matrix such that for every element,i'll have the nodes
of the element and nodes from other elements which share a common edge.
This is the final result in this case is:
I2 = [A(1,:) A(2,1) A(2,3) A(3,1) A(3,2) ; A(2,:) A(1,2) A(1,4) A(4,1) A(4,2) ;
A(3,:) A(4,1) A(4,3) A(1,3) A(1,4) ; A(4,:) A(3,2) A(3,4) A(2,3) A(2,4)];

The Attempt at a Solution


I created matrix B (all the edges of A) and C (to get a column representation
of the edges).
B=[A(:,[1 3]) ; A(:,[2 4]) ; A(:,[1 2]) ; A(:,[3 4]) ] ' ;
C = reshape(B , 8 , [ ] ) ' ;
 

Attachments

  • physics.png
    physics.png
    5.3 KB · Views: 433
Last edited:
  • #4
The nodes are colored BLUE and edges red,green,...Each element consist of the four nodes in that box. eg A(1) = {1 2 5 6},A(2) = {3 4 7 8}.The final solution is made of nodes in an element and and nodes (usually 2nodes) from neighbouring elements which share a common edge(straight line) eg for element 1: E(1) = {1 2 5 6 3 7 9 10}.
E(2) = {3 4 7 8 2 6 11 12}...likewise for E(3) and E(4).

I hope this helps.

Thank You
 
  • #5
I just finished the algorithm. It can handle N = 15 instantly, and I verified it works correctly with N = 2. However, I'm not sure if it actually gets the right answers for anything beyond N = 2. Have fun.

Code:
N = 15;
for meshR = 1:N
    for meshC = 1:N
        r = (1:2)+(meshR-1)*2;
        c = (1:2)+(meshC-1)*2;
        ans1 = r + (c(1)-1)*N*2;
        ans2 = horzcat(ans1, ans1+N*2);
        if meshR < N %add contact to right
            ans1 = r(2) + 1 + (c(1)-1)*N*2;
            ans2 = horzcat(horzcat(ans2, ans1),ans1+N*2);
        end
        if meshR > 1 %add contact to left
            ans1 = r(1) - 1 + (c(1)-1)*N*2;
            ans2 = horzcat(horzcat(ans2, ans1),ans1+N*2);
        end
        if meshC < N %add contact above
            ans1 = r + c(2)*N*2;
            ans2 = horzcat(ans2, ans1);
        end
        if meshC > 1 %add contact below
            ans1 = r + (c(1)-2)*N*2;
            ans2 = horzcat(ans2, ans1);
        end
        I2{N*(meshC-1)+meshR} = ans2;
    end
end
%for k = 1:N^2
%   I2{k}
%end
 
  • #6
Dear Sir,
Thank you so much for your assistance.For two months,i've struggled with this.It forms 20% of my thesis work.Seeing the results has given me good health.

Thank You.
 
  • #7
qwuasi said:
Dear Sir,
Thank you so much for your assistance.For two months,i've struggled with this.It forms 20% of my thesis work.Seeing the results has given me good health.

Thank You.

No problem. If you want to cite me, pm me and I'll give you my real name. But I don't care if you use my algorithm without citation.
 

Related to Is Concatenating Matrices Possible for Different Mesh Sizes?

What is matrix concatenation?

Matrix concatenation is the process of combining two or more matrices into a single matrix by stacking them either horizontally or vertically.

Why is matrix concatenation useful?

Matrix concatenation allows for the efficient manipulation and analysis of large datasets, as well as the ability to perform complex mathematical operations on multiple matrices simultaneously.

What are some common tricks for matrix concatenation?

Some common tricks for matrix concatenation include using the cat function in MATLAB, using the numpy.concatenate function in Python, and using the cbind and rbind functions in R.

How do you handle mismatched dimensions when concatenating matrices?

In order to concatenate matrices, they must have the same number of rows or columns. To handle mismatched dimensions, you can use the reshape function to change the dimensions of one or more matrices before concatenating them.

Are there any limitations to matrix concatenation?

One limitation of matrix concatenation is that it can only be performed on numerical matrices. Additionally, if the matrices being concatenated have different data types, they will be converted to a common data type, potentially resulting in data loss.

Similar threads

  • Precalculus Mathematics Homework Help
Replies
14
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
20
Views
4K
  • Programming and Computer Science
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • Calculus and Beyond Homework Help
Replies
17
Views
10K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
137
  • Calculus and Beyond Homework Help
Replies
2
Views
2K
  • Programming and Computer Science
Replies
22
Views
3K
  • Calculus and Beyond Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
4K
Back
Top