本文整理汇总了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--)
{
//.........这里部分代码省略.........