NABLA
Nabla Ain't Basic Linear Algebra
|
Vectors, which the library is all about, are represented by the vector
template class.
In general the usage of vector
is very similar to the STL vector
or valarray
classes. Actually it is closer to valarray
which models sequence or C-style array, not the container concept defined by the STL.
Here is how you can create vectors:
Here an empty vector is created: it has zero size and holds no elements. Notice that the template must be parameterized with the type of elements, just like the STL vector
.
Here an R3 vector is created (since double
models real values). That is a vector of real (double precision floating point) values with size equal to three (3 elements). The size of a given vector can be acquired using size()
member function:
Here a 3 element vector is created with all element values initialized to zero (0.
).
resize()
member function:
vector
can be accessed in two ways:
The first is the overloaded subscript operator[]
and the second is the overloaded function call operator()
.
vector
can be constructed from as well as assigned a valid vector expression (see documentation for vector_expression
):
Note that v1
and v2
must have the same sizes.
vector
objects can be very efficiently swapped:
These two ways have identical effect.
matrix
template class.
To create a rectangular matrix
write something like
Here m
is an empty matrix with no elements. As in the vector
case you can specify the size of the matrix and a value for initialization:
The number of rows and columns of a matrix can be acquired using rows()
and cols()
member functions:
A matrix
can be resized using resize()
member function:
using overloaded function call operator()
.
However there are numerous alternative ways to do that:
Pick your favourite!
matrix
can be constructed from and assigned a valid matrix expression (see documentation for matrix_expression
):
Note that m1
and m2
must have conforming sizes.
matrix
objects can be very efficiently swapped:
These two ways have identical effect.
Here v
is the source vector, vm
is the mapped vector and m
is the mapping matrix.
To map a vector using a matrix use the map()
function:
Here m*v
represents a well defined matrix-vector product.
Personally I consider this implementation both concise and conscious. The writer's intention is explicitly expressed and all mess is hidden away.