当前位置: 首页>>代码示例>>C#>>正文


C# VectorD类代码示例

本文整理汇总了C#中VectorD的典型用法代码示例。如果您正苦于以下问题:C# VectorD类的具体用法?C# VectorD怎么用?C# VectorD使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


VectorD类属于命名空间,在下文中一共展示了VectorD类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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 VectorD Integrate(VectorD x0, double t0, double t1)
 {
     double dt = (t1 - t0);
       VectorD d = FirstOrderDerivative(x0, t0);
       VectorD result = x0 + dt * d;
       return result;
 }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:14,代码来源:ExplicitEulerIntegratorD.cs

示例2: PrincipalComponentAnalysisD

        //--------------------------------------------------------------
        /// <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="VectorD.NumberOfElements"/>.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="points"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="points"/> is empty.
        /// </exception>
        public PrincipalComponentAnalysisD(IList<VectorD> points)
        {
            if (points == null)
            throw new ArgumentNullException("points");
              if (points.Count == 0)
            throw new ArgumentException("The list of points is empty.");

              // Compute covariance matrix.
              MatrixD covarianceMatrix = StatisticsHelper.ComputeCovarianceMatrix(points);

              // Perform Eigenvalue decomposition.
              EigenvalueDecompositionD evd = new EigenvalueDecompositionD(covarianceMatrix);

              int numberOfElements = evd.RealEigenvalues.NumberOfElements;
              Variances = new VectorD(numberOfElements);
              V = new MatrixD(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] = double.NegativeInfinity;
              }
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:43,代码来源:PrincipalComponentAnalysisD.cs

示例3: TestCorrelation2

        public void TestCorrelation2()
        {
            var data = new VectorD[] {
                new VectorD(6, 10),
                new VectorD(10, 13),
                new VectorD(6, 8),
                new VectorD(10, 15),
                new VectorD(5, 8),
                new VectorD(3, 6),
                new VectorD(5, 9),
                new VectorD(9, 10),
                new VectorD(3, 7),
                new VectorD(3, 3),
                new VectorD(11, 18),
                new VectorD(6, 14),
                new VectorD(11, 18),
                new VectorD(9, 11),
                new VectorD(7, 12),
                new VectorD(5, 5),
                new VectorD(8, 7),
                new VectorD(7, 12),
                new VectorD(7, 7),
                new VectorD(9, 7)
            };
            var cor = BaseStatistics.Correlation(data, 0, 1);

            Assert.AreEqual<double>(0.749659, Math.Round(cor, 6));
        }
开发者ID:umebayashi,项目名称:CLR,代码行数:28,代码来源:BaseStatisticsTest.cs

示例4: FindIntersection

        public bool FindIntersection(Line2D other, out VectorD intersection)
        {
            /* http://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect
             * Now there are five cases:
             * If r × s = 0 and (q − p) × r = 0, then the two lines are collinear. If in addition, either 0 ≤ (q − p) · r ≤ r · r or 0 ≤ (p − q) · s ≤ s · s, then the two lines are overlapping.
             * If r × s = 0 and (q − p) × r = 0, but neither 0 ≤ (q − p) · r ≤ r · r nor 0 ≤ (p − q) · s ≤ s · s, then the two lines are collinear but disjoint.
             * If r × s = 0 and (q − p) × r ≠ 0, then the two lines are parallel and non-intersecting.
             * If r × s ≠ 0 and 0 ≤ t ≤ 1 and 0 ≤ u ≤ 1, the two line segments meet at the point p + t r = q + u s.
             * Otherwise, the two line segments are not parallel but do not intersect.
             */

            // line1.Start = p
            // line2.Start = q

            var r = Stop - Start;
            var s = other.Stop - other.Start;
            var startPointVector = (other.Start - Start);

            var denom = r.Cross(s); // denom = r × s

            var firstScalar = startPointVector.Cross(s) / denom; // firstScalar = t
            var secondScalar = startPointVector.Cross(r) / denom; // secondScalar = u
            intersection = Start + (firstScalar * r);
            // ReSharper disable CompareOfFloatsByEqualityOperator
            return denom != 0d && firstScalar >= 0d && firstScalar <= 1d && secondScalar >= 0d && secondScalar <= 1d;
            // ReSharper restore CompareOfFloatsByEqualityOperator
        }
开发者ID:Melamew,项目名称:iLynx.Common,代码行数:27,代码来源:Line2D.cs

示例5: Add

 public void Add()
 {
     VectorD v1 = new VectorD(new double[] { 1, 2, 3, 4, 5 });
       VectorD v2 = new VectorD(new double[] { 6, 7, 8, 9, 10 });
       VectorD v3 = VectorD.Add(v1, v2);
       Assert.AreEqual(new VectorD(new double[] { 7, 9, 11, 13, 15 }), v3);
 }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:7,代码来源:VectorDTest.cs

示例6: TestVectorDProd

		public void TestVectorDProd()
		{
			var vector = new VectorD(2.5, 3.0, 4.1);
			var prod = Math.Round(vector.Prod(), 2);

			Assert.AreEqual<double>(30.75, prod);
		}
