Package org.djunits.vecmat.d1
Class Vector1<Q extends Quantity<Q>>
java.lang.Object
org.djunits.vecmat.def.VectorMatrix<Q,V,SI,H,VT>
org.djunits.vecmat.def.Vector<Q,Vector1<Q>,Vector1<SIQuantity>,Vector1<?>,Vector1<Q>>
org.djunits.vecmat.d1.Vector1<Q>
- Type Parameters:
Q- the quantity type
- All Implemented Interfaces:
Serializable,Iterable<Q>,Additive<Vector1<Q>>,Scalable<Vector1<Q>>,Value<Vector1<Q>,,Q> Vector.Row<Vector1<Q>,,Q> Hadamard<Vector1<?>,,Vector1<SIQuantity>> Normed<Q>
public class Vector1<Q extends Quantity<Q>>
extends Vector<Q,Vector1<Q>,Vector1<SIQuantity>,Vector1<?>,Vector1<Q>>
implements Vector.Row<Vector1<Q>,Q>
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:
-
Nested Class Summary
-
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.Return the vector 'as' a vector with a known quantity, using a unit to express the result in.intcols()Return the number of columns.booleanQ[]Return the vector as an array of scalars.double[]Return a row-major array of SI-values for this matrix or vector.inthashCode()instantiateSi(double xSiNew) Return a 1-vector with x value 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.booleanReturn whether this vector is a row vector.iterator()Create and return an iterator over the scalars in this vector in proper sequence.max()Return the maximum value of the entries of the vector or matrix.mean()Return the mean value of the entries of the vector or matrix.median()Return the median value of the entries of the vector or matrix.min()Return the minimum value of the entries of the vector or matrix.negate()Negate this element, based on the SI-values.intReturn the number of non-zero entries in the vector, matrix or table.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.Create a Vector1 without needing generics.Create a Vector1 without needing generics.of(Q x) Create a Vector1 without needing generics.of(Q[] data) Create a Vector1 without needing generics.Create a Vector1 without needing generics.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.doublesi(int index) Retrieve an si-value from the vector.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 entries of the vector or matrix.Return a transposed vector or matrix, where rows and columns have been swapped.double[]Return a row-major possibly UNSAFE array of SI-values for this matrix or vector.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.VectorMatrix
asMatrix1x1, asMatrix2x2, asMatrix3x3, asMatrixNxM, asMatrixNxN, asQuantityTable, asVector1, asVector2Col, asVector2Row, asVector3Col, asVector3Row, asVectorNCol, asVectorNRow, checkMultiply, checkMultiply, divideElements, divideEntries, getDisplayUnit, invertEntries, multiplyElements, multiplyEntries, multiplyEntries, nnz, setDisplayUnit, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.djunits.vecmat.operations.Hadamard
divideEntriesMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface org.djunits.value.Value
getDisplayUnit, isAbsolute, setDisplayUnit, setDisplayUnitMethods inherited from interface org.djunits.vecmat.def.Vector.Row
format, format, format
-
Constructor Details
-
Vector1
Create a new Vector1 with a display unit.- Parameters:
xSi- the x-value expressed in the SI unit for the quantitydisplayUnit- the display unit of the vector
-
-
Method Details
-
instantiateSi
Return a 1-vector with x value 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>,Vector1<Q extends Quantity<Q>>, Vector1<SIQuantity>, Vector1<?>, Vector1<Q extends Quantity<Q>>> - 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
-
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. -
nonZeroCount
public int nonZeroCount()Description copied from class:VectorMatrixReturn the number of non-zero entries in the vector, matrix or table. Note that NaN and Infinity count as a non-zero element. The value -0.0 counts as 0.0. -
transpose
Description copied from class:VectorMatrixReturn a transposed vector or matrix, where rows and columns have been swapped. -
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>,Vector1<Q extends Quantity<Q>>, Vector1<SIQuantity>, Vector1<?>, Vector1<Q extends Quantity<Q>>> - 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
-
isColumnVector
public boolean isColumnVector()Description copied from class:VectorReturn whether this vector is a column vector. -
isRowVector
public boolean isRowVector()Description copied from class:VectorReturn whether this vector is a row vector. -
si
Description copied from class:VectorRetrieve an si-value from the vector.- Specified by:
siin classVector<Q extends Quantity<Q>,Vector1<Q extends Quantity<Q>>, Vector1<SIQuantity>, Vector1<?>, Vector1<Q extends Quantity<Q>>> - 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. -
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
-
unsafeSiArray
public double[] unsafeSiArray()Description copied from class:VectorMatrixReturn a row-major possibly UNSAFE array of SI-values for this matrix or vector. The method might give access to the underlying data structure, so treat the data carefully. -
getSiArray
public double[] getSiArray()Description copied from class:VectorMatrixReturn a row-major array of SI-values for this matrix or vector. This is guaranteed to be a safe copy. -
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>>- Overrides:
scaleByin classVectorMatrix<Q extends Quantity<Q>,Vector1<Q extends Quantity<Q>>, Vector1<SIQuantity>, Vector1<?>, Vector1<Q extends Quantity<Q>>> - 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>>- Overrides:
addin classVectorMatrix<Q extends Quantity<Q>,Vector1<Q extends Quantity<Q>>, Vector1<SIQuantity>, Vector1<?>, Vector1<Q extends Quantity<Q>>> - 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>>- Overrides:
subtractin classVectorMatrix<Q extends Quantity<Q>,Vector1<Q extends Quantity<Q>>, Vector1<SIQuantity>, Vector1<?>, Vector1<Q extends Quantity<Q>>> - 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. -
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. -
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 entries of the vector or matrix. -
min
Description copied from class:VectorMatrixReturn the minimum value of the entries of the vector or matrix. -
max
Description copied from class:VectorMatrixReturn the maximum value of the entries of the vector or matrix. -
median
Description copied from class:VectorMatrixReturn the median value of the entries of the vector or matrix. -
sum
Description copied from class:VectorMatrixReturn the sum of the values of the entries 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>,Vector1<Q extends Quantity<Q>>, Vector1<SIQuantity>, Vector1<?>, Vector1<Q extends Quantity<Q>>> - Parameters:
increment- the quantity by which to increase the values of the vector or matrix- Returns:
- a vector or matrix with entries 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>,Vector1<Q extends Quantity<Q>>, Vector1<SIQuantity>, Vector1<?>, Vector1<Q extends Quantity<Q>>> - Parameters:
decrement- the quantity by which to decrease the values of the vector or matrix- Returns:
- a vector or matrix with entries that are decremented by the given quantity
-
isRelative
public boolean isRelative()Description copied from interface:ValueIndicate whether this is a Relative Value. -
of
Create a Vector1 without needing generics.- Type Parameters:
Q- the quantity type- Parameters:
xInUnit- the x-value expressed in the unitunit- the unit of the data, which will also be used as the display unit- Returns:
- a new Vector1 with a unit
-
of
Create a Vector1 without needing generics.- Type Parameters:
Q- the quantity type- Parameters:
x- the x-value expressed as a quantity- Returns:
- a new Vector1 with a unit
-
of
Create a Vector1 without needing generics.- Type Parameters:
Q- the quantity type- Parameters:
dataInUnit- the x-value expressed as an array in the display unitunit- the unit of the data, which will also be used as the display unit- Returns:
- a new Vector1 with a unit
-
ofSi
Create a Vector1 without needing generics.- Type Parameters:
Q- the quantity type- Parameters:
xSi- the x-value expressed in the SI unitdisplayUnit- the display unit to use- Returns:
- a new Vector1 with the display unit
-
ofSi
Create a Vector1 without needing generics.- Type Parameters:
Q- the quantity type- Parameters:
dataSi- the x-value expressed as an array in the SI unitsdisplayUnit- the display unit to use- Returns:
- a new Vector1 with a unit
-
of
Create a Vector1 without needing generics.- Type Parameters:
Q- the quantity type- Parameters:
data- the x-value expressed as an array of quantities- Returns:
- a new Vector1 with a unit
-
as
public <TQ extends Quantity<TQ>> Vector1<TQ> as(Unit<?, TQ> targetUnit) throws IllegalArgumentExceptionReturn 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 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
-