#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 17 15:20:00 2024

@author: sam
"""

import numpy as np
from scipy.special import p_roots

def I(f,a,b,n): # functions from last week
    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

def f(x,y): # different function
    return np.cos(x)*np.exp(y)

def squad2d(f,a,b,c,d): # same as last question
    def yint(f,x,c,d):
        def fy(y):
            return f(x,y)
        return I(fy,c,d,13)
    def fx(x):
        return yint(f,x,c,d)
    return I(fx,a,b,13)



print(squad2d(f,0,1,0,1))