import numpy as np

def g(w):
    return (w[0] - 2)**2 + 4*(w[1] + 1)**2

def grad_g(w):
    return np.array([2*(w[0] - 2),
                     8*(w[1] + 1)])

# Problem 5 asks you to use alpha = 0.05 and 30 iterations.
w = np.array([0.0, 0.0])
alpha = 0.05

for k in range(30):
    w = w - alpha*grad_g(w)

print("final w =", w)
print("final cost =", g(w))

# Try printing k, w, and g(w) inside the loop to see the path.
