vectorNormComplex

Computes various norms of a vector or the difference of two vectors.

Synopsis

vectorNormComplex (x)

Required Arguments

complex x[] (Input)
Input vector for which the norm is to be computed

Return Value

The requested norm of the input vector. If the norm cannot be computed, NaN is returned. By default, the two norm of x, \(\|x\|_2\), is computed.

Optional Arguments

oneNorm
Return the 1-norm.
infNorm (Output)
Return the infinity norm.
secondVector (Input)
Return the norm of x-y.

Description

By default, vectorNormComplex computes the Euclidean norm

\[\left(\sum_{i=0}^{n-1} x_i^2\right)^{\frac{1}{2}}\]

If the option oneNorm is selected, the 1-norm

\[\sum_{i=0}^{n-1} \left|x_i\right|\]

is returned. If the option infNorm is selected, the infinity norm

\[\max ∣x_i∣\]

is returned. In the case of the infinity norm, the program also returns the index of the element with maximum modulus. If secondVector is selected, then the norm of x - y is computed.

Examples

Example 1

In this example, the Euclidean norm of an input vector is computed.

from __future__ import print_function
from pyimsl.math.vectorNormComplex import vectorNormComplex
x = [1 + 2j, 3 + 4j, -2 - 1j, 4 + 5j]

norm = vectorNormComplex(x)
print("Euclidean norm of x = %f" % norm)

Output

Euclidean norm of x = 8.717798

Example 2

This example computes \(\max|x_i-y_i|\) and prints the norm and index.

from __future__ import print_function
from pyimsl.math.vectorNormComplex import vectorNormComplex
x = [1 + 2j, 3 + 4j, -2 - 1j, 4 + 5j]
y = [4 + 3j, 2 + 1j, -1 - 2j, -5 - 4j]

index = []
norm = vectorNormComplex(x, secondVector=y, infNorm=index)
print("Infinity norm of x-y = %f" % norm)
print("at location %d\n" % index[0])

Output

Infinity norm of x-y = 12.727922
at location 3