

import numpy as np

E = np.array([-0.7746, 0.00, 0.7746])
c = np.array([0.5556, 0.8889, 0.5556])

def gaussQuad(f, a, b, E, c):
    x = np.zeros(3)
    for i in range(3):
        x[i] = (b+a)/2 + (b-a)/2 *E[i]

    return (b-a)/2 * (c[0]*f(x[0]) + c[1]*f(x[1]) + c[2]*f(x[2]))


f = lambda x: 3*x
a ,b = 0.2, 1.5

Gauss = gaussQuad(f, a, b, E, c)
print("Gaussian Approx.= ", Gauss)


GaussExact=3.315
Et= abs((GaussExact-Gauss)/GaussExact)*100
print('Et=%',Et)




