I would like to convert upper triangle part of the matrix to the vector.
For example I have the following matrix (4x4 for simplicity):
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
How can I get upper triangle part of the matrix, written 'by rows':
1 2 3 4 6 7 8 11 12 16
And how can I get upper triangle part of the matrix, written 'by columns':
1 2 6 3 7 11 4 8 12 16
Thanks for your help!
Edited: Here is a code generating identity matrix:
program main
use constants ! global vairables and conventional constants
use trans ! transformation between different frames
implicit none
integer :: ii, ij
real*8,dimension(4,4) :: R_reg
!call cpu_time(tic)
write(*,*) "check1" !check-point
!creating diagonal unity matrix
DO ii = 1, 4
DO ij = 1, 4
R_reg(ij,ii) = (ij/ii)*(ii/ij) !integer division
END DO
END DO
write(*,*) "check2" !check-point
!create the test .txt file:
open(50, file='R_reg.txt', status='replace')
DO ii=1, 4
write(50,*) R_reg(ii,:)
END DO
close(50)
write(*,*) "check3" !check-point
end program