edu.northwestern.at.utils.math.matrix
Class MatrixFromString

java.lang.Object
  extended by edu.northwestern.at.utils.math.matrix.MatrixFromString

public class MatrixFromString
extends java.lang.Object

MatrixFromString provides methods for parsing a string containing a matrix.

MatrixFromString can parse the following types of matrix input.

You can use the method MatrixFromStringParser to parse other types of matrix definition strings as long as these can be specified in terms of regular expressions. MatrixFromStringParser underlies all the parsing methods here.

While it is possible to parse simple MathML using regular expressions, as we do here, it may be better to use an XML parser. To do this, uncomment the imports above for org.jdom.* and see the comments below preceding the method fromMathMLString .


Nested Class Summary
static class MatrixFromString.MatrixFromStringParser
          General recursive descent parser class for matrices whose forma can be parsed with regular expressions.
 
Field Summary
static MatrixFromString.MatrixFromStringParser gaussMatrixFromString
           
static MatrixFromString.MatrixFromStringParser mathMLMatrixFromString
           
static MatrixFromString.MatrixFromStringParser matlabMatrixFromString
           
static MatrixFromString.MatrixFromStringParser plainTextMatrixFromString
           
 
Constructor Summary
protected MatrixFromString()
          Don't allow instantiation, but do allow overrides.
 
Method Summary
static Matrix fromGaussString(java.lang.String src)
          Parse a matrix definition string in Gauss format.
static Matrix fromMathMLString(java.lang.String src)
          Parse a matrix definition string in MathML format.
static Matrix fromMatlabString(java.lang.String src)
          Parse a matrix definition string in Matlab format.
static Matrix fromPlainTextString(java.lang.String src)
          Parse a matrix definition string in plain text format.
static Matrix parseMatrix(java.lang.String src, MatrixFromString.MatrixFromStringParser parser)
          Parse a matrix definition string with a specified Matrix parser.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

matlabMatrixFromString

public static final MatrixFromString.MatrixFromStringParser matlabMatrixFromString

gaussMatrixFromString

public static final MatrixFromString.MatrixFromStringParser gaussMatrixFromString

plainTextMatrixFromString

public static final MatrixFromString.MatrixFromStringParser plainTextMatrixFromString

mathMLMatrixFromString

public static final MatrixFromString.MatrixFromStringParser mathMLMatrixFromString
Constructor Detail

MatrixFromString

protected MatrixFromString()
Don't allow instantiation, but do allow overrides.

Method Detail

parseMatrix

public static Matrix parseMatrix(java.lang.String src,
                                 MatrixFromString.MatrixFromStringParser parser)
Parse a matrix definition string with a specified Matrix parser.

Parameters:
src - String containing matrix definition.
parser - The matrix parser to use.
Returns:
The matrix corresponding to the definition string.

fromMatlabString

public static Matrix fromMatlabString(java.lang.String src)
Parse a matrix definition string in Matlab format.

Parameters:
src - String containing matrix definition.
Returns:
The matrix corresponding to the definition string.

Sample matrix definition: [ -2,3.5,6; 7,8, 9.0; 10,-11,12 ]


fromGaussString

public static Matrix fromGaussString(java.lang.String src)
Parse a matrix definition string in Gauss format.

Parameters:
src - String containing matrix definition.
Returns:
The matrix corresponding to the definition string.

Sample matrix definition: { 2 -3.5 6 , 7 -8 9.0, 10 11 12}


fromPlainTextString

public static Matrix fromPlainTextString(java.lang.String src)
Parse a matrix definition string in plain text format.

Parameters:
src - String containing matrix definition.
Returns:
The matrix corresponding to the definition string.

Sample matrix definition:

2 -3.5 6
7 -8 9.0
10 11 12


fromMathMLString

public static Matrix fromMathMLString(java.lang.String src)
Parse a matrix definition string in MathML format.

Parameters:
src - String containing matrix definition.
Returns:
The matrix corresponding to the definition string.

Sample matrix definition:

<matrix> <matrixrow> <cn>-2</cn> <cn>3.5</cn> <cn>6</cn> </matrixrow> <matrixrow> <cn>7</cn> <cn>8</cn> <cn>9.0</cn> </matrixrow> <matrixrow> <cn>19</cn> <cn>-11</cn> <cn>12</cn> </matrixrow> </matrix>