Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
27230 Discussions

How to assign values to matrix in fortran90

MI84
Novice
445 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 I
399 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
Black Belt
435 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
430 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?

andrew_4619
Honored Contributor I
400 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
358 Views
Reply