import ccj.*; public class Mproduct { public static void main(String[] args) { double[][] rot = new double[3][3]; double alpha = Math.PI / 2; /* 45 degrees */ rot[0][0] = Math.cos(alpha); rot[0][1] = -Math.sin(alpha); rot[0][2] = 0; rot[1][0] = Math.sin(alpha); rot[1][1] = Math.cos(alpha); rot[1][2] = 0; rot[2][0] = 0; rot[2][1] = 0; rot[2][2] = 1; double[][] t1 = new double[3][3]; t1[0][0] = 1; t1[0][1] = 0; t1[0][2] = -4; t1[1][0] = 0; t1[1][1] = 1; t1[1][2] = -3; t1[2][0] = 0; t1[2][1] = 0; t1[2][2] = 1; double[][] t2 = new double[3][3]; t2[0][0] = 1; t2[0][1] = 0; t2[0][2] = 4; t2[1][0] = 0; t2[1][1] = 1; t2[1][2] = 3; t2[2][0] = 0; t2[2][1] = 0; t2[2][2] = 1; double[][] a = mproduct(t2, mproduct(rot, t1)); printMatrix(a); } public static double[][] mproduct(double[][] a, double[][] b) { if (a[0].length != b.length) throw new IllegalArgumentException(); double[][] r = new double[a.length][b[0].length]; int i; for (i = 0; i < a.length; i++) { int j; for (j = 0; j < b[0].length; j++) { int k; double sum = 0; for (k = 0; k < a[0].length; k++) sum = sum + a[i][k] * b[k][j]; r[i][j] = sum; } } return r; } public static void printMatrix(double[][] m) { int i; for (i = 0; i < m.length; i++) { int j; for (j = 0; j < m[i].length; j++) Console.out.printf("%10.2f", m[i][j]); Console.out.println(); } } }