This file provides a short description on how to use class Norm and inherited classes from CAPD package - for more details see header file "capd/vectalg/Norm.h"
The template class Norm is defined in the namespace capd::vectalg and it has two parameters - type of vector and type of matrix whose norms will be computed. Class Norm is an abstract class that defines two purely virtual operators for computing norms of vectors and matrices.
template<typename VectorType,typename MatrixType> class Norm{ public: typedef typename VectorType::ScalarType ScalarType; virtual ScalarType operator()(const VectorType &iv) const = 0; virtual ScalarType operator()(const MatrixType &iv) const = 0; virtual std::string show(void) const = 0; virtual Norm *clone(void) const = 0; virtual ~Norm() {} };
The CAPD package implements six inherited classes from abstract class Norm
In order to compute a norm of vector or matrix one needs to create an instance of one of the inherited classes and call the suitable virtual operator.
typedef capd::vectalg::Vector<double,0> DVector; typedef capd::vectalg::Matrix<double,0,0> DMatrix; double data[] = {-10.,1.,1.,1.,2.,-20.,0.,-1.,1.,2.,-30.,4.,3.,1.,2.,0.}; // we create a matrix from given table of numbers DMatrix P(4,4,data); // vector v will be first row of matrix P DVector v = P.row(0); capd::vectalg::EuclNorm<DVector,DMatrix> euclNorm; capd::vectalg::SumLNorm<DVector,DMatrix> sumLogNorm; // now we can compute norms of vectors and matrices by using operator() std::cout << "EuclNorm(P)=" << euclNorm(P) << std::endl; std::cout << "SumLNorm(v)=" << sumLogNorm(v) << std::endl;
Author: Daniel Wilczak, last modified on July 7, 2008.