Class AbstractMatrixField
java.lang.Object
com.singularsys.extensions.matrix.AbstractMatrixField
- All Implemented Interfaces:
FieldI,IntegerConvertor,MatrixFieldI,JepComponent,Serializable
- Direct Known Subclasses:
DoubleMatrixField,SequenceMatrixField
An abstract base class for implementations of MatrixFieldI. In general the
GenericMatrixField
should be used. This class is for case when the matrix does not implement
GenericMatrix such as an
double[][].- Since:
- Jep 3.5 / Extensions 2.0
- Author:
- Richard Morris
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructionAbstractMatrixField(MatrixFactoryI mf, boolean skipElements) Constructor where operations on the base field can be switched off. -
Method Summary
Modifier and TypeMethodDescriptionAdds two matrices or vectors.protected abstract Objectprotected abstract MatrixIprotected abstract VectorIAdd two vectorsLogical and.protected abstract BooleanDefault inefficient implementation.protected ObjectDefault inefficient implementation.Determinant of a matrixprotected ObjectReturn the determinant of a matrix.Divides two members of the field.protected abstract Objectprotected abstract MatrixIprotected abstract VectorIThe dot product of two vectorsprotected ObjectDefault inefficient implementation.Try to convert argument to base type of elements of Vector/Matrix.Equalsprotected abstract Booleanprotected abstract Booleanprotected abstract BooleanGreater or equal toprotected abstract BooleanGreater thanprotected abstract BooleanReturns the inverse of a square matrix.protected MatrixIFinds the inverse of a matrix.Less than or equals toprotected abstract BooleanLess thanprotected abstract Booleanprotected MatrixIFinds the minor matrix formed by excluding a row and vectorThe modulus of two members of the field.protected abstract ObjectMultiplies two members of the field.protected abstract Objectprotected abstract MatrixIprotected abstract MatrixIprotected abstract VectorIprotected voidIn place multiply all elements of a row by a numberprotected abstract VectorIprotected abstract VectorIprotected abstract MatrixINot Equalsprotected abstract BooleanThe negation -x of an element.protected abstract Objectprotected abstract MatrixIprotected abstract VectorIprotected abstract Booleanprotected abstract BooleanLogical not.protected abstract BooleanLogical or.protected abstract BooleanThe power operator.protected abstract ObjectSolve equation A * X = Bprotected MatrixIprotected VectorISubtract two members of the field.protected abstract Objectprotected abstract MatrixIprotected voidsubtractMul(MatrixI m, int targetRow, int sourceRow, Object mul) In place subtract a multiple of the source row from the targetm(t,j) = m(t,j) - mul * m(s,j)protected abstract VectorIprotected voidIn place swap of two rowsTrace of a matrixprotected ObjectDefault inefficient implementation.Transpose of a matrixprotected ObjectTranspose of a vector, i.e. a copy of the vector.Methods 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
getLightWeightInstance, init
-
Field Details
-
mf
-
-
Constructor Details
-
AbstractMatrixField
Construction- Parameters:
mf- corresponding matrix factory
-
AbstractMatrixField
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
- Throws:
EvaluationException
-
addVV
Add two vectors- Parameters:
lv- lhs vectorrv- rhs vector- Returns:
- the sum of the vectors
- Throws:
EvaluationException- if the dimension do not match
-
addMM
- Throws:
EvaluationException
-
add
Adds two matrices or vectors. Calls eitheraddVV(VectorI, VectorI),addMM(MatrixI, MatrixI)oraddEle(Object, Object)* 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- if sizes do not match or attempts to add object of other types
-
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
-
subEle
- Throws:
EvaluationException
-
subVV
- Throws:
EvaluationException
-
subMM
- 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
-
negEle
- Throws:
EvaluationException
-
negV
- Throws:
EvaluationException
-
negM
- 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
-
mulEle
- Throws:
EvaluationException
-
mulVO
- Throws:
EvaluationException
-
mulMO
- Throws:
EvaluationException
-
mulVV
- Throws:
EvaluationException
-
mulVM
- Throws:
EvaluationException
-
mulMV
- Throws:
EvaluationException
-
mulMM
- 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
-
divEle
- Throws:
EvaluationException
-
divVO
- Throws:
EvaluationException
-
divMO
- 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
-
modEle
- Throws:
EvaluationException
-
mod
Description 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
- Throws:
EvaluationException
-
pow
Description 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
- Throws:
EvaluationException
-
eqVV
- Throws:
EvaluationException
-
eqMM
- 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
-
neEle
- Throws:
EvaluationException
-
neVV
- Throws:
EvaluationException
-
neMM
- Throws:
EvaluationException
-
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
-
andEle
- Throws:
EvaluationException
-
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
-
orEle
- Throws:
EvaluationException
-
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
-
notEle
- Throws:
EvaluationException
-
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
-
gtEle
- 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
-
geEle
- Throws:
EvaluationException
-
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
-
ltEle
- Throws:
EvaluationException
-
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
-
leEle
- Throws:
EvaluationException
-
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
-
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
-
transM
- Throws:
EvaluationException
-
transV
Transpose of a vector, i.e. a copy of the vector. Default implementation is just to inefficiently return a copy of the vector.- Parameters:
l- a vector- Returns:
- a new vector
- Throws:
EvaluationException- if necessary
-
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
-
dotVV
Default inefficient implementation. Will only be called if vectors are of equal lengths- Parameters:
lv- lhs vectorrv- rhs vector- Returns:
- The dot product
- Throws:
EvaluationException- on error
-
cross
Default inefficient implementation.- Specified by:
crossin interfaceMatrixFieldI- Parameters:
l-r-- Returns:
- a vector with the cross product
- Throws:
EvaluationException- if vectors not of length 3
-
crossVV
Default inefficient implementation.- Throws:
EvaluationException
-
traceM
Default inefficient implementation.- Throws:
EvaluationException
-
trace
Trace of a matrix- Specified by:
tracein interfaceMatrixFieldI- Parameters:
l- the matrix- Returns:
- the trace
- Throws:
EvaluationException
-
det
Determinant of a matrix- Specified by:
detin interfaceMatrixFieldI- Parameters:
m- the matrix- Returns:
- the determinant
- Throws:
EvaluationException- if matrix is not square.
-
detM
Return the determinant of a matrix. Does not check sizes.- Parameters:
mat- the matrix- Returns:
- the determinant
- Throws:
EvaluationException- on error
-
minor
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- on error
-
swapRows
In place swap of two rows- Parameters:
m- matrixi- index of first rowj- index of second row- Throws:
EvaluationException- on error
-
mulRow
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- on error
-
subtractMul
protected void subtractMul(MatrixI m, int targetRow, int sourceRow, Object mul) throws EvaluationException In place subtract a multiple of the source row from the targetm(t,j) = m(t,j) - mul * m(s,j)- Parameters:
m- matrix to operate ontargetRow- row to modifysourceRow- source rowmul- multiplier- Throws:
EvaluationException
-
invM
Finds the inverse of a matrix. Default implementation uses Gauss-Jordan with partial pivoting- Parameters:
mat- the matrix- Returns:
- the inverse
- Throws:
EvaluationException- if matrix is singular
-
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
-