program test
  use aln
  implicit none
  integer, parameter :: dim=5
  real, dimension(dim,dim) :: a,lup
  integer, dimension(dim-1) :: trans
  real, dimension(dim) :: x0,x,b
  integer :: i,j,k
  call random_seed      ! initialise le generateur pseudo aleatoire
  call random_number(x0)  ! tire au hasard dans [0,1] les coeff de x
  print*,"vecteur x0 aleatoire:"
  print*,x0
    print*,"premier essai : *****************"
    ! symetrique definie positive bien conditionnee (diag. dom.),
    a = reshape((/((1/(1.+abs(i-j)),i=1,dim),j=1,dim)/),(/dim,dim/))
    do i=1,dim
       a(i,i)=-1.1*(sum(a(:,i))-a(i,i))
    end do
    call calcul_et_affiche
    print*,"deuxieme essai ******************"
    ! symetrique definie positive mal conditionnee (mat. de Hilbert),
    a = reshape((/((1.0/(1+i+j),i=1,dim),j=1,dim)/),(/dim,dim/))
    call calcul_et_affiche
contains
  subroutine calcul_et_affiche
    print*, "matrice a:"
    do k=1,dim
       print*,a(k,1:dim)
    end do
    lup=a; call aelup(lup,trans)
    print*, "matrice lup:"
    do k=1,dim
       print*,lup(k,1:dim)
    end do
    b=pmv(a,x0)
    x=b; call lupxeb(lup,trans,x)
    print*," pivots :",trans
    print*,"erreur :",maxval(abs(x-x0))
  end subroutine calcul_et_affiche
end program test
