Skip to content
DeepForgeby svx
All problems
MediumCalculusca-299

Gauss-Legendre 2-Point on Interval

Problem

Map two-point Gauss-Legendre to a general interval [a, b]: nodes are c +/- (b - a) / (2 * sqrt(3)) with c = (a + b) / 2, and each weight is (b - a) / 2.

Given polynomial coefficients and the interval bounds, return the quadrature estimate.

Hint

Affine-map the standard nodes and scale the weights by half the interval length.

Test cases

case 1
in: [[0,0,1],0,1]
expected: 0.3333333333333333
case 2
in: [[1,1],-1,1]
expected: 2
case 3
in: [[0,0,0,2],0,2]
expected: 7.999999999999999
Starter codePython
def gauss_legendre_2_interval(coeffs, a, b):
    # Your code here
    pass

3 test cases · run your code against them in the editor