Class GenericMatrixField<E>
java.lang.Object
com.singularsys.extensions.matrix.genericmat.GenericMatrixField<E>
- Type Parameters:
E- Type of the individual elements.Subclasses should implement the methods
addEle(Object, Object)to add elements of the base field.
- All Implemented Interfaces:
FieldI,IntegerConvertor,MatrixFieldI,JepComponent,Serializable
- Direct Known Subclasses:
ComplexMatrixField,FieldMatrixField,GenericFieldMatrixField,SimpleMatrixField
A Generic matrix field providing default implementations
for all operations.
Sub classes just need to provide implementations of
addEle(Object, Object) etc.- Author:
- Richard Morris
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionStandard constructor.GenericMatrixField(GenericMatrixFactory<E> mf, boolean skipElements) Constructor where operations on the base field can be switched off. -
Method Summary
Modifier and TypeMethodDescriptionprotected GenericMatrix<E> add(GenericMatrix<E> lm, GenericMatrix<E> rm) protected GenericVector<E> add(GenericVector<E> lv, GenericVector<E> rv) Add two members of the field.protected abstract EAdds two elements of the vector/matrixLogical and.protected abstract Booleanprotected EGet the current "size" of an elementprotected booleanCompare current "size" to maximum.cross(GenericVector<E> lv, GenericVector<E> rv) The cross product of two vectorsprotected Edet(GenericMatrix<E> l) The determinant of a matrixprotected GenericMatrix<E> div(GenericMatrix<E> lm, Object r) protected GenericVector<E> div(GenericVector<E> lv, Object r) Divides two members of the field.protected abstract Eprotected Edot(GenericVector<E> lv, GenericVector<E> rv) The dot product of two vectorsTry to convert argument to base type of elements of Vector/Matrix.protected booleaneq(GenericMatrix<E> lm, GenericMatrix<E> rm) protected booleaneq(GenericVector<E> lv, GenericVector<E> rv) Equalsprotected abstract BooleanGreater or equal toprotected abstract BooleanGets 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 fieldGreater thanprotected abstract BooleanReturns the inverse of a square matrix.protected GenericMatrix<E> invMat(GenericMatrix<E> mat) Less than or equals toprotected abstract BooleanLess thanprotected abstract Booleanprotected GenericMatrix<E> minor(GenericMatrix<E> l, int row, int col) Creates the matrix of minors by excluding one row and one columnMod operation not defined for matricesprotected abstract Eprotected 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, 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, Object r) Multiplies two members of the field.protected abstract ENot Equalsprotected abstract Booleanprotected GenericMatrix<E> neg(GenericMatrix<E> lm) protected GenericVector<E> neg(GenericVector<E> lv) The negation -x of an element.protected abstract ELogical not.protected abstract BooleanLogical or.protected abstract BooleanPow operation not defined for matricesprotected abstract ESolve 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) Subtract two members of the field.protected abstract Eprotected voidsubtractMul(GenericMatrix<E> m, int targetRow, int sourceRow, E mul) Subtracts a multiple of the source row from the targetm(t,j) = m(t,j) - mul * m(s,j)protected voidIn place swap of two rowstrace(GenericMatrix<E> l) Returns the trace of a matrix.protected GenericMatrix<E> trans(GenericMatrix<E> l) protected GenericVector<E> trans(GenericVector<E> l) Transpose of a matrixMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.singularsys.extensions.field.IntegerConvertor
convertFromInt, convertToIntMethods inherited from interface com.singularsys.jep.JepComponent
init
-
Field Details
-
mf
-
-
Constructor Details
-
GenericMatrixField
Standard constructor.- Parameters:
mf- The factory used to generate matrices
-
GenericMatrixField
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. It is 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 Details
-
addEle
Adds two elements of the vector/matrix- Parameters:
l- lhs elementr- rhs element- Returns:
- their sum
- Throws:
EvaluationException
-
subEle
- Throws:
EvaluationException
-
negEle
- Throws:
EvaluationException
-
mulEle
- Throws:
EvaluationException
-
modEle
- Throws:
EvaluationException
-
divEle
- Throws:
EvaluationException
-
powEle
- Throws:
EvaluationException
-
eqEle
- Throws:
EvaluationException
-
neEle
- Throws:
EvaluationException
-
ltEle
- Throws:
EvaluationException
-
leEle
- Throws:
EvaluationException
-
gtEle
- Throws:
EvaluationException
-
geEle
- Throws:
EvaluationException
-
andEle
- Throws:
EvaluationException
-
orEle
- Throws:
EvaluationException
-
notEle
- Throws:
EvaluationException
-
add
Description 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
-
elementValue
Try to convert argument to base type of elements of Vector/Matrix. CallsMatrixFactoryI.elementValue(Object)to check base value is correct type.- Parameters:
o- item to convert- Returns:
- o
- Throws:
EvaluationException- if the argument is a vector or matrix
-
add
- Throws:
EvaluationException
-
add
- Throws:
EvaluationException
-
sub
Description 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
- Throws:
EvaluationException
-
sub
- Throws:
EvaluationException
-
neg
Description 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
- Throws:
EvaluationException
-
neg
- Throws:
EvaluationException
-
mul
Description 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
- Throws:
EvaluationException
-
mul
- Throws:
EvaluationException
-
mul
- Throws:
EvaluationException
-
mul
- Throws:
EvaluationException
-
mul
- Throws:
EvaluationException
-
mul
- Throws:
EvaluationException
-
div
Description 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
- Throws:
EvaluationException
-
div
- Throws:
EvaluationException
-
mod
Mod operation not defined for matrices- Specified by:
modin interfaceFieldI- Parameters:
l- left-hand argumentr- right-hand argument- Returns:
- null
- Throws:
EvaluationException
-
pow
Pow operation not defined for matrices- Specified by:
powin interfaceFieldI- Parameters:
l- left-hand argumentr- right-hand argument- Returns:
- null
- Throws:
EvaluationException
-
eq
Description 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
Description 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
- Throws:
EvaluationException
-
eq
- Throws:
EvaluationException
-
gt
Description 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
Description 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
Description 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
Description 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
Description copied from interface:FieldILogical and.- Specified by:
andin 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
-
or
Description 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
Description 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
Description copied from interface:MatrixFieldIThe determinant of a matrix- Specified by:
detin interfaceMatrixFieldI- Parameters:
l-- Returns:
- the determinant of mat if it is a matrix
- Throws:
EvaluationException
-
det
- Throws:
EvaluationException
-
trace
Description copied from interface:MatrixFieldIReturns the trace of a matrix.- Specified by:
tracein interfaceMatrixFieldI- Parameters:
l- the matrix- Returns:
- the trace
- Throws:
EvaluationException
-
trace
- Throws:
EvaluationException
-
minor
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
-
trans
Description copied from interface:MatrixFieldITranspose of a matrix- Specified by:
transin interfaceMatrixFieldI- Parameters:
l- the matrix- Returns:
- a matrix containing the transpose
- Throws:
EvaluationException
-
trans
-
trans
- Throws:
EvaluationException
-
dot
Description copied from interface:MatrixFieldIThe dot product of two vectors- Specified by:
dotin interfaceMatrixFieldI- Parameters:
l-r-- Returns:
- the dot product if both arguments are vectors, null otherwise.
- Throws:
EvaluationException
-
dot
- Throws:
EvaluationException
-
cross
Description copied from interface:MatrixFieldIThe cross product of two vectors- Specified by:
crossin interfaceMatrixFieldI- Parameters:
l-r-- Returns:
- a vector with the cross product
- Throws:
EvaluationException- if either vectors not of length 3
-
cross
- Throws:
EvaluationException
-
swapRows
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 Subtracts a multiple of the source row from the targetm(t,j) = m(t,j) - mul * m(s,j)- Parameters:
m-targetRow-sourceRow-mul-- Throws:
EvaluationException
-
getZero
Description copied from interface:FieldIGet the additive identity for this field -
getOne
Description copied from interface:FieldIGet the multiplicative identity for this field. -
invMat
- Throws:
EvaluationException
-
calcSize
Get the current "size" of an element- Parameters:
ele-- Returns:
- Throws:
EvaluationException
-
cmpSize
Compare current "size" to maximum.- Parameters:
size- currentmax- maximum- Returns:
- true is size > max
- Throws:
EvaluationException
-
inv
Description 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
- Throws:
EvaluationException
-
solveMV
- Throws:
EvaluationException
-
solve
Description 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
-
getLightWeightInstance
Description copied from interface:JepComponentGets a light-weight instance suitable for using in multiple threads.- Specified by:
getLightWeightInstancein interfaceJepComponent- Returns:
- either a new instance, null or 'this'.
-