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)
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

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