FORTRAN 90 - Insert Matrices into Other Matrices

  • Context: Fortran 
  • Thread starter Thread starter JP12321
  • Start date Start date
  • Tags Tags
    Fortran Matrices
Click For Summary
SUMMARY

The discussion focuses on embedding matrices within other matrices using Fortran 90, specifically in the context of implementing a Gauss-Seidel algorithm for large matrices. The user compares this functionality to MATLAB, where matrix insertion is straightforward. A solution is proposed involving the use of a 4D array to manage multiple matrices, with specific indexing to copy matrix values into a 2D array. The conversation highlights the differences in array storage between Fortran and C, emphasizing the need for careful handling of matrix dimensions.

PREREQUISITES
  • Understanding of Fortran 90 syntax and array manipulation
  • Familiarity with matrix operations and indexing
  • Knowledge of Gauss-Seidel algorithm principles
  • Basic understanding of multi-grid methods in numerical analysis
NEXT STEPS
  • Research Fortran 90 array storage and memory management techniques
  • Learn about 4D arrays in Fortran 90 and their applications
  • Explore matrix operations in Fortran 90, focusing on copying and embedding
  • Study the implementation of the Gauss-Seidel algorithm in Fortran 90
USEFUL FOR

Numerical analysts, Fortran developers, and anyone implementing matrix operations in Fortran 90, particularly in the context of solving large systems of equations.

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:
  • Like
Likes   Reactions: BvU
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)
 

Similar threads

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