Exemplo n.º 1
0
  public Vector getColumn(int index) {
    validateRowIndex(index);

    Vector column = new Vector(rows.length);
    for (int i = 0; i < rows.length; ++i) {
      column.setValue(i, rows[i].getValue(index));
    }
    return column;
  }
Exemplo n.º 2
0
  public Matrix(Vector[] vector) {
    List<Vector> vectorList = new ArrayList<>(Arrays.asList(vector));
    Vector max = Collections.max(vectorList, new LengthComparator());

    int maxLength = max.getSize();

    this.rows = new Vector[vector.length];

    for (int i = 0; i < vector.length; ++i) {
      rows[i] = new Vector(maxLength);
      rows[i].sum(vector[i]);
    }
  }
Exemplo n.º 3
0
  public String toString() {
    StringBuilder string = new StringBuilder();

    string.append("{");

    for (Vector e : this.rows) {
      string.append(e.toString()).append(",");
    }

    string.delete(string.length() - 1, string.length());
    string.append("}");
    return string.toString();
  }
Exemplo n.º 4
0
  public void setRow(int index, Vector vector) {
    validateColumnIndex(index);

    if (isInsideRow(vector.getSize())) {
      for (int i = 0; i < rows.length; ++i) {
        Vector tmp = new Vector(rows[i]);

        this.rows[i] = new Vector(vector.getSize());
        this.rows[i].sum(tmp);
      }
    }

    for (int i = 0; i < vector.getLength(); ++i) {
      rows[index].setValue(i, vector.getValue(i));
    }
  }
Exemplo n.º 5
0
  public Vector multiplicationOnVector(Vector vector) {
    try {
      if (vector.getSize() != rows[0].getSize()) {
        throw new Exception("Длинна вектора не совпадает с колличеством столбцов в матрице");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    Vector resultVector = new Vector(vector.getSize());

    for (int i = 0; i < rows.length; ++i) {
      double result = 0;

      for (int j = 0; j < rows[i].getSize(); ++j) {
        result += rows[i].getValue(j) * vector.getValue(j);
      }

      resultVector.setValue(i, result);
    }
    return resultVector;
  }