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


Java Sin类代码示例

本文整理汇总了Java中org.apache.commons.math3.analysis.function.Sin的典型用法代码示例。如果您正苦于以下问题:Java Sin类的具体用法?Java Sin怎么用?Java Sin使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Sin类属于org.apache.commons.math3.analysis.function包,在下文中一共展示了Sin类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSinFunction

import org.apache.commons.math3.analysis.function.Sin; //导入依赖的package包/类
/**
 * Test of transformer for the sine function.
 */
@Test
public void testSinFunction() {
    UnivariateFunction f = new Sin();
    FastSineTransformer transformer;
    transformer = new FastSineTransformer(DstNormalization.STANDARD_DST_I);
    double min, max, result[], tolerance = 1E-12; int N = 1 << 8;

    min = 0.0; max = 2.0 * FastMath.PI;
    result = transformer.transform(f, min, max, N, TransformType.FORWARD);
    Assert.assertEquals(N >> 1, result[2], tolerance);
    for (int i = 0; i < N; i += (i == 1 ? 2 : 1)) {
        Assert.assertEquals(0.0, result[i], tolerance);
    }

    min = -FastMath.PI; max = FastMath.PI;
    result = transformer.transform(f, min, max, N, TransformType.FORWARD);
    Assert.assertEquals(-(N >> 1), result[2], tolerance);
    for (int i = 0; i < N; i += (i == 1 ? 2 : 1)) {
        Assert.assertEquals(0.0, result[i], tolerance);
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:25,代码来源:FastSineTransformerTest.java

示例2: testTransformFunctionSizeNotAPowerOfTwo

import org.apache.commons.math3.analysis.function.Sin; //导入依赖的package包/类
@Test
public void testTransformFunctionSizeNotAPowerOfTwo() {
    final int n = 127;
    final UnivariateFunction f = new Sin();
    final DftNormalization[] norm;
    norm = DftNormalization.values();
    final TransformType[] type;
    type = TransformType.values();
    for (int i = 0; i < norm.length; i++) {
        for (int j = 0; j < type.length; j++) {
            final FastFourierTransformer fft;
            fft = new FastFourierTransformer(norm[i]);
            try {
                fft.transform(f, 0.0, Math.PI, n, type[j]);
                Assert.fail(norm[i] + ", " + type[j] +
                    ": MathIllegalArgumentException was expected");
            } catch (MathIllegalArgumentException e) {
                // Expected behaviour
            }
        }
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:23,代码来源:FastFourierTransformerTest.java

示例3: testTransformFunctionNotStrictlyPositiveNumberOfSamples

import org.apache.commons.math3.analysis.function.Sin; //导入依赖的package包/类
@Test
public void testTransformFunctionNotStrictlyPositiveNumberOfSamples() {
    final int n = -128;
    final UnivariateFunction f = new Sin();
    final DftNormalization[] norm;
    norm = DftNormalization.values();
    final TransformType[] type;
    type = TransformType.values();
    for (int i = 0; i < norm.length; i++) {
        for (int j = 0; j < type.length; j++) {
            final FastFourierTransformer fft;
            fft = new FastFourierTransformer(norm[i]);
            try {
                fft.transform(f, 0.0, Math.PI, n, type[j]);
                fft.transform(f, 0.0, Math.PI, n, type[j]);
                Assert.fail(norm[i] + ", " + type[j] +
                    ": NotStrictlyPositiveException was expected");
            } catch (NotStrictlyPositiveException e) {
                // Expected behaviour
            }
        }
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:24,代码来源:FastFourierTransformerTest.java

示例4: testTransformFunctionInvalidBounds

import org.apache.commons.math3.analysis.function.Sin; //导入依赖的package包/类
@Test
public void testTransformFunctionInvalidBounds() {
    final int n = 128;
    final UnivariateFunction f = new Sin();
    final DftNormalization[] norm;
    norm = DftNormalization.values();
    final TransformType[] type;
    type = TransformType.values();
    for (int i = 0; i < norm.length; i++) {
        for (int j = 0; j < type.length; j++) {
            final FastFourierTransformer fft;
            fft = new FastFourierTransformer(norm[i]);
            try {
                fft.transform(f, Math.PI, 0.0, n, type[j]);
                Assert.fail(norm[i] + ", " + type[j] +
                    ": NumberIsTooLargeException was expected");
            } catch (NumberIsTooLargeException e) {
                // Expected behaviour
            }
        }
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:23,代码来源:FastFourierTransformerTest.java

示例5: testSinMin

import org.apache.commons.math3.analysis.function.Sin; //导入依赖的package包/类
@Test
public void testSinMin() {
    UnivariateFunction f = new Sin();
    UnivariateOptimizer underlying = new BrentOptimizer(1e-10, 1e-14);
    JDKRandomGenerator g = new JDKRandomGenerator();
    g.setSeed(44428400075l);
    UnivariateMultiStartOptimizer<UnivariateFunction> optimizer =
        new UnivariateMultiStartOptimizer<UnivariateFunction>(underlying, 10, g);
    optimizer.optimize(300, f, GoalType.MINIMIZE, -100.0, 100.0);
    UnivariatePointValuePair[] optima = optimizer.getOptima();
    for (int i = 1; i < optima.length; ++i) {
        double d = (optima[i].getPoint() - optima[i-1].getPoint()) / (2 * FastMath.PI);
        Assert.assertTrue(FastMath.abs(d - FastMath.rint(d)) < 1.0e-8);
        Assert.assertEquals(-1.0, f.value(optima[i].getPoint()), 1.0e-10);
        Assert.assertEquals(f.value(optima[i].getPoint()), optima[i].getValue(), 1.0e-10);
    }
    Assert.assertTrue(optimizer.getEvaluations() > 200);
    Assert.assertTrue(optimizer.getEvaluations() < 300);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:20,代码来源:UnivariateMultiStartOptimizerTest.java

示例6: testSinMin

import org.apache.commons.math3.analysis.function.Sin; //导入依赖的package包/类
@Test
public void testSinMin() {
    UnivariateFunction f = new Sin();
    UnivariateOptimizer optimizer = new BrentOptimizer(1e-10, 1e-14);
    Assert.assertEquals(3 * Math.PI / 2, optimizer.optimize(200, f, GoalType.MINIMIZE, 4, 5).getPoint(), 1e-8);
    Assert.assertTrue(optimizer.getEvaluations() <= 50);
    Assert.assertEquals(200, optimizer.getMaxEvaluations());
    Assert.assertEquals(3 * Math.PI / 2, optimizer.optimize(200, f, GoalType.MINIMIZE, 1, 5).getPoint(), 1e-8);
    Assert.assertTrue(optimizer.getEvaluations() <= 100);
    Assert.assertTrue(optimizer.getEvaluations() >= 15);
    try {
        optimizer.optimize(10, f, GoalType.MINIMIZE, 4, 5);
        Assert.fail("an exception should have been thrown");
    } catch (TooManyEvaluationsException fee) {
        // expected
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:18,代码来源:BrentOptimizerTest.java

示例7: testMath855

import org.apache.commons.math3.analysis.function.Sin; //导入依赖的package包/类
/**
 * Contrived example showing that prior to the resolution of MATH-855,
 * the algorithm, by always returning the last evaluated point, would
 * sometimes not report the best point it had found.
 */
@Test
public void testMath855() {
    final double minSin = 3 * Math.PI / 2;
    final double offset = 1e-8;
    final double delta = 1e-7;
    final UnivariateFunction f1 = new Sin();
    final UnivariateFunction f2 = new StepFunction(new double[] { minSin, minSin + offset, minSin + 5 * offset },
                                                   new double[] { 0, -1, 0 });
    final UnivariateFunction f = FunctionUtils.add(f1, f2);
    final UnivariateOptimizer optimizer = new BrentOptimizer(1e-8, 1e-100);
    final UnivariatePointValuePair result
        = optimizer.optimize(200, f, GoalType.MINIMIZE,
                             minSin - 6.789 * delta,
                             minSin + 9.876 * delta);

    final double sol = result.getPoint();
    final double expected = 4.712389027602411;

    // System.out.println("min=" + (minSin + offset) + " f=" + f.value(minSin + offset));
    // System.out.println("sol=" + sol + " f=" + f.value(sol));
    // System.out.println("exp=" + expected + " f=" + f.value(expected));

    Assert.assertTrue("Best point not reported", f.value(sol) <= f.value(expected));
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:30,代码来源:BrentOptimizerTest.java

示例8: testSinFunction

import org.apache.commons.math3.analysis.function.Sin; //导入依赖的package包/类
/**
 * Test of integrator for the sine function.
 */
@Test
public void testSinFunction() {
    UnivariateFunction f = new Sin();
    UnivariateIntegrator integrator = new RombergIntegrator();
    double min, max, expected, result, tolerance;

    min = 0; max = FastMath.PI; expected = 2;
    tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
    result = integrator.integrate(100, f, min, max);
    Assert.assertTrue(integrator.getEvaluations() < 50);
    Assert.assertTrue(integrator.getIterations()  < 10);
    Assert.assertEquals(expected, result, tolerance);

    min = -FastMath.PI/3; max = 0; expected = -0.5;
    tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
    result = integrator.integrate(100, f, min, max);
    Assert.assertTrue(integrator.getEvaluations() < 50);
    Assert.assertTrue(integrator.getIterations()  < 10);
    Assert.assertEquals(expected, result, tolerance);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:24,代码来源:RombergIntegratorTest.java

示例9: testSinFunction

import org.apache.commons.math3.analysis.function.Sin; //导入依赖的package包/类
/**
 * Test of integrator for the sine function.
 */
@Test
public void testSinFunction() {
    UnivariateFunction f = new Sin();
    UnivariateIntegrator integrator = new MidPointIntegrator();
    
    double min = 0;
    double max = FastMath.PI;
    double expected = 2;
    double tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
    double result = integrator.integrate(Integer.MAX_VALUE, f, min, max);
    Assert.assertTrue(integrator.getEvaluations() < Integer.MAX_VALUE / 2);
    Assert.assertTrue(integrator.getIterations() < MidPointIntegrator.MIDPOINT_MAX_ITERATIONS_COUNT / 2);
    Assert.assertEquals(expected, result, tolerance);

    min = -FastMath.PI/3;
    max = 0;
    expected = -0.5;
    tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
    result = integrator.integrate(Integer.MAX_VALUE, f, min, max);
    Assert.assertTrue(integrator.getEvaluations() < Integer.MAX_VALUE / 2);
    Assert.assertTrue(integrator.getIterations() < MidPointIntegrator.MIDPOINT_MAX_ITERATIONS_COUNT / 2);
    Assert.assertEquals(expected, result, tolerance);

}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:28,代码来源:MidPointIntegratorTest.java

示例10: testSinFunction

import org.apache.commons.math3.analysis.function.Sin; //导入依赖的package包/类
/**
 * Test of integrator for the sine function.
 */
@Test
public void testSinFunction() {
    UnivariateFunction f = new Sin();
    UnivariateIntegrator integrator = new TrapezoidIntegrator();
    double min, max, expected, result, tolerance;

    min = 0; max = FastMath.PI; expected = 2;
    tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
    result = integrator.integrate(10000, f, min, max);
    Assert.assertTrue(integrator.getEvaluations() < 2500);
    Assert.assertTrue(integrator.getIterations()  < 15);
    Assert.assertEquals(expected, result, tolerance);

    min = -FastMath.PI/3; max = 0; expected = -0.5;
    tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
    result = integrator.integrate(10000, f, min, max);
    Assert.assertTrue(integrator.getEvaluations() < 2500);
    Assert.assertTrue(integrator.getIterations()  < 15);
    Assert.assertEquals(expected, result, tolerance);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:24,代码来源:TrapezoidIntegratorTest.java

示例11: testSinFunction

import org.apache.commons.math3.analysis.function.Sin; //导入依赖的package包/类
@Test
public void testSinFunction() {
    UnivariateFunction f = new Sin();
    BaseAbstractUnivariateIntegrator integrator
        = new IterativeLegendreGaussIntegrator(5, 1.0e-14, 1.0e-10, 2, 15);
    double min, max, expected, result, tolerance;

    min = 0; max = FastMath.PI; expected = 2;
    tolerance = FastMath.max(integrator.getAbsoluteAccuracy(),
                         FastMath.abs(expected * integrator.getRelativeAccuracy()));
    result = integrator.integrate(10000, f, min, max);
    Assert.assertEquals(expected, result, tolerance);

    min = -FastMath.PI/3; max = 0; expected = -0.5;
    tolerance = FastMath.max(integrator.getAbsoluteAccuracy(),
            FastMath.abs(expected * integrator.getRelativeAccuracy()));
    result = integrator.integrate(10000, f, min, max);
    Assert.assertEquals(expected, result, tolerance);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:20,代码来源:IterativeLegendreGaussIntegratorTest.java

示例12: testSinFunction

import org.apache.commons.math3.analysis.function.Sin; //导入依赖的package包/类
/**
 * Test of integrator for the sine function.
 */
@Test
public void testSinFunction() {
    UnivariateFunction f = new Sin();
    UnivariateIntegrator integrator = new SimpsonIntegrator();
    double min, max, expected, result, tolerance;

    min = 0; max = FastMath.PI; expected = 2;
    tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
    result = integrator.integrate(1000, f, min, max);
    Assert.assertTrue(integrator.getEvaluations() < 100);
    Assert.assertTrue(integrator.getIterations()  < 10);
    Assert.assertEquals(expected, result, tolerance);

    min = -FastMath.PI/3; max = 0; expected = -0.5;
    tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
    result = integrator.integrate(1000, f, min, max);
    Assert.assertTrue(integrator.getEvaluations() < 50);
    Assert.assertTrue(integrator.getIterations()  < 10);
    Assert.assertEquals(expected, result, tolerance);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:24,代码来源:SimpsonIntegratorTest.java

示例13: testSinFunction

import org.apache.commons.math3.analysis.function.Sin; //导入依赖的package包/类
@Test
public void testSinFunction() {
    UnivariateFunction f = new Sin();
    BaseAbstractUnivariateIntegrator integrator = new LegendreGaussIntegrator(5, 1.0e-14, 1.0e-10, 2, 15);
    double min, max, expected, result, tolerance;

    min = 0; max = FastMath.PI; expected = 2;
    tolerance = FastMath.max(integrator.getAbsoluteAccuracy(),
                         FastMath.abs(expected * integrator.getRelativeAccuracy()));
    result = integrator.integrate(10000, f, min, max);
    Assert.assertEquals(expected, result, tolerance);

    min = -FastMath.PI/3; max = 0; expected = -0.5;
    tolerance = FastMath.max(integrator.getAbsoluteAccuracy(),
            FastMath.abs(expected * integrator.getRelativeAccuracy()));
    result = integrator.integrate(10000, f, min, max);
    Assert.assertEquals(expected, result, tolerance);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:19,代码来源:LegendreGaussIntegratorTest.java

示例14: testSinFunction

import org.apache.commons.math3.analysis.function.Sin; //导入依赖的package包/类
/**
 * Test of solver for the sine function.
 */
@Test
public void testSinFunction() {
    UnivariateFunction f = new Sin();
    UnivariateSolver solver = new MullerSolver();
    double min, max, expected, result, tolerance;

    min = 3.0; max = 4.0; expected = FastMath.PI;
    tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
                FastMath.abs(expected * solver.getRelativeAccuracy()));
    result = solver.solve(100, f, min, max);
    Assert.assertEquals(expected, result, tolerance);

    min = -1.0; max = 1.5; expected = 0.0;
    tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
                FastMath.abs(expected * solver.getRelativeAccuracy()));
    result = solver.solve(100, f, min, max);
    Assert.assertEquals(expected, result, tolerance);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:22,代码来源:MullerSolverTest.java

示例15: testSinZero

import org.apache.commons.math3.analysis.function.Sin; //导入依赖的package包/类
@Test
public void testSinZero() {
    // The sinus function is behaved well around the root at pi. The second
    // order derivative is zero, which means linear approximating methods
    // still converge quadratically.
    UnivariateFunction f = new Sin();
    double result;
    UnivariateSolver solver = getSolver();

    result = solver.solve(100, f, 3, 4);
    //System.out.println(
    //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
    Assert.assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
    Assert.assertTrue(solver.getEvaluations() <= 6);
    result = solver.solve(100, f, 1, 4);
    //System.out.println(
    //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
    Assert.assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
    Assert.assertTrue(solver.getEvaluations() <= 7);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:21,代码来源:BaseSecantSolverAbstractTest.java


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