pure subroutine lowrank(this, matrix, rank, method)
class(tsvd), intent(inout) :: this
real(rk), dimension(:, :), intent(in) :: matrix
integer, intent(in) :: rank
character(*), intent(in), optional :: method
real(rk), dimension(:, :), allocatable :: U, VT
real(rk), dimension(:), allocatable :: S
integer :: i, j, irank
this%matrix = matrix
this%nrow = size(matrix,1)
this%ncol = size(matrix,2)
this%rank = rank
allocate(U(this%nrow,this%nrow), S(min(this%nrow,this%ncol)), VT(this%ncol,this%ncol))
call svd(this%matrix, U,S,VT, method)
allocate(this%matrix_app(this%nrow,this%ncol))
this%matrix_app = 0.0_rk
do irank = 1, rank
do j = 1,this%ncol
do i = 1,this%nrow
this%matrix_app(i,j) = this%matrix_app(i,j) + U(i, irank)*S(irank)*VT(irank, j)
end do
end do
end do
end subroutine lowrank