/// <summary> /// 向量和矩阵相乘 /// </summary> /// <param name="vector">向量</param> /// <param name="matrix">矩阵</param> /// <returns>乘积</returns> public static char[] MultiplyMod26(char[] vector, MatrixIntGF26 matrix) { if (vector.Length != matrix.row) { throw new Exception("无法进行乘法运算,向量的维度和矩阵的行数不相等"); } var result = new char[vector.Length]; double temp; for (int i = 0; i < result.Length; i++) { temp = 0; for (int j = 0; j < matrix.column; j++) { temp += vector[j] * matrix.elements[j, i]; } result[i] = (char)Mod(SolveDouble(temp)); } return(result); }
/// <summary> /// 两个矩阵相乘 /// </summary> /// <param name="b"></param> /// <returns></returns> public MatrixIntGF26 MultifyMod(MatrixIntGF26 b) { if (this.column != b.row) { throw new Exception($"{this.row}行{this.column}列和{b.row}行{b.column}列的两个矩阵无法进行计算"); } var result = new int[this.row, b.column]; for (int i = 0; i < this.row; i++) { for (int j = 0; j < b.column; j++) { double temp = 0; for (int k = 0; k < this.column; k++) { temp += this.elements[i, k] * b.elements[k, j]; } result[i, j] = Mod(SolveDouble(temp)); } } return(new MatrixIntGF26(result)); }