c Demonstration program for solving matrix equations
      program matsol
      parameter (nmax=10) ! array size
      parameter (eps=1.0e-6) ! numerical bandwidth

      dimension a(nmax,nmax),yx(nmax) ! data arrays

      logical sing

c     read matrix and vector on right-hand side
      read *,nr,nc
      if (nr.gt.nmax.or.nc.gt.nmax) stop 'Matrix too large for arrays!'
      read *,((a(i,j),j=1,nc),i=1,nr)
      read *,(yx(i),i=1,nr)

c     display matrix and vector
      call bm_matshow(a,nr,nc,nmax)
      print *,'^(-1)*'
      call bm_vecshow(nr,yx)
      print *,'='

c     solve equation, returning solution in first nc elements of yx
      call bm_matsolg(a,nr,nc,nmax,eps,yx,sing,res,det)
      if (sing) then
         print *,'Matrix singular!'
      else
         call bm_vecshow(nc,yx)
         print *,'with residue=',res,', determinant=',det
      endif

      end
