Vectors and Matrices
Defining Vectors
The Linear Algebra Module provides the objects you need to write code that uses numerical linear algebra. Vectors and matrices are at the heart of linear algebra, so we present these concepts early in the documentation.
The abstract concept of a vector is the most important abstraction of linear algebra. From a mathematical point of view, a vector space is simply a set whose elements satisfy a set of axioms. In a computational context, however, we can specify a vector in a much more concrete way. Because we are interested only in finite-dimensional vectors, each vector in a given space is uniquely identified by a sequence of numbers. Thus, in the Linear Algebra Module, a vector is simply a one-dimensional array of numbers.
The C++ classes used to represent vectors are the Essential Math Module classes
RWMathVec<double>,
RWMathVec<float>, and
RWMathVec<DComplex>. They are based on a data-view architecture which is used heavily throughout the Linear Algebra Module and the Essential Math Module. If you haven't done so already, please read the chapter, “Vector, Matrix, and Array Classes,” in the
Essential Math Module User’s Guide and the class description in the
SourcePro API Reference Guide for a good understanding of the benefits and potential pitfalls of this approach.
In general, the vector classes are designed to be efficient and intuitive. For efficiency and expressiveness, reference counting semantics are used where possible; for example, subscripting and the copy constructor both return new views of the same data. Details are given in the Essential Math Module documentation, but here is a simple example, described line by line.
#include <iostream>
#include <rw/dvec.h> // 1
int main()
{
RWMathVec<double> x = "[ 2 3 8 9 3 2 1 ]"; // 2
RWMathVec<double> y(7,0); // 3
y("2:5") = 4; // 4
RWMathVec<double> z = x+y; // 5
std::cout << z; // 6
return 0;
}