FORTRAN 90 - Insert Matrices into Other Matrices

In summary, the conversation is about creating a Gauss-Seidel algorithm in Fortran 90 for solving large matrices, and the individual is seeking help with embedding matrices within other matrices. The conversation suggests using a 4D array where the first two indices select the desired matrix, and copying the selected matrix to a 2D array for use in matrix style operations. The person also mentions that Fortran array storage is different and may need to be reviewed before implementing this method.
  • #1
JP12321
1
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
  • #2
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 BvU
  • #3
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)
 

What is FORTRAN 90?

FORTRAN 90 (short for Formula Translation 90) is a high-level programming language commonly used in scientific and engineering applications. It was first introduced in the 1950s and has evolved over the years to include new features and capabilities.

What are matrices in FORTRAN 90?

A matrix in FORTRAN 90 is a two-dimensional array of data elements. It is used to store and manipulate data in a tabular form, with rows and columns. Matrices are commonly used in scientific and mathematical computations.

How do I insert one matrix into another in FORTRAN 90?

To insert one matrix into another in FORTRAN 90, you can use the built-in function reshape. This function allows you to change the shape of a matrix by specifying the number of rows and columns. You can also use the merge function to combine two matrices into a single one.

What is the purpose of inserting matrices into other matrices in FORTRAN 90?

Inserting matrices into other matrices in FORTRAN 90 allows you to combine and manipulate different sets of data. This can be useful in various scientific and engineering applications, such as solving systems of linear equations, performing matrix operations, and data analysis.

Are there any limitations to inserting matrices into other matrices in FORTRAN 90?

Yes, there are some limitations to inserting matrices into other matrices in FORTRAN 90. For example, the matrices must have compatible dimensions for the insertion to be successful. Additionally, if the matrices are not of the same type, they may need to be converted before being inserted. It is important to carefully consider the data types and dimensions of the matrices before attempting to insert them into each other.

Similar threads

  • Programming and Computer Science
Replies
5
Views
8K
Replies
6
Views
748
  • Programming and Computer Science
Replies
8
Views
1K
Replies
22
Views
1K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
2
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
2
Views
881
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
4
Views
1K
  • General Math
Replies
3
Views
1K
Back
Top