Esempio n. 1
0
        /// <summary>
        /// Permite fazer a leitura de um vector a partir de texto.
        /// </summary>
        /// <param name="lines">O tamanho do vector.</param>
        /// <param name="vectorString">O texto que representa o vector.</param>
        /// <returns>O vector.</returns>
        public IMathVector <double> ReadVector(int length, string vectorString)
        {
            var integerParser      = new DoubleExpressionParser();
            var vectorFactory      = new ArrayVectorFactory <double>();
            var reader             = new StringReader(vectorString);
            var stringSymbolReader = new StringSymbolReader(reader, false);
            var vectorReader       = new ConfigVectorReader <double, string, string, CharSymbolReader <string> >(
                length,
                vectorFactory);

            vectorReader.MapInternalDelimiters("left_bracket", "right_bracket");
            vectorReader.AddBlanckSymbolType("blancks");
            vectorReader.SeparatorSymbType = "comma";

            var vector = default(IMathVector <double>);

            if (vectorReader.TryParseVector(stringSymbolReader, integerParser, out vector))
            {
                return(vector);
            }
            else
            {
                throw new Exception("An error has occured while reading integer vector.");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Faz a leitura de uma matriz de valores numéricos.
        /// </summary>
        /// <param name="lines">The number of lines.</param>
        /// <param name="columns">The number of columns.</param>
        /// <param name="arrayString">O texto que representa a matriz.</param>
        /// <returns>A matriz lida.</returns>
        public ArrayMathMatrix <double> ReadArray(int lines, int columns, string arrayString)
        {
            var expressionParser   = new DoubleExpressionParser();
            var reader             = new StringReader(arrayString);
            var stringSymbolReader = new StringSymbolReader(reader, false);
            var arrayMatrixFactory = new ArrayMathMatrixFactory <double>();
            var arrayMatrixReader  = new ConfigMatrixReader <double, IMathMatrix <double>, string, string>(
                lines,
                columns);

            arrayMatrixReader.MapInternalDelimiters("left_bracket", "right_bracket");
            arrayMatrixReader.AddBlanckSymbolType("blancks");
            arrayMatrixReader.SeparatorSymbType = "comma";

            var matrix = default(IMathMatrix <double>);

            if (arrayMatrixReader.TryParseMatrix(stringSymbolReader, expressionParser, (i, j) => arrayMatrixFactory.CreateMatrix(i, j), out matrix))
            {
                return(matrix as ArrayMathMatrix <double>);
            }
            else
            {
                throw new ArgumentException("Can't read the specified matrix.");
            }
        }