title: Finding coefficients of linear combination of independent rows in matrix
body: <p>Doing project in Java. I use Gauss Jordain algorithm to find which rows and columns of a matrix are linearly independent and which are linear combinations of the independent ones. I can find rank by rows and columns. </p>
  
  <p>But what I really need, and am lost on how to do, is find coefficients that generate dependent rows and columns as linear combination of independent ones.</p>
  
  <p>I guess answer is in some modification of Gauss Jordain and/or tracking all the multiplication and division coefficients, but my brain is locking up on how to do it.</p>
  
  <p>Basic function is reduction to row echelon form and then I build others on it.</p>
  
  <pre><code>    public static void toRREF(double[][] M) {
          int rowCount = M.length;
      if (rowCount == 0)          
      return;
      int columnCount = M[0].length;
      int lead = 0;
      for (int r = 0; r &lt; rowCount; r++) {
        if (lead &gt;= columnCount)
        break;
          {
           int i = r;
           while (M[i][lead] == 0) {
             i++;
             if (i == rowCount) {
          i = r;
          lead++;
          if (lead == columnCount)
          return;
             }
           }
           double[] temp = M[r];
           M[r] = M[i];
               M[i] = temp;
          }
          {
          double lv = M[r][lead];
          for (int j = 0; j &lt; columnCount; j++)
          M[r][j] /= lv;
          }
          for (int i = 0; i &lt; rowCount; i++) {
              if (i != r) {
                  double lv = M[i][lead];
                  for (int j = 0; j &lt; columnCount; j++)
                  M[i][j] -= lv * M[r][j];
              }
          }
          lead++;
      }
  }
  </code></pre>