Package org.djunits.vecmat.d1
Class Vector1<Q extends Quantity<Q,U>,U extends UnitInterface<U,Q>>
java.lang.Object
org.djunits.vecmat.def.VectorMatrix<Q,U,M,SI,H>
org.djunits.vecmat.def.Matrix<Q,U,V,SI,H>
org.djunits.vecmat.def.Vector<Q,U,Vector1<Q,U>,Vector1<SIQuantity,SIUnit>,Vector1<?,?>>
org.djunits.vecmat.d1.Vector1<Q,U>
- Type Parameters:
Q- the quantity typeU- the unit type
- All Implemented Interfaces:
Serializable,Iterable<Q>,Additive<Vector1<Q,,U>> Scalable<Vector1<Q,,U>> Value<U,,Vector1<Q, U>> Hadamard<Vector1<?,,?>, Vector1<SIQuantity, SIUnit>> Normed<Q,,U> VectorTransposable<Vector1<Q,U>>
public class Vector1<Q extends Quantity<Q,U>,U extends UnitInterface<U,Q>>
extends Vector<Q,U,Vector1<Q,U>,Vector1<SIQuantity,SIUnit>,Vector1<?,?>>
implements VectorTransposable<Vector1<Q,U>>
Vector1 implements a vector with one real-valued entry. The vector is immutable, except for the display unit, which can be
changed. Some of the method that have been defined already for a generic vector have been re-implemented for efficiency.
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.Add an element to this element, based on the SI-values.Return the a vector or matrix with entries that contain the sum of the element and the increment.<TQ extends Quantity<TQ,TU>, TU extends UnitInterface<TU, TQ>>
Vector1<TQ,TU> as(TU targetUnit) Return the vector 'as' a vector with a known quantity, using a unit to express the result in.intcols()Return the number of columns.booleandouble[]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.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 as an array of scalars.inthashCode()instantiateSi(double xSiNew) Return a column or row vector with x and y values in SI or BASE units.instantiateSi(double[] siNew) Return a new vector or matrix with the given SI or BASE values.instantiateSi(double[] siNew, SIUnit siUnit) Return a new vector or matrix in SI-units with the given SI or BASE values.booleanReturn whether this vector is a column vector.booleanIndicate whether this is a Relative Value.iterator()Create and return an iterator over the scalars in this vector in proper sequence.max()Return the maximum value of the elements of the vector or matrix.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.mgetColumnVector(int mCol) Return a quantity column (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.negate()Negate this element, based on the SI-values.normL1()Return the L1-norm of this element, expressed as a quantity.normL2()Return the L2-norm of this element, expressed as a quantity.normLinf()Return the L∞-norm of this element, expressed as a quantity.normLp(int p) Return the Lp-norm of this element, expressed as a quantity.static <Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>>
Vector1<Q,U> of(double xInUnit, U displayUnit) Create a Vector1 without needing generics.introws()Return the number of rows.scaleBy(double factor) Scale the element by a dimensionless factor, based on the SI-values.double[]si()Return the contents of the vector as an array.doublesi(int index) Retrieve an si-value from the vector.doublesi(int row, int col) Return the si-value at position (row, col), where both row and col are 0-based values.intsize()Retrieve the size of the vector.Subtract an element from this element, based on the SI-values.Return the a vector or matrix with entries that contain the value minus the decrement.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.Transpose the vector (swap rows and columns).x()Return the x-value of the vector as a quantity with the correct unit.doublexSi()Return the x-value of the vector in SI or BASE units.Methods inherited from class org.djunits.vecmat.def.Matrix
checkMultiply, checkMultiply, multiplyMethods inherited from class org.djunits.vecmat.def.VectorMatrix
asMatrixNxM, asQuantityTable, checkCol, checkRow, divideElements, divideElements, get, getColumnScalars, getDisplayUnit, getRowScalars, getScalarGrid, invertElements, mcheckCol, mcheckRow, mget, mgetColumnScalars, mgetColumnSi, mgetRowScalars, mgetRowSi, msi, multiplyElements, multiplyElements, multiplyElements, setDisplayUnitMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.djunits.vecmat.operations.Hadamard
divideElementsMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface org.djunits.value.Value
isAbsolute, setDisplayUnit
-
Constructor Details
-
Vector1
Create a new Vector1 with a unit.- Parameters:
xInUnit- the x-value expressed in the given unitdisplayUnit- the display unit to use
-
-
Method Details
-
instantiateSi
Return a column or row vector with x and y values in SI or BASE units.- Parameters:
xSiNew- the x value in SI or BASE units- Returns:
- a new column or row vector with adapted x and y values
-
instantiateSi
Description copied from class:VectorMatrixReturn a new vector or matrix with the given SI or BASE values.- Specified by:
instantiateSiin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, Vector1<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, Vector1<SIQuantity, SIUnit>, Vector1<?, ?>> - 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
-
of
public static <Q extends Quantity<Q,U>, Vector1<Q,U extends UnitInterface<U, Q>> U> of(double xInUnit, U displayUnit) Create a Vector1 without needing generics.- Type Parameters:
Q- the quantity typeU- the unit type- Parameters:
xInUnit- the x-value expressed in the display unitdisplayUnit- the display unit to use- Returns:
- a new Vector1 with a unit
-
size
public int size()Description copied from class:VectorRetrieve the size of the vector. -
rows
public int rows()Description copied from class:VectorMatrixReturn the number of rows. -
cols
public int cols()Description copied from class:VectorMatrixReturn the number of columns. -
transpose
Description copied from interface:VectorTransposableTranspose the vector (swap rows and columns). -
instantiateSi
Description copied from class:VectorMatrixReturn a new vector or matrix in SI-units with the given SI or BASE values.- Specified by:
instantiateSiin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, Vector1<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, Vector1<SIQuantity, SIUnit>, Vector1<?, ?>> - 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
Description copied from class:VectorMatrixReturn the si-value at position (row, col), where both row and col are 0-based values.- Specified by:
siin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, Vector1<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, Vector1<SIQuantity, SIUnit>, Vector1<?, ?>> - 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.
-
isColumnVector
public boolean isColumnVector()Description copied from class:VectorReturn whether this vector is a column vector. -
getRowVector
Description copied from class:VectorMatrixReturn a quantity row (0-based) from the vector or matrix. Note that the specific vector to return can be tightened by the implementing class.- Specified by:
getRowVectorin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, Vector1<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, Vector1<SIQuantity, SIUnit>, Vector1<?, ?>> - Parameters:
row- the row number to retrieve (0-based)- Returns:
- a row vector with the data at the given row
-
mgetRowVector
Description copied from class:VectorMatrixReturn a quantity row (1-based) from the vector or matrix. Note that the specific vector to return can be tightened by the implementing class.- Specified by:
mgetRowVectorin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, Vector1<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, Vector1<SIQuantity, SIUnit>, Vector1<?, ?>> - Parameters:
mRow- the row number to retrieve (1-based)- Returns:
- a row vector with the data at the given row
-
getColumnVector
Description copied from class:VectorMatrixReturn a quantity column (0-based) from the vector or matrix. Note that the specific vector to return can be tightened by the implementing class.- Specified by:
getColumnVectorin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, Vector1<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, Vector1<SIQuantity, SIUnit>, Vector1<?, ?>> - Parameters:
col- the column number to retrieve (0-based)- Returns:
- a column vector with the data at the given column
-
mgetColumnVector
Description copied from class:VectorMatrixReturn a quantity column (1-based) from the vector or matrix. Note that the specific vector to return can be tightened by the implementing class.- Specified by:
mgetColumnVectorin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, Vector1<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, Vector1<SIQuantity, SIUnit>, Vector1<?, ?>> - Parameters:
mCol- the column number to retrieve (1-based)- Returns:
- a column vector with the data at the given column
-
getRowSi
public double[] getRowSi(int row) Description copied from class:VectorMatrixReturn an array with SI-values for the given row (0-based) from the vector or matrix.- Specified by:
getRowSiin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, Vector1<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, Vector1<SIQuantity, SIUnit>, Vector1<?, ?>> - Parameters:
row- the row number to retrieve (0-based)- Returns:
- an array with SI-values with the data at the given row
-
getColumnSi
public double[] getColumnSi(int col) Description copied from class:VectorMatrixReturn an array with SI-values for the given column (0-based) from the vector or matrix.- Specified by:
getColumnSiin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, Vector1<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, Vector1<SIQuantity, SIUnit>, Vector1<?, ?>> - Parameters:
col- the column number to retrieve (0-based)- Returns:
- an array with SI-values with the data at the given column
-
si
Description copied from class:VectorRetrieve an si-value from the vector.- Specified by:
siin classVector<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, Vector1<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, Vector1<SIQuantity, SIUnit>, Vector1<?, ?>> - Parameters:
index- the index (0-based) to retrieve the value from- Returns:
- the value as a Scalar
- Throws:
IndexOutOfBoundsException- in case index is out of bounds
-
iterator
Description copied from class:VectorCreate and return an iterator over the scalars in this vector in proper sequence.- Specified by:
iteratorin interfaceIterable<Q extends Quantity<Q,U>> - Specified by:
iteratorin classVector<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, Vector1<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, Vector1<SIQuantity, SIUnit>, Vector1<?, ?>> - Returns:
- an iterator over the scalars in this vector in proper sequence
-
getScalarArray
Description copied from class:VectorReturn the vector as an array of scalars. -
xSi
public double xSi()Return the x-value of the vector in SI or BASE units.- Returns:
- the x-value of the vector in SI or BASE units
-
si
public double[] si()Return the contents of the vector as an array. -
x
Return the x-value of the vector as a quantity with the correct unit.- Returns:
- the x-value of the vector as a quantity with the correct unit
-
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.- Specified by:
scaleByin interfaceScalable<Q extends Quantity<Q,U>> - Overrides:
scaleByin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, Vector1<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, Vector1<SIQuantity, SIUnit>, Vector1<?, ?>> - Parameters:
factor- the dimensionless scale factor- Returns:
- a new element with all of its SI-values scaled by the dimensionless factor
-
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.- Specified by:
addin interfaceAdditive<Q extends Quantity<Q,U>> - Overrides:
addin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, Vector1<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, Vector1<SIQuantity, SIUnit>, Vector1<?, ?>> - Parameters:
other- the element to add to this element- Returns:
- the sum of the SI-values of this element and the SI-values of the other element
-
subtract
Description copied from interface:AdditiveSubtract an element from this element, based on the SI-values.- Specified by:
subtractin interfaceAdditive<Q extends Quantity<Q,U>> - Overrides:
subtractin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, Vector1<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, Vector1<SIQuantity, SIUnit>, Vector1<?, ?>> - Parameters:
other- the element to subtract from this element- Returns:
- a new element with the SI-values of this element minus the SI-values of the other element
-
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.- Specified by:
negatein interfaceAdditive<Q extends Quantity<Q,U>> - Overrides:
negatein classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, Vector1<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, Vector1<SIQuantity, SIUnit>, Vector1<?, ?>> - Returns:
- a new element with all of its SI-values 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.- Specified by:
absin interfaceAdditive<Q extends Quantity<Q,U>> - Overrides:
absin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, Vector1<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, Vector1<SIQuantity, SIUnit>, Vector1<?, ?>> - Returns:
- a new element with the absolute value for all of its SI-values
-
normL1
Description copied from interface:NormedReturn the L1-norm of this element, expressed as a quantity. The L1-norm is |x1| + |x2| + ... + |xn|. -
normL2
Description copied from interface:NormedReturn the L2-norm of this element, expressed as a quantity. The L2-norm is sqrt(x1^2 + x2^2 + ... + xn^2). -
normLp
Description copied from interface:NormedReturn the Lp-norm of this element, expressed as a quantity. The Ln-norm is (x1^p + x2^p + ... + xn^p)^(1/p). -
normLinf
Description copied from interface:NormedReturn the L∞-norm of this element, expressed as a quantity. The L∞-norm is max(|x1|, |x2|, ..., |xn|). -
mean
Description copied from class:VectorMatrixReturn the mean value of the elements of the vector or matrix. -
min
Description copied from class:VectorMatrixReturn the minimum value of the elements of the vector or matrix. -
max
Description copied from class:VectorMatrixReturn the maximum value of the elements of the vector or matrix. -
mode
Description copied from class:VectorMatrixReturn the largest value of the elements of the vector or matrix. -
median
Description copied from class:VectorMatrixReturn the median value of the elements of the vector or matrix. -
sum
Description copied from class:VectorMatrixReturn the sum of the values of the elements of the vector or matrix. -
add
Description copied from class:VectorMatrixReturn the a vector or matrix with entries that contain the sum of the element and the increment.- Overrides:
addin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, Vector1<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, Vector1<SIQuantity, SIUnit>, Vector1<?, ?>> - 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
Description copied from class:VectorMatrixReturn the a vector or matrix with entries that contain the value minus the decrement.- Overrides:
subtractin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, Vector1<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, Vector1<SIQuantity, SIUnit>, Vector1<?, ?>> - 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
-
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>> - Overrides:
isRelativein classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, Vector1<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, Vector1<SIQuantity, SIUnit>, Vector1<?, ?>> - Returns:
- whether this is a Relative Value
-
as
public <TQ extends Quantity<TQ,TU>, Vector1<TQ,TU extends UnitInterface<TU, TQ>> TU> as(TU targetUnit) throws IllegalArgumentException Return the vector 'as' a vector with a known quantity, using a unit to express the result in. Throw a Runtime exception when the SI units of this vector and the target vector do not match.- Type Parameters:
TQ- target quantity typeTU- target unit type- Parameters:
targetUnit- the unit to convert the vector to- Returns:
- a quantity typed in the target vector class
- Throws:
IllegalArgumentException- when the units do not match
-
hashCode
public int hashCode() -
equals
-
toString
Description copied from interface:ValueReturn a concise description of this value with the values expressed in the specified unit.- Specified by:
toStringin interfaceValue<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>> - Overrides:
toStringin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, Vector1<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, Vector1<SIQuantity, SIUnit>, Vector1<?, ?>> - Parameters:
withUnit- the unit into which the values are converted for display- Returns:
- a String with the value contents expressed in the specified unit
-
toString
Description copied from interface:ValueReturn a concise description of this value.- Specified by:
toStringin interfaceValue<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>> - Overrides:
toStringin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, Vector1<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, Vector1<SIQuantity, SIUnit>, Vector1<?, ?>> - Returns:
- a String with the value contents, without the type, with the unit attached.
-