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


C# DenseVector.Clear方法代码示例

本文整理汇总了C#中DenseVector.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# DenseVector.Clear方法的具体用法?C# DenseVector.Clear怎么用?C# DenseVector.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DenseVector的用法示例。


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

示例1: Approximate

        /// <summary>
        /// Approximates the solution to the matrix equation <b>Ax = b</b>.
        /// </summary>
        /// <param name="rhs">The right hand side vector.</param>
        /// <param name="lhs">The left hand side vector. Also known as the result vector.</param>
        public void Approximate(Vector rhs, Vector lhs)
        {
            if (rhs == null)
            {
                throw new ArgumentNullException("rhs");
            }

            if (lhs == null)
            {
                throw new ArgumentNullException("lhs");
            }

            if (_decompositionLU == null)
            {
                throw new ArgumentException(Resources.ArgumentMatrixDoesNotExist);
            }

            if ((lhs.Count != rhs.Count) || (lhs.Count != _decompositionLU.RowCount))
            {
                throw new ArgumentException(Resources.ArgumentVectorsSameLength);
            }

            // Solve:
            // Lz = y
            // Which gives
            // for (int i = 1; i < matrix.RowLength; i++)
            // {
            //     z_i = l_ii^-1 * (y_i - SUM_(j<i) l_ij * z_j)
            // }
            // NOTE: l_ii should be 1 because u_ii has to be the value
            Vector rowValues = new DenseVector(_decompositionLU.RowCount);
            for (var i = 0; i < _decompositionLU.RowCount; i++)
            {
                // Clear the rowValues 
                rowValues.Clear();
                _decompositionLU.Row(i, rowValues);

                var sum = 0.0;
                for (var j = 0; j < i; j++)
                {
                    sum += rowValues[j] * lhs[j];
                }

                lhs[i] = rhs[i] - sum;
            }

            // Solve:
            // Ux = z
            // Which gives
            // for (int i = matrix.RowLength - 1; i > -1; i--)
            // {
            //     x_i = u_ii^-1 * (z_i - SUM_(j > i) u_ij * x_j)
            // }
            for (var i = _decompositionLU.RowCount - 1; i > -1; i--)
            {
                _decompositionLU.Row(i, rowValues);

                var sum = 0.0;
                for (var j = _decompositionLU.RowCount - 1; j > i; j--)
                {
                    sum += rowValues[j] * lhs[j];
                }

                lhs[i] = 1 / rowValues[i] * (lhs[i] - sum);
            }
        }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:71,代码来源:IncompleteLU.cs

示例2: Solve


//.........这里部分代码省略.........
                utemp.Multiply(-rho, temp);
                xtemp.Add(temp, temp2);
                temp2.CopyTo(xtemp);

                gtemp.Multiply(alpha, gtemp);
                xtemp.Add(gtemp, temp2);
                temp2.CopyTo(xtemp);

                // Check convergence and stop if we are converged.
                if (!ShouldContinue(iterationNumber, xtemp, input, residuals))
                {
                    // Calculate the true residual
                    CalculateTrueResidual(matrix, residuals, xtemp, input);

                    // Now recheck the convergence
                    if (!ShouldContinue(iterationNumber, xtemp, input, residuals))
                    {
                        // We're all good now.
                        // Exit from the while loop.
                        break;
                    }
                }

                // FOR (i = 1,2, ...., k)
                for (var i = 0; i < k; i++)
                {
                    // z_d = u_(jk+1)
                    u.CopyTo(zd);

                    // z_g = r_(jk+i)
                    residuals.CopyTo(zg);

                    // z_w = 0
                    zw.Clear();

                    // FOR (s = i, ...., k-1) AND j >= 1
                    Complex beta;
                    if (iterationNumber >= 1)
                    {
                        for (var s = i; s < k - 1; s++)
                        {
                            // beta^(jk+i)_((j-1)k+s) = -q^t_(s+1) z_d / c_((j-1)k+s)
                            beta = -_startingVectors[s + 1].DotProduct(zd) / c[s];

                            // z_d = z_d + beta^(jk+i)_((j-1)k+s) d_((j-1)k+s)
                            d[s].Multiply(beta, temp);
                            zd.Add(temp, temp2);
                            temp2.CopyTo(zd);

                            // z_g = z_g + beta^(jk+i)_((j-1)k+s) g_((j-1)k+s)
                            g[s].Multiply(beta, temp);
                            zg.Add(temp, temp2);
                            temp2.CopyTo(zg);

                            // z_w = z_w + beta^(jk+i)_((j-1)k+s) w_((j-1)k+s)
                            w[s].Multiply(beta, temp);
                            zw.Add(temp, temp2);
                            temp2.CopyTo(zw);
                        }
                    }

                    beta = rho * c[k - 1];
                    if (beta.Real.AlmostEqual(0, 1) && beta.Imaginary.AlmostEqual(0, 1))
                    {
                        throw new Exception("Iterative solver experience a numerical break down");
                    }
开发者ID:KeithVanderzanden,项目名称:mmbot,代码行数:67,代码来源:MlkBiCgStab.cs


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