|
|
|
@ -63,36 +63,38 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Factorization |
|
|
|
{ |
|
|
|
var matrixI = UserDefinedMatrix.Identity(order); |
|
|
|
var factorGramSchmidt = matrixI.GramSchmidt(); |
|
|
|
var q = factorGramSchmidt.Q; |
|
|
|
var r = factorGramSchmidt.R; |
|
|
|
|
|
|
|
Assert.AreEqual(matrixI.RowCount, factorGramSchmidt.Q.RowCount); |
|
|
|
Assert.AreEqual(matrixI.ColumnCount, factorGramSchmidt.Q.ColumnCount); |
|
|
|
Assert.AreEqual(matrixI.RowCount, q.RowCount); |
|
|
|
Assert.AreEqual(matrixI.ColumnCount, q.ColumnCount); |
|
|
|
|
|
|
|
for (var i = 0; i < factorGramSchmidt.R.RowCount; i++) |
|
|
|
for (var i = 0; i < r.RowCount; i++) |
|
|
|
{ |
|
|
|
for (var j = 0; j < factorGramSchmidt.R.ColumnCount; j++) |
|
|
|
for (var j = 0; j < r.ColumnCount; j++) |
|
|
|
{ |
|
|
|
if (i == j) |
|
|
|
{ |
|
|
|
Assert.AreEqual(Complex32.One, factorGramSchmidt.R[i, j]); |
|
|
|
Assert.AreEqual(Complex32.One, r[i, j]); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Assert.AreEqual(Complex32.Zero, factorGramSchmidt.R[i, j]); |
|
|
|
Assert.AreEqual(Complex32.Zero, r[i, j]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for (var i = 0; i < factorGramSchmidt.Q.RowCount; i++) |
|
|
|
for (var i = 0; i < q.RowCount; i++) |
|
|
|
{ |
|
|
|
for (var j = 0; j < factorGramSchmidt.Q.ColumnCount; j++) |
|
|
|
for (var j = 0; j < q.ColumnCount; j++) |
|
|
|
{ |
|
|
|
if (i == j) |
|
|
|
{ |
|
|
|
Assert.AreEqual(Complex32.One, factorGramSchmidt.Q[i, j]); |
|
|
|
Assert.AreEqual(Complex32.One, q[i, j]); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Assert.AreEqual(Complex32.Zero, factorGramSchmidt.Q[i, j]); |
|
|
|
Assert.AreEqual(Complex32.Zero, q[i, j]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -120,29 +122,31 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Factorization |
|
|
|
{ |
|
|
|
var matrixA = MatrixLoader.GenerateRandomUserDefinedMatrix(row, column); |
|
|
|
var factorGramSchmidt = matrixA.GramSchmidt(); |
|
|
|
var q = factorGramSchmidt.Q; |
|
|
|
var r = factorGramSchmidt.R; |
|
|
|
|
|
|
|
// Make sure the Q has the right dimensions.
|
|
|
|
Assert.AreEqual(row, factorGramSchmidt.Q.RowCount); |
|
|
|
Assert.AreEqual(column, factorGramSchmidt.Q.ColumnCount); |
|
|
|
Assert.AreEqual(row, q.RowCount); |
|
|
|
Assert.AreEqual(column, q.ColumnCount); |
|
|
|
|
|
|
|
// Make sure the R has the right dimensions.
|
|
|
|
Assert.AreEqual(column, factorGramSchmidt.R.RowCount); |
|
|
|
Assert.AreEqual(column, factorGramSchmidt.R.ColumnCount); |
|
|
|
Assert.AreEqual(column, r.RowCount); |
|
|
|
Assert.AreEqual(column, r.ColumnCount); |
|
|
|
|
|
|
|
// Make sure the R factor is upper triangular.
|
|
|
|
for (var i = 0; i < factorGramSchmidt.R.RowCount; i++) |
|
|
|
for (var i = 0; i < r.RowCount; i++) |
|
|
|
{ |
|
|
|
for (var j = 0; j < factorGramSchmidt.R.ColumnCount; j++) |
|
|
|
for (var j = 0; j < r.ColumnCount; j++) |
|
|
|
{ |
|
|
|
if (i > j) |
|
|
|
{ |
|
|
|
Assert.AreEqual(Complex32.Zero, factorGramSchmidt.R[i, j]); |
|
|
|
Assert.AreEqual(Complex32.Zero, r[i, j]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Make sure the Q*R is the original matrix.
|
|
|
|
var matrixQfromR = factorGramSchmidt.Q * factorGramSchmidt.R; |
|
|
|
var matrixQfromR = q * r; |
|
|
|
for (var i = 0; i < matrixQfromR.RowCount; i++) |
|
|
|
{ |
|
|
|
for (var j = 0; j < matrixQfromR.ColumnCount; j++) |
|
|
|
@ -153,7 +157,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Factorization |
|
|
|
} |
|
|
|
|
|
|
|
// Make sure the Q is unitary --> (Q*)x(Q) = I
|
|
|
|
var matrixQсtQ = factorGramSchmidt.Q.ConjugateTranspose() * factorGramSchmidt.Q; |
|
|
|
var matrixQсtQ = q.ConjugateTranspose() * q; |
|
|
|
for (var i = 0; i < matrixQсtQ.RowCount; i++) |
|
|
|
{ |
|
|
|
for (var j = 0; j < matrixQсtQ.ColumnCount; j++) |
|
|
|
|