/// <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."); } }
/// <summary> /// Permite fazer a leitura de uma matriz. /// </summary> /// <typeparam name="T">O tipo de elementos na matriz.</typeparam> /// <param name="lines">O número de linhas.</param> /// <param name="columns">O número de colunas.</param> /// <param name="matrixText">A representação textual da matriz.</param> /// <param name="matrixFactory">A fábrica responsável pela criação de matrizes.</param> /// <param name="elementParser">O leitor de elementos.</param> /// <param name="readNegativeNumbers">Indica se são lidos os números negativos.</param> /// <returns>A matriz.</returns> public static M ReadMatrix <T, M>( int lines, int columns, string matrixText, Func <int, int, M> matrixFactory, IParse <T, string, string> elementParser, bool readNegativeNumbers = false) where M : IMatrix <T> { var reader = new StringReader(matrixText); var stringSymbolReader = new StringSymbolReader(reader, readNegativeNumbers); var arrayMatrixReader = new ConfigMatrixReader <T, M, string, string>( lines, columns); arrayMatrixReader.MapInternalDelimiters("left_bracket", "right_bracket"); arrayMatrixReader.AddBlanckSymbolType("blancks"); arrayMatrixReader.SeparatorSymbType = "comma"; var matrix = default(M); if (arrayMatrixReader.TryParseMatrix( stringSymbolReader, elementParser, matrixFactory, out matrix)) { return(matrix); } else { throw new Exception("Can't read matrix."); } }