In [1]:
'''Utility for plotting a 2nd deg polynomial and
its derivative
'''
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import matplotlib.pyplot as plt
In [5]:
# plt.style.use('grayscale')
plt.style.use('ggplot')
x = np.arange(-1, 2, 0.1)
In [6]:
# polynomial coefficients
c = [1, -1, -1]
# polynomial coefficients of derivative
d = [2, -1]
# generate output value
y = np.polyval(c, x)
z = np.polyval(d, x)
In [9]:
plt.xlabel('x')
plt.ylabel(r'$y\/\/\/and\/\/\/\frac{dy}{dx}$')
plt.plot(x, y, label=r'$y=x^2 -x -1$')
plt.plot(x, z, label=r'$\frac{dy}{dx},\/\/\/y_{min}\/\/at\/\/x=0.5$')
plt.legend(loc=0)
plt.grid(b=True)
# plt.savefig("sgd.png")
plt.show()
plt.close('all')