# -*- coding: utf-8 -*-
"""
Created on Thu Sep  8 16:28:24 2022

@author: Chris

Lab 7 Q1
"""
import numpy as np
import matplotlib.pyplot as plt
import myquad as myq

def f(x,y):
    f = x*y
    return f


def squadz(f,a,b,c,d):
    # Numerically integrates f(x,y) over x and y on the
    # rectangular interval x \in [a,b] and y\in [c,d].
    #
    # Uses nested Gauss-Legengre integration,
    # where the tolerance of the inner integrals is fixed 
    # at 1e-5.
    
    tol = 1e-5  # tolerance of inner integrals
    
    def yint(f,x,c,d):
        # Integrates f over y for a given value of x
        tol = 1e-5

        f1 = lambda y: f(x,y)
        
        yint =  myq.quadz(f1,c,d,tol)
        
        return yint

    f2 = lambda x: yint(f,x,c,d)
    
    squadz = myq.quadz(f2,a,b,tol)
    
    return squadz
    
a,b = 0, 2
c,d = 0, 3

result = squadz(f,a,b,c,d)
    
print(result)






