Extreme Optimization >
Mathematics Library for .NET >
User's Guide >
Current Page >
Mathematical properties
Extreme Optimization Mathematics Library for .NET
Mathematical properties
The Extreme Optimization Mathematics Library 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:
Vector v = new GeneralVector(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]);
Dim v As Vector = New GeneralVector(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));
|
| C# | VB.NET | |
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
integer and
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:
Vector v = new Vector(1, 2, 3, 4, 5);
double a, b;
// No arguments: the standard Euclidian norm:
a = v.Norm();
Console.WriteLine("|v| = {0}", a);
// One norm:
a = v.Norm(1);
b = v.OneNorm();
Console.WriteLine("one norm(v) = {0} = {1}", a, b);
// +inf and -inf norms:
a = v.Norm(Double.PositiveInfinity);
Console.WriteLine("+inf norm(v) = {0}", a);
a = v.Norm(Double.NegativeInfinity);
Console.WriteLine("-inf norm(v) = {0}", a);
// Zero norm:
a = v.Norm(0);
b = v.Length;
Console.WriteLine("zero-norm(v) = {0} = {1}", a, b);
// You can get the square of the two norm with the
// NormSquared method.
a = v.NormSquared();
b = v.Norm();
Console.WriteLine("|v|^2 = {0} = {0}", a, b*b);
Dim v As Vector = New GeneralVector(1, 2, 3, 4, 5)
Dim a, b As Double
' No arguments: the standard Euclidian norm:
a = v.Norm()
Console.WriteLine("|v| = {0}", a)
' One norm:
a = v.Norm(1)
b = v.OneNorm()
Console.WriteLine("one norm(v) = {0} = {1}", a, b)
' +inf and -inf norms:
a = v.Norm(Double.PositiveInfinity)
Console.WriteLine("+inf norm(v) = {0}", a)
a = v.Norm(Double.NegativeInfinity)
Console.WriteLine("-inf norm(v) = {0}", a)
' Zero norm:
a = v.Norm(0)
b = v.Length
Console.WriteLine("zero-norm(v) = {0} = {1}", a, b)
' You can get the square of the two norm with the
' NormSquared method.
a = v.NormSquared()
b = v.Norm()
Console.WriteLine("|v|^2 = {0} = {0}", a, b*b);Dim v As Vector = New GeneralVector(1.0, 2.0, 4.0, 8.0)
|
| C# | VB.NET | |
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 Mathematics Library 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:
Copyright 2004-2008,
Extreme Optimization. All rights reserved.
Extreme Optimization, Complexity made simple, M#, and M
Sharp are trademarks of ExoAnalytics Inc.
Microsoft, Visual C#, Visual Basic, Visual Studio, Visual
Studio.NET, and the Visual Studio Logo are registered trademarks of Microsoft Corporation