
Potęgowanie macierzy (Java)
Reguły potęgowania:
![]()
![]()
O transpozycji macierzy opowiem w innym wpisie.
![]()
![]()
Do potęgowania możemy uzyć metody pow(Matrix, int) z klasy MatrixUtil.
public static Matrix pow(Matrix matrix, int times) {
if (matrix.isSquareMatrix()) {
Matrix t = null;
try {
t = matrix.clone();
} catch (CloneNotSupportedException e1) {
e1.printStackTrace();
}
for (int i = 0; i < times - 1; i++) {
try {
t = t.multiply2(matrix.clone());
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
}
return t;
}
return null;
}
Klasa Matrix027
double[] array1 = {1, 2, 3, 4};
Matrix matrix1 = new Matrix(array1, 2);
ArrayUtil.print(array1);
Matrix t = MatrixUtil.pow(matrix1, 2);
t.printToConsole();
Podnosimy macierz do kwadratu.
Po uruchomieniu klasy na konsoli zobaczymy:
[1.0, 2.0, 3.0, 4.0] 7.0 10.0 15.0 22.0
Pliki do ściągnięcia
Moduł matrices – aktualny stan projektu = 010
