예제 #1
0
        public virtual DoubleMatrix getUpdatedMatrix(System.Func <DoubleArray, DoubleMatrix> g, DoubleArray x, DoubleArray deltaX, DoubleArray deltaY, DoubleMatrix matrix)
        {
            ArgChecker.notNull(deltaX, "deltaX");
            ArgChecker.notNull(deltaY, "deltaY");
            ArgChecker.notNull(matrix, "matrix");
            DoubleArray v1     = (DoubleArray)_algebra.multiply(deltaX, matrix);
            double      length = _algebra.getInnerProduct(v1, deltaY);

            if (length == 0)
            {
                return(matrix);
            }
            v1 = (DoubleArray)_algebra.scale(v1, 1.0 / length);
            DoubleArray  v2 = (DoubleArray)_algebra.subtract(deltaX, _algebra.multiply(matrix, deltaY));
            DoubleMatrix m  = _algebra.getOuterProduct(v2, v1);

            return((DoubleMatrix)_algebra.add(matrix, m));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void test()
        public virtual void test()
        {
            const int n = 97;

            double[] a = new double[n - 1];
            double[] b = new double[n];
            double[] c = new double[n - 1];
            double[] x = new double[n];

            for (int ii = 0; ii < n; ii++)
            {
                b[ii] = RANDOM.nextRandom();
                x[ii] = RANDOM.nextRandom();
                if (ii < n - 1)
                {
                    a[ii] = RANDOM.nextRandom();
                    c[ii] = RANDOM.nextRandom();
                }
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final TridiagonalMatrix m = new TridiagonalMatrix(b, a, c);
            TridiagonalMatrix m = new TridiagonalMatrix(b, a, c);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleArray xVec = com.opengamma.strata.collect.array.DoubleArray.copyOf(x);
            DoubleArray xVec = DoubleArray.copyOf(x);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleArray yVec = (com.opengamma.strata.collect.array.DoubleArray) MA.multiply(m, xVec);
            DoubleArray yVec = (DoubleArray)MA.multiply(m, xVec);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] xSolv = solvTriDag(m, yVec).toArray();
            double[] xSolv = solvTriDag(m, yVec).toArray();

            for (int i = 0; i < n; i++)
            {
                assertEquals(x[i], xSolv[i], 1e-9);
            }

            DoubleArray resi = (DoubleArray)MA.subtract(MA.multiply(m, DoubleArray.copyOf(xSolv)), yVec);
            double      err  = MA.getNorm2(resi);

            assertEquals(0.0, err, 1e-14);
        }