Algorithms and Subroutines for Solving Differential Equations
Routine Name: infNorm
Author: Philip Nelson
Language: C++
infNorm
calculates the infinity norm of a vector which is also the maximum element
infNorm(std::array<T, N> v)
requires:
std::array<T, N> v
- a column vector of type T
and size M
A double with the value of the infinity norm
template <typename T, std::size_t N>
double infNorm(std::array<T, N> v)
{
T max = std::abs(v[0]);
for (auto&& x : v)
max = std::max(max, std::abs(x));
return max;
}
int main()
{
std::array<double, 4> v = {11, 18, -20, 5};
std::cout << " v\n" << v << std::endl;
std::cout << "Infinity Norm: " << infNorm(v) << std::endl;
}
v
[ 11 18 -20 5 ]
Infinity Norm: 20
Last Modification date: 07 February 2018