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


C# SparseMatrix.Clone方法代码示例

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


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

示例1: Solve

            public static Status Solve(int NumberOfEquations, SparseMatrix aMatrix, SparseArray bVector, SparseArray xVector)
            {
                var aMatrixClone = aMatrix.Clone();

                var RowMaximumVector = new Dictionary<int, double>();

                int i;
                for (i = 0; i < NumberOfEquations; i++)
                {
                    double temp = 0;

                    for (var j = 0; j < NumberOfEquations; j++)
                    {
                        var Test = Math.Abs(aMatrix[i, j]);

                        if (Test > temp)
                            temp = Test;
                    }

                    RowMaximumVector[i] = temp;

                    if (temp == 0)
                        return Status.Singular;
                }

                var PivotRowArray = new Dictionary<int, int>();

                for (var r = 0; r < NumberOfEquations; r++)
                {
                    double MaximumValue = 0;
                    var RowMaximumValueIndex = r;

                    double Temp;

                    for (i = r; i < NumberOfEquations; i++)
                    {
                        Temp = aMatrixClone[i, r];

                        for (var j = 0; j < r; j++) Temp = Temp - aMatrixClone[i, j] * aMatrixClone[j, r];

                        aMatrixClone[i, r] = Temp;

                        var test = Math.Abs(Temp / RowMaximumVector[i]);

                        if (!(test > MaximumValue))
                            continue;

                        MaximumValue = test;
                        RowMaximumValueIndex = i;
                    }

                    if (MaximumValue == 0)
                        return Status.IllConditioned;

                    RowMaximumVector[RowMaximumValueIndex] = RowMaximumVector[r];
                    PivotRowArray[r] = RowMaximumValueIndex;

                    for (i = 0; i < NumberOfEquations; i++)
                    {
                        Temp = aMatrixClone[r, i];
                        aMatrixClone[r, i] = aMatrixClone[RowMaximumValueIndex, i];
                        aMatrixClone[RowMaximumValueIndex, i] = Temp;
                    }

                    for (i = r + 1; i < NumberOfEquations; i++)
                    {
                        Temp = aMatrixClone[r, i];

                        for (var j = 0; j < r; j++) Temp = Temp - aMatrixClone[r, j] * aMatrixClone[j, i];
                        aMatrixClone[r, i] = Temp / aMatrixClone[r, r];
                    }
                }

                var ResidualVector = new Dictionary<int, double>();

                for (i = 0; i < NumberOfEquations; i++)
                {
                    xVector[i] = 0;
                    ResidualVector[i] = bVector[i];
                }

                var Iteration = 0;
                var NotConverged = true;

                do
                {

                    for (i = 0; i < NumberOfEquations; i++)
                    {
                        var PivotRowIndex = PivotRowArray[i];
                        var Temp = ResidualVector[PivotRowIndex];
                        ResidualVector[PivotRowIndex] = ResidualVector[i];

                        for (var j = 0; j < i; j++) Temp -= aMatrixClone[i, j] * ResidualVector[j];

                        ResidualVector[i] = Temp / aMatrixClone[i, i];
                    }

                    for (i = NumberOfEquations - 1; i >= 0; i--)
                    {
//.........这里部分代码省略.........
开发者ID:MathewSachin,项目名称:Equamatics,代码行数:101,代码来源:LinearGaussElimination.cs


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