Computes various norms of a vector or the difference of two vectors.
Synopsis
#include <imsl.h>
floatimsl_c_vector_norm (intn, f_complexx[],…, 0)
The type d_complex function is imsl_z_vector_norm.
Required Arguments
intn (Input)
The length of the input vector(s).
f_complexx[] (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.
Synopsis with Optional Arguments
#include<imsl.h>
floatimsl_c_vector_norm (intn, f_complexx[],
IMSL_ONE_NORM,
IMSL_INF_NORM, int*index,
IMSL_SECOND_VECTOR, f_complexy[],
0)
Optional Arguments
IMSL_ONE_NORM
Compute the one norm,
IMSL_INF_NORM, int*index (Output)
Compute the infinity norm,
The index at which the vector has its maximum absolute value is also returned.
IMSL_SECOND_VECTOR, f_complexy[] (Input)
Compute the norm of x minus y,
∥x-y∥, instead of ∥x∥
Description
By default, imsl_c_vector_norm computes the Euclidean norm
If the option IMSL_ONE_NORM is selected, the 1-norm
is returned. If the option IMSL_INF_NORM is selected, the infinity norm
max ∣xi∣
is returned. In the case of the infinity norm, the program also returns the index of the element with maximum modulus. If IMSL_SECOND_VECTOR 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.
#include <stdio.h>
#include <imsl.h>
int main()
{
f_complex x[4] = {
{1.0, 2.0},
{3.0, 4.0},
{-2.0, -1.0},
{4.0, 5.0}
};
float norm;
norm = imsl_c_vector_norm (4, x, 0);
printf("Euclidean norm of x = %f\n", norm);
}
Output
Euclidean norm of x = 8.717798
Example 2
This example computes max ∣xi-yi∣ and prints the norm and index.