計算ルーチン: 複素エルミート半正定値行列のコレスキー分解

LAPACKサンプルソースコード : 使用ルーチン名:ZPSTRF

ホーム > LAPACKサンプルプログラム目次 > 計算ルーチン > 複素エルミート半正定値行列のコレスキー分解

概要

本サンプルはFortran言語によりLAPACKルーチンZPSTRFを利用するサンプルプログラムです。

入力データ

(本ルーチンの詳細はZPSTRF のマニュアルページを参照)

このデータをダウンロード
ZPSTRF Example Program Data
  5 'L'                                                               : n, uplo
(12.40, 0.00)
( 2.39, 0.00) ( 1.63, 0.00)
( 5.50, 0.05) ( 1.04, 0.10) ( 2.45, 0.00)
( 4.47, 0.00) ( 1.14, 0.00) ( 1.98,-0.03) ( 1.71, 0.00)
(11.89, 0.00) ( 1.81, 0.00) ( 5.28,-0.02) ( 4.14, 0.00) (11.63, 0.00) : End of A

出力結果

(本ルーチンの詳細はZPSTRF のマニュアルページを参照)

この出力例をダウンロード
 ZPSTRF Example Program Results

 Computed rank:   3

 Factor
                1             2             3             4             5
 1  ( 3.52, 0.00)
 2  ( 0.68, 0.00) ( 1.08, 0.00)
 3  ( 1.27, 0.00) ( 0.26, 0.00) ( 0.18, 0.00)
 4  ( 1.56, 0.01) (-0.02, 0.08) ( 0.01,-0.05) ( 0.00, 0.00)
 5  ( 3.38, 0.00) (-0.45, 0.00) (-0.17, 0.00) ( 0.00, 0.00) ( 0.00, 0.00)

 PIV
                1             2             4             3             5

ソースコード

(本ルーチンの詳細はZPSTRF のマニュアルページを参照)

※本サンプルソースコードのご利用手順は「サンプルのコンパイル及び実行方法」をご参照下さい。


このソースコードをダウンロード
    Program zpstrf_example

!     ZPSTRF Example Program Text

!     Copyright 2017, Numerical Algorithms Group Ltd. http://www.nag.com

!     .. Use Statements ..
      Use lapack_example_aux, Only: nagf_file_print_matrix_complex_gen_comp, &
        nagf_file_print_matrix_integer_comp
      Use lapack_interfaces, Only: zpstrf
      Use lapack_precision, Only: dp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Complex (Kind=dp), Parameter :: zero = (0.0E0_dp, 0.0E0_dp)
      Integer, Parameter :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=dp) :: tol
      Integer :: i, ifail, info, j, lda, n, rank
      Character (1) :: uplo
!     .. Local Arrays ..
      Complex (Kind=dp), Allocatable :: a(:, :)
      Real (Kind=dp), Allocatable :: work(:)
      Integer, Allocatable :: piv(:)
      Character (1) :: clabs(1), rlabs(1)
!     .. Executable Statements ..
      Write (nout, *) 'ZPSTRF Example Program Results'
!     Skip heading in data file
      Read (nin, *)
      Read (nin, *) n, uplo
      lda = n
      Allocate (a(lda,n), piv(n), work(2*n))

!     Read A from data file
      If (uplo=='U') Then
        Read (nin, *)(a(i,i:n), i=1, n)
      Else If (uplo=='L') Then
        Read (nin, *)(a(i,1:i), i=1, n)
      End If
      tol = -1.0_dp

!     Factorize A
      Call zpstrf(uplo, n, a, lda, piv, rank, tol, work, info)

!     Zero out columns rank+1 to n
      If (uplo=='U') Then
        Do j = rank + 1, n
          a(rank+1:j, j) = zero
        End Do
      Else If (uplo=='L') Then
        Do j = rank + 1, n
          a(j:n, j) = zero
        End Do
      End If

!     Print rank
      Write (nout, *)
      Write (nout, '(1X,A15,I3)') 'Computed rank: ', rank

!     Print factor
      Write (nout, *)
      Flush (nout)
      ifail = 0
      Call nagf_file_print_matrix_complex_gen_comp(uplo, 'Nonunit', n, n, a, &
        lda, 'Bracketed', 'F5.2', 'Factor', 'Integer', rlabs, 'Integer', &
        clabs, 80, 0, ifail)

!     Print pivot indices
      Write (nout, *)
      Write (nout, *) 'PIV'
      Flush (nout)
      ifail = 0
      Call nagf_file_print_matrix_integer_comp('General', 'Non-unit', 1, n, &
        piv, 1, 'I14', ' ', 'No', rlabs, 'No', clabs, 80, 1, ifail)

    End Program


ご案内
関連情報
Privacy Policy  /  Trademarks