scivision / fortran2018-examples

Fortran 2018 standard examples with broad applications
MIT License
398 stars 68 forks source link

fortran program svd_example ! Declare variables integer, parameter :: m = 4, n = 3, lda = 4, ldu = 4, ldvt = 3 integer :: i, j, info real(kind=8) :: a(lda,n), s(n), u(ldu,m), vt(ldvt,n), superb(min(m,n)-1) ! Initialize matrix A with some random values do j=1,n do i=1,m a(i,j) = dble((i-1) + (j-1)*m) end do end do ! Compute the SVD of matrix A using LAPACK routine DGESVD call dgesvd('A', 'A', m, n, a, lda, s, u, ldu, vt, ldvt, superb, info) ! Print the results: matrices U and Vt and vector S. write(*,'(a)') 'Matrix U:' do i=1,m write(*,'(4f8.2)') (u(i,j),j=1,min(m,n)) end do write(*,*) write(*,'(a)') 'Vector S:' write(*,'(3f8.2)') (s(j),j=1,min(m,n)) write(*,*) write(*,'(a)') 'Matrix Vt:' do i=1,min(m,n) write(*,'(3f8.2,a,f8.2)') (vt(i,j),' ',char(10),superb(i)) end do end program svd_example #9

Closed aarav7834 closed 1 year ago