Привет ребят, помогите разобраться.
У меня 2 класса Vektor и Matrix.
Код:
public class Vektor {
private double[] vektor;
public Vektor() {
this.vektor = new double[0];
}
public Vektor(Vektor copy) {
vektor = cop.vektor;
}
public Vektor(double[] vek) {
int N = vek.length;
this.vektor = new double[N];
for (int i = 0; i < N; i++)
this.vektor[i] = vek[i];
}
public Vektor(int size) {
this.vektor = new double[size];
}
}
Код:
public class Matrix {
private double[][] matrix;
private int row;
private int col;
public Matrix() {
this.matrix = new double[0][0];
}
public Matrix(double[][] z) {
matrix = z;
spalten = getCol();
zeilen = getRow();
}
public Matrix(Matrix d) {
row = d.getRow();
col = d.getCol();
matrix = new double[row][col];
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
matrix[i][j] = d.matrix[i][j];
}
}
}
public int getCol() {
return matrix.length;
}
public int getRow() {
return matrix[0].length;
}
public Matrix(double[] eind) {
int counter = 0;
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix.length; j++) {
matrix[i][j] = eind[counter];
counter++;
}
}
}
public Matrix(int row, int col) {
this.matrix = new double[row][col];
}
public Matrix(int zahl) {
this.matrix = new double[zahl][zahl];
}
public int[] getLength() {
int[] laenge = new int[matrix.length];
System.out.println(" Array: " + laenge.length);
return laenge;
}
public boolean isQuadratisch() {
for (row = 0; row < matrix.length; row++) {
for (col = 0; col < matrix.length; col++)
if (row != spalten) {
System.out.println(" is not Square");
}
}
return false;
}
//Сумма елементов в каждой строке
public Vektor summeRow() {
double[] summe = new double[matrix.length];
double sum = 0;
for (int row = 0; row < matrix.length; row++) {
for (int col = 0; col < matrix[row].length; col++) {
sum = sum + matrix[row][col];
}
summe[row] = sum;
System.out.println("Summe in zeile[" + row + "]: " + sum);
}
return new Vektor(summe);
}
//максимум в каждой строке
public Vektor maxRow() {
double[] maxValues = new double[matrix.length];
for (int row = 0; row < matrix.length; row++) {
double max = matrix[row][0];
for (int col = 1; col < matrix[row].length; col++) {
if (matrix[row][col] > max)
max = matrix[row][col];
}
maxValues[row] = max;
System.out.println("Maximum in zeile[" + row + "]: " + max);
}
return new Vektor(maxValues);
}
//удаление строки и столбца
public Matrix ohneZeileSpalte(int iZeile, int jSpalte) {
if (iZeile > matrix[0].length && jSpalte > matrix.length) {
System.out.println("Can't delete");
}
int nR, nW, mR, mW;
Matrix newMatrix= new Matrix(zeilen-1,spalten-1);
for (nR=0, nW=0; nR<zeilen; nR++)
{
if (nR!=iZeile-1)
{
for (mR=0, mW=0; mR<spalten; mR++)
{
if (mR!=jSpalte-1)
{
newMatrix.setElement(nW, mW,matrix[nR][mR]);
mW++;
System.out.print(matrix[nR][mR]+" ");
}
}
nW++;
}
System.out.println();
}
return new Matrix(newMatrix);
}
//cumulative
public Vektor cumulRow(int iRow) {
double[] getZ = new double[getZeile()];
for (row= 0; row < matrix.length;row++) {
if (row == iRow - 1) {
for (int col = 0; col < matrix[zeilen].length; col++) {
???????;
}
}
}
return new Vektor(getZ);
}
}
Задача такая, функция cumulRow(int iRow) должна накапливать(не знаю как точно на русском, на английском cumulative) суммы из iRow и возвратить как Vektor, т.е.
моя матрица:
1 5 3
5 2 4
1 1 1
беру iRow вторую линию 5 2 4,
начало 5 -> первый елемент 5
потом прибовляем 2-> 5+2=7 , второй елемент 7
к 7 прибовляем 4->третий елемент 11
вернуть Vektor(5, 7, 11).