Vector class

The Vector class

Most of the class code is not optimized for high performance but for readability. You should be able to read the functions and understand what is going on with basic linear algebra knowledge.

The vector can be either a row or column vector. More reading about vectors

final Matrix a = Matrix([[1, 2], [3, 4]]);
final Vector b = Vector.column([2, 3]);
final Matrix e = Matrix([[8], [18]]);
Matrix result = a * b;
print(result);
print(result == e);

This prints

[[8.0], [18.0]]
true

Constructors

Vector.column(List<double> values)
Creates a column vector from the list of values given.
factory
Vector.fillColumn(int count, [double fill = 0.0])
Creates a column vector with count elements filled with fill
factory
Vector.fillRow(int count, [double fill = 0.0])
Creates a row vector with count elements filled with fill
factory
Vector.fromMatrix(Matrix matrix)
Converts a Matrix to a Vector if one of its dimensions is 1 will throw MatrixInvalidDimensions if that is not the case.
factory
Vector.row(List<double> values)
Creates a row vector from the list of values given.
factory

Properties

elements int
Returns the number of elements in the vector.
no setter
hashCode int
Returns the hashCode for the matrix.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
type VectorType
Returns the VectorType of the vector.
no setter

Methods

crossProduct(Vector other) Vector
Calculates the cross product for two 3-dimensional vectors.
dotProduct(Vector other) double
Calculates the dot product for two 3-dimensional vectors.
magnitude() double
Returns the magnitude, length or Euclidean norm of the vector.
manhattanNorm() double
Returns the Manhattan norm of the vector.
map(MatrixMapFunc f) Vector
Maps this Vector via function f to a new Vector.
mean() double
Returns element wise mean of the vector.
norm() double
Returns the Euclidean norm of the vector.
normalize() Vector
Normalizes this Vector to have magnitude 1.0
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
sum() double
Returns element wise sum of the vector.
toList([bool deepCopy = true]) List<double>
Returns the List<double> of this Vector
toMatrix([bool deepCopy = true]) Matrix
Returns the Matrix representation of this Vector
toString() String
Prints the content of the matrix.
override
transpose() Vector
Transposes a Vector from row or column to column or row.

Operators

operator *(dynamic other) Matrix
Multiplies two vectors, note the return value is a Matrix. If you need a scalar result add 0, and if you need the Vector result add .toVector()
operator +(Vector other) Vector
Adds two vectors
operator -(Vector other) Vector
Subtracts two vectors
operator ==(dynamic other) bool
Returns true if the vectors are the same ( or close with 1e-9 relative )
override
operator [](int element) double
Access the element's value in the vector.
operator []=(int element, double value) → void
Write values to elements of the vector.
operator ~() Vector
Negate all values