program main
end program main

subroutine a01021 (n,a,b,x)
  ! Risolve il sistema triangolare superiore ax=b
  implicit none

  integer :: n
  real(kind(0.d0)),dimension(n) :: b,x
  real(kind(0.d0)),dimension(n,n) :: a

  integer :: i,j
  real(kind(0.d0)) :: s

  do i=n,1
     s=0
     do j=i+1,n
        s=s+x(i)*a(i,j)
     end do
     x(i)=(b(i)-s)/a(i,i)
  end do
end subroutine a01021

subroutine a01022 (n,x,y,a)
  ! Valuta a in x, dove a e` il polinomio a(1)+a(2)*x+a(3)*x^2+...
  implicit none

  integer :: n
  real(kind(0.d0)) :: x,y
  real(kind(0.d0)),dimension(n+1) :: a

  integer :: i

  y=a(n+1)
  do i=n,1,-1
     y=y*x+a(i)
  end do

end subroutine a01022

subroutine a01023 (n,u,v,x,y)
  ! Calcola (I-uv^t)x
  implicit none

  integer :: n
  real(kind(0.d0)),dimension(n) :: u,v,x,y

  integer :: i
  real(kind(0.d0)) :: s

  ! Calcolo v^T x
  s=0
  do i=1,n
     s=s+v(i)*x(i)
  end do

  y=x-s*u
end subroutine a01023

subroutine a01025 (n,a,x,y)
  ! Calcola il prodotto di una matrice particolare per un vettore
  implicit none

  integer :: n
  real(kind(0.d0)) ::a 
  real(kind(0.d0)),dimension(n) :: x,y

  integer :: i

  y(1)=x(1)-a*x(n)
  do i=2,n
     y(i)=x(i)-a*x(i-1)
  end do
  
end subroutine a01025

