Top Description Methods
org.apache.commons.math3.linear

public Interface FieldVector<T extends FieldElement<T>>

Known Direct Implementers
org.apache.commons.math3.linear.SparseFieldVector, org.apache.commons.math3.linear.ArrayFieldVector
Type Parameters
<T>
the type of the field elements
Imports
org.apache.commons.math3.Field, .FieldElement, org.apache.commons.math3.exception.DimensionMismatchException, .MathArithmeticException, .NotPositiveException, .NullArgumentException, .OutOfRangeException

Interface defining a field-valued vector with basic algebraic operations.

vector element indexing is 0-based -- e.g., getEntry(0) returns the first element of the vector.

The various mapXxx and mapXxxToSelf methods operate on vectors element-wise, i.e. they perform the same operation (adding a scalar, applying a function ...) on each element in turn. The mapXxx versions create a new vector to hold the result and do not change the instance. The mapXxxToSelf versions use the instance itself to store the results, so the instance is changed by these methods. In both cases, the result vector is returned by the methods, this allows to use the fluent API style, like this:

  RealVector result = v.mapAddToSelf(3.0).mapTanToSelf().mapSquareToSelf();

Note that as almost all operations on FieldElement throw NullArgumentException when operating on a null element, it is the responsibility of FieldVector implementations to make sure no null elements are inserted into the vector. This must be done in all constructors and all setters.

Since
2.0

Method Summary

Modifier and TypeMethod and Description
public FieldVector<T>

Returns:

this + v
add
(FieldVector<T>
vector to be added
v
)

Compute the sum of this and v.

public FieldVector<T>

Returns:

a new vector
append
(FieldVector<T>
vector to append to this one.
v
)

Construct a vector by appending a vector to this vector.

public FieldVector<T>

Returns:

a new vector
append
(T
T to append.
d
)

Construct a vector by appending a T to this vector.

public FieldVector<T>

Returns:

vector copy
copy
()

Returns a (deep) copy of this.

public T

Returns:

the scalar dot product of this and v
dotProduct
(FieldVector<T>
vector with which dot product should be computed
v
)

Compute the dot product.

public FieldVector<T>

Returns:

a vector containing this[i] / v[i] for all i
ebeDivide
(FieldVector<T>
vector by which instance elements must be divided
v
)

Element-by-element division.

public FieldVector<T>

Returns:

a vector containing this[i] * v[i] for all i
ebeMultiply
(FieldVector<T>
vector by which instance elements must be multiplied
v
)

Element-by-element multiplication.

public T[]

Returns:

T array of entries
getData
()
Deprecated as of 3.1, to be removed in 4.0. Please use the toArray() method instead.

Returns vector entries as a T array.

public int

Returns:

size
getDimension
()

Returns the size of the vector.

public T

Returns:

the vector entry at index.
getEntry
(int
Index location of entry to be fetched.
index
)

Returns the entry in the specified index.

public Field<T>

Returns:

type of field elements of the vector
getField
()

Get the type of field elements of the vector.

public FieldVector<T>

Returns:

a vector containing n elements.
getSubVector
(int
index of first element.
index
,
int
number of elements to be retrieved.
n
)

Get a subvector from consecutive elements.

public FieldVector<T>

Returns:

this + d
mapAdd
(T
value to be added to each entry
d
)

Map an addition operation to each entry.

public FieldVector<T>

Returns:

for convenience, return this
mapAddToSelf
(T
value to be added to each entry
d
)

Map an addition operation to each entry.

public FieldVector<T>

Returns:

this / d
mapDivide
(T
value to divide all entries by
d
)

Map a division operation to each entry.

public FieldVector<T>

Returns:

for convenience, return this
mapDivideToSelf
(T
value to divide all entries by
d
)

Map a division operation to each entry.

public FieldVector<T>

Returns:

a vector containing the result of applying the function to each entry.
mapInv
()

Map the 1/x function to each entry.

public FieldVector<T>

Returns:

for convenience, return this
mapInvToSelf
()

Map the 1/x function to each entry.

public FieldVector<T>

Returns:

this * d
mapMultiply
(T
value to multiply all entries by
d
)

Map a multiplication operation to each entry.

public FieldVector<T>

Returns:

for convenience, return this
mapMultiplyToSelf
(T
value to multiply all entries by
d
)

Map a multiplication operation to each entry.

public FieldVector<T>

Returns:

this - d
mapSubtract
(T
value to be subtracted to each entry
d
)

Map a subtraction operation to each entry.

public FieldVector<T>

Returns:

