Esempio n. 1
0
int main(int argc, char *argv[])
{
    acb_t r, s, a, b;
    arf_t inr, outr;
    long digits, prec;

    if (argc < 2)
    {
        printf("integrals d\n");
        printf("compute integrals using d decimal digits of precision\n");
        return 1;
    }

    acb_init(r);
    acb_init(s);
    acb_init(a);
    acb_init(b);
    arf_init(inr);
    arf_init(outr);

    arb_calc_verbose = 0;

    digits = atol(argv[1]);
    prec = digits * 3.32193;
    printf("Digits: %ld\n", digits);

    printf("----------------------------------------------------------------\n");
    printf("Integral of sin(t) from 0 to 100.\n");
    arf_set_d(inr, 0.125);
    arf_set_d(outr, 1.0);
    TIMEIT_ONCE_START
    acb_set_si(a, 0);
    acb_set_si(b, 100);
    acb_calc_integrate_taylor(r, sinx, NULL, a, b, inr, outr, prec, 1.1 * prec);
    printf("RESULT:\n");
    acb_printd(r, digits); printf("\n");
    TIMEIT_ONCE_STOP

    printf("----------------------------------------------------------------\n");
    printf("Elliptic integral F(phi, m) = integral of 1/sqrt(1 - m*sin(t)^2)\n");
    printf("from 0 to phi, with phi = 6+6i, m = 1/2. Integration path\n");
    printf("0 -> 6 -> 6+6i.\n");
    arf_set_d(inr, 0.2);
    arf_set_d(outr, 0.5);
    TIMEIT_ONCE_START
    acb_set_si(a, 0);
    acb_set_si(b, 6);
    acb_calc_integrate_taylor(r, elliptic, NULL, a, b, inr, outr, prec, 1.1 * prec);
    acb_set_si(a, 6);
    arb_set_si(acb_realref(b), 6);
    arb_set_si(acb_imagref(b), 6);
    acb_calc_integrate_taylor(s, elliptic, NULL, a, b, inr, outr, prec, 1.1 * prec);
    acb_add(r, r, s, prec);
    printf("RESULT:\n");
    acb_printd(r, digits); printf("\n");
    TIMEIT_ONCE_STOP

    printf("----------------------------------------------------------------\n");
    printf("Bessel function J_n(z) = (1/pi) * integral of cos(t*n - z*sin(t))\n");
    printf("from 0 to pi. With n = 10, z = 20 + 10i.\n");
    arf_set_d(inr, 0.1);
    arf_set_d(outr, 0.5);
    TIMEIT_ONCE_START
    acb_set_si(a, 0);
    acb_const_pi(b, 3 * prec);
    acb_calc_integrate_taylor(r, bessel, NULL, a, b, inr, outr, prec, 3 * prec);
    acb_div(r, r, b, prec);
    printf("RESULT:\n");
    acb_printd(r, digits); printf("\n");
    TIMEIT_ONCE_STOP

    acb_clear(r);
    acb_clear(s);
    acb_clear(a);
    acb_clear(b);
    arf_clear(inr);
    arf_clear(outr);

    flint_cleanup();
    return 0;
}
Esempio n. 2
0
int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("integrate_taylor....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 150 * arb_test_multiplier(); iter++)
    {
        acb_t ans, res, a, b;
        arf_t inr, outr;
        double t;
        slong goal, prec;

        acb_init(ans);
        acb_init(res);
        acb_init(a);
        acb_init(b);
        arf_init(inr);
        arf_init(outr);

        goal = 2 + n_randint(state, 300);
        prec = 2 + n_randint(state, 300);

        acb_randtest(a, state, 1 + n_randint(state, 200), 2);
        acb_randtest(b, state, 1 + n_randint(state, 200), 2);

        acb_cos(ans, a, prec);
        acb_cos(res, b, prec);
        acb_sub(ans, ans, res, prec);

        t = (1 + n_randint(state, 20)) / 10.0;
        arf_set_d(inr, t);
        arf_set_d(outr, t + (1 + n_randint(state, 20)) / 5.0);

        acb_calc_integrate_taylor(res, sin_x, NULL,
            a, b, inr, outr, goal, prec);

        if (!acb_overlaps(res, ans))
        {
            flint_printf("FAIL! (iter = %wd)\n", iter);
            flint_printf("prec = %wd, goal = %wd\n", prec, goal);
            flint_printf("inr = "); arf_printd(inr, 15); flint_printf("\n");
            flint_printf("outr = "); arf_printd(outr, 15); flint_printf("\n");
            flint_printf("a = "); acb_printd(a, 15); flint_printf("\n");
            flint_printf("b = "); acb_printd(b, 15); flint_printf("\n");
            flint_printf("res = "); acb_printd(res, 15); flint_printf("\n\n");
            flint_printf("ans = "); acb_printd(ans, 15); flint_printf("\n\n");
            abort();
        }

        acb_clear(ans);
        acb_clear(res);
        acb_clear(a);
        acb_clear(b);
        arf_clear(inr);
        arf_clear(outr);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}