Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Java программирование > Общие вопросы по Java, Java SE, Kotlin
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 15.04.2012, 23:30   #1
seide
 
Регистрация: 06.11.2011
Сообщений: 6
По умолчанию Редактирование матрицы

Привет ребят, помогите разобраться.
У меня 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).
seide вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Первый элемент - размерность матрицы, остальные образуют строки этой матрицы Anastasiya_Pot Помощь студентам 2 10.04.2012 09:46
Язык СИ! Динамическое выделение памяти под массивы и матрицы, передача матрицы в функции Андрей! Общие вопросы C/C++ 33 31.01.2012 22:07
С++.три матрицы, упорядочить строки той матрицы у которой больше нулевых строк Ирина1992 Помощь студентам 12 20.11.2011 13:01
Ф-ия, определяющая сумму строк матрицы, если на главной диагонали матрицы имеется отрицательный эл-т. Volk_xD Помощь студентам 6 05.01.2011 13:39
На главную диагональ матрицы поместить наибольшие элементы этой матрицы mivel Помощь студентам 2 23.12.2009 21:19