Vectors and Matrices

The Vectors and Matrices component provides a C++ implementation of the fundamental types Matrix and Vector, currently used to define more complex data structures.

The Vector and Matrix classes support vectors and matrices of real values with standard operations such as addition, multiplication, transposition, inversion etc.

Vectors and matrices have arbitrary ranges which must be defined at declaration time and cannot be changed after declaration.

Example

math_Vector v(1, 3);
// a vector of dimension 3 with range (1..3)
math_Matrix m(0, 2, 0, 2);
// a matrix of dimension 3x3 with range (0..2, 0..2)
math_Vector v(N1, N2);
// a vector of dimension N2-N1+1 with range (N1..N2)

Vector and Matrix objects follow "value semantics", that is, they cannot be shared and are copied though assignment.

Example

math_Vector v1(1, 3), v2(0, 2);
v2 = v1; // v1 is copied into v2
// a modification of v1 does not affect v2

Vector and Matrix elements can be retrieved using indexes, which must be in the range defined upon Vector/Matrix creation. The elements can be initialized with some numerical value upon creation as well.

Example

math_Vector v(1, 3);
math_Matrix m(1, 3, 1, 3);
Standard_Real value;
v(2) = 1.0;
value = v(1);
m(1, 3) = 1.0;
value = m(2, 2);

Some operations on Vector and Matrix objects may not be legal. In this case an exception is raised. Two standard exceptions are used:

- Standard_DimensionError exception is raised when two matrices or vectors involved in an operation are of incompatible dimensions.

- Standard_RangeError exception is raised if an attempt to access outside the range defined upon creation of a vector or a matrix is made.

Example

math_Vector v1(1, 3), v2(1, 2), v3(0, 2);
v1 = v2; // error:
// Standard_DimensionError is raised
v1 = v3; // OK: ranges are not equal
// but dimensions are compatible
v1(0) = 2.0; // error:
// Standard_RangeError is raised