実対称固有値問題: パック形式の対称行列 : (全ての固有値およびオプショナルで固有ベクトル)

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

概要

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

対称行列のすべての固有値を求めます。

\begin{displaymath}
A = \left(
\begin{array}{rrrr}
1 & 2 & 3 & 4 \\
2 & 2 &...
... 4 \\
3 & 3 & 3 & 4 \\
4 & 4 & 4 & 4
\end{array} \right),
\end{displaymath}

計算された固有値の誤差限界近似値もあわせて求めます。

入力データ

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

このデータをダウンロード
DSPEV Example Program Data

  4                  :Value of N

  1.0  2.0  3.0  4.0
       2.0  3.0  4.0
            3.0  4.0
                 4.0 :End of matrix A

出力結果

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

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

 Eigenvalues
    -2.0531 -0.5146 -0.2943 12.8621

 Error estimate for the eigenvalues
        2.9E-15

ソースコード

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

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


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

!     DSPEV Example Program Text

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

!     .. Use Statements ..
      Use lapack_interfaces, Only: dspev
      Use lapack_precision, Only: dp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter :: nin = 5, nout = 6
      Character (1), Parameter :: uplo = 'U'
!     .. Local Scalars ..
      Real (Kind=dp) :: eerrbd, eps
      Integer :: i, info, j, n
!     .. Local Arrays ..
      Real (Kind=dp), Allocatable :: ap(:), w(:), work(:)
      Real (Kind=dp) :: dummy(1, 1)
!     .. Intrinsic Procedures ..
      Intrinsic :: abs, epsilon, max
!     .. Executable Statements ..
      Write (nout, *) 'DSPEV Example Program Results'
      Write (nout, *)
!     Skip heading in data file
      Read (nin, *)
      Read (nin, *) n

      Allocate (ap((n*(n+1))/2), w(n), work(3*n))

!     Read the upper or lower triangular part of the matrix A from
!     data file

      If (uplo=='U') Then
        Read (nin, *)((ap(i+(j*(j-1))/2),j=i,n), i=1, n)
      Else If (uplo=='L') Then
        Read (nin, *)((ap(i+((2*n-j)*(j-1))/2),j=1,i), i=1, n)
      End If

!     Solve the symmetric eigenvalue problem
      Call dspev('No vectors', uplo, n, ap, w, dummy, 1, work, info)

      If (info==0) Then

!       Print solution

        Write (nout, *) 'Eigenvalues'
        Write (nout, 100) w(1:n)

!       Get the machine precision, EPS and compute the approximate
!       error bound for the computed eigenvalues.  Note that for
!       the 2-norm, max( abs(W(i)) ) = norm(A), and since the
!       eigenvalues are returned in ascending order
!       max( abs(W(i)) ) = max( abs(W(1)), abs(W(n)))

        eps = epsilon(1.0E0_dp)
        eerrbd = eps*max(abs(w(1)), abs(w(n)))

!       Print the approximate error bound for the eigenvalues

        Write (nout, *)
        Write (nout, *) 'Error estimate for the eigenvalues'
        Write (nout, 110) eerrbd
      Else
        Write (nout, 120) 'Failure in DSPEV. INFO =', info
      End If

100   Format (3X, (8F8.4))
110   Format (4X, 1P, 6E11.1)
120   Format (1X, A, I4)
    End Program


ご案内
関連情報
Privacy Policy  /  Trademarks