本文整理匯總了Java中org.apache.commons.math.linear.FieldLUDecompositionImpl類的典型用法代碼示例。如果您正苦於以下問題:Java FieldLUDecompositionImpl類的具體用法?Java FieldLUDecompositionImpl怎麽用?Java FieldLUDecompositionImpl使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FieldLUDecompositionImpl類屬於org.apache.commons.math.linear包,在下文中一共展示了FieldLUDecompositionImpl類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: AdamsNordsieckTransformer
import org.apache.commons.math.linear.FieldLUDecompositionImpl; //導入依賴的package包/類
/** Simple constructor.
* @param nSteps number of steps of the multistep method
* (excluding the one being computed)
*/
private AdamsNordsieckTransformer(final int nSteps) {
// compute exact coefficients
FieldMatrix<BigFraction> bigP = buildP(nSteps);
FieldDecompositionSolver<BigFraction> pSolver =
new FieldLUDecompositionImpl<BigFraction>(bigP).getSolver();
BigFraction[] u = new BigFraction[nSteps];
Arrays.fill(u, BigFraction.ONE);
BigFraction[] bigC1 = pSolver.solve(u);
// update coefficients are computed by combining transform from
// Nordsieck to multistep, then shifting rows to represent step advance
// then applying inverse transform
BigFraction[][] shiftedP = bigP.getData();
for (int i = shiftedP.length - 1; i > 0; --i) {
// shift rows
shiftedP[i] = shiftedP[i - 1];
}
shiftedP[0] = new BigFraction[nSteps];
Arrays.fill(shiftedP[0], BigFraction.ZERO);
FieldMatrix<BigFraction> bigMSupdate =
pSolver.solve(new Array2DRowFieldMatrix<BigFraction>(shiftedP, false));
// convert coefficients to double
update = MatrixUtils.bigFractionMatrixToRealMatrix(bigMSupdate);
c1 = new double[nSteps];
for (int i = 0; i < nSteps; ++i) {
c1[i] = bigC1[i].doubleValue();
}
}
示例2: testDimensions
import org.apache.commons.math.linear.FieldLUDecompositionImpl; //導入依賴的package包/類
/** test dimensions */
public void testDimensions() {
FieldMatrix<Fraction> matrix = new Array2DRowFieldMatrix<Fraction>(testData);
FieldLUDecomposition<Fraction> LU = new FieldLUDecompositionImpl<Fraction>(matrix);
assertEquals(testData.length, LU.getL().getRowDimension());
assertEquals(testData.length, LU.getL().getColumnDimension());
assertEquals(testData.length, LU.getU().getRowDimension());
assertEquals(testData.length, LU.getU().getColumnDimension());
assertEquals(testData.length, LU.getP().getRowDimension());
assertEquals(testData.length, LU.getP().getColumnDimension());
}
示例3: testNonSquare
import org.apache.commons.math.linear.FieldLUDecompositionImpl; //導入依賴的package包/類
/** test non-square matrix */
public void testNonSquare() {
try {
new FieldLUDecompositionImpl<Fraction>(new Array2DRowFieldMatrix<Fraction>(new Fraction[][] {
{ Fraction.ZERO, Fraction.ZERO },
{ Fraction.ZERO, Fraction.ZERO },
{ Fraction.ZERO, Fraction.ZERO }
}));
} catch (InvalidMatrixException ime) {
// expected behavior
} catch (Exception e) {
fail("wrong exception caught");
}
}
示例4: testLLowerTriangular
import org.apache.commons.math.linear.FieldLUDecompositionImpl; //導入依賴的package包/類
/** test that L is lower triangular with unit diagonal */
public void testLLowerTriangular() {
FieldMatrix<Fraction> matrix = new Array2DRowFieldMatrix<Fraction>(testData);
FieldMatrix<Fraction> l = new FieldLUDecompositionImpl<Fraction>(matrix).getL();
for (int i = 0; i < l.getRowDimension(); i++) {
assertEquals(Fraction.ONE, l.getEntry(i, i));
for (int j = i + 1; j < l.getColumnDimension(); j++) {
assertEquals(Fraction.ZERO, l.getEntry(i, j));
}
}
}
示例5: testUUpperTriangular
import org.apache.commons.math.linear.FieldLUDecompositionImpl; //導入依賴的package包/類
/** test that U is upper triangular */
public void testUUpperTriangular() {
FieldMatrix<Fraction> matrix = new Array2DRowFieldMatrix<Fraction>(testData);
FieldMatrix<Fraction> u = new FieldLUDecompositionImpl<Fraction>(matrix).getU();
for (int i = 0; i < u.getRowDimension(); i++) {
for (int j = 0; j < i; j++) {
assertEquals(Fraction.ZERO, u.getEntry(i, j));
}
}
}
示例6: testSingular
import org.apache.commons.math.linear.FieldLUDecompositionImpl; //導入依賴的package包/類
/** test singular */
public void testSingular() {
FieldLUDecomposition<Fraction> lu =
new FieldLUDecompositionImpl<Fraction>(new Array2DRowFieldMatrix<Fraction>(testData));
assertTrue(lu.getSolver().isNonSingular());
lu = new FieldLUDecompositionImpl<Fraction>(new Array2DRowFieldMatrix<Fraction>(singular));
assertFalse(lu.getSolver().isNonSingular());
lu = new FieldLUDecompositionImpl<Fraction>(new Array2DRowFieldMatrix<Fraction>(bigSingular));
assertFalse(lu.getSolver().isNonSingular());
}
示例7: testMatricesValues1
import org.apache.commons.math.linear.FieldLUDecompositionImpl; //導入依賴的package包/類
/** test matrices values */
public void testMatricesValues1() {
FieldLUDecomposition<Fraction> lu =
new FieldLUDecompositionImpl<Fraction>(new Array2DRowFieldMatrix<Fraction>(testData));
FieldMatrix<Fraction> lRef = new Array2DRowFieldMatrix<Fraction>(new Fraction[][] {
{ new Fraction(1), new Fraction(0), new Fraction(0) },
{ new Fraction(2), new Fraction(1), new Fraction(0) },
{ new Fraction(1), new Fraction(-2), new Fraction(1) }
});
FieldMatrix<Fraction> uRef = new Array2DRowFieldMatrix<Fraction>(new Fraction[][] {
{ new Fraction(1), new Fraction(2), new Fraction(3) },
{ new Fraction(0), new Fraction(1), new Fraction(-3) },
{ new Fraction(0), new Fraction(0), new Fraction(-1) }
});
FieldMatrix<Fraction> pRef = new Array2DRowFieldMatrix<Fraction>(new Fraction[][] {
{ new Fraction(1), new Fraction(0), new Fraction(0) },
{ new Fraction(0), new Fraction(1), new Fraction(0) },
{ new Fraction(0), new Fraction(0), new Fraction(1) }
});
int[] pivotRef = { 0, 1, 2 };
// check values against known references
FieldMatrix<Fraction> l = lu.getL();
TestUtils.assertEquals(lRef, l);
FieldMatrix<Fraction> u = lu.getU();
TestUtils.assertEquals(uRef, u);
FieldMatrix<Fraction> p = lu.getP();
TestUtils.assertEquals(pRef, p);
int[] pivot = lu.getPivot();
for (int i = 0; i < pivotRef.length; ++i) {
assertEquals(pivotRef[i], pivot[i]);
}
// check the same cached instance is returned the second time
assertTrue(l == lu.getL());
assertTrue(u == lu.getU());
assertTrue(p == lu.getP());
}
示例8: testMatricesValues2
import org.apache.commons.math.linear.FieldLUDecompositionImpl; //導入依賴的package包/類
/** test matrices values */
public void testMatricesValues2() {
FieldLUDecomposition<Fraction> lu =
new FieldLUDecompositionImpl<Fraction>(new Array2DRowFieldMatrix<Fraction>(luData));
FieldMatrix<Fraction> lRef = new Array2DRowFieldMatrix<Fraction>(new Fraction[][] {
{ new Fraction(1), new Fraction(0), new Fraction(0) },
{ new Fraction(3), new Fraction(1), new Fraction(0) },
{ new Fraction(1), new Fraction(0), new Fraction(1) }
});
FieldMatrix<Fraction> uRef = new Array2DRowFieldMatrix<Fraction>(new Fraction[][] {
{ new Fraction(2), new Fraction(3), new Fraction(3) },
{ new Fraction(0), new Fraction(-3), new Fraction(-1) },
{ new Fraction(0), new Fraction(0), new Fraction(4) }
});
FieldMatrix<Fraction> pRef = new Array2DRowFieldMatrix<Fraction>(new Fraction[][] {
{ new Fraction(1), new Fraction(0), new Fraction(0) },
{ new Fraction(0), new Fraction(0), new Fraction(1) },
{ new Fraction(0), new Fraction(1), new Fraction(0) }
});
int[] pivotRef = { 0, 2, 1 };
// check values against known references
FieldMatrix<Fraction> l = lu.getL();
TestUtils.assertEquals(lRef, l);
FieldMatrix<Fraction> u = lu.getU();
TestUtils.assertEquals(uRef, u);
FieldMatrix<Fraction> p = lu.getP();
TestUtils.assertEquals(pRef, p);
int[] pivot = lu.getPivot();
for (int i = 0; i < pivotRef.length; ++i) {
assertEquals(pivotRef[i], pivot[i]);
}
// check the same cached instance is returned the second time
assertTrue(l == lu.getL());
assertTrue(u == lu.getU());
assertTrue(p == lu.getP());
}
示例9: testMatricesValues1
import org.apache.commons.math.linear.FieldLUDecompositionImpl; //導入依賴的package包/類
/** test matrices values */
public void testMatricesValues1() {
FieldLUDecomposition<Fraction> lu =
new FieldLUDecompositionImpl<Fraction>(new Array2DRowFieldMatrix<Fraction>(testData));
FieldMatrix<Fraction> lRef = new Array2DRowFieldMatrix<Fraction>(new Fraction[][] {
{ new Fraction(1), new Fraction(0), new Fraction(0) },
{ new Fraction(2), new Fraction(1), new Fraction(0) },
{ new Fraction(1), new Fraction(-2), new Fraction(1) }
});
FieldMatrix<Fraction> uRef = new Array2DRowFieldMatrix<Fraction>(new Fraction[][] {
{ new Fraction(1), new Fraction(2), new Fraction(3) },
{ new Fraction(0), new Fraction(1), new Fraction(-3) },
{ new Fraction(0), new Fraction(0), new Fraction(-1) }
});
FieldMatrix<Fraction> pRef = new Array2DRowFieldMatrix<Fraction>(new Fraction[][] {
{ new Fraction(1), new Fraction(0), new Fraction(0) },
{ new Fraction(0), new Fraction(1), new Fraction(0) },
{ new Fraction(0), new Fraction(0), new Fraction(1) }
});
int[] pivotRef = { 0, 1, 2 };
// check values against known references
FieldMatrix<Fraction> l = lu.getL();
TestUtils.assertEquals(lRef, l);
FieldMatrix<Fraction> u = lu.getU();
TestUtils.assertEquals(uRef, u);
FieldMatrix<Fraction> p = lu.getP();
TestUtils.assertEquals(pRef, p);
int[] pivot = lu.getPivot();
for (int i = 0; i < pivotRef.length; ++i) {
assertEquals(pivotRef[i], pivot[i]);
}
// check the same cached instance is returned the second time
assertTrue(l == lu.getL());
assertTrue(u == lu.getU());
assertTrue(p == lu.getP());
}
示例10: testMatricesValues2
import org.apache.commons.math.linear.FieldLUDecompositionImpl; //導入依賴的package包/類
/** test matrices values */
public void testMatricesValues2() {
FieldLUDecomposition<Fraction> lu =
new FieldLUDecompositionImpl<Fraction>(new Array2DRowFieldMatrix<Fraction>(luData));
FieldMatrix<Fraction> lRef = new Array2DRowFieldMatrix<Fraction>(new Fraction[][] {
{ new Fraction(1), new Fraction(0), new Fraction(0) },
{ new Fraction(3), new Fraction(1), new Fraction(0) },
{ new Fraction(1), new Fraction(0), new Fraction(1) }
});
FieldMatrix<Fraction> uRef = new Array2DRowFieldMatrix<Fraction>(new Fraction[][] {
{ new Fraction(2), new Fraction(3), new Fraction(3) },
{ new Fraction(0), new Fraction(-3), new Fraction(-1) },
{ new Fraction(0), new Fraction(0), new Fraction(4) }
});
FieldMatrix<Fraction> pRef = new Array2DRowFieldMatrix<Fraction>(new Fraction[][] {
{ new Fraction(1), new Fraction(0), new Fraction(0) },
{ new Fraction(0), new Fraction(0), new Fraction(1) },
{ new Fraction(0), new Fraction(1), new Fraction(0) }
});
int[] pivotRef = { 0, 2, 1 };
// check values against known references
FieldMatrix<Fraction> l = lu.getL();
TestUtils.assertEquals(lRef, l);
FieldMatrix<Fraction> u = lu.getU();
TestUtils.assertEquals(uRef, u);
FieldMatrix<Fraction> p = lu.getP();
TestUtils.assertEquals(pRef, p);
int[] pivot = lu.getPivot();
for (int i = 0; i < pivotRef.length; ++i) {
assertEquals(pivotRef[i], pivot[i]);
}
// check the same cached instance is returned the second time
assertTrue(l == lu.getL());
assertTrue(u == lu.getU());
assertTrue(p == lu.getP());
}
示例11: AdamsNordsieckTransformer
import org.apache.commons.math.linear.FieldLUDecompositionImpl; //導入依賴的package包/類
/** Simple constructor.
* @param nSteps number of steps of the multistep method
* (excluding the one being computed)
*/
private AdamsNordsieckTransformer(final int nSteps) {
// compute exact coefficients
FieldMatrix<BigFraction> bigP = buildP(nSteps);
FieldDecompositionSolver<BigFraction> pSolver =
new FieldLUDecompositionImpl<BigFraction>(bigP).getSolver();
BigFraction[] u = new BigFraction[nSteps];
Arrays.fill(u, BigFraction.ONE);
BigFraction[] bigC1 = pSolver.solve(u);
// update coefficients are computed by combining transform from
// Nordsieck to multistep, then shifting rows to represent step advance
// then applying inverse transform
BigFraction[][] shiftedP = bigP.getData();
for (int i = shiftedP.length - 1; i > 0; --i) {
// shift rows
shiftedP[i] = shiftedP[i - 1];
}
shiftedP[0] = new BigFraction[nSteps];
Arrays.fill(shiftedP[0], BigFraction.ZERO);
FieldMatrix<BigFraction> bigMSupdate =
pSolver.solve(new Array2DRowFieldMatrix<BigFraction>(shiftedP, false));
// initialization coefficients, computed from a R matrix = abs(P)
bigP.walkInOptimizedOrder(new DefaultFieldMatrixChangingVisitor<BigFraction>(BigFraction.ZERO) {
/** {@inheritDoc} */
@Override
public BigFraction visit(int row, int column, BigFraction value) {
return ((column & 0x1) == 0x1) ? value : value.negate();
}
});
FieldMatrix<BigFraction> bigRInverse =
new FieldLUDecompositionImpl<BigFraction>(bigP).getSolver().getInverse();
// convert coefficients to double
initialization = MatrixUtils.bigFractionMatrixToRealMatrix(bigRInverse);
update = MatrixUtils.bigFractionMatrixToRealMatrix(bigMSupdate);
c1 = new double[nSteps];
for (int i = 0; i < nSteps; ++i) {
c1[i] = bigC1[i].doubleValue();
}
}
示例12: testPAEqualLU
import org.apache.commons.math.linear.FieldLUDecompositionImpl; //導入依賴的package包/類
/** test PA = LU */
public void testPAEqualLU() {
FieldMatrix<Fraction> matrix = new Array2DRowFieldMatrix<Fraction>(testData);
FieldLUDecomposition<Fraction> lu = new FieldLUDecompositionImpl<Fraction>(matrix);
FieldMatrix<Fraction> l = lu.getL();
FieldMatrix<Fraction> u = lu.getU();
FieldMatrix<Fraction> p = lu.getP();
TestUtils.assertEquals(p.multiply(matrix), l.multiply(u));
matrix = new Array2DRowFieldMatrix<Fraction>(testDataMinus);
lu = new FieldLUDecompositionImpl<Fraction>(matrix);
l = lu.getL();
u = lu.getU();
p = lu.getP();
TestUtils.assertEquals(p.multiply(matrix), l.multiply(u));
matrix = new Array2DRowFieldMatrix<Fraction>(FractionField.getInstance(), 17, 17);
for (int i = 0; i < matrix.getRowDimension(); ++i) {
matrix.setEntry(i, i, Fraction.ONE);
}
lu = new FieldLUDecompositionImpl<Fraction>(matrix);
l = lu.getL();
u = lu.getU();
p = lu.getP();
TestUtils.assertEquals(p.multiply(matrix), l.multiply(u));
matrix = new Array2DRowFieldMatrix<Fraction>(singular);
lu = new FieldLUDecompositionImpl<Fraction>(matrix);
assertFalse(lu.getSolver().isNonSingular());
assertNull(lu.getL());
assertNull(lu.getU());
assertNull(lu.getP());
matrix = new Array2DRowFieldMatrix<Fraction>(bigSingular);
lu = new FieldLUDecompositionImpl<Fraction>(matrix);
assertFalse(lu.getSolver().isNonSingular());
assertNull(lu.getL());
assertNull(lu.getU());
assertNull(lu.getP());
}