Example #1
0
def test_jacobi_precise():
    x, w = gauss_jacobi(3, Rational(-1, 2), Rational(1, 2), 40)
    assert [str(r) for r in x] == [
        '-0.6234898018587335305250048840042398106323',
        '0.2225209339563144042889025644967947594664',
        '0.9009688679024191262361023195074450511659']
    assert [str(r) for r in w] == [
        '0.3379547635663543330553835737094171534907',
        '1.097332224279111467485302294320899710461',
        '1.706305665744327437921957515249186020246']

    x, w = gauss_jacobi(3, 2, 3, 40)
    assert [str(r) for r in x] == [
        '-0.4611587037808976179121958105554375981274',
        '0.1043853303832390210914918407615869143233',
        '0.6295006461249313240934312425211234110769']
    assert [str(r) for r in w] == [
        '0.1793761350221326596137764371503859752628',
        '0.6159564099114715430909548532229749439714',
        '0.2713341217330624639619353762933057474325']
Example #2
0
def test_jacobi_precise():
    x, w = gauss_jacobi(3, -S.Half, S.Half, 40)
    assert [str(r) for r in x] == [
        '-0.6234898018587335305250048840042398106323',
        '0.2225209339563144042889025644967947594664',
        '0.9009688679024191262361023195074450511659'
    ]
    assert [str(r) for r in w] == [
        '0.3379547635663543330553835737094171534907',
        '1.097332224279111467485302294320899710461',
        '1.706305665744327437921957515249186020246'
    ]

    x, w = gauss_jacobi(3, 2, 3, 40)
    assert [str(r) for r in x] == [
        '-0.4611587037808976179121958105554375981274',
        '0.1043853303832390210914918407615869143233',
        '0.6295006461249313240934312425211234110769'
    ]
    assert [str(r) for r in w] == [
        '0.1793761350221326596137764371503859752628',
        '0.6159564099114715430909548532229749439714',
        '0.2713341217330624639619353762933057474325'
    ]
Example #3
0
def test_jacobi():
    x, w = gauss_jacobi(1, -S.Half, S.Half, 17)
    assert [str(r) for r in x] == ['0.50000000000000000']
    assert [str(r) for r in w] == ['3.1415926535897932']

    x, w = gauss_jacobi(2, -S.Half, S.Half, 17)
    assert [str(r)
            for r in x] == ['-0.30901699437494742', '0.80901699437494742']
    assert [str(r) for r in w] == ['0.86831485369082398', '2.2732777998989693']

    x, w = gauss_jacobi(3, -S.Half, S.Half, 17)
    assert [str(r) for r in x] == [
        '-0.62348980185873353', '0.22252093395631440', '0.90096886790241913'
    ]
    assert [str(r) for r in w] == [
        '0.33795476356635433', '1.0973322242791115', '1.7063056657443274'
    ]

    x, w = gauss_jacobi(4, -S.Half, S.Half, 17)
    assert [str(r) for r in x] == [
        '-0.76604444311897804', '-0.17364817766693035', '0.50000000000000000',
        '0.93969262078590838'
    ]
    assert [str(r) for r in w] == [
        '0.16333179083642836', '0.57690240318269103', '1.0471975511965977',
        '1.3541609083740761'
    ]

    x, w = gauss_jacobi(5, -S.Half, S.Half, 17)
    assert [str(r) for r in x] == [
        '-0.84125353283118117', '-0.41541501300188643', '0.14231483827328514',
        '0.65486073394528506', '0.95949297361449739'
    ]
    assert [str(r) for r in w] == [
        '0.090675770007435371', '0.33391416373675607', '0.65248870981926643',
        '0.94525424081394926', '1.1192597692123861'
    ]

    x, w = gauss_jacobi(1, 2, 3, 17)
    assert [str(r) for r in x] == ['0.14285714285714286']
    assert [str(r) for r in w] == ['1.0666666666666667']

    x, w = gauss_jacobi(2, 2, 3, 17)
    assert [str(r)
            for r in x] == ['-0.24025307335204215', '0.46247529557426437']
    assert [str(r)
            for r in w] == ['0.48514624517838660', '0.58152042148828007']

    x, w = gauss_jacobi(3, 2, 3, 17)
    assert [str(r) for r in x] == [
        '-0.46115870378089762', '0.10438533038323902', '0.62950064612493132'
    ]
    assert [str(r) for r in w] == [
        '0.17937613502213266', '0.61595640991147154', '0.27133412173306246'
    ]

    x, w = gauss_jacobi(4, 2, 3, 17)
    assert [str(r) for r in x] == [
        '-0.59903470850824782', '-0.14761105199952565', '0.32554377081188859',
        '0.72879429738819258'
    ]
    assert [str(r) for r in w] == [
        '0.067809641836772187', '0.38956404952032481', '0.47995970868024150',
        '0.12933326662932816'
    ]

    x, w = gauss_jacobi(5, 2, 3, 17)
    assert [str(r) for r in x] == [
        '-0.69045775012676106', '-0.32651993134900065', '0.082337849552034905',
        '0.47517887061283164', '0.79279429464422850'
    ]
    assert [str(r) for r in w] == [
        '0.027410178066337099', '0.21291786060364828', '0.43908437944395081',
        '0.32220656547221822', '0.065047683080512268'
    ]
