38 lines
819 B
C#
38 lines
819 B
C#
namespace Cryville.Common.Math {
|
|
public class ColumnVector<T> {
|
|
readonly T[] content;
|
|
public int Size {
|
|
get;
|
|
private set;
|
|
}
|
|
public ColumnVector(int size) {
|
|
content = new T[size];
|
|
Size = size;
|
|
}
|
|
public ColumnVector(T[] c) {
|
|
Size = c.Length;
|
|
content = c;
|
|
}
|
|
public T this[int i] {
|
|
get {
|
|
return content[i];
|
|
}
|
|
set {
|
|
content[i] = value;
|
|
}
|
|
}
|
|
public T Dot(ColumnVector<float> lhs, IVectorOperator<T> o) {
|
|
T res = default(T);
|
|
for (var i = 0; i < Size; i++)
|
|
res = o.Add(res, o.ScalarMultiply(lhs[i], content[i]));
|
|
return res;
|
|
}
|
|
public static ColumnVector<float> WithPolynomialCoefficients(int size, float num) {
|
|
var m = new ColumnVector<float>(size);
|
|
for (var i = 0; i < size; i++)
|
|
m[i] = (float)System.Math.Pow(num, i);
|
|
return m;
|
|
}
|
|
}
|
|
}
|