Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29280 Discussions

How to assign values to matrix in fortran90

MI84
Novice
3,164 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 III
3,118 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
3,154 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
3,149 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 III
3,119 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
3,077 Views
0 Kudos
Reply