void CompositeIntegrator::integrate() {

    mResult = 0;

    mGrid.resetIteration();

    while (mGrid.hasNextInterval()) {
        
        const Interval& interval = mGrid.nextInterval();

        QuadratureRule* localIntegrator = mFactory->create(mFunction, 
                                                interval.xLow, interval.xHigh);

        localIntegrator->integrate();

        mResult += localIntegrator->getResult();
    }
}
コード例 #2
0
int main(int argc, char* argv[]) {

    double a = 0;
    double b = 2;

    if (argc != 3 && argc != 5) {
        printHelp(argv);
        return 1;
    }

    if (strlen(argv[1]) > 1) {
        printHelp(argv);
        return 2;
    } 
    char method = argv[1][0];

    int functionIndex = atoi(argv[2]);
    if (functionIndex == 0) {
        printHelp(argv);
        return 3;
    }

    if (argc == 5) {
        a = atof(argv[3]);
        b = atof(argv[4]);
        if (b <= a) {
            printHelp(argv);
            return 4;
        }
    }

    fptr func = chooseFunc(functionIndex);
    QuadratureRule* integrator = createMethod(method, func, a, b);

    printf("performing integration\n");
    integrator->integrate();
    printf("result of integrating function %d in interval [%5.3lf, %5.3lf] = %5.3lf\n",
            functionIndex, a, b, integrator->getResult());

    return 0;
}