import os
os.chdir("/home/guerzhoy/Desktop/Link to CSC321")

from numpy import *
from matplotlib.pyplot import *

def f(x):
    return .1*x**2 + sin(.1*(x-2)**2)

def dfdx(x):
    return .2*x+cos(.1*(x-2)**2)*(.2*(x-2))


def grad_descent(f, dfdx, init_x, alpha):
    EPS = 1e-5
    prev_x = init_x-2*EPS
    x = init_x
    
    while abs(x - prev_x) >  EPS:
        prev_x = x
        x -= alpha*dfdx(x)
        print x, f(x)
    
    return x
    
    
    


x = arange(-10, 10, .1)
y = f(x)

figure(1)
plot(x, y)
xlabel("x")
ylabel("$.1 x^2 + sin(.1 (x-2)^2)$")
show()
