Computes various norms of a vector or the difference of two vectors.
Synopsis
#include<imsl.h>
floatimsl_f_vector_norm (int n, float*x, …., 0)
The type double function is imsl_d_vector_norm.
Required Arguments
intn (Input) The length of the input vector(s).
float*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, , is computed.
Synopsis with Optional Arguments
#include<imsl.h>
floatimsl_f_vector_norm (intn, float*x,
IMSL_ONE_NORM,
IMSL_INF_NORM, int*index,
IMSL_SECOND_VECTOR, float*y,0)
Optional Arguments
IMSL_ONE_NORM Compute the one norm,
IMSL_INF_NORM, int *index (Output) Compute the infinity norm,
IMSL_SECOND_VECTOR, float*y (Input) Compute the norm of x minus y,
∥x-y∥, instead of ∥x∥
Description
By default, imsl_f_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()
{
float x[] = {1.0, 3.0, -2.0, 4.0};
float norm;
int n;
n = sizeof(x)/sizeof(*x);
norm = imsl_f_vector_norm (n, x, 0);
printf("Euclidean norm of x = %f\n", norm);
}
Output
Euclidean norm of x = 5.477226
Example 2
This example computes max |xi−yi| and prints the norm and index.