示例#1
0
        static void Main(string[] args)
        {
            string matrixProduct;
            string inputFile = "";

            if (args.Length < 1)
            {
                Console.WriteLine("Error: No argument received for input file");
                return;
            }
            if (args.Length < 2)
            {
                Console.WriteLine("No argument received for string. String assumed to be the empty string.");
                inputFile     = args[0];
                matrixProduct = "";
            }
            else
            {
                inputFile     = args[0];
                matrixProduct = args[1];
            }

            var symbols = new HashSet <char>(MatrixSolver.Computations.Constants.RegularLanguage.Symbols);

            foreach (var symbol in matrixProduct)
            {
                if (!symbols.Contains(symbol))
                {
                    throw new ArgumentException($"String contained unknown symbol {symbol}");
                }
            }

            // TODO: Duplicate of main function. Expose this procedure somewhere to reduce duplicate code.
            var json = File.ReadAllText(inputFile);
            var data = JsonConvert.DeserializeObject <InputData>(json);

            data.ThrowIfNull();
            var vectorX  = new ImmutableVector2D(data.VectorX);
            var vectorY  = new ImmutableVector2D(data.VectorY);
            var matrices = data.Matrices.Select(m => new ImmutableMatrix2x2(As2DArray(m, 2, 2))).ToArray();

            Console.WriteLine($"Computing matrix product M = {matrixProduct}");
            var M = RegularLanguageHelper.MatrixProductStringToMatrix(matrixProduct);

            Console.WriteLine($"Calculated M = {M}");

            var expectedY = M * vectorX;

            if (expectedY.Equals(vectorY))
            {
                Console.WriteLine($"Mx = y is solved for M = {M}, x = {vectorX}, y = {vectorY}");
            }
            else
            {
                Console.WriteLine($"Expected vector y = {vectorY}, but instead found y = {expectedY}");
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("No argument for filename provided");
                return;
            }
            var fileName = args[0];

            var words = File.ReadAllText(fileName).Split(
                new[] { Environment.NewLine },
                StringSplitOptions.None
                );

            foreach (var word in words)
            {
                var matrix = RegularLanguageHelper.MatrixProductStringToMatrix(word);

                Console.WriteLine($"phi({word}) = {matrix}");
            }
        }