Extreme Optimization >
User's Guide >
Vector and Matrix Library >
Vectors >
Mathematical Properties
Extreme Optimization User's Guide
User's Guide
Up: Vectors Next: Operations on Vectors Previous: Accessing Vector Components Contents
Mathematical properties
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 Code |
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]); |
| Visual Basic | Copy Code |
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)); |
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:
| C# | Copy Code |
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); |
| Visual Basic | Copy Code |
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) |
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:
Up: Vectors Next: Operations on Vectors Previous: Accessing Vector Components Contents
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