Class AbstractMatrixField
- java.lang.Object
-
- com.singularsys.extensions.matrix.AbstractMatrixField
-
- All Implemented Interfaces:
FieldI,IntegerConvertor,MatrixFieldI,JepComponent,java.io.Serializable
- Direct Known Subclasses:
DoubleMatrixField,SequenceMatrixField
public abstract class AbstractMatrixField extends java.lang.Object implements MatrixFieldI
An abstract base class for implementations of MatrixFieldI. In general theGenericMatrixFieldshould be used. This class is for case when the matrix does not implementGenericMatrixsuch as andouble[][].- Since:
- Jep 3.5 / Extensions 2.0
- Author:
- Richard Morris
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected MatrixFactoryImf
-
Constructor Summary
Constructors Constructor Description AbstractMatrixField(MatrixFactoryI mf)ConstructionAbstractMatrixField(MatrixFactoryI mf, boolean skipElements)Constructor where operations on the base field can be switched off.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.Objectadd(java.lang.Object l, java.lang.Object r)Adds two matrices or vectors.protected abstract java.lang.ObjectaddEle(java.lang.Object l, java.lang.Object r)protected abstract MatrixIaddMM(MatrixI l, MatrixI r)protected abstract VectorIaddVV(VectorI lv, VectorI rv)Add two vectorsjava.lang.Booleanand(java.lang.Object l, java.lang.Object r)Logical and.protected abstract java.lang.BooleanandEle(java.lang.Object l, java.lang.Object r)java.lang.Objectcross(java.lang.Object l, java.lang.Object r)Default inefficient implementation.protected java.lang.ObjectcrossVV(VectorI lv, VectorI rv)Default inefficient implementation.java.lang.Objectdet(java.lang.Object m)Determinant of a matrixprotected java.lang.ObjectdetM(MatrixI mat)Return the determinant of a matrix.java.lang.Objectdiv(java.lang.Object l, java.lang.Object r)Divides two members of the field.protected abstract java.lang.ObjectdivEle(java.lang.Object l, java.lang.Object r)protected abstract MatrixIdivMO(MatrixI l, java.lang.Object r)protected abstract VectorIdivVO(VectorI l, java.lang.Object r)java.lang.Objectdot(java.lang.Object l, java.lang.Object r)The dot product of two vectorsprotected java.lang.ObjectdotVV(VectorI lv, VectorI rv)Default inefficient implementation.java.lang.Booleaneq(java.lang.Object l, java.lang.Object r)Equalsprotected abstract java.lang.BooleaneqEle(java.lang.Object l, java.lang.Object r)protected abstract java.lang.BooleaneqMM(MatrixI l, MatrixI r)protected abstract java.lang.BooleaneqVV(VectorI l, VectorI r)java.lang.Booleange(java.lang.Object l, java.lang.Object r)Greater or equal toprotected abstract java.lang.BooleangeEle(java.lang.Object l, java.lang.Object r)java.lang.Booleangt(java.lang.Object l, java.lang.Object r)Greater thanprotected abstract java.lang.BooleangtEle(java.lang.Object l, java.lang.Object r)java.lang.Objectinv(java.lang.Object l)Returns the inverse of a square matrix.protected MatrixIinvM(MatrixI mat)Finds the inverse of a matrix.java.lang.Booleanle(java.lang.Object l, java.lang.Object r)Less than or equals toprotected abstract java.lang.BooleanleEle(java.lang.Object l, java.lang.Object r)java.lang.Booleanlt(java.lang.Object l, java.lang.Object r)Less thanprotected abstract java.lang.BooleanltEle(java.lang.Object l, java.lang.Object r)protected MatrixIminor(MatrixI m, int row, int col)Finds the minor matrix formed by excluding a row and vectorjava.lang.Objectmod(java.lang.Object l, java.lang.Object r)The modulus of two members of the field.protected abstract java.lang.ObjectmodEle(java.lang.Object l, java.lang.Object r)java.lang.Objectmul(java.lang.Object l, java.lang.Object r)Multiplies two members of the field.protected abstract java.lang.ObjectmulEle(java.lang.Object l, java.lang.Object r)protected abstract MatrixImulMM(MatrixI l, MatrixI r)protected abstract MatrixImulMO(MatrixI l, java.lang.Object r)protected abstract VectorImulMV(MatrixI l, VectorI r)protected voidmulRow(MatrixI m, int row, java.lang.Object mul)In place multiply all elements of a row by a numberprotected abstract VectorImulVM(VectorI l, MatrixI r)protected abstract VectorImulVO(VectorI l, java.lang.Object r)protected abstract MatrixImulVV(VectorI l, VectorI r)java.lang.Booleanne(java.lang.Object l, java.lang.Object r)Not Equalsprotected abstract java.lang.BooleanneEle(java.lang.Object l, java.lang.Object r)java.lang.Objectneg(java.lang.Object l)The negation -x of an element.protected abstract java.lang.ObjectnegEle(java.lang.Object l)protected abstract MatrixInegM(MatrixI l)protected abstract VectorInegV(VectorI lv)protected abstract java.lang.BooleanneMM(MatrixI l, MatrixI r)protected abstract java.lang.BooleanneVV(VectorI l, VectorI r)java.lang.Booleannot(java.lang.Object l)Logical not.protected abstract java.lang.BooleannotEle(java.lang.Object l)java.lang.Booleanor(java.lang.Object l, java.lang.Object r)Logical or.protected abstract java.lang.BooleanorEle(java.lang.Object l, java.lang.Object r)java.lang.Objectpow(java.lang.Object l, java.lang.Object r)The power operator.protected abstract java.lang.ObjectpowEle(java.lang.Object l, java.lang.Object r)java.lang.Objectsolve(java.lang.Object A, java.lang.Object B)Solve equation A * X = Bprotected MatrixIsolveMM(MatrixI A, MatrixI b)protected VectorIsolveMV(MatrixI A, VectorI b)java.lang.Objectsub(java.lang.Object l, java.lang.Object r)Subtract two members of the field.protected abstract java.lang.ObjectsubEle(java.lang.Object l, java.lang.Object r)protected abstract MatrixIsubMM(MatrixI l, MatrixI r)protected voidsubtractMul(MatrixI m, int targetRow, int sourceRow, java.lang.Object mul)In place Subtract a multiply of the source row from the targetm(t,j) = m(t,j) - mul * m(s,j)protected abstract VectorIsubVV(VectorI lv, VectorI rv)protected voidswapRows(MatrixI m, int i, int j)In place swap of two rowsjava.lang.Objecttrace(java.lang.Object l)Trace of a matrixjava.lang.ObjecttraceM(MatrixI m)Default inefficient implementation.java.lang.Objecttrans(java.lang.Object l)Transpose of a matrixprotected java.lang.ObjecttransM(MatrixI mat)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.singularsys.extensions.field.implementations.IntegerConvertor
convertFromInt, convertToInt
-
Methods inherited from interface com.singularsys.jep.JepComponent
getLightWeightInstance, init
-
-
-
-
Field Detail
-
mf
protected MatrixFactoryI mf
-
-
Constructor Detail
-
AbstractMatrixField
public AbstractMatrixField(MatrixFactoryI mf)
Construction- Parameters:
mf- corresponding matrix factory
-
AbstractMatrixField
public AbstractMatrixField(MatrixFactoryI mf, boolean skipElements)
Constructor where operations on the base field can be switched off. By default the add operator will add vectors/matrices over a base field and also add elements in that field. So it will calculate (2,3)+(4,5) but also 6+7. Setting skipElements to true means that it will calculate (2,3)+(4,5) but return null if given 6+7. This will need to be specified by some other field. Its not intended to use this constructor but left here for case where it is needed.- Parameters:
mf- The factory used to generate matricesskipElements- whether to skip operations on the base elements
-
-
Method Detail
-
addEle
protected abstract java.lang.Object addEle(java.lang.Object l, java.lang.Object r) throws EvaluationException- Throws:
EvaluationException
-
addVV
protected abstract VectorI addVV(VectorI lv, VectorI rv) throws EvaluationException
Add two vectors- Parameters:
lv- lhs vectorrv- rhs vector- Returns:
- the sum of the vectors
- Throws:
EvaluationException- if the dimension do not match
-
addMM
protected abstract MatrixI addMM(MatrixI l, MatrixI r) throws EvaluationException
- Throws:
EvaluationException
-
add
public java.lang.Object add(java.lang.Object l, java.lang.Object r) throws EvaluationExceptionAdds two matrices or vectors. Calls eitheraddVV(VectorI, VectorI)oraddMM(MatrixI, MatrixI)depending on the arguments.- Specified by:
addin interfaceFieldI- Parameters:
l- left hand argumentr- right hand argument- Returns:
- the sum of the arguments if l and r are of both of type VectorI or both of type MatrixI or null otherwise.
- Throws:
EvaluationException- on error
-
subEle
protected abstract java.lang.Object subEle(java.lang.Object l, java.lang.Object r) throws EvaluationException- Throws:
EvaluationException
-
subVV
protected abstract VectorI subVV(VectorI lv, VectorI rv) throws EvaluationException
- Throws:
EvaluationException
-
subMM
protected abstract MatrixI subMM(MatrixI l, MatrixI r) throws EvaluationException
- Throws:
EvaluationException
-
sub
public java.lang.Object sub(java.lang.Object l, java.lang.Object r) throws EvaluationExceptionDescription copied from interface:FieldISubtract two members of the field.- Specified by:
subin interfaceFieldI- Parameters:
l- left hand argumentr- right hand argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException- on error
-
negEle
protected abstract java.lang.Object negEle(java.lang.Object l) throws EvaluationException- Throws:
EvaluationException
-
negV
protected abstract VectorI negV(VectorI lv) throws EvaluationException
- Throws:
EvaluationException
-
negM
protected abstract MatrixI negM(MatrixI l) throws EvaluationException
- Throws:
EvaluationException
-
neg
public java.lang.Object neg(java.lang.Object l) throws EvaluationExceptionDescription copied from interface:FieldIThe negation -x of an element.- Specified by:
negin interfaceFieldI- Parameters:
l- the argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException- on error
-
mulEle
protected abstract java.lang.Object mulEle(java.lang.Object l, java.lang.Object r) throws EvaluationException- Throws:
EvaluationException
-
mulVO
protected abstract VectorI mulVO(VectorI l, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
mulMO
protected abstract MatrixI mulMO(MatrixI l, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
mulVV
protected abstract MatrixI mulVV(VectorI l, VectorI r) throws EvaluationException
- Throws:
EvaluationException
-
mulVM
protected abstract VectorI mulVM(VectorI l, MatrixI r) throws EvaluationException
- Throws:
EvaluationException
-
mulMV
protected abstract VectorI mulMV(MatrixI l, VectorI r) throws EvaluationException
- Throws:
EvaluationException
-
mulMM
protected abstract MatrixI mulMM(MatrixI l, MatrixI r) throws EvaluationException
- Throws:
EvaluationException
-
mul
public java.lang.Object mul(java.lang.Object l, java.lang.Object r) throws EvaluationExceptionDescription copied from interface:FieldIMultiplies two members of the field.- Specified by:
mulin interfaceFieldI- Parameters:
l- left hand argumentr- right hand argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException- on error
-
divEle
protected abstract java.lang.Object divEle(java.lang.Object l, java.lang.Object r) throws EvaluationException- Throws:
EvaluationException
-
divVO
protected abstract VectorI divVO(VectorI l, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
divMO
protected abstract MatrixI divMO(MatrixI l, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
div
public java.lang.Object div(java.lang.Object l, java.lang.Object r) throws EvaluationExceptionDescription copied from interface:FieldIDivides two members of the field.- Specified by:
divin interfaceFieldI- Parameters:
l- left hand argumentr- right hand argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException- on error
-
modEle
protected abstract java.lang.Object modEle(java.lang.Object l, java.lang.Object r) throws EvaluationException- Throws:
EvaluationException
-
mod
public java.lang.Object mod(java.lang.Object l, java.lang.Object r) throws EvaluationExceptionDescription copied from interface:FieldIThe modulus of two members of the field.- Specified by:
modin interfaceFieldI- Parameters:
l- left hand argumentr- right hand argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException- on error
-
powEle
protected abstract java.lang.Object powEle(java.lang.Object l, java.lang.Object r) throws EvaluationException- Throws:
EvaluationException
-
pow
public java.lang.Object pow(java.lang.Object l, java.lang.Object r) throws EvaluationExceptionDescription copied from interface:FieldIThe power operator.- Specified by:
powin interfaceFieldI- Parameters:
l- left hand argumentr- right hand argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException- on error
-
eqEle
protected abstract java.lang.Boolean eqEle(java.lang.Object l, java.lang.Object r) throws EvaluationException- Throws:
EvaluationException
-
eqVV
protected abstract java.lang.Boolean eqVV(VectorI l, VectorI r) throws EvaluationException
- Throws:
EvaluationException
-
eqMM
protected abstract java.lang.Boolean eqMM(MatrixI l, MatrixI r) throws EvaluationException
- Throws:
EvaluationException
-
eq
public java.lang.Boolean eq(java.lang.Object l, java.lang.Object r) throws EvaluationExceptionDescription copied from interface:FieldIEquals- Specified by:
eqin interfaceFieldI- Parameters:
l- left hand argumentr- right hand argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException- on error
-
neEle
protected abstract java.lang.Boolean neEle(java.lang.Object l, java.lang.Object r) throws EvaluationException- Throws:
EvaluationException
-
neVV
protected abstract java.lang.Boolean neVV(VectorI l, VectorI r) throws EvaluationException
- Throws:
EvaluationException
-
neMM
protected abstract java.lang.Boolean neMM(MatrixI l, MatrixI r) throws EvaluationException
- Throws:
EvaluationException
-
ne
public java.lang.Boolean ne(java.lang.Object l, java.lang.Object r) throws EvaluationExceptionDescription copied from interface:FieldINot Equals- Specified by:
nein interfaceFieldI- Parameters:
l- left hand argumentr- right hand argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException- on error
-
andEle
protected abstract java.lang.Boolean andEle(java.lang.Object l, java.lang.Object r) throws EvaluationException- Throws:
EvaluationException
-
and
public java.lang.Boolean and(java.lang.Object l, java.lang.Object r) throws EvaluationExceptionDescription copied from interface:FieldILogical and.- Specified by:
andin interfaceFieldI- Parameters:
l- left hand argument implimentationr- right hand argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException- on error
-
orEle
protected abstract java.lang.Boolean orEle(java.lang.Object l, java.lang.Object r) throws EvaluationException- Throws:
EvaluationException
-
or
public java.lang.Boolean or(java.lang.Object l, java.lang.Object r) throws EvaluationExceptionDescription copied from interface:FieldILogical or.- Specified by:
orin interfaceFieldI- Parameters:
l- left hand argumentr- right hand argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException- on error
-
notEle
protected abstract java.lang.Boolean notEle(java.lang.Object l) throws EvaluationException- Throws:
EvaluationException
-
not
public java.lang.Boolean not(java.lang.Object l) throws EvaluationExceptionDescription copied from interface:FieldILogical not.- Specified by:
notin interfaceFieldI- Parameters:
l- argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException- on error
-
gtEle
protected abstract java.lang.Boolean gtEle(java.lang.Object l, java.lang.Object r) throws EvaluationException- Throws:
EvaluationException
-
gt
public java.lang.Boolean gt(java.lang.Object l, java.lang.Object r) throws EvaluationExceptionDescription copied from interface:FieldIGreater than- Specified by:
gtin interfaceFieldI- Parameters:
l- left hand argumentr- right hand argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException- on error
-
geEle
protected abstract java.lang.Boolean geEle(java.lang.Object l, java.lang.Object r) throws EvaluationException- Throws:
EvaluationException
-
ge
public java.lang.Boolean ge(java.lang.Object l, java.lang.Object r) throws EvaluationExceptionDescription copied from interface:FieldIGreater or equal to- Specified by:
gein interfaceFieldI- Parameters:
l- left hand argumentr- right hand argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException- on error
-
ltEle
protected abstract java.lang.Boolean ltEle(java.lang.Object l, java.lang.Object r) throws EvaluationException- Throws:
EvaluationException
-
lt
public java.lang.Boolean lt(java.lang.Object l, java.lang.Object r) throws EvaluationExceptionDescription copied from interface:FieldILess than- Specified by:
ltin interfaceFieldI- Parameters:
l- left hand argumentr- right hand argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException- on error
-
leEle
protected abstract java.lang.Boolean leEle(java.lang.Object l, java.lang.Object r) throws EvaluationException- Throws:
EvaluationException
-
le
public java.lang.Boolean le(java.lang.Object l, java.lang.Object r) throws EvaluationExceptionDescription copied from interface:FieldILess than or equals to- Specified by:
lein interfaceFieldI- Parameters:
l- left hand argumentr- right hand argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException- on error
-
trans
public java.lang.Object trans(java.lang.Object l) throws EvaluationExceptionDescription copied from interface:MatrixFieldITranspose of a matrix- Specified by:
transin interfaceMatrixFieldI- Parameters:
l- the matrix- Returns:
- a matrix containing the transpose
- Throws:
EvaluationException
-
transM
protected java.lang.Object transM(MatrixI mat) throws EvaluationException
- Throws:
EvaluationException
-
dot
public java.lang.Object dot(java.lang.Object l, java.lang.Object r) throws EvaluationExceptionDescription copied from interface:MatrixFieldIThe dot product of two vectors- Specified by:
dotin interfaceMatrixFieldI- Returns:
- the dot product if both arguments are vectors, null otherwise.
- Throws:
EvaluationException
-
dotVV
protected java.lang.Object dotVV(VectorI lv, VectorI rv) throws EvaluationException
Default inefficient implementation. Will only be called if vectors are of equal lengths- Parameters:
lv- lhs vectorrv- rhs vector- Returns:
- Throws:
EvaluationException
-
cross
public java.lang.Object cross(java.lang.Object l, java.lang.Object r) throws EvaluationExceptionDefault inefficient implementation.- Specified by:
crossin interfaceMatrixFieldI- Returns:
- a vector with the cross product
- Throws:
EvaluationException- if vectors not of length 3
-
crossVV
protected java.lang.Object crossVV(VectorI lv, VectorI rv) throws EvaluationException
Default inefficient implementation.- Throws:
EvaluationException
-
traceM
public java.lang.Object traceM(MatrixI m) throws EvaluationException
Default inefficient implementation.- Throws:
EvaluationException
-
trace
public java.lang.Object trace(java.lang.Object l) throws EvaluationExceptionTrace of a matrix- Specified by:
tracein interfaceMatrixFieldI- Parameters:
l- the matrix- Returns:
- the trace
- Throws:
EvaluationException
-
det
public java.lang.Object det(java.lang.Object m) throws EvaluationExceptionDeterminant of a matrix- Specified by:
detin interfaceMatrixFieldI- Parameters:
m- the matrix- Returns:
- the determinant
- Throws:
EvaluationException- if matrix is not square.
-
detM
protected java.lang.Object detM(MatrixI mat) throws EvaluationException
Return the determinant of a matrix. Does not check sizes.- Parameters:
mat- the matrix- Returns:
- the determinant
- Throws:
EvaluationException
-
minor
protected MatrixI minor(MatrixI m, int row, int col) throws EvaluationException
Finds the minor matrix formed by excluding a row and vector- Parameters:
m- the matrixrow- row to removecol- column to remove- Returns:
- new smaller matrix
- Throws:
EvaluationException
-
swapRows
protected void swapRows(MatrixI m, int i, int j) throws EvaluationException
In place swap of two rows- Parameters:
m- matrixi- index of first rowj- index of second row- Throws:
EvaluationException
-
mulRow
protected void mulRow(MatrixI m, int row, java.lang.Object mul) throws EvaluationException
In place multiply all elements of a row by a number- Parameters:
m- the matrixrow- the row to multiplymul- value to multiply by- Throws:
EvaluationException
-
subtractMul
protected void subtractMul(MatrixI m, int targetRow, int sourceRow, java.lang.Object mul) throws EvaluationException
In place Subtract a multiply of the source row from the targetm(t,j) = m(t,j) - mul * m(s,j)- Parameters:
m-targetRow-sourceRow-mul-- Throws:
EvaluationException
-
invM
protected MatrixI invM(MatrixI mat) throws EvaluationException
Finds the inverse of a matrix. Default implementation uses Gauss-Jordan with partial pivoting- Parameters:
mat-- Returns:
- Throws:
EvaluationException- if matrix is singular
-
inv
public java.lang.Object inv(java.lang.Object l) throws EvaluationExceptionDescription copied from interface:MatrixFieldIReturns the inverse of a square matrix.- Specified by:
invin interfaceMatrixFieldI- Parameters:
l- the matrix- Returns:
- the trace
- Throws:
EvaluationException- if matrix is not square or is singular
-
solveMM
protected MatrixI solveMM(MatrixI A, MatrixI b) throws EvaluationException
- Throws:
EvaluationException
-
solveMV
protected VectorI solveMV(MatrixI A, VectorI b) throws EvaluationException
- Throws:
EvaluationException
-
solve
public java.lang.Object solve(java.lang.Object A, java.lang.Object B) throws EvaluationExceptionDescription copied from interface:MatrixFieldISolve equation A * X = B- Specified by:
solvein interfaceMatrixFieldI- Parameters:
A- a square matrixB- either a vector or matrix with same number of rows as A- Returns:
- a vector or matrix solving equations
- Throws:
EvaluationException- if matrix is not square or is singular
-
-