Esempio n. 1
0
        private string MultiplyVectorAndMatrix(string vectorFile, string matrixFile)
        {
            WriteLog(LogStrings.TryingToMultiplyMatrixAndVector(matrixFile, vectorFile));

            int[,] matrix = GetMatrixFromFile(matrixFile);
            int[] vector = GetVectorFromFile(vectorFile);

            if (matrix.GetLength(1) != vector.Length)
            {
                return(null);
            }

            string       fileName = GetFileName(vectorFile, matrixFile);
            StreamWriter writer   = new StreamWriter(fileName);

            int length = matrix.GetLength(0);

            writer.WriteLine(length);

            for (int i = 0; i < length; i++)
            {
                BigInteger number = 0;

                for (int j = 0; j < vector.Length; j++)
                {
                    number += matrix[i, j] * vector[j];
                }

                writer.Write(number);
                if (i != length - 1)
                {
                    writer.Write(' ');
                }
            }

            WriteLog(LogStrings.MultiplicationWasSuccessful(matrixFile, vectorFile));

            writer.Close();

            return(fileName);
        }