#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 10 15:14:35 2024

@author: sam
"""

from scipy.special import p_roots
import numpy as np

def f(x):
    return np.exp(-2*x)*np.cos(x)

def I(f,a,b,n):
    I = 0
    x,w = p_roots(n)
    for i in range(len(x)):
        I += w[i]*f((b-a)/2*x[i]+(a+b)/2)
    I *= (b-a)/2
    return I

print(I(f,1,3,13)) #calls function I now with different function f and bounds [1,3]