Orbital library

## orbital.math Interface Vector

All Superinterfaces:
Arithmetic, Normed, Tensor

`public interface Vectorextends Tensor`

Represents a mathematical vector of any dimension n.

 v∈V=Rn, v = (v0,v1,v2,…,vn-1)T = ( v0 ) v1 ⋮ vn-1

The components vi∈R are any arithmetic objects forming a ring. (Rn,+,·) form a (free) R-module with the law of composition + and the law of action ·. If R is a field the vectors even form a vector space over R, which justifies the name vector. If R is an integrity domain, then Rn≅Rm ⇔ n=m.

A vector space over a field R is a set V with an algebraic structure of
 (1) (V,+) is an Abelian group with the law of composition +:V×V→V; (v,w)↦v+w (2) ·:R×V→V; (λ,v)↦λ·v is a law of action (the scalar multiplication · or sometimes ·) ("a") λ·(μ·v) = (λ⋅μ)·v ("d") (λ+μ)·v = λ·v + μ·v ("d") λ·(v+w) = λ·v + λ·w ("n") 1·v = v
∀λ,μ∈R, v,w∈V.

If you intend to use mutable arithmetic elements, note the discussion of mutations per reference vs. explicit cloning in `Tensor.set(int[],Arithmetic)` which generally holds for all operations that set component values.

Also note that some few methods will change its instance and explicitly `return this` to allow chaining of structural changes, whilst arithmetic methods will leave a vector unchanged but return a modified version. Refer to the documentation of the individual methods for details.

Author:
André Platzer
`ValueFactory.tensor(Arithmetic[])`, `ValueFactory.valueOf(Arithmetic[])`, `ValueFactory.valueOf(double[])`
Invariants:
super ∧ rank()==1
Structure:
extends Tensor

Field Summary

Fields inherited from interface orbital.math.Arithmetic
`numerical`

Method Summary
` Vector` `add(Vector b)`
Adds two vectors returning a vector.
` Vector` `cross(Vector b)`
Vector-cross-product of two vectors.
` int` `dimension()`
Returns the dimension of the vector.
` Arithmetic` `get(int i)`
Returns the value at the component specified by index.
` Vector` `insert(Arithmetic v)`
Append a value to this vector.
` Vector` ```insert(int index, Arithmetic v)```
Insert a value into this vector at the specified index.
` Vector` ```insertAll(int index, Vector v)```
Insert all components of a vector into this vector at the specified index.
` Vector` `insertAll(Vector v)`
Append all components of a vector to this vector.
` java.util.ListIterator` `iterator()`
Returns an iterator over all components.
` Vector` `multiply(Matrix B)`
Multiplies a vector with a matrix returning a vector.
` Vector` `multiply(Scalar s)`
Multiplies a vector with a scalar returning a vector.
` Arithmetic` `multiply(Vector b)`
Scalar-dot-product ⟨·,·⟩:V×V→F of two vectors.
` Real` `norm(double p)`
Returns the norm || ||p of this vector.
` Vector` `remove(int index)`
Remove the component at an index from this vector.
` Vector` `scale(Scalar s)`
Multiplies a vector with a scalar returning a vector.
` void` ```set(int i, Arithmetic vi)```
Sets a value at the component specified by index.
` Vector` `subtract(Vector b)`
Subtracts two vectors returning a vector.
` Vector` ```subVector(int i1, int i2)```
Get a sub-vector view ranging (i1:i2) inclusive.
` Arithmetic[]` `toArray()`
Returns an array containing all the elements in this vector.
` Matrix` `transpose()`
Returns this vector transposed.

Methods inherited from interface orbital.math.Tensor
`add, clone, dimensions, entries, get, indices, multiply, rank, set, setSubTensor, subTensor, subTensor, subTensorTransposed, subtract, tensor`

Methods inherited from interface orbital.math.Arithmetic
`add, divide, equals, inverse, isOne, isZero, minus, multiply, one, power, scale, subtract, toString, valueFactory, zero`

Methods inherited from interface orbital.math.Normed
`norm`

Method Detail

### dimension

`int dimension()`
Returns the dimension of the vector. The dimension is the number `n` of elements contained.

### get

`Arithmetic get(int i)`
Returns the value at the component specified by index.

Of course, this method only has a meaning for free modules like vector spaces.

### set

```void set(int i,
Arithmetic vi)
throws java.lang.UnsupportedOperationException```
Sets a value at the component specified by index.

Of course, this method only has a meaning for free modules like vector spaces.

Throws:
`java.lang.UnsupportedOperationException` - if this vector is constant and does not allow modifications.

### iterator

`java.util.ListIterator iterator()`
Returns an iterator over all components.

