diff --git a/src/Numerics/LinearAlgebra/Double/Vector.cs b/src/Numerics/LinearAlgebra/Double/Vector.cs
index 07adaa61..27b67cd0 100644
--- a/src/Numerics/LinearAlgebra/Double/Vector.cs
+++ b/src/Numerics/LinearAlgebra/Double/Vector.cs
@@ -608,6 +608,37 @@ namespace MathNet.Numerics.LinearAlgebra.Double
this.Count,
index => result[index] = this[index] * other[index]);
}
+
+ ///
+ /// Returns the value of the absolute minimum element.
+ ///
+ /// The value of the absolute minimum element.
+ public virtual double AbsoluteMinimum()
+ {
+ return Math.Abs(this[AbsoluteMinimumIndex()]);
+ }
+
+ ///
+ /// Returns the index of the absolute minimum element.
+ ///
+ /// The index of absolute minimum element.
+ public virtual int AbsoluteMinimumIndex()
+ {
+ int index = 0;
+ double min = System.Math.Abs(this[index]);
+ for (int i = 1; i < Count; i++)
+ {
+ double test = System.Math.Abs(this[i]);
+ if (test < min)
+ {
+ index = i;
+ min = test;
+ }
+ }
+ return index;
+ }
+
+
#endregion
#region Arithmetic Operator Overloading
@@ -1076,6 +1107,35 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return matrix;
}
+ ///
+ /// Creates a vector containing specified elements.
+ ///
+ /// The first element to begin copying from.
+ /// The number of elements to copy.
+ /// A vector containing a copy of the specified elements.
+ /// - If is not positive or
+ /// greater than or equal to the size of the vector.
+ /// - If + is greater than or equal to the size of the vector.
+ ///
+ /// If is not positive.
+ public virtual Vector SubVector(int start, int length)
+ {
+ if (start < 0 || start >= Count)
+ {
+ throw new ArgumentOutOfRangeException("start");
+ }
+ if (start + length > Count)
+ {
+ throw new ArgumentOutOfRangeException("start");
+ }
+
+ Vector result = CreateVector(length);
+
+ CommonParallel.For(start,
+ start + length, index => result[index-start] = this[index]);
+ return result;
+ }
+
#endregion
#region Implemented Interfaces
diff --git a/src/UnitTests/LinearAlgebraTests/Double/VectorTests.Arithmetic.cs b/src/UnitTests/LinearAlgebraTests/Double/VectorTests.Arithmetic.cs
index 56dee3ae..a9b429f7 100644
--- a/src/UnitTests/LinearAlgebraTests/Double/VectorTests.Arithmetic.cs
+++ b/src/UnitTests/LinearAlgebraTests/Double/VectorTests.Arithmetic.cs
@@ -782,5 +782,41 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
}
}
+ [Test]
+ public void CanFindAbsoluteMinimumIndex()
+ {
+ Vector source = CreateVector(_data);
+ int expected = 0;
+ int actual = source.AbsoluteMinimumIndex();
+ Assert.AreEqual(expected, actual);
+ }
+
+ [Test]
+ public void CanFindAbsoluteMinimum()
+ {
+ Vector source = CreateVector(_data);
+ double expected = 1;
+ double actual = source.AbsoluteMinimum();
+ Assert.AreEqual(expected, actual);
+
+ }
+
+ [Test]
+ [Row(0, 5)]
+ [Row(2, 2)]
+ [Row(1, 4)]
+ [Row(6, 10, ExpectedException = typeof(ArgumentOutOfRangeException))]
+ [Row(1, 10, ExpectedException = typeof(ArgumentOutOfRangeException))]
+ public void SubVector(int start, int length)
+ {
+ Vector vector = CreateVector(_data);
+ Vector sub = vector.SubVector(start, length);
+ Assert.AreEqual(length, sub.Count);
+ for (int i = 0; i < length; i++)
+ {
+ Assert.AreEqual(vector[i + start], sub[i]);
+ }
+ }
+
}
}
\ No newline at end of file