本文整理汇总了C#中VectorF类的典型用法代码示例。如果您正苦于以下问题:C# VectorF类的具体用法?C# VectorF怎么用?C# VectorF使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VectorF类属于命名空间,在下文中一共展示了VectorF类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add
public void Add()
{
VectorF v1 = new VectorF(new float[] { 1, 2, 3, 4, 5 });
VectorF v2 = new VectorF(new float[] { 6, 7, 8, 9, 10 });
VectorF v3 = VectorF.Add(v1, v2);
Assert.AreEqual(new VectorF(new float[] { 7, 9, 11, 13, 15 }), v3);
}
示例2: PrincipalComponentAnalysisF
//--------------------------------------------------------------
/// <summary>
/// Creates the principal component analysis for the given list of points.
/// </summary>
/// <param name="points">
/// The list of data points. All points must have the same
/// <see cref="VectorF.NumberOfElements"/>.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="points"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// <paramref name="points"/> is empty.
/// </exception>
public PrincipalComponentAnalysisF(IList<VectorF> points)
{
if (points == null)
throw new ArgumentNullException("points");
if (points.Count == 0)
throw new ArgumentException("The list of points is empty.");
// Compute covariance matrix.
MatrixF covarianceMatrix = StatisticsHelper.ComputeCovarianceMatrix(points);
// Perform Eigenvalue decomposition.
EigenvalueDecompositionF evd = new EigenvalueDecompositionF(covarianceMatrix);
int numberOfElements = evd.RealEigenvalues.NumberOfElements;
Variances = new VectorF(numberOfElements);
V = new MatrixF(numberOfElements, numberOfElements);
// Sort eigenvalues by decreasing value.
// Since covarianceMatrix is symmetric, we have no imaginary eigenvalues.
for (int i = 0; i < Variances.NumberOfElements; i++)
{
int index = evd.RealEigenvalues.IndexOfLargestElement;
Variances[i] = evd.RealEigenvalues[index];
V.SetColumn(i, evd.V.GetColumn(index));
evd.RealEigenvalues[index] = float.NegativeInfinity;
}
}
示例3: NodeDestDistInt
/// <summary>Creates a new instance of NodeDestDistInt.</summary>
/// <param name="node">The source Node.</param>
/// <param name="dest">The destination of the new node.</param>
/// <param name="dist">The distance from the source node to the nearest intersection.</param>
/// <param name="intersections">The number of intersections.</param>
public NodeDestDistInt(Node node, VectorF dest, FInt dist, int intersections)
{
this.Node = node;
this.Dest = dest;
this.Dist = dist;
this.Intersections = intersections;
}
示例4: Integrate
/// <summary>
/// Computes the new state x1 at time t1.
/// </summary>
/// <param name="x0">The state x0 at time t0.</param>
/// <param name="t0">The time t0.</param>
/// <param name="t1">The target time t1 for which the new state x1 is computed.</param>
/// <returns>The new state x1 at time t1.</returns>
public override VectorF Integrate(VectorF x0, float t0, float t1)
{
float dt = (t1 - t0);
VectorF d = FirstOrderDerivative(x0, t0);
VectorF result = x0 + dt * d;
return result;
}
示例5: Test1
public void Test1()
{
VectorF state = new VectorF(new float[]{ 0, 1 });
VectorF result = new RungeKutta4IntegratorF(GetFirstOrderDerivatives).Integrate(state, 2, 2.5f);
Assert.AreEqual(0f, result[0]);
Assert.AreEqual(3.061035156f, result[1]);
}
示例6: GetFirstOrderDerivatives
public VectorF GetFirstOrderDerivatives(VectorF x, float t)
{
// A dummy function: f(x[index], t) = index * t;
VectorF result = new VectorF(x.NumberOfElements);
for (int i = 0; i < result.NumberOfElements; i++)
result[i] = i*t;
return result;
}
示例7: EigenvalueDecompositionF
//--------------------------------------------------------------
/// <summary>
/// Creates the eigenvalue decomposition of the given matrix.
/// </summary>
/// <param name="matrixA">The square matrix A.</param>
/// <exception cref="ArgumentNullException">
/// <paramref name="matrixA"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// <paramref name="matrixA"/> is non-square (rectangular).
/// </exception>
public EigenvalueDecompositionF(MatrixF matrixA)
{
if (matrixA == null)
throw new ArgumentNullException("matrixA");
if (matrixA.IsSquare == false)
throw new ArgumentException("The matrix A must be square.", "matrixA");
_n = matrixA.NumberOfColumns;
_d = new VectorF(_n);
_e = new VectorF(_n);
_isSymmetric = matrixA.IsSymmetric;
if (_isSymmetric)
{
_v = matrixA.Clone();
// Tridiagonalize.
ReduceToTridiagonal();
// Diagonalize.
TridiagonalToQL();
}
else
{
_v = new MatrixF(_n, _n);
// Abort if A contains NaN values.
// If we continue with NaN values, we run into an infinite loop.
for (int i = 0; i < _n; i++)
{
for (int j = 0; j < _n; j++)
{
if (Numeric.IsNaN(matrixA[i, j]))
{
_e.Set(float.NaN);
_v.Set(float.NaN);
_d.Set(float.NaN);
return;
}
}
}
// Storage of nonsymmetric Hessenberg form.
MatrixF matrixH = matrixA.Clone();
// Working storage for nonsymmetric algorithm.
float[] ort = new float[_n];
// Reduce to Hessenberg form.
ReduceToHessenberg(matrixH, ort);
// Reduce Hessenberg to real Schur form.
HessenbergToRealSchur(matrixH);
}
}
示例8: SolveWithDefaultInitialGuess
public void SolveWithDefaultInitialGuess()
{
MatrixF A = new MatrixF(new float[,] { { 4 } });
VectorF b = new VectorF(new float[] { 20 });
JacobiMethodF solver = new JacobiMethodF();
VectorF x = solver.Solve(A, b);
Assert.IsTrue(VectorF.AreNumericallyEqual(new VectorF(1, 5), x));
Assert.AreEqual(2, solver.NumberOfIterations);
}
示例9: Test1
public void Test1()
{
MatrixF A = new MatrixF(new float[,] { { 4 } });
VectorF b = new VectorF(new float[] { 20 });
SorMethodF solver = new SorMethodF();
VectorF x = solver.Solve(A, null, b);
Assert.IsTrue(VectorF.AreNumericallyEqual(new VectorF(1, 5), x));
Assert.AreEqual(2, solver.NumberOfIterations);
}
示例10: Test1
public void Test1()
{
VectorF state = new VectorF (new float[]{ 1, 2, 3, 4, 5, 6 });
VectorF result = new ExplicitEulerIntegratorF(GetFirstOrderDerivatives).Integrate(state, 2, 2.5f);
Assert.AreEqual(1f, result[0]);
Assert.AreEqual(3f, result[1]);
Assert.AreEqual(5f, result[2]);
Assert.AreEqual(7f, result[3]);
Assert.AreEqual(9f, result[4]);
Assert.AreEqual(11f, result[5]);
}
示例11: Test4
public void Test4()
{
MatrixF A = new MatrixF(new float[,] { { -12, 2 },
{ 2, 3 }});
VectorF b = new VectorF(new float[] { 20, 28 });
SorMethodF solver = new SorMethodF();
VectorF x = solver.Solve(A, null, b);
VectorF solution = MatrixF.SolveLinearEquations(A, b);
Assert.IsTrue(VectorF.AreNumericallyEqual(solution, x));
}
示例12: Test1
public void Test1()
{
VectorF state = new VectorF (new float[] { 0, 1, 2, 3, 4, 5 });
VectorF result = new MidpointIntegratorF(GetFirstOrderDerivatives).Integrate(state, 2, 2.5f);
Assert.AreEqual(0f, result[0]);
Assert.AreEqual(2.125f, result[1]);
Assert.AreEqual(4.25f, result[2]);
Assert.AreEqual(6.375f, result[3]);
Assert.AreEqual(8.5f, result[4]);
Assert.AreEqual(10.625f, result[5]);
}
示例13: Test2
public void Test2()
{
MatrixF A = new MatrixF(new float[,] { { 1, 0 },
{ 0, 1 }});
VectorF b = new VectorF(new float[] { 20, 28 });
JacobiMethodF solver = new JacobiMethodF();
VectorF x = solver.Solve(A, null, b);
Assert.IsTrue(VectorF.AreNumericallyEqual(b, x));
Assert.AreEqual(2, solver.NumberOfIterations);
}
示例14: Test3
public void Test3()
{
MatrixF A = new MatrixF(new float[,] { { 2, 0 },
{ 0, 2 }});
VectorF b = new VectorF(new float[] { 20, 28 });
GaussSeidelMethodF solver = new GaussSeidelMethodF();
VectorF x = solver.Solve(A, null, b);
Assert.IsTrue(VectorF.AreNumericallyEqual(b / 2, x));
Assert.AreEqual(2, solver.NumberOfIterations);
}
示例15: Test5
public void Test5()
{
MatrixF A = new MatrixF(new float[,] { { -21, 2, -4, 0 },
{ 2, 3, 0.1f, -1 },
{ 2, 10, 111.1f, -11 },
{ 23, 112, 111.1f, -143 }});
VectorF b = new VectorF(new float[] { 20, 28, -12, 0.1f });
GaussSeidelMethodF solver = new GaussSeidelMethodF();
VectorF x = solver.Solve(A, null, b);
VectorF solution = MatrixF.SolveLinearEquations(A, b);
Assert.IsTrue(VectorF.AreNumericallyEqual(solution, x));
}