package calculations; /** * This program shows how a repetitive vector-matrix-multiplication can converge to a fixed point. * Such a calculation is mentioned in the lecture during the topic of the random web-surfer. * @author Felix & Lars */ public class VectorMatrixMultiplication { /** * Multiplies a vector times a matrix. * @param v Input vector to be multiplied (from the left hand side) with the matrix. * @param m Input matrix to be multiplied (from the right hand side) with the vector. * Since matrix multiplications aren't commutative, it's important to specify that the * this method multiplies the vector times the matrix and not vice-versa. * Otherwise the result would again be a matrix and not a vector! */ public static double[] multiply(double[] v, double[][] m) { assert (v.length == m.length); // vector length must be equal so matrix height double[] res = new double[m.length]; // result vector for (int j=0; j < m[0].length; ++j) { // for every row of the matrix res[j] = 0; // initial value (actually also done by the java VM) for (int i=0; i