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

# Forward difference
def fordiff(f,x,h):
    return (f(x+h)-f(x))/h

#Backward difference
def backdiff(f,x,h):
    return (f(x)-f(x-h))/h

#Central difference
def centdiff(f,x,h):
    return (f(x+h/2)-f(x-h/2))/h

print(fordiff(np.cos,0,10**-5))
print(backdiff(np.cos,0,10**-5))
print(centdiff(np.cos,0,10**-5))


