#!/usr/bin/python3

import numpy as np
import matplotlib.pyplot as plt
import math as math

def f(x): #x^2 sin(1/x)
    return (x**2)*np.sin(1/x)

def diff(f,h,order,x): #returns the numerical derivative of a function
    if order > 1:
        return (diff(f,h,order-1,x+h)-diff(f,h,order-1,x-h))/(2*h)
    else:
        return (f(x+h)-f(x-h))/(2*h)
    

x = np.linspace(-1,1) #set domain as [-1,1]

plt.plot(x,diff(f,1e-9,2,x)) #plot f''(x)
plt.show()

