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

@author: sam
"""

import numpy as np
import matplotlib.pyplot as plt

def f(x):
    return np.sin(x)**2

def montyn(f,a,b,N):
    U = np.random.uniform(a,b,N)
    I = 0
    for i in range(len(U)):
        I += f(U[i])
    I *= (b-a)/len(U)
    return I



for i in range(1,10000):
    plt.plot(i,montyn(f,0,np.pi,i),'.') # plots the approximation for increasing numbers of numbers sampled