Fortran FORTRAN 90 - Insert Matrices into Other Matrices

  • Thread starter Thread starter JP12321
  • Start date Start date
  • Tags Tags
    Fortran Matrices
AI Thread Summary
The discussion centers on the challenge of embedding matrices within other matrices in Fortran 90, similar to how it's done in MATLAB. The original poster seeks assistance with this task while developing a Gauss-Seidel algorithm for large matrices. A suggestion is made to consider using a 4D array to manage the matrices, assuming they are of the same size. It is noted that Fortran's array storage differs from C, which may require copying the selected matrix to a 2D array for operations. The provided example illustrates how to assign sections of the larger matrix B with the values from matrix A, emphasizing the need to understand Fortran's syntax and array handling.
JP12321
Messages
1
Reaction score
0
TL;DR Summary
I need help making a matrix, with elements that contain other matrices! If you have even a basic knowledge of MATLAB then I have provided the code for this, to make it a bit more descriptive.
Thanks.
Hi,

I haven't made a code for it yet, however I will be making a Gauss-Seidel algroithm in Fortran 90, for solving very large matrices (actually to initiate the multi-gird method but that's irrelevant for this). As part of this, I wish to insert matrices into other matrices.

in MATLAB this is very simple, for example:
A=[1,2;3,4]
B=[A,A;A,A]
Outputs:
B =

1 2 1 2
3 4 3 4
1 2 1 2
3 4 3 4

However I have been having difficulties achieving the same with Fortran.

Please ignore the context - I don't require help with the GS/MG methods, I just need help embedding matrices (for other topics too), if at all possible!

Thanks in advance,

JP.
 
Technology news on Phys.org
Have you considered creating a 4D array where the first two indices select the matrix of interest?

Also I am assuming all the matrices are the same size.

The one problem I see that you may need to copy the selected matrix to a 2D array for use in any matrix style operations.

In C code, that would be unnecessary but I think in Fortran array storage is different and you’ll need to review that first.
 
Last edited:
something to the effect:
B[1:2,1:2 ] = A[1:2,1:2]
B[1:2,3:4 ] = A[1:2,1:2]
B[3:4,1:2 ] = A[1:2,1:2]
B[3:4,3:4 ] = A[1:2,1:2]

if I remember my fortran90 correctly... ( can't find my fortran90 book right now)
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
5
Views
9K
Replies
8
Views
2K
Replies
21
Views
3K
Replies
4
Views
2K
Replies
4
Views
2K
Replies
19
Views
6K
Replies
2
Views
2K
Replies
3
Views
8K
Back
Top