Example #4
0
def test_jacobi():
    x, w = gauss_jacobi(1, Rational(-1, 2), Rational(1, 2), 17)
    assert [str(r) for r in x] == ['0.50000000000000000']
    assert [str(r) for r in w] == ['3.1415926535897932']

    x, w = gauss_jacobi(2, Rational(-1, 2), Rational(1, 2), 17)
    assert [str(r) for r in x] == ['-0.30901699437494742',
                                   '0.80901699437494742']
    assert [str(r) for r in w] == ['0.86831485369082398',
                                   '2.2732777998989693']

    x, w = gauss_jacobi(3, Rational(-1, 2), Rational(1, 2), 17)
    assert [str(r) for r in x] == ['-0.62348980185873353',
                                   '0.22252093395631440',
                                   '0.90096886790241913']
    assert [str(r) for r in w] == ['0.33795476356635433',
                                   '1.0973322242791115',
                                   '1.7063056657443274']

    x, w = gauss_jacobi(4, Rational(-1, 2), Rational(1, 2), 17)
    assert [str(r) for r in x] == ['-0.76604444311897804',
                                   '-0.17364817766693035',
                                   '0.50000000000000000',
                                   '0.93969262078590838']
    assert [str(r) for r in w] == ['0.16333179083642836',
                                   '0.57690240318269103',
                                   '1.0471975511965977',
                                   '1.3541609083740761']

    x, w = gauss_jacobi(5, Rational(-1, 2), Rational(1, 2), 17)
    assert [str(r) for r in x] == ['-0.84125353283118117',
                                   '-0.41541501300188643',
                                   '0.14231483827328514',
                                   '0.65486073394528506',
                                   '0.95949297361449739']
    assert [str(r) for r in w] == ['0.090675770007435372',
                                   '0.33391416373675607',
                                   '0.65248870981926643',
                                   '0.94525424081394926',
                                   '1.1192597692123861']

    x, w = gauss_jacobi(1, 2, 3, 17)
    assert [str(r) for r in x] == ['0.14285714285714286']
    assert [str(r) for r in w] == ['1.0666666666666667']

    x, w = gauss_jacobi(2, 2, 3, 17)
    assert [str(r) for r in x] == ['-0.24025307335204215',
                                   '0.46247529557426437']
    assert [str(r) for r in w] == ['0.48514624517838660',
                                   '0.58152042148828007']

    x, w = gauss_jacobi(3, 2, 3, 17)
    assert [str(r) for r in x] == ['-0.46115870378089762',
                                   '0.10438533038323902',
                                   '0.62950064612493132']
    assert [str(r) for r in w] == ['0.17937613502213266',
                                   '0.61595640991147154',
                                   '0.27133412173306246']

    x, w = gauss_jacobi(4, 2, 3, 17)
    assert [str(r) for r in x] == ['-0.59903470850824782',
                                   '-0.14761105199952565',
                                   '0.32554377081188859',
                                   '0.72879429738819258']
    assert [str(r) for r in w] == ['0.067809641836772187',
                                   '0.38956404952032481',
                                   '0.47995970868024150',
                                   '0.12933326662932816']

    x, w = gauss_jacobi(5, 2, 3, 17)
    assert [str(r) for r in x] == ['-0.69045775012676106',
                                   '-0.32651993134900065',
                                   '0.082337849552034905',
                                   '0.47517887061283164',
                                   '0.79279429464422850']
    assert [str(r) for r in w] == ['0.027410178066337099',
                                   '0.21291786060364828',
                                   '0.43908437944395081',
                                   '0.32220656547221822',
                                   '0.065047683080512268']