Code for Solving Many Tridiagonal Systems


      program vtrid
      parameter(nmax=20,mmax=30)
      dimension a(mmax,nmax), b(mmax,nmax), c(mmax,nmax), d(mmax,nmax)
      dimension ratio(mmax)
c
c   here mmax tridiagonal systems each of size nmax must be defined
c   to suit the problem at hand.  the example system below is only
c   for testing purposes
c
      do 50 n = 1,nmax
      do 51 m = 1,mmax
      a(m,n) = -1.
      b(m,n) = 2.
      c(m,n) = -1.
      d(m,n) = 0.0
51    continue
      do 52 m = 1,mmax
      d(m,1) = 1.
      d(m,nmax) = 1.
52    continue
50    continue

      do 1 n = 2,nmax
      do 10 m = 1,mmax
      ratio(m) = a(m,n)/b(m,n-1)
      b(m,n) = b(m,n) - ratio(m)*c(m,n-1)
      d(m,n) = d(m,n) - ratio(m)*d(m,n-1)
10    continue
 1    continue
      do 60 m = 1,mmax
      d(m,nmax) = d(m,nmax)/b(m,nmax)
60    continue
      do 2 n = nmax-1,1,-1
      do 20 m = 1,mmax
      d(m,n) = (d(m,n) - c(m,n)*d(m,n+1))/b(m,n)
20    continue
 2    continue
      print*, d(3,4)
      end