diff --git a/src/Numerics/LinearAlgebra/Double/DenseVector.cs b/src/Numerics/LinearAlgebra/Double/DenseVector.cs
index ebc9e39a..29202a4c 100644
--- a/src/Numerics/LinearAlgebra/Double/DenseVector.cs
+++ b/src/Numerics/LinearAlgebra/Double/DenseVector.cs
@@ -770,6 +770,45 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return index;
}
+ ///
+ /// Returns the value of the absolute minimum element.
+ ///
+ /// The value of the absolute minimum element.
+ public override double AbsoluteMinimum()
+ {
+ return Math.Abs(this.Data[this.AbsoluteMinimumIndex()]);
+ }
+
+ ///
+ /// Returns the value of the absolute maximum element.
+ ///
+ /// The value of the absolute maximum element.
+ public override double AbsoluteMaximum()
+ {
+ return Math.Abs(this.Data[this.AbsoluteMaximumIndex()]);
+ }
+
+ ///
+ /// Returns the index of the absolute maximum element.
+ ///
+ /// The index of absolute maximum element.
+ public override int AbsoluteMaximumIndex()
+ {
+ var index = 0;
+ var max = Math.Abs(this.Data[index]);
+ for (var i = 1; i < this.Count; i++)
+ {
+ var test = Math.Abs(this.Data[i]);
+ if (test > max)
+ {
+ index = i;
+ max = test;
+ }
+ }
+
+ return index;
+ }
+
///
/// Creates a vector containing specified elements.
///
@@ -1101,7 +1140,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// If the n vector is non poisitive.
public override Vector Random(int length, IContinuousDistribution randomDistribution)
{
- if (length < 0)
+ if (length < 1)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "length");
}
@@ -1127,7 +1166,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// If the n vector is non poisitive.
public override Vector Random(int length, IDiscreteDistribution randomDistribution)
{
- if (length < 0)
+ if (length < 1)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "length");
}
diff --git a/src/Numerics/LinearAlgebra/Double/Vector.cs b/src/Numerics/LinearAlgebra/Double/Vector.cs
index 6e14c1c6..5c44bad7 100644
--- a/src/Numerics/LinearAlgebra/Double/Vector.cs
+++ b/src/Numerics/LinearAlgebra/Double/Vector.cs
@@ -810,6 +810,36 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return index;
}
+ ///
+ /// Returns the value of the absolute maximum element.
+ ///
+ /// The value of the absolute maximum element.
+ public virtual double AbsoluteMaximum()
+ {
+ return Math.Abs(this[this.AbsoluteMaximumIndex()]);
+ }
+
+ ///
+ /// Returns the index of the absolute maximum element.
+ ///
+ /// The index of absolute maximum element.
+ public virtual int AbsoluteMaximumIndex()
+ {
+ var index = 0;
+ var max = Math.Abs(this[index]);
+ for (var i = 1; i < this.Count; i++)
+ {
+ var test = Math.Abs(this[i]);
+ if (test > max)
+ {
+ index = i;
+ max = test;
+ }
+ }
+
+ return index;
+ }
+
///
/// Returns the value of maximum element.
///
diff --git a/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs
index 2505df18..b2c25cf7 100644
--- a/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs
+++ b/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs
@@ -296,6 +296,24 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
Assert.AreEqual(expected, actual);
}
+ [Test]
+ public void CanFindAbsoluteMaximumIndex()
+ {
+ var source = this.CreateVector(this._data);
+ var expected = 0;
+ var actual = source.AbsoluteMaximumIndex();
+ Assert.AreEqual(expected, actual);
+ }
+
+ [Test]
+ public void CanFindAbsoluteMaximum()
+ {
+ var source = this.CreateVector(this._data);
+ double expected = 1;
+ var actual = source.AbsoluteMaximum();
+ Assert.AreEqual(expected, actual);
+ }
+
[Test]
public void CanFindMaximumIndex()
{