Vector0 class

A simple vector class for conjugate gradient calculations.

This class provides basic vector operations needed for the conjugate gradient method, including addition, subtraction, scalar multiplication, dot product, and norm calculation.

Constructors, destructors, conversion operators

Vector0(size_t size)
Construct a new Vector0 object with given size.
Vector0(const std::vector<double>& v)
Construct a new Vector0 from a std::vector.

Public functions

auto operator[](size_t i) -> double&
Access element at index i.
auto operator[](size_t i) const -> const double&
Access element at index i (const version)
auto size() const -> size_t
Get the size of the vector.
auto operator+=(const Vector0& rhs) -> Vector0&
Add another vector to this vector.
auto operator-=(const Vector0& rhs) -> Vector0&
Subtract another vector from this vector.
auto operator*=(double scalar) -> Vector0&
Multiply this vector by a scalar.
auto dot(const Vector0& other) const -> double
Compute the dot product with another vector.
auto norm() const -> double
Compute the L2 norm of the vector.

Function documentation

Vector0::Vector0(size_t size)

Construct a new Vector0 object with given size.

Parameters
size in The size of the vector

Vector0::Vector0(const std::vector<double>& v)

Construct a new Vector0 from a std::vector.

Parameters
in The std::vector to copy from

double& Vector0::operator[](size_t i)

Access element at index i.

Parameters
in Index of the element
Returns Reference to the element

const double& Vector0::operator[](size_t i) const

Access element at index i (const version)

Parameters
in Index of the element
Returns Const reference to the element

size_t Vector0::size() const

Get the size of the vector.

Returns Size of the vector

Vector0& Vector0::operator+=(const Vector0& rhs)

Add another vector to this vector.

Parameters
rhs in The vector to add
Returns Reference to this vector after addition

Vector0& Vector0::operator-=(const Vector0& rhs)

Subtract another vector from this vector.

Parameters
rhs in The vector to subtract
Returns Reference to this vector after subtraction

Vector0& Vector0::operator*=(double scalar)

Multiply this vector by a scalar.

Parameters
scalar in The scalar value to multiply
Returns Reference to this vector after multiplication

double Vector0::dot(const Vector0& other) const

Compute the dot product with another vector.

Parameters
other in The other vector
Returns The dot product result

double Vector0::norm() const

Compute the L2 norm of the vector.

Returns The L2 norm (Euclidean length)