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; for (var i = 0; i < Size; i++) res = o.Add(res, o.ScalarMultiply(lhs[i], content[i])); return res; } /// /// Fills a column vector with polynomial coefficients. /// /// The column vector. /// The base number. public static void FillWithPolynomialCoefficients(ColumnVector vec, float num) { for (var i = 0; i < vec.Size; i++) vec[i] = (float)System.Math.Pow(num, i); } } }