Specified by:
`iterator` in interface `Tensor`
Returns:
an iterator that iterates over v0,…,vn-1.
Postconditions:
RES.supports(#nextIndex()} ∧ RES.supports(#previousIndex()} ∧ RES.supports(#add(Object)} ∧ RES.supports(#remove()}

### subVector

```Vector subVector(int i1,
int i2)```
Get a sub-vector view ranging (i1:i2) inclusive.

The returned vector is a structurally unmodifiable view.

Returns:
a matrix view of the specified part of this matrix.
Preconditions:
i1<=i2 && valid(i1) && valid(i2)

### norm

`Real norm(double p)`
Returns the norm || ||p of this vector.

This method implements p-norms, where
||x||p = (|x1|p + … + |xn|p)1/p.
||x|| = max {|x1|,…,|xn|}.

Preconditions:
p>=1

`Vector add(Vector b)`
Adds two vectors returning a vector.

Preconditions:
dimension() == b.dimension()
Postconditions:
RES.dimension() == dimension() && RES.get(i) == get(i) + b.get(i)
Attributes:
associative, neutral (0), inverse (-v), commutative

### subtract

`Vector subtract(Vector b)`
Subtracts two vectors returning a vector.

Preconditions:
dimension() == b.dimension()
Postconditions:
RES.dimension() == dimension() && RES.get(i) == get(i) - b.get(i)
Attributes:
associative

### multiply

`Arithmetic multiply(Vector b)`
Scalar-dot-product ⟨·,·⟩:V×V→F of two vectors.

⟨·,·⟩:V×V→R is a real scalar product and V a euclidian vector space, if ∀x,y∈V:

 (bl) ⟨.,y⟩ and ⟨x,.⟩ are linear "bilinear" (s) ⟨x,y⟩ = ⟨y,x⟩ "symmetric" (this method is commutative) (pdef) ⟨x,x⟩≥0 and ⟨x,x⟩=0 ⇔ x=0 "positive definite"

⟨·,·⟩:V×V→C is a complex scalar product and V a unitarian vector space, if ∀x,y∈V:

 (ll) ⟨·,y⟩ is linear "left-linear" (h) ⟨x,y⟩ = ⟨y,x⟩ "hermite" (pdef) ⟨x,x⟩≥0 and ⟨x,x⟩=0 ⇔ x=0 "positive definite"

A scalar product ⟨·,·⟩ induces a norm ||.||:V→[0,∞); x ↦ ||x|| := √x,x

The standard scalar-product which will often be implemented, is
(x,y) ↦ ⟨x,y⟩ = xT·y = i=0n-1 xi⋅yi. It belongs to the euclidian 2-norm and is the inner product of vectors.

`Normed`
Preconditions:
dimension() == b.dimension()
Postconditions:
RES.dimension() == dimension() && RES == ⟨this, b⟩

### scale

`Vector scale(Scalar s)`
Multiplies a vector with a scalar returning a vector.

Returns:
v
Preconditions:
true
Postconditions:
RES.dimension().equals(dimension()) && RES.get(i) == s⋅get(i)
Attributes:
associative, neutral

### multiply

`Vector multiply(Scalar s)`
Multiplies a vector with a scalar returning a vector.

`scale(Scalar)`

### multiply

`Vector multiply(Matrix B)`
Multiplies a vector with a matrix returning a vector. If row-vector `v` is sized `n` and the matrix `A` is sized `n×m`, the resulting row-vector `v∙A` is sized `m`. This is an inner product.

Preconditions:
dimension() == B.dimension().height

### cross

`Vector cross(Vector b)`
Vector-cross-product of two vectors.
×:R3×R3R3; (x,y) ↦ x×y = (x1y2-x2y1, x2y0-x0y2, x0y1-x1y0)

cross is antisymmetric: y×x = -(x×y)

Returns:
the cross-product vector which will be orthogonal on this and b. x×yxx×yy.
Preconditions:
dimension() == 3 && dimension() == b.dimension(), (dimension() == 3 || dimension() == 2) && dimension() == b.dimension()
Postconditions:
RES.multiply(this) == 0 && RES.multiply(b) == 0.
Attributes:
antisymmetric

### transpose

`Matrix transpose()`
Returns this vector transposed. Also distinguished via vector.multiply(matrix) or matrix.multiply(vector) instead.

`Matrix.transpose()`

### insert

```Vector insert(int index,
Arithmetic v)```
Insert a value into this vector at the specified index.

Returns:
this.
Preconditions:
0<=index && index<=dimension()
Postconditions:
RES == this && RES.dimension() == OLD(dimension()) + 1

### insertAll

```Vector insertAll(int index,
Vector v)```
Insert all components of a vector into this vector at the specified index.

Returns:
this.
Preconditions:
0<=index && index<=dimension()
Postconditions:
RES == this && RES.dimension() == OLD(dimension()) + v.dimension()

### insert

`Vector insert(Arithmetic v)`
Append a value to this vector.

Returns:
this.
Postconditions:
RES == this && RES.dimension() == OLD(dimension()) + 1

### insertAll

`Vector insertAll(Vector v)`
Append all components of a vector to this vector.

Returns:
this.
Postconditions:
RES == this && RES.dimension() == OLD(dimension()) + v.dimension()

### remove

`Vector remove(int index)`
Remove the component at an index from this vector.

Returns:
this.
Postconditions:
RES == this && RES.dimension() == OLD(dimension()) - 1

### toArray

`Arithmetic[] toArray()`
Returns an array containing all the elements in this vector.

`Object.clone()`