The Extreme Optimization Numerical Libraries for .NET provides access to all common mathematical
properties of vectors. Because of the cost involved in computing these properties, in particular for large vectors,
these properties have been implemented as methods.
General properties
The Length property returns the number of
elements in the vector.
The GetComponents()()() property returns a
Double array containing the components of a vector. The components are copied from
the vector's private storage to a new array.
The following example illustrates these properties:
| C# | Copy |
|---|
Vector v = Vector.Create(1.0, 2.0, 4.0, 8.0);
Console.WriteLine("Length of vector v = {0}", v.Length);
double[] c = v.GetComponents();
Console.WriteLine("Components: {0}, {1}, {2}, {3}", c[0], c[1], c[2], c[3]);
|
| Visual Basic | Copy |
|---|
Dim v As Vector = Vector.Create(1.0, 2.0, 4.0, 8.0)
Console.WriteLine("Length of vector v = {0}", v.Length)
Dim c As Double() = v.GetComponents()
Console.WriteLine("Components: {0}, {1}, {2}, {3}", c(0), c(1), c(2), c(3));
|
Vector Norms
The norm of a vector is a measure for the size of the vector. Most common is the two-norm, defined as the sum of
the squares of the components of a vector. The two-norm of a three-dimensional vector corresponds to the common
Euclidian length of the vector. The Norm()()() method,
without arguments, returns the two-norm. The NormSquared()()() method returns the square of the two-norm,
which is the same as the sum of the squares of the components.
The one-norm of a vector is the sum of the absolute values of its components. The OneNorm method returns this
value.
Other norms can be defined. In general, the p-norm of a vector a with components
ai is defined as
The parameter p can be any real number. If p is negative and one of the components is zero, then
the norm is always zero. Two overloads of the Norm()()()
method provide optimized norm calculation for Norm(Int32) and Norm(Double) arguments. The most commonly used
values of p, along with their meaning, are summarized in the table below:
The example below illustrates the various norm methods:
| C# | Copy |
|---|
Vector v = new Vector(1, 2, 3, 4, 5);
double a, b;
a = v.Norm();
Console.WriteLine("|v| = {0}", a);
a = v.Norm(1);
b = v.OneNorm();
Console.WriteLine("one norm(v) = {0} = {1}", a, b);
a = v.Norm(Double.PositiveInfinity);
Console.WriteLine("+inf norm(v) = {0}", a);
a = v.Norm(Double.NegativeInfinity);
Console.WriteLine("-inf norm(v) = {0}", a);
a = v.Norm(0);
b = v.Length;
Console.WriteLine("zero-norm(v) = {0} = {1}", a, b);
a = v.NormSquared();
b = v.Norm();
Console.WriteLine("|v|^2 = {0} = {0}", a, b*b);
|
| Visual Basic | Copy |
|---|
Dim v As Vector = Vector.Create(1, 2, 3, 4, 5)
Dim a, b As Double
a = v.Norm()
Console.WriteLine("|v| = {0}", a)
a = v.Norm(1)
b = v.OneNorm()
Console.WriteLine("one norm(v) = {0} = {1}", a, b)
a = v.Norm(Double.PositiveInfinity)
Console.WriteLine("+inf norm(v) = {0}", a)
a = v.Norm(Double.NegativeInfinity)
Console.WriteLine("-inf norm(v) = {0}", a)
a = v.Norm(0)
b = v.Length
Console.WriteLine("zero-norm(v) = {0} = {1}", a, b)
a = v.NormSquared()
b = v.Norm()
Console.WriteLine("|v|^2 = {0} = {1}", a, b*b);Dim v As Vector = Vector.Create(1.0, 2.0, 4.0, 8.0)
|
In the above example, the variable a always contains the value calculated using the general norm method. The
variable b contains the value obtained using the equivalent specialized method, if available.
Extreme values
The Extreme Optimization Numerical Libraries for .NET provides methods for providing extreme values of
the components of a vector, as well as the index of the component with the extreme value. The following table
summarizes the methods that can be used to obtain the value or index of an extreme value: