示例#1
0
  public void leftMultiply(Matrix other) {
    // other * this
    if (other.col != this.row) {
      System.err.println("attempt to multiply incompatible matrices.");
      System.exit(1);
    } else {

      tempCopy();

      for (int i = 0; i < other.row; i++) {
        for (int j = 0; j < tempElements[0].length; j++) {
          // multiply other row by this col to get replacement elements[i][j]
          double replacement = 0;
          for (int k = 0; k < other.col; k++) {
            replacement += other.get(k, i) * tempElements[k][j];
          }
          this.set(j, i, replacement);
        }
      }
    }
  }
示例#2
0
  public void rightMultiply(Matrix other) {
    // this * other
    if (this.col != other.row) {
      System.err.println("attempt to multiply incompatible matrices.");
      System.exit(1);
    } else {

      tempCopy();

      for (int i = 0; i < tempElements.length; i++) {
        for (int j = 0; j < other.col; j++) {
          // multiply this row by other col to get replacement elements[i][j]
          double replacement = 0;
          for (int k = 0; k < tempElements[0].length; k++) {
            replacement += tempElements[i][k] * other.get(j, k);
          }
          this.set(j, i, replacement);
        }
      }
    }
  }