Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28445 Discussions

How to assign values to matrix in fortran90

MI84
Novice
1,633 Views

 

Hi everyone. I'm new to Fortran. I wrote a code that contains a 2 * 2 matrix. Its elements are as follows: MATRIX (1,1) = ENERGY - eB MATRIX (1,2) = ek1 MATRIX (2,1) = ek2 MATRIX (2,2) = ENERGY - eA Now I want to assign the values I mentioned above to the matrix with the RESHAPE command. But the compiler shows the following error: error # 6366: The shapes of the array expressions do not conform Please guide me in solving this case. thank you.
 
 
 
 
 
 
 
 
 

 

 

 
 
0 Kudos
1 Solution
andrew_4619
Honored Contributor II
1,587 Views

matrix = reshape( [a,b,c,d],[2,2] )

you are assigning the whole matrix in that command "[" is the same as the older "(/" BTW

View solution in original post

4 Replies
jimdempseyatthecove
Honored Contributor III
1,623 Views

>>MATRIX(M,N)=RESHAPE((/ (ENERGY-eB),ek2,ek1,(ENERGY-eA) /),(/ M,L /))

MATRIX(M,N) is a scalar (a single cell in array MATRIX), the result of the RESHAPE is an array.

Jim Dempsey

MI84
Novice
1,618 Views

Thank you for your help. How can I assign those values to matrix elements? Is there a solution other than using the RESHAPE command?

0 Kudos
andrew_4619
Honored Contributor II
1,588 Views

matrix = reshape( [a,b,c,d],[2,2] )

you are assigning the whole matrix in that command "[" is the same as the older "(/" BTW

MI84
Novice
1,546 Views
0 Kudos
Reply