Package org.djunits.vecmat.def
Class VectorMatrix<Q extends Quantity<Q,U>,U extends UnitInterface<U,Q>,VM extends VectorMatrix<Q,U,VM,SI,H>,SI extends VectorMatrix<SIQuantity,SIUnit,SI,?,?>,H extends VectorMatrix<?,?,?,?,?>>
java.lang.Object
org.djunits.vecmat.def.VectorMatrix<Q,U,VM,SI,H>
- Type Parameters:
Q- the quantity typeU- the unit typeVM- the 'SELF' vector or matrix typeSI- the vector or matrix type with generics <SIQuantity, SIUnit<H- the generic vector or matrix type with generics <?, ?< for Hadamard operations
- All Implemented Interfaces:
Serializable,Additive<VM>,Scalable<VM>,Value<U,,VM> Hadamard<H,SI>
- Direct Known Subclasses:
Matrix,QuantityTable
public abstract class VectorMatrix<Q extends Quantity<Q,U>,U extends UnitInterface<U,Q>,VM extends VectorMatrix<Q,U,VM,SI,H>,SI extends VectorMatrix<SIQuantity,SIUnit,SI,?,?>,H extends VectorMatrix<?,?,?,?,?>>
extends Object
implements Value<U,VM>, Scalable<VM>, Additive<VM>, Hadamard<H,SI>
VectorMatrix contains a number of standard operations on vectors and matrices of relative quantities.
Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djunits.org. The DJUNITS project is distributed under a three-clause BSD-style license.
- Author:
- Alexander Verbraeck
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabs()Make the SI-values of this element absolute.Return the a vector or matrix with entries that contain the sum of the element and the increment.Add an element to this element, based on the SI-values.Convert this vector or matrix to aMatrixNxM.Convert this vector or matrix to aQuantityTable.protected voidcheckCol(int col) Check if the 0-based column is within bounds.protected voidcheckRow(int row) Check if the 0-based row is within bounds.abstract intcols()Return the number of columns.divideElements(H other) Divide the elements of this vector, matrix or table on an element-by-element basis with those of another collection of the same type (but possibly representing another quantity).divideElements(Dimensionless quantity) Multiply the elements of this vector, matrix or table by the given quantity.get(int row, int col) Return the quantity at position (row, col), where both row and col are 0-based values.Q[]getColumnScalars(int col) Retrieve a column (0-based) from the matrix as an array of scalars.abstract double[]getColumnSi(int col) Return an array with SI-values for the given column (0-based) from the vector or matrix.getColumnVector(int col) Return a quantity column (0-based) from the vector or matrix.Retrieve the unit of this Value.Q[]getRowScalars(int row) Retrieve a row (0-based) from the matrix as an array of scalars.abstract double[]getRowSi(int row) Return an array with SI-values for the given row (0-based) from the vector or matrix.getRowVector(int row) Return a quantity row (0-based) from the vector or matrix.Q[][]Return the vector or matrix as a 2D array of scalars.abstract VMinstantiateSi(double[] siNew) Return a new vector or matrix with the given SI or BASE values.abstract SIinstantiateSi(double[] siNew, SIUnit siUnit) Return a new vector or matrix in SI-units with the given SI or BASE values.Invert the vector, matrix or table on an element-by-element basis.booleanIndicate whether this is a Relative Value.max()Return the maximum value of the elements of the vector or matrix.protected voidmcheckCol(int mCol) Check if the 1-based column is within bounds.protected voidmcheckRow(int mRow) Check if the 1-based row is within bounds.mean()Return the mean value of the elements of the vector or matrix.median()Return the median value of the elements of the vector or matrix.mget(int mRow, int mCol) Return the quantity at position (row, col), where both row and col are 1-based values.Q[]mgetColumnScalars(int mCol) Retrieve a column (1-based) from the matrix as an array of scalars.double[]mgetColumnSi(int mCol) Return an array with SI-values for the given column (1-based) from the vector or matrix.mgetColumnVector(int mCol) Return a quantity column (1-based) from the vector or matrix.Q[]mgetRowScalars(int mRow) Retrieve a row (1-based) from the matrix as an array of scalars.double[]mgetRowSi(int mRow) Return an array with SI-values for the given row (1-based) from the vector or matrix.mgetRowVector(int mRow) Return a quantity row (1-based) from the vector or matrix.min()Return the minimum value of the elements of the vector or matrix.mode()Return the largest value of the elements of the vector or matrix.doublemsi(int mRow, int mCol) Return the si-value at position (row, col), where both row and col are 1-based values.multiplyElements(H other) Multiply the elements of this vector, matrix or table on an element-by-element basis with those of another collection of the same type (but possibly representing another quantity).multiplyElements(Quantity<?, ?> quantity) Multiply the elements of this vector, matrix or table by the given quantity.multiplyElements(Dimensionless quantity) Multiply the elements of this vector, matrix or table by the given quantity.negate()Negate this element, based on the SI-values.abstract introws()Return the number of rows.scaleBy(double factor) Scale the element by a dimensionless factor, based on the SI-values.setDisplayUnit(U newUnit) Set a new display unit for the value.abstract double[]si()Return a row-major array of SI-values for this matrix or vector.abstract doublesi(int row, int col) Return the si-value at position (row, col), where both row and col are 0-based values.Return the a vector or matrix with entries that contain the value minus the decrement.Subtract an element from this element, based on the SI-values.sum()Return the sum of the values of the elements of the vector or matrix.toString()Return a concise description of this value.Return a concise description of this value with the values expressed in the specified unit.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.djunits.vecmat.operations.Hadamard
divideElementsMethods inherited from interface org.djunits.value.Value
isAbsolute, setDisplayUnit
-
Constructor Details
-
VectorMatrix
Create a new vector or matrix with a unit.- Parameters:
displayUnit- the display unit to use
-
-
Method Details
-
getDisplayUnit
Description copied from interface:ValueRetrieve the unit of this Value.- Specified by:
getDisplayUnitin interfaceValue<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>> - Returns:
- the unit of this Value
-
setDisplayUnit
Description copied from interface:ValueSet a new display unit for the value. Internally, the value will not changed since it is stored in a base unit.- Specified by:
setDisplayUnitin interfaceValue<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>> - Parameters:
newUnit- the new display unit of this value- Returns:
- 'this' for fluent design
-
rows
public abstract int rows()Return the number of rows.- Returns:
- the number of rows
-
cols
public abstract int cols()Return the number of columns.- Returns:
- the number of columns
-
instantiateSi
Return a new vector or matrix with the given SI or BASE values.- Parameters:
siNew- the values for the new vector or matrix in row-major format- Returns:
- a new matrix with the provided SI or BASE values
-
instantiateSi
Return a new vector or matrix in SI-units with the given SI or BASE values.- Parameters:
siNew- the values for the new vector or matrix in row-major formatsiUnit- the new unit for the new vector or matrix- Returns:
- a new matrix with the provided SI or BASE values
-
si
public abstract double[] si()Return a row-major array of SI-values for this matrix or vector. Note that this is NOT a safe copy.- Returns:
- the row-major array of SI-values
-
si
Return the si-value at position (row, col), where both row and col are 0-based values.- Parameters:
row- the row (0-based)col- the column (0-based)- Returns:
- the si-value at position (row, col)
- Throws:
IndexOutOfBoundsException- when row or col < 0 or larger than number of rows/columns - 1.
-
msi
Return the si-value at position (row, col), where both row and col are 1-based values.- Parameters:
mRow- the row (1-based)mCol- the column (1-based)- Returns:
- the si-value at position (row, col)
- Throws:
IndexOutOfBoundsException- when row or col < 1 or larger than number of rows/columns.
-
get
Return the quantity at position (row, col), where both row and col are 0-based values.- Parameters:
row- the row (0-based)col- the column (0-based)- Returns:
- the quantity at position (row, col)
- Throws:
IndexOutOfBoundsException- when row or col < 0 or larger than number of rows/columns - 1.
-
mget
Return the quantity at position (row, col), where both row and col are 1-based values.- Parameters:
mRow- the row (1-based)mCol- the column (1-based)- Returns:
- the quantity at position (row, col)
- Throws:
IndexOutOfBoundsException- when row or col < 1 or larger than number of rows/columns.
-
getScalarGrid
Return the vector or matrix as a 2D array of scalars.- Returns:
- a new Q[rows()][cols()] array; entry [i-1][j-1] contains get(i, j).
-
getRowVector
Return a quantity row (0-based) from the vector or matrix. Note that the specific vector to return can be tightened by the implementing class.- Parameters:
row- the row number to retrieve (0-based)- Returns:
- a row vector with the data at the given row
-
mgetRowVector
Return a quantity row (1-based) from the vector or matrix. Note that the specific vector to return can be tightened by the implementing class.- Parameters:
mRow- the row number to retrieve (1-based)- Returns:
- a row vector with the data at the given row
-
getColumnVector
Return a quantity column (0-based) from the vector or matrix. Note that the specific vector to return can be tightened by the implementing class.- Parameters:
col- the column number to retrieve (0-based)- Returns:
- a column vector with the data at the given column
-
mgetColumnVector
Return a quantity column (1-based) from the vector or matrix. Note that the specific vector to return can be tightened by the implementing class.- Parameters:
mCol- the column number to retrieve (1-based)- Returns:
- a column vector with the data at the given column
-
getRowSi
public abstract double[] getRowSi(int row) Return an array with SI-values for the given row (0-based) from the vector or matrix.- Parameters:
row- the row number to retrieve (0-based)- Returns:
- an array with SI-values with the data at the given row
-
mgetRowSi
public double[] mgetRowSi(int mRow) Return an array with SI-values for the given row (1-based) from the vector or matrix.- Parameters:
mRow- the row number to retrieve (1-based)- Returns:
- an array with SI-values with the data at the given row
-
getColumnSi
public abstract double[] getColumnSi(int col) Return an array with SI-values for the given column (0-based) from the vector or matrix.- Parameters:
col- the column number to retrieve (0-based)- Returns:
- an array with SI-values with the data at the given column
-
mgetColumnSi
public double[] mgetColumnSi(int mCol) Return an array with SI-values for the given column (1-based) from the vector or matrix.- Parameters:
mCol- the column number to retrieve (1-based)- Returns:
- an array with SI-values with the data at the given column
-
isRelative
public boolean isRelative()Description copied from interface:ValueIndicate whether this is a Relative Value.- Specified by:
isRelativein interfaceValue<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>> - Returns:
- whether this is a Relative Value
-
checkRow
protected void checkRow(int row) Check if the 0-based row is within bounds.- Parameters:
row- the 0-based row to check- Throws:
IndexOutOfBoundsException- when row is out of bounds
-
checkCol
protected void checkCol(int col) Check if the 0-based column is within bounds.- Parameters:
col- the 0-based column to check- Throws:
IndexOutOfBoundsException- when column is out of bounds
-
mcheckRow
protected void mcheckRow(int mRow) Check if the 1-based row is within bounds.- Parameters:
mRow- the 1-based row to check- Throws:
IndexOutOfBoundsException- when row is out of bounds
-
mcheckCol
protected void mcheckCol(int mCol) Check if the 1-based column is within bounds.- Parameters:
mCol- the 1-based column to check- Throws:
IndexOutOfBoundsException- when column is out of bounds
-
getRowScalars
Retrieve a row (0-based) from the matrix as an array of scalars.- Parameters:
row- row of the values to retrieve (0-based)- Returns:
- the row as a Scalar array
- Throws:
IndexOutOfBoundsException- in case row is out of bounds
-
mgetRowScalars
Retrieve a row (1-based) from the matrix as an array of scalars.- Parameters:
mRow- row of the values to retrieve (1-based)- Returns:
- the row as a Scalar array
- Throws:
IndexOutOfBoundsException- in case row is out of bounds
-
getColumnScalars
Retrieve a column (0-based) from the matrix as an array of scalars.- Parameters:
col- column of the values to retrieve (0-based)- Returns:
- the column as a Scalar array
- Throws:
IndexOutOfBoundsException- in case column is out of bounds
-
mgetColumnScalars
Retrieve a column (1-based) from the matrix as an array of scalars.- Parameters:
mCol- column of the values to retrieve (1-based)- Returns:
- the column as a Scalar array
- Throws:
IndexOutOfBoundsException- in case column is out of bounds
-
mean
Return the mean value of the elements of the vector or matrix.- Returns:
- the mean value of the elements of the vector or matrix
-
min
Return the minimum value of the elements of the vector or matrix.- Returns:
- the minimum value of the elements of the vector or matrix
-
max
Return the maximum value of the elements of the vector or matrix.- Returns:
- the maximum value of the elements of the vector or matrix
-
mode
Return the largest value of the elements of the vector or matrix.- Returns:
- the largest value of the elements of the vector or matrix
-
median
Return the median value of the elements of the vector or matrix.- Returns:
- the median value of the elements of the vector or matrix
-
sum
Return the sum of the values of the elements of the vector or matrix.- Returns:
- the sum of the values of the elements of the vector or matrix
-
add
Return the a vector or matrix with entries that contain the sum of the element and the increment.- Parameters:
increment- the quantity by which to increase the values of the vector or matrix- Returns:
- a vector or matrix with elements that are incremented by the given quantity
-
subtract
Return the a vector or matrix with entries that contain the value minus the decrement.- Parameters:
decrement- the quantity by which to decrease the values of the vector or matrix- Returns:
- a vector or matrix with elements that are decremented by the given quantity
-
add
Description copied from interface:AdditiveAdd an element to this element, based on the SI-values. Note that this can lead to unwanted effects for elements with Offset scales: 10 °C + 5 °C = 288.15 °C and not 15 °C. -
subtract
Description copied from interface:AdditiveSubtract an element from this element, based on the SI-values. -
negate
Description copied from interface:AdditiveNegate this element, based on the SI-values. Note that this can lead to unwanted effects for elements with Offset scales. A temperature in Celsius that is negated, will have its Kelvin temperatures negated. -
abs
Description copied from interface:AdditiveMake the SI-values of this element absolute. A new element wil be returned. Note that this can lead to unwanted effects for elements with Offset scales. A temperature of -10 degrees Celsius will have its Kelvin temperatures negated. -
scaleBy
Description copied from interface:ScalableScale the element by a dimensionless factor, based on the SI-values. Note that this can lead to unwanted effects for elements with Offset scales. 2 * 10 °C = 293.15 °C and not 20 °C. -
multiplyElements
Multiply the elements of this vector, matrix or table by the given quantity. This is actually a Hadamard operation, but since it is equivalent to a scaleBy operation, it is included in this interface.- Parameters:
quantity- the scalar quantity to multiply by- Returns:
- a vector, matrix or table where the elements have been multiplied by the given quantity
-
divideElements
Multiply the elements of this vector, matrix or table by the given quantity. This is actually a Hadamard operation, but since it is equivalent to a scaleBy operation, it is included in this interface.- Parameters:
quantity- the scalar quantity to multiply by- Returns:
- a vector, matrix or table where the elements have been multiplied by the given quantity
-
invertElements
Description copied from interface:HadamardInvert the vector, matrix or table on an element-by-element basis.- Specified by:
invertElementsin interfaceHadamard<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>> - Returns:
- a vector, matrix or table with an element-by-element inversion (1/value) of the elements
-
multiplyElements
Description copied from interface:HadamardMultiply the elements of this vector, matrix or table on an element-by-element basis with those of another collection of the same type (but possibly representing another quantity).- Specified by:
multiplyElementsin interfaceHadamard<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>> - Parameters:
other- the other collection of the same type- Returns:
- a vector, matrix or table with an element-by-element multiplication of its elements
-
divideElements
Description copied from interface:HadamardDivide the elements of this vector, matrix or table on an element-by-element basis with those of another collection of the same type (but possibly representing another quantity).- Specified by:
divideElementsin interfaceHadamard<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>> - Parameters:
other- the other collection of the same type- Returns:
- a vector, matrix or table with an element-by-element division of this collection's elements and other's elements
-
multiplyElements
Description copied from interface:HadamardMultiply the elements of this vector, matrix or table by the given quantity.- Specified by:
multiplyElementsin interfaceHadamard<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>> - Parameters:
quantity- the scalar quantity to multiply by- Returns:
- a vector, matrix or table where the elements have been multiplied by the given quantity
-
asMatrixNxM
Convert this vector or matrix to aMatrixNxM.- Returns:
- a
MatrixNxNwith identical SI data and display unit
-
asQuantityTable
Convert this vector or matrix to aQuantityTable.- Returns:
- a
QuantityTablewith identical SI data and display unit
-
toString
Description copied from interface:ValueReturn a concise description of this value with the values expressed in the specified unit. -
toString
Description copied from interface:ValueReturn a concise description of this value.
-