Class GenericMatrixField<E>
- java.lang.Object
-
- com.singularsys.extensions.matrix.genericmat.GenericMatrixField<E>
-
- Type Parameters:
E- Type of an individual element.Subclasses should implement the methods
addEle(Object, Object)to add elements of the base field.
- All Implemented Interfaces:
FieldI,IntegerConvertor,MatrixFieldI,JepComponent,java.io.Serializable
- Direct Known Subclasses:
ComplexMatrixField,FieldMatrixField,GenericFieldMatrixField,SimpleMatrixField
public abstract class GenericMatrixField<E> extends java.lang.Object implements MatrixFieldI
A Generic matrix field providing default implementations for all operations. Sub classes just need to provide implementations ofaddEle(Object, Object)etc.- Author:
- Richard Morris
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected GenericMatrixFactory<E>mf
-
Constructor Summary
Constructors Constructor Description GenericMatrixField(GenericMatrixFactory<E> mf)Standard constructor.GenericMatrixField(GenericMatrixFactory<E> 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 protected GenericMatrix<E>add(GenericMatrix<E> lm, GenericMatrix<E> rm)protected GenericVector<E>add(GenericVector<E> lv, GenericVector<E> rv)java.lang.Objectadd(java.lang.Object l, java.lang.Object r)Add two members of the field.protected abstract EaddEle(E l, E r)Adds two elements of the vector/matrixjava.lang.Booleanand(java.lang.Object l, java.lang.Object r)Logical and.protected abstract java.lang.BooleanandEle(E l, E r)protected EcalcSize(E ele)Get the current "size" of an elementprotected booleancmpSize(E size, E max)Compare current "size" to maximum.java.lang.Objectcross(GenericVector<E> lv, GenericVector<E> rv)java.lang.Objectcross(java.lang.Object l, java.lang.Object r)The cross product of two vectorsprotected Edet(GenericMatrix<E> l)java.lang.Objectdet(java.lang.Object l)The determinant of a matrixprotected GenericMatrix<E>div(GenericMatrix<E> lm, java.lang.Object r)protected GenericVector<E>div(GenericVector<E> lv, java.lang.Object r)java.lang.Objectdiv(java.lang.Object l, java.lang.Object r)Divides two members of the field.protected abstract EdivEle(E l, E r)protected Edot(GenericVector<E> lv, GenericVector<E> rv)java.lang.Objectdot(java.lang.Object l, java.lang.Object r)The dot product of two vectorsprotected booleaneq(GenericMatrix<E> lm, GenericMatrix<E> rm)protected booleaneq(GenericVector<E> lv, GenericVector<E> rv)java.lang.Booleaneq(java.lang.Object l, java.lang.Object r)Equalsprotected abstract java.lang.BooleaneqEle(E l, E r)java.lang.Booleange(java.lang.Object l, java.lang.Object r)Greater or equal toprotected abstract java.lang.BooleangeEle(E l, E r)JepComponentgetLightWeightInstance()Gets a light-weight instance suitable for using in multiple threads.abstract EgetOne()Get the multiplicative identity for this field.abstract EgetZero()Get the additive identity for this fieldjava.lang.Booleangt(java.lang.Object l, java.lang.Object r)Greater thanprotected abstract java.lang.BooleangtEle(E l, E r)voidinit(Jep jep)Initialize the component.java.lang.Objectinv(java.lang.Object l)Returns the inverse of a square matrix.protected GenericMatrix<E>invMat(GenericMatrix<E> mat)java.lang.Booleanle(java.lang.Object l, java.lang.Object r)Less than or equals toprotected abstract java.lang.BooleanleEle(E l, E r)java.lang.Booleanlt(java.lang.Object l, java.lang.Object r)Less thanprotected abstract java.lang.BooleanltEle(E l, E r)protected GenericMatrix<E>minor(GenericMatrix<E> l, int row, int col)Creates the matrix of minors by excluding one row and one columnjava.lang.Objectmod(java.lang.Object l, java.lang.Object r)Mod operation not defined for matricesprotected abstract EmodEle(E l, E r)protected GenericMatrix<E>mul(GenericMatrix<E> lm, GenericMatrix<E> rm)protected GenericVector<E>mul(GenericMatrix<E> lm, GenericVector<E> rv)protected GenericMatrix<E>mul(GenericMatrix<E> lm, java.lang.Object r)protected GenericVector<E>mul(GenericVector<E> lv, GenericMatrix<E> rm)protected GenericMatrix<E>mul(GenericVector<E> lv, GenericVector<E> rv)protected GenericVector<E>mul(GenericVector<E> lv, java.lang.Object r)java.lang.Objectmul(java.lang.Object l, java.lang.Object r)Multiplies two members of the field.protected abstract EmulEle(E l, E r)java.lang.Booleanne(java.lang.Object l, java.lang.Object r)Not Equalsprotected abstract java.lang.BooleanneEle(E l, E r)protected GenericMatrix<E>neg(GenericMatrix<E> lm)protected GenericVector<E>neg(GenericVector<E> lv)java.lang.Objectneg(java.lang.Object l)The negation -x of an element.protected abstract EnegEle(E l)java.lang.Booleannot(java.lang.Object l)Logical not.protected abstract java.lang.BooleannotEle(E l)java.lang.Booleanor(java.lang.Object l, java.lang.Object r)Logical or.protected abstract java.lang.BooleanorEle(E l, E r)java.lang.Objectpow(java.lang.Object l, java.lang.Object r)Pow operation not defined for matricesprotected abstract EpowEle(E l, E r)java.lang.Objectsolve(java.lang.Object A, java.lang.Object B)Solve equation A * X = Bprotected MatrixIsolveMM(GenericMatrix<E> A, GenericMatrix<E> b)protected VectorIsolveMV(GenericMatrix<E> A, GenericVector<E> b)protected GenericMatrix<E>sub(GenericMatrix<E> lm, GenericMatrix<E> rm)protected GenericVector<E>sub(GenericVector<E> lv, GenericVector<E> rv)java.lang.Objectsub(java.lang.Object l, java.lang.Object r)Subtract two members of the field.protected abstract EsubEle(E l, E r)protected voidsubtractMul(GenericMatrix<E> m, int targetRow, int sourceRow, E mul)Subtract a multiply of the source row from the targetm(t,j) = m(t,j) - mul * m(s,j)protected voidswapRows(MatrixI m, int i, int j)In place swap of two rowsjava.lang.Objecttrace(GenericMatrix<E> l)java.lang.Objecttrace(java.lang.Object l)Returns the trace of a matrix.protected GenericMatrix<E>trans(GenericMatrix<E> l)java.lang.Objecttrans(java.lang.Object l)Transpose of a matrix-
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
-
-
-
-
Field Detail
-
mf
protected GenericMatrixFactory<E> mf
-
-
Constructor Detail
-
GenericMatrixField
public GenericMatrixField(GenericMatrixFactory<E> mf)
Standard constructor.- Parameters:
mf- The factory used to generate matrices
-
GenericMatrixField
public GenericMatrixField(GenericMatrixFactory<E> 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 E addEle(E l, E r) throws EvaluationException
Adds two elements of the vector/matrix- Parameters:
l- lhs elementr- rhs element- Returns:
- their sum
- Throws:
EvaluationException
-
subEle
protected abstract E subEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
negEle
protected abstract E negEle(E l) throws EvaluationException
- Throws:
EvaluationException
-
mulEle
protected abstract E mulEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
modEle
protected abstract E modEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
divEle
protected abstract E divEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
powEle
protected abstract E powEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
eqEle
protected abstract java.lang.Boolean eqEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
neEle
protected abstract java.lang.Boolean neEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
ltEle
protected abstract java.lang.Boolean ltEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
leEle
protected abstract java.lang.Boolean leEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
gtEle
protected abstract java.lang.Boolean gtEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
geEle
protected abstract java.lang.Boolean geEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
andEle
protected abstract java.lang.Boolean andEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
orEle
protected abstract java.lang.Boolean orEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
notEle
protected abstract java.lang.Boolean notEle(E l) throws EvaluationException
- Throws:
EvaluationException
-
add
public java.lang.Object add(java.lang.Object l, java.lang.Object r) throws EvaluationExceptionDescription copied from interface:FieldIAdd two members of the field.- Specified by:
addin 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
-
add
protected GenericVector<E> add(GenericVector<E> lv, GenericVector<E> rv) throws EvaluationException
- Throws:
EvaluationException
-
add
protected GenericMatrix<E> add(GenericMatrix<E> lm, GenericMatrix<E> rm) 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
-
sub
protected GenericMatrix<E> sub(GenericMatrix<E> lm, GenericMatrix<E> rm) throws EvaluationException
- Throws:
EvaluationException
-
sub
protected GenericVector<E> sub(GenericVector<E> lv, GenericVector<E> rv) 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
-
neg
protected GenericMatrix<E> neg(GenericMatrix<E> lm) throws EvaluationException
- Throws:
EvaluationException
-
neg
protected GenericVector<E> neg(GenericVector<E> lv) 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
-
mul
protected GenericMatrix<E> mul(GenericMatrix<E> lm, GenericMatrix<E> rm) throws EvaluationException
- Throws:
EvaluationException
-
mul
protected GenericVector<E> mul(GenericMatrix<E> lm, GenericVector<E> rv) throws EvaluationException
- Throws:
EvaluationException
-
mul
protected GenericVector<E> mul(GenericVector<E> lv, GenericMatrix<E> rm) throws EvaluationException
- Throws:
EvaluationException
-
mul
protected GenericMatrix<E> mul(GenericVector<E> lv, GenericVector<E> rv) throws EvaluationException
- Throws:
EvaluationException
-
mul
protected GenericMatrix<E> mul(GenericMatrix<E> lm, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
mul
protected GenericVector<E> mul(GenericVector<E> lv, 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
-
div
protected GenericVector<E> div(GenericVector<E> lv, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
div
protected GenericMatrix<E> div(GenericMatrix<E> lm, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
mod
public java.lang.Object mod(java.lang.Object l, java.lang.Object r) throws EvaluationExceptionMod operation not defined for matrices- Specified by:
modin interfaceFieldI- Parameters:
l- left hand argumentr- right hand argument- Returns:
- null
- Throws:
EvaluationException
-
pow
public java.lang.Object pow(java.lang.Object l, java.lang.Object r) throws EvaluationExceptionPow operation not defined for matrices- Specified by:
powin interfaceFieldI- Parameters:
l- left hand argumentr- right hand argument- Returns:
- null
- 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
-
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
-
eq
protected boolean eq(GenericMatrix<E> lm, GenericMatrix<E> rm) throws EvaluationException
- Throws:
EvaluationException
-
eq
protected boolean eq(GenericVector<E> lv, GenericVector<E> rv) 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
-
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
-
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
-
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
-
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
-
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
-
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
-
det
public java.lang.Object det(java.lang.Object l) throws EvaluationExceptionDescription copied from interface:MatrixFieldIThe determinant of a matrix- Specified by:
detin interfaceMatrixFieldI- Returns:
- the determinant of mat if it is a matrix
- Throws:
EvaluationException
-
det
protected E det(GenericMatrix<E> l) throws EvaluationException
- Throws:
EvaluationException
-
trace
public java.lang.Object trace(java.lang.Object l) throws EvaluationExceptionDescription copied from interface:MatrixFieldIReturns the trace of a matrix.- Specified by:
tracein interfaceMatrixFieldI- Parameters:
l- the matrix- Returns:
- the trace
- Throws:
EvaluationException
-
trace
public java.lang.Object trace(GenericMatrix<E> l) throws EvaluationException
- Throws:
EvaluationException
-
minor
protected GenericMatrix<E> minor(GenericMatrix<E> l, int row, int col) throws EvaluationException
Creates the matrix of minors by excluding one row and one column- Parameters:
l-row- the row to excludecol- the column to exclude- Returns:
- matrix of minors
- Throws:
EvaluationException
-
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
-
trans
protected GenericMatrix<E> trans(GenericMatrix<E> l)
-
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
-
dot
protected E dot(GenericVector<E> lv, GenericVector<E> rv) throws EvaluationException
- Throws:
EvaluationException
-
cross
public java.lang.Object cross(java.lang.Object l, java.lang.Object r) throws EvaluationExceptionDescription copied from interface:MatrixFieldIThe cross product of two vectors- Specified by:
crossin interfaceMatrixFieldI- Returns:
- a vector with the cross product
- Throws:
EvaluationException- if either vectors not of length 3
-
cross
public java.lang.Object cross(GenericVector<E> lv, GenericVector<E> rv) throws EvaluationException
- 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
-
subtractMul
protected void subtractMul(GenericMatrix<E> m, int targetRow, int sourceRow, E mul) throws EvaluationException
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
-
getZero
public abstract E getZero()
Description copied from interface:FieldIGet the additive identity for this field
-
getOne
public abstract E getOne()
Description copied from interface:FieldIGet the multiplicative identity for this field.
-
invMat
protected GenericMatrix<E> invMat(GenericMatrix<E> mat) throws EvaluationException
- Throws:
EvaluationException
-
calcSize
protected E calcSize(E ele) throws EvaluationException
Get the current "size" of an element- Parameters:
ele-- Returns:
- Throws:
EvaluationException
-
cmpSize
protected boolean cmpSize(E size, E max) throws EvaluationException
Compare current "size" to maximum.- Parameters:
size- currentmax- maximum- Returns:
- true is size > max
- Throws:
EvaluationException
-
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(GenericMatrix<E> A, GenericMatrix<E> b) throws EvaluationException
- Throws:
EvaluationException
-
solveMV
protected VectorI solveMV(GenericMatrix<E> A, GenericVector<E> 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
-
init
public void init(Jep jep)
Description copied from interface:JepComponentInitialize the component. This methods is called whenever a component is added to Jep. Hence it allows components to keep track of the other components they may rely on.- Specified by:
initin interfaceJepComponent- Parameters:
jep- the current Jep instance
-
getLightWeightInstance
public JepComponent getLightWeightInstance()
Description copied from interface:JepComponentGets a light-weight instance suitable for using in multiple threads.- Specified by:
getLightWeightInstancein interfaceJepComponent- Returns:
- either an new instance, null or 'this'.
-
-