Fortran FORTRAN 90 - Insert Matrices into Other Matrices

  • Thread starter Thread starter JP12321
  • Start date Start date
  • Tags Tags
    Fortran Matrices
Click For 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
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)
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 5 ·
Replies
5
Views
9K
  • · Replies 8 ·
Replies
8
Views
2K
Replies
2
Views
2K
  • · Replies 21 ·
Replies
21
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 19 ·
Replies
19
Views
6K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
8K
  • · Replies 3 ·
Replies
3
Views
2K