PROGRAM nag_tri_lin_sys_ex03 ! Example Program Text for nag_tri_lin_sys ! NAG fl90, Release 4. NAG Copyright 2000. ! .. Use Statements .. USE nag_examples_io, ONLY : nag_std_in, nag_std_out USE nag_tri_lin_sys, ONLY : nag_tri_lin_sol, nag_tri_lin_cond USE nag_write_mat, ONLY : nag_write_gen_mat ! .. Implicit None Statement .. IMPLICIT NONE ! .. Intrinsic Functions .. INTRINSIC EPSILON, KIND ! .. Parameters .. INTEGER, PARAMETER :: wp = KIND(1.0D0) ! .. Local Scalars .. INTEGER :: i, j, n, nrhs REAL (wp) :: rcond_inf CHARACTER (1) :: uplo ! .. Local Arrays .. REAL (wp), ALLOCATABLE :: a(:), b(:,:), bwd_err(:), fwd_err(:) ! .. Executable Statements .. WRITE (nag_std_out,*) 'Example Program Results for nag_tri_lin_sys_ex03' READ (nag_std_in,*) ! Skip heading in data file READ (nag_std_in,*) n, nrhs READ (nag_std_in,*) uplo ALLOCATE (a((n*(n+1))/2),b(n,nrhs),bwd_err(nrhs), & fwd_err(nrhs)) ! Allocate storage SELECT CASE (uplo) CASE ('L','l') DO i = 1, n READ (nag_std_in,*) (a(i+((2*n-j)*(j-1))/2),j=1,i) END DO CASE ('U','u') DO i = 1, n READ (nag_std_in,*) (a(i+(j*(j-1))/2),j=i,n) END DO END SELECT READ (nag_std_in,*) (b(i,:),i=1,n) ! Compute the condition number rcond_inf = nag_tri_lin_cond(uplo,a) WRITE (nag_std_out,*) WRITE (nag_std_out,'(1X,''kappa(A) (1/rcond_inf)''/2X,ES11.2)') 1/ & rcond_inf IF (rcond_inf<=EPSILON(1.0_wp)) THEN WRITE (nag_std_out,*) WRITE (nag_std_out,*) ' ** WARNING ** ' WRITE (nag_std_out,*) & 'The matrix is almost singular: the solution may have no accuracy.' WRITE (nag_std_out,*) & 'Examine the forward error bounds estimates returned in fwd_err.' END IF ! Solve the system of equations CALL nag_tri_lin_sol(uplo,a,b,bwd_err=bwd_err,fwd_err=fwd_err) WRITE (nag_std_out,*) CALL nag_write_gen_mat(b,int_col_labels=.TRUE., & title='Solution vectors (one vector per column)') WRITE (nag_std_out,*) WRITE (nag_std_out,*) 'Backward error bounds' WRITE (nag_std_out,'(2X,4ES11.2)') bwd_err WRITE (nag_std_out,*) WRITE (nag_std_out,*) 'Forward error bounds (estimates)' WRITE (nag_std_out,'(2X,4ES11.2)') fwd_err DEALLOCATE (a,b,bwd_err,fwd_err) ! Deallocate storage END PROGRAM nag_tri_lin_sys_ex03