diff --git a/src/Numerics/LinearAlgebra/Complex/Vector.cs b/src/Numerics/LinearAlgebra/Complex/Vector.cs
index b32957c9..39514064 100644
--- a/src/Numerics/LinearAlgebra/Complex/Vector.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Vector.cs
@@ -146,6 +146,19 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
DoMultiply(1 / scalar, result);
}
+ ///
+ /// Divides a scalar by each element of the vector and stores the result in the result vector.
+ ///
+ /// The scalar to divide.
+ /// The vector to store the result of the division.
+ protected override void DoDivideByThis(Complex scalar, Vector result)
+ {
+ for (var index = 0; index < Count; index++)
+ {
+ result.At(index, scalar / At(index));
+ }
+ }
+
///
/// Pointwise multiplies this vector with another vector and stores the result into the result vector.
///
diff --git a/src/Numerics/LinearAlgebra/Complex32/Vector.cs b/src/Numerics/LinearAlgebra/Complex32/Vector.cs
index 60a3ffc3..93aece30 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Vector.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Vector.cs
@@ -146,6 +146,19 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
DoMultiply(1 / scalar, result);
}
+ ///
+ /// Divides a scalar by each element of the vector and stores the result in the result vector.
+ ///
+ /// The scalar to divide.
+ /// The vector to store the result of the division.
+ protected override void DoDivideByThis(Complex32 scalar, Vector result)
+ {
+ for (var index = 0; index < Count; index++)
+ {
+ result.At(index, scalar / At(index));
+ }
+ }
+
///
/// Pointwise multiplies this vector with another vector and stores the result into the result vector.
///
diff --git a/src/Numerics/LinearAlgebra/Double/Vector.cs b/src/Numerics/LinearAlgebra/Double/Vector.cs
index 26510d32..f6427777 100644
--- a/src/Numerics/LinearAlgebra/Double/Vector.cs
+++ b/src/Numerics/LinearAlgebra/Double/Vector.cs
@@ -145,6 +145,19 @@ namespace MathNet.Numerics.LinearAlgebra.Double
DoMultiply(1 / scalar, result);
}
+ ///
+ /// Divides a scalar by each element of the vector and stores the result in the result vector.
+ ///
+ /// The scalar to divide.
+ /// The vector to store the result of the division.
+ protected override void DoDivideByThis(double scalar, Vector result)
+ {
+ for (var index = 0; index < Count; index++)
+ {
+ result.At(index, scalar / At(index));
+ }
+ }
+
///
/// Pointwise multiplies this vector with another vector and stores the result into the result vector.
///
diff --git a/src/Numerics/LinearAlgebra/Generic/Matrix.cs b/src/Numerics/LinearAlgebra/Generic/Matrix.cs
index 322ea3c8..96217271 100644
--- a/src/Numerics/LinearAlgebra/Generic/Matrix.cs
+++ b/src/Numerics/LinearAlgebra/Generic/Matrix.cs
@@ -110,7 +110,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
{
for (var i = 0; i < columnVectors[j].Count; i++)
{
- matrix.At(i, j, columnVectors[j][i]);
+ matrix.At(i, j, columnVectors[j].At(i));
}
}
@@ -149,7 +149,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
{
for (var j = 0; j < rowVectors[i].Count; j++)
{
- matrix.At(i, j, rowVectors[i][j]);
+ matrix.At(i, j, rowVectors[i].At(j));
}
}
@@ -640,7 +640,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
for (var i = 0; i < min; i++)
{
- diagonal[i] = At(i, i);
+ diagonal.At(i, At(i, i));
}
return diagonal;
@@ -962,7 +962,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
for (var i = 0; i < min; i++)
{
- At(i, i, source[i]);
+ At(i, i, source.At(i));
}
}
diff --git a/src/Numerics/LinearAlgebra/Generic/Vector.BCL.cs b/src/Numerics/LinearAlgebra/Generic/Vector.BCL.cs
index 4a6c31c0..5484f060 100644
--- a/src/Numerics/LinearAlgebra/Generic/Vector.BCL.cs
+++ b/src/Numerics/LinearAlgebra/Generic/Vector.BCL.cs
@@ -96,7 +96,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
{
for (int i = 0; i < Count; ++i)
{
- if (this[i].Equals(item))
+ if (At(i).Equals(item))
return i;
}
return -1;
diff --git a/src/Numerics/LinearAlgebra/Generic/Vector.cs b/src/Numerics/LinearAlgebra/Generic/Vector.cs
index a32d1260..cb2b69b3 100644
--- a/src/Numerics/LinearAlgebra/Generic/Vector.cs
+++ b/src/Numerics/LinearAlgebra/Generic/Vector.cs
@@ -191,6 +191,17 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// The vector to store the result of the subtraction.
protected abstract void DoSubtract(T scalar, Vector result);
+ ///
+ /// Subtracts each element of the vector from a scalar and stores the result in the result vector.
+ ///
+ /// The scalar to subtract from.
+ /// The vector to store the result of the subtraction.
+ protected virtual void DoSubtractFrom(T scalar, Vector result)
+ {
+ DoNegate(result);
+ result.DoAdd(scalar, result);
+ }
+
///
/// Subtracts another vector to this vector and stores the result into the result vector.
///
@@ -219,6 +230,13 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// The vector to store the result of the division.
protected abstract void DoDivide(T scalar, Vector result);
+ ///
+ /// Divides a scalar by each element of the vector and stores the result in the result vector.
+ ///
+ /// The scalar to divide.
+ /// The vector to store the result of the division.
+ protected abstract void DoDivideByThis(T scalar, Vector result);
+
///
/// Computes the modulus for each element of the vector for the given divisor.
///
@@ -391,6 +409,40 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
DoSubtract(scalar, result);
}
+ ///
+ /// Subtracts each element of the vector from a scalar.
+ ///
+ /// The scalar to subtract from.
+ /// A new vector containing the subtraction of the scalar and this vector.
+ public Vector SubtractFrom(T scalar)
+ {
+ var result = CreateVector(Count);
+ DoSubtractFrom(scalar, result);
+ return result;
+ }
+
+ ///
+ /// Subtracts each element of the vector from a scalar and stores the result in the result vector.
+ ///
+ /// The scalar to subtract from.
+ /// The vector to store the result of the subtraction.
+ /// If the result vector is .
+ /// If this vector and are not the same size.
+ public void SubtractFrom(T scalar, Vector result)
+ {
+ if (result == null)
+ {
+ throw new ArgumentNullException("result");
+ }
+
+ if (Count != result.Count)
+ {
+ throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
+ }
+
+ DoSubtractFrom(scalar, result);
+ }
+
///
/// Returns a negated vector.
///
@@ -623,6 +675,40 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
DoDivide(scalar, result);
}
+ ///
+ /// Divides a scalar by each element of the vector.
+ ///
+ /// The scalar to divide.
+ /// A new vector that is the division of the vector and the scalar.
+ public Vector DevideByThis(T scalar)
+ {
+ var result = CreateVector(Count);
+ DoDivideByThis(scalar, result);
+ return result;
+ }
+
+ ///
+ /// Divides a scalar by each element of the vector and stores the result in the result vector.
+ ///
+ /// The scalar to divide.
+ /// The vector to store the result of the division.
+ /// If the result vector is .
+ /// If this vector and are not the same size.
+ public void DivideByThis(T scalar, Vector result)
+ {
+ if (result == null)
+ {
+ throw new ArgumentNullException("result");
+ }
+
+ if (Count != result.Count)
+ {
+ throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
+ }
+
+ DoDivideByThis(scalar, result);
+ }
+
///
/// Computes the modulus for each element of the vector for the given divisor.
///
@@ -795,7 +881,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
for (var i = 0; i < u.Count; i++)
{
- matrix.SetRow(i, v.Multiply(u[i]));
+ matrix.SetRow(i, v.Multiply(u.At(i)));
}
return matrix;
@@ -948,9 +1034,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
throw new ArgumentNullException("rightSide");
}
- var res = rightSide.Negate();
- res.Add(leftSide, res);
- return res;
+ return rightSide.SubtractFrom(leftSide);
}
///
@@ -1005,6 +1089,23 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
return leftSide.DotProduct(rightSide);
}
+ ///
+ /// Divides a scalar with a vector.
+ ///
+ /// The scalar to divide.
+ /// The vector.
+ /// The result of the division.
+ /// If is .
+ public static Vector operator /(T leftSide, Vector rightSide)
+ {
+ if (rightSide == null)
+ {
+ throw new ArgumentNullException("rightSide");
+ }
+
+ return rightSide.DevideByThis(leftSide);
+ }
+
///
/// Divides a vector with a scalar.
///
@@ -1022,6 +1123,24 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
return leftSide.Divide(rightSide);
}
+ ///
+ /// Pointwise divides two Vectors.
+ ///
+ /// The vector to divide.
+ /// The other vector.
+ /// The result of the division.
+ /// If and are not the same size.
+ /// If is .
+ public static Vector operator /(Vector leftSide, Vector rightSide)
+ {
+ if (leftSide == null)
+ {
+ throw new ArgumentNullException("leftSide");
+ }
+
+ return leftSide.PointwiseDivide(rightSide);
+ }
+
///
/// Computes the modulus of each element of the vector of the given divisor.
///
@@ -1091,7 +1210,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// The value of maximum element.
public T Maximum()
{
- return this[MaximumIndex()];
+ return At(MaximumIndex());
}
///
@@ -1106,7 +1225,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// The value of the minimum element.
public T Minimum()
{
- return this[MinimumIndex()];
+ return At(MinimumIndex());
}
///
diff --git a/src/Numerics/LinearAlgebra/Single/Vector.cs b/src/Numerics/LinearAlgebra/Single/Vector.cs
index ed86d2f2..9996a41e 100644
--- a/src/Numerics/LinearAlgebra/Single/Vector.cs
+++ b/src/Numerics/LinearAlgebra/Single/Vector.cs
@@ -145,6 +145,19 @@ namespace MathNet.Numerics.LinearAlgebra.Single
DoMultiply(1 / scalar, result);
}
+ ///
+ /// Divides a scalar by each element of the vector and stores the result in the result vector.
+ ///
+ /// The scalar to divide.
+ /// The vector to store the result of the division.
+ protected override void DoDivideByThis(float scalar, Vector result)
+ {
+ for (var index = 0; index < Count; index++)
+ {
+ result.At(index, scalar / At(index));
+ }
+ }
+
///
/// Pointwise multiplies this vector with another vector and stores the result into the result vector.
///