namespace Cryville.Common.Math {
///
/// Represents a column vector of vector type .
///
/// The vector type of the elements.
public class ColumnVector {
readonly T[] content;
///
/// The size of the vector.
///
public int Size {
get;
private set;
}
///
/// Creates a column vector with specified size.
///
/// The size of the vector.
public ColumnVector(int size) {
content = new T[size];
Size = size;
}
///
/// Creates a column vector from an array.
///
/// The array.
public ColumnVector(T[] c) {
Size = c.Length;
content = c;
}
///
/// Gets or sets the element at the specified index.
///
/// The zero-based index of the element to get or set.
/// The element at the specified index.
public T this[int i] {
get {
return content[i];
}
set {
content[i] = value;
}
}
///
/// Performs dot operation with a column vector.
///
/// The lefthand column vector.
/// The vector operator.
/// The result of the dot operation.
public T Dot(ColumnVector lhs, IVectorOperator o) {
T res = default(T);
for (var i = 0; i < Size; i++)
res = o.Add(res, o.ScalarMultiply(lhs[i], content[i]));
return res;
}
///
/// Creates a column vector and fills it with polynomial coefficients.
///
/// The size of the column vector.
/// The base number.
/// A column vector filled with polynomial coefficients.
public static ColumnVector WithPolynomialCoefficients(int size, float num) {
var m = new ColumnVector(size);
for (var i = 0; i < size; i++)
m[i] = (float)System.Math.Pow(num, i);
return m;
}
}
}