title: Tridiagonal matrix algorithm /Thomas algorithm issues
body: <p>I am pretty new to programming and struggling with my Java code for the tridiagonal matrix algorithm. </p>
  
  <p>The tridagonal matrix is formed as a double array, length 3 at the 1st level, lengths n-1,n and n-1 respectively at the 2nd level</p>
  
  <p>The code compiles but is not producing the right vector. Was wondering if someone can spot the error. Also there is a divisibility by 0 issue in the formula, is there some way to get around this? I have seen this algorithm in other languages but am not experienced enough to see the error! Thanks for your help</p>
  
  <pre><code>static double [] linearSolve( double [][] T, double [] v)
  {
      double []x ;
      x= new double [v.length];
  
      if (T== null || v == null)
      { 
          x = null;
      }
      else if (isValidTridiagonal(T)== true &amp;&amp; v.length==T[1].length) 
      { 
  
          T[0][0]=T[0][0]/T[1][0];
          v[0]= v[0]/T[1][0];
          x = new double [v.length];
  
          for (int j=1;j&lt;v.length-1;j++)
          {
  
  
              double d = 1.0/(T[1][j]-(T[0][j-1]*T[2][j]));
              T[0][j]= T[0][j]*d;
              v[j]= v[j]-(T[2][j]*v[j-1]*d);
          }
  
          x[v.length-1]=v[v.length-1];
          for(int j=v.length-2;j!=-1;j--)
          {
              x[j]=v[j]-T[0][j]*x[j+1];
          }
          return x;
  
      }
      else
      {
          x =null;
      }
      return x;
  }
  </code></pre>