开发者ID:umebayashi,项目名称:mathmatix.net,代码行数:7,代码来源:VectorTest.cs

示例7: Test1

        public void Test1()
        {
            VectorD state = new VectorD(new double[]{ 0, 1 });
              VectorD result = new RungeKutta4IntegratorD(GetFirstOrderDerivatives).Integrate(state, 2, 2.5);

              Assert.AreEqual(0, result[0]);
              Assert.AreEqual(3.06103515625, result[1]);
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:8,代码来源:RungeKutta4IntegratorDTest.cs

示例8: GetFirstOrderDerivatives

 public VectorD GetFirstOrderDerivatives(VectorD x, double t)
 {
     // A dummy function: f(x[index], t) = index * t;
       VectorD result = new VectorD(x.NumberOfElements);
       for (int i = 0; i < result.NumberOfElements; i++)
     result[i] = i*t;
       return result;
 }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:8,代码来源:ExplicitEulerIntegratorDTest.cs

示例9: TestUnion

		public void TestUnion()
		{
			var x = new VectorD(2, 4, 6, 8);
			var y = new VectorD(4, 8, 12, 14, 16);
			var union = x.Union(y);

			Assert.AreEqual<VectorD>(
				new VectorD(2, 4, 6, 8, 12, 14, 16),
				union);
		}
开发者ID:umebayashi,项目名称:mathmatix.net,代码行数:10,代码来源:VectorTest.cs

示例10: TestIntersect

        public void TestIntersect()
        {
            var x = new VectorD(2, 4, 6, 8);
            var y = new VectorD(4, 8, 12, 14, 16);
            var intersect = x.Intersect(y);

            Assert.AreEqual<VectorD>(
                new VectorD(4, 8),
                intersect);
        }
开发者ID:umebayashi,项目名称:Descartes,代码行数:10,代码来源:VectorTest.cs

示例11: EigenvalueDecompositionD

        //--------------------------------------------------------------
        /// <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 EigenvalueDecompositionD(MatrixD 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 VectorD(_n);
              _e = new VectorD(_n);

              _isSymmetric = matrixA.IsSymmetric;

              if (_isSymmetric)
              {
            _v = matrixA.Clone();

            // Tridiagonalize.
            ReduceToTridiagonal();

            // Diagonalize.
            TridiagonalToQL();
              }
              else
              {
            _v = new MatrixD(_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(double.NaN);
              _v.Set(double.NaN);
              _d.Set(double.NaN);
              return;
            }
              }
            }

            // Storage of nonsymmetric Hessenberg form.
            MatrixD matrixH = matrixA.Clone();
            // Working storage for nonsymmetric algorithm.
            double[] ort = new double[_n];

            // Reduce to Hessenberg form.
            ReduceToHessenberg(matrixH, ort);

            // Reduce Hessenberg to real Schur form.
            HessenbergToRealSchur(matrixH);
              }
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:66,代码来源:EigenvalueDecompositionD.cs

示例12: SolveWithDefaultInitialGuess

        public void SolveWithDefaultInitialGuess()
        {
            MatrixD A = new MatrixD(new double[,] { { 4 } });
              VectorD b = new VectorD(new double[] { 20 });

              JacobiMethodD solver = new JacobiMethodD();
              VectorD x = solver.Solve(A, b);

              Assert.IsTrue(VectorD.AreNumericallyEqual(new VectorD(1, 5), x));
              Assert.AreEqual(2, solver.NumberOfIterations);
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:11,代码来源:JacobiMethodDTest.cs

示例13: Test1

        public void Test1()
        {
            MatrixD A = new MatrixD(new double[,] { { 4 } });
              VectorD b = new VectorD(new double[] { 20 });

              SorMethodD solver = new SorMethodD();
              VectorD x = solver.Solve(A, null, b);

              Assert.IsTrue(VectorD.AreNumericallyEqual(new VectorD(1, 5), x));
              Assert.AreEqual(2, solver.NumberOfIterations);
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:11,代码来源:SorMethodDTest.cs

示例14: Test2

        public void Test2()
        {
            MatrixD A = new MatrixD(new double[,] { { 1, 0 },
                                              { 0, 1 }});
              VectorD b = new VectorD(new double[] { 20, 28 });

              JacobiMethodD solver = new JacobiMethodD();
              VectorD x = solver.Solve(A, null, b);

              Assert.IsTrue(VectorD.AreNumericallyEqual(b, x));
              Assert.AreEqual(2, solver.NumberOfIterations);
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:12,代码来源:JacobiMethodDTest.cs

示例15: Test1

        public void Test1()
        {
            VectorD state = new VectorD (new double[] { 0, 1, 2, 3, 4, 5 });
              VectorD result = new MidpointIntegratorD(GetFirstOrderDerivatives).Integrate(state, 2, 2.5);

              Assert.AreEqual(0, result[0]);
              Assert.AreEqual(2.125, result[1]);
              Assert.AreEqual(4.25, result[2]);
              Assert.AreEqual(6.375, result[3]);
              Assert.AreEqual(8.5, result[4]);
              Assert.AreEqual(10.625, result[5]);
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:12,代码来源:MidpointIntegratorDTest.cs


注:本文中的VectorD类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。