vector_norm (complex)

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

Synopsis

#include <imsl.h>

float imsl_c_vector_norm (int n, f_complex x[],, 0)

The type d_complex function is imsl_z_vector_norm.

Required Arguments

int n (Input)

The length of the input vector(s).

f_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, x2 , is computed.

Synopsis with Optional Arguments

#include <imsl.h>

float imsl_c_vector_norm (int n, f_complex x[],

IMSL_ONE_NORM,

IMSL_INF_NORM, int *index,

IMSL_SECOND_VECTOR, f_complex y[],

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_complex y[] (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.

 

#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}

};

f_complex y[4] = {

{4.0, 3.0},

{2.0, 1.0},

{-1.0, -2.0},

{-5.0, -4.0}

};

float norm;

int index;

 

norm = imsl_c_vector_norm (4, x,

IMSL_SECOND_VECTOR, y,

IMSL_INF_NORM, &index,

0);

 

printf("Infinity norm of x-y = %f ", norm);

printf("at location %d\n", index);

}

Output

 

Infinity norm of x-y = 12.727922 at location 3