Example #1
0
import matplotlib
import numpy as np
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import answer

delta = 0.025
x = np.arange(-0.5, 1.5, delta)
y = np.arange(-1.5, 0.5, delta)
X, Y = np.meshgrid(x, y)
Z3 = answer.f3([X, Y])

fig, ax = plt.subplots()
CS = ax.contour(X, Y, Z3, 20)
ax.clabel(CS, inline=1, fontsize=10)
ax.set_title('gradient descent for f3(x), step_size=0.1')


def plot2Dpoint(x, y):
    ax.hold(True)
    plt.scatter(x, y)


def grad3(x, y):
    gama = 0.1
    for i in range(50):
        s1 = x
        s2 = y
        print('s1 :', s1)
        print('s2 :', s2)
        g1 = answer.grad_f3([float(x), float(y)])[0]
Example #2
0
def plot_point3(x,y,c):
	p = np.array([x,y,answer.f3([x,y])])
	ax = plt.gca()
	ax.hold(True)
	ax.scatter(p[0], p[1], p[2], color=c)