View on GitHub

computational-mathematics

Contains basic implementations of a number of standard procedures in scientific computing and computational mathematics.

Routine Name: matrixNormL1

Author: Christopher Johnson

Language: C++11. Tested with g++ compiler.

Declared in “matrix.h”

Description/Purpose: Computes the l1 norm of input matrix.

Input: Matrix m, typedef of std::vector<std::vector<double>>.

Output: Returns a double, giving the computed l1 norm of the matrix.

Usage/Example:

A Matrix must first be defined, and then the method may be called.

Matrix a(5, Vector{-2,-1,0,1,2}); \\Creates a vector with 5 rows of [-2,-1,0,-1,-2]
std::cout << "The l1 matrix norm of A is " << matrixNormL1(a) << ".\n";

Output from the lines above:

The l1 matrix norm of A is 10.

Implementation/Code: The following is the code for matrixNormL1(m)

double matrixNormL1 (Matrix m)
{
    double maxColumnSum = 0;
    for (int j=0;j<m[0].size();j++)
    {
        double sum = 0;
        for (int i=0;i<m.size();i++)
            sum+= std::abs(m[i][j]);
        if (sum > maxColumnSum)
            maxColumnSum = sum;
    }
    return maxColumnSum;
}

Last Modified: October/2017