Matice v Jave
-
MoRk4
Light Star
- Príspevky: 294
- Registrovaný: 31 júl 2009, 17:55
- Bydlisko: Liptovsky Mikulas (Slovensko)
Matice v Jave
Caute, dostal som ako zadanie na semestralku spravit triedu Matica, ktorá má správy na výpočet determinantu, inverznej matice, transponovanej matice a násobenie dvoch matíc. Neviem ako mam zacat. Ako by ste postupovali vy? Dakujem za rady.
-
harrison314
Hardcore addict
- Príspevky: 8219
- Registrovaný: 27 máj 2009, 20:42
- Bydlisko: Bratislava
- Kontaktovať používateľa:
Re: Matice v Jave
Ja by som si v IDE vytvoril novy projekt, potom dal nan pravym a zvolil "Add new class", nazval by som ju matica a dopisal nejaky kod.
-
MoRk4
Light Star
- Príspevky: 294
- Registrovaný: 31 júl 2009, 17:55
- Bydlisko: Liptovsky Mikulas (Slovensko)
Re: Matice v Jave
No ty si ale inteligentny...
-
harrison314
Hardcore addict
- Príspevky: 8219
- Registrovaný: 27 máj 2009, 20:42
- Bydlisko: Bratislava
- Kontaktovať používateľa:
Re: Matice v Jave
Tak sory, ale po tvojej otazke sa nedalo reagovat inak. Napisal si s cim mas problem, ani nic konkretne...
Ale asi kazdemu je jasne, ze si na wikipedii najdes ako sa dane veci pocitaju a potom to nakodis.
Ale asi kazdemu je jasne, ze si na wikipedii najdes ako sa dane veci pocitaju a potom to nakodis.
-
miki690
Medium Professional
- Príspevky: 1255
- Registrovaný: 07 okt 2005, 22:07
- Bydlisko: KE
- Kontaktovať používateľa:
Re: Matice v Jave
Pripravil som ti kostru triedy, snad ti to na zaciatok postaci
Netestoval som tie konstruktory, je mozne ze som niekde spravil chyb, tak si to skontroluj
Kód: Vybrať všetko
import java.util.Arrays;
public class Matrix {
private int[][] content;
private int rows;
private int cols;
Matrix(int[][] arr){
//create copy from array to ensure immutability
content = new int[arr.length][];
for (int i = 0; i<arr.length; i++){
content[i]=arr[i].clone();
}
rows = arr[0].length;
cols = arr.length;
}
Matrix(Matrix m){
content = m.getContent();
rows = m.getRows();
cols = m.getCols();
}
public int[][] getContent() {
//return copy of original value to ensure immutability
int [][] myInt = new int[content.length][];
for(int i = 0; i < content.length; i++)
myInt[i] = content[i].clone();
return myInt;
}
public int getRows() {
return rows;
}
public int getCols() {
return cols;
}
/**
* Transpose matrix
*
* @return new object containing transposed matrix to this
*/
public Matrix transpose(){
if (content == null){
throw new IllegalStateException("Undefined matrix values");
}
// Your alhorithm here
throw new UnsupportedOperationException("Not Implemented yet !"); //remove this line when finished
}
/**
* Count determinant of matrix
*
* @return determinant
*/
public long det(){
// Your alhorithm here
throw new UnsupportedOperationException("Not Implemented yet !"); //remove this line when finished
}
/**
* Multiplies this matrix with another matrix object;
*
* @param in input matrix
* @return new Matrix object containing resullt
* @throws IllegalArgumentException when dimensions of matrices does not comply to the rules of matrix mulitplication
*/
public Matrix multiply(Matrix in){
// Your alhorithm here
throw new UnsupportedOperationException("Not Implemented yet !"); //remove this line when finished
}
@Override
public String toString() {
return "Matrix{" +
"content=" + (content == null ? null : Arrays.asList(content)) +
'}';
}
}