Coder Social home page Coder Social logo

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 about fortran2018-examples CLOSED

aarav7834 avatar aarav7834 commented on May 28, 2024
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

from fortran2018-examples.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.