for convenience, return this
mapSubtractToSelf
(T
value to be subtracted to each entry
d
)

Map a subtraction operation to each entry.

public FieldMatrix<T>

Returns:

the matrix outer product between instance and v
outerProduct
(FieldVector<T>
vector with which outer product should be computed
v
)

Compute the outer product.

public FieldVector<T>

Returns:

projection of this onto v
projection
(FieldVector<T>
vector onto which this must be projected
v
)

Find the orthogonal projection of this vector onto another vector.

public void
set(T
single value to set for all elements
value
)

Set all elements to a single value.

public void
setEntry(int
element index.
index
,
T
new value for the element.
value
)

Set a single element.

public void
setSubVector(int
index of first element to be set.
index
,
FieldVector<T>
vector containing the values to set.
v
)

Set a set of consecutive elements.

public FieldVector<T>

Returns:

this - v
subtract
(FieldVector<T>
vector to be subtracted
v
)

Compute this minus v.

public T[]

Returns:

array containing a copy of vector elements
toArray
()

Convert the vector to a T array.

Method Detail

addback to summary
public FieldVector<T> add(FieldVector<T> v) throws DimensionMismatchException

Compute the sum of this and v.

Parameters
v:FieldVector<T>

vector to be added

Returns:FieldVector<T>

this + v

Exceptions
DimensionMismatchException:
if v is not the same size as this
appendback to summary
public FieldVector<T> append(FieldVector<T> v)

Construct a vector by appending a vector to this vector.

Parameters
v:FieldVector<T>

vector to append to this one.

Returns:FieldVector<T>

a new vector

appendback to summary
public FieldVector<T> append(T d)

Construct a vector by appending a T to this vector.

Parameters
d:T

T to append.

Returns:FieldVector<T>

a new vector

copyback to summary
public FieldVector<T> copy()

Returns a (deep) copy of this.

Returns:FieldVector<T>

vector copy

dotProductback to summary
public T dotProduct(FieldVector<T> v) throws DimensionMismatchException

Compute the dot product.

Parameters
v:FieldVector<T>

vector with which dot product should be computed

Returns:T

the scalar dot product of this and v

Exceptions
DimensionMismatchException:
if v is not the same size as this
ebeDivideback to summary
public FieldVector<T> ebeDivide(FieldVector<T> v) throws DimensionMismatchException, MathArithmeticException

Element-by-element division.

Parameters
v:FieldVector<T>

vector by which instance elements must be divided

Returns:FieldVector<T>

a vector containing this[i] / v[i] for all i

Exceptions
DimensionMismatchException:
if v is not the same size as this
MathArithmeticException:
if one entry of v is zero.
ebeMultiplyback to summary
public FieldVector<T> ebeMultiply(FieldVector<T> v) throws DimensionMismatchException

Element-by-element multiplication.

Parameters
v:FieldVector<T>

vector by which instance elements must be multiplied

Returns:FieldVector<T>

a vector containing this[i] * v[i] for all i

Exceptions
DimensionMismatchException:
if v is not the same size as this
getDataback to summary
public T[] getData()

Deprecated

as of 3.1, to be removed in 4.0. Please use the toArray() method instead.

Returns vector entries as a T array.

Returns:T[]

T array of entries

Annotations
@Deprecated
getDimensionback to summary
public int getDimension()

Returns the size of the vector.

Returns:int

size

getEntryback to summary
public T getEntry(int index) throws OutOfRangeException

Returns the entry in the specified index.

Parameters
index:int

Index location of entry to be fetched.

Returns:T

the vector entry at index.

Exceptions
OutOfRangeException:
if the index is not valid.
See Also
setEntry(int, FieldElement)
getFieldback to summary
public Field<T> getField()

Get the type of field elements of the vector.

Returns:Field<T>

type of field elements of the vector

getSubVectorback to summary
public FieldVector<T> getSubVector(int index, int n) throws OutOfRangeException, NotPositiveException

Get a subvector from consecutive elements.

Parameters
index:int

index of first element.

n:int

number of elements to be retrieved.

Returns:FieldVector<T>

a vector containing n elements.

Exceptions
OutOfRangeException:
if the index is not valid.
NotPositiveException:
if the number of elements if not positive.
mapAddback to summary
public FieldVector<T> mapAdd(T d) throws NullArgumentException

Map an addition operation to each entry.

Parameters
d:T

value to be added to each entry

Returns:FieldVector<T>

this + d

Exceptions
NullArgumentException:
if d is null.
mapAddToSelfback to summary
public FieldVector<T> mapAddToSelf(T d) throws NullArgumentException

Map an addition operation to each entry.

The instance is changed by this method.

Parameters
d:T

value to be added to each entry

Returns:FieldVector<T>

for convenience, return this

Exceptions
NullArgumentException:
if d is null.
mapDivideback to summary
public FieldVector<T> mapDivide(T d) throws NullArgumentException, MathArithmeticException

Map a division operation to each entry.

Parameters
d:T

value to divide all entries by

Returns:FieldVector<T>

this / d

Exceptions
NullArgumentException:
if d is null.
MathArithmeticException:
if d is zero.
mapDivideToSelfback to summary
public FieldVector<T> mapDivideToSelf(T d) throws NullArgumentException, MathArithmeticException

Map a division operation to each entry.

The instance is changed by this method.

Parameters
d:T

value to divide all entries by

Returns:FieldVector<T>

for convenience, return this

Exceptions
NullArgumentException:
if d is null.
MathArithmeticException:
if d is zero.
mapInvback to summary
public FieldVector<T> mapInv() throws MathArithmeticException

Map the 1/x function to each entry.

Returns:FieldVector<T>

a vector containing the result of applying the function to each entry.

Exceptions
MathArithmeticException:
if one of the entries is zero.
mapInvToSelfback to summary
public FieldVector<T> mapInvToSelf() throws MathArithmeticException

Map the 1/x function to each entry.

The instance is changed by this method.

Returns:FieldVector<T>

for convenience, return this

Exceptions
MathArithmeticException:
if one of the entries is zero.
mapMultiplyback to summary
public FieldVector<T> mapMultiply(T d) throws NullArgumentException

Map a multiplication operation to each entry.

Parameters
d:T

value to multiply all entries by

Returns:FieldVector<T>

this * d

Exceptions
NullArgumentException:
if d is null.
mapMultiplyToSelfback to summary
public FieldVector<T> mapMultiplyToSelf(T d) throws NullArgumentException

Map a multiplication operation to each entry.

The instance is changed by this method.

Parameters
d:T

value to multiply all entries by

Returns:FieldVector<T>

for convenience, return this

Exceptions
NullArgumentException:
if d is null.
mapSubtractback to summary
public FieldVector<T> mapSubtract(T d) throws NullArgumentException

Map a subtraction operation to each entry.

Parameters
d:T

value to be subtracted to each entry

Returns:FieldVector<T>

this - d

Exceptions
NullArgumentException:
if d is null
mapSubtractToSelfback to summary
public FieldVector<T> mapSubtractToSelf(T d) throws NullArgumentException

Map a subtraction operation to each entry.

The instance is changed by this method.

Parameters
d:T

value to be subtracted to each entry

Returns:FieldVector<T>

for convenience, return this

Exceptions
NullArgumentException:
if d is null
outerProductback to summary
public FieldMatrix<T> outerProduct(FieldVector<T> v)

Compute the outer product.

Parameters
v:FieldVector<T>

vector with which outer product should be computed

Returns:FieldMatrix<T>

the matrix outer product between instance and v

projectionback to summary
public FieldVector<T> projection(FieldVector<T> v) throws DimensionMismatchException, MathArithmeticException

Find the orthogonal projection of this vector onto another vector.

Parameters
v:FieldVector<T>

vector onto which this must be projected

Returns:FieldVector<T>

projection of this onto v

Exceptions
DimensionMismatchException:
if v is not the same size as this
MathArithmeticException:
if v is the null vector.
setback to summary
public void set(T value)

Set all elements to a single value.

Parameters
value:T

single value to set for all elements

setEntryback to summary
public void setEntry(int index, T value) throws OutOfRangeException

Set a single element.

Parameters
index:int

element index.

value:T

new value for the element.

Exceptions
OutOfRangeException:
if the index is not valid.
See Also
getEntry(int)
setSubVectorback to summary
public void setSubVector(int index, FieldVector<T> v) throws OutOfRangeException

Set a set of consecutive elements.

Parameters
index:int

index of first element to be set.

v:FieldVector<T>

vector containing the values to set.

Exceptions
OutOfRangeException:
if the index is not valid.
subtractback to summary
public FieldVector<T> subtract(FieldVector<T> v) throws DimensionMismatchException

Compute this minus v.

Parameters
v:FieldVector<T>

vector to be subtracted

Returns:FieldVector<T>

this - v

Exceptions
DimensionMismatchException:
if v is not the same size as this
toArrayback to summary
public T[] toArray()

Convert the vector to a T array.

The array is independent from vector data, it's elements are copied.

Returns:T[]

array containing a copy of vector elements