2.7.4.2. Smooth vs non-smoothΒΆ

Draws a figure to explain smooth versus non smooth optimization.

  • ../../../_images/sphx_glr_plot_smooth_001.png
  • ../../../_images/sphx_glr_plot_smooth_002.png
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-1.5, 1.5, 101)
# A smooth function
plt.figure(1, figsize=(3, 2.5))
plt.clf()
plt.plot(x, np.sqrt(.2 + x**2), linewidth=2)
plt.text(-1, 0, '$f$', size=20)
plt.ylim(ymin=-.2)
plt.axis('off')
plt.tight_layout()
# A non-smooth function
plt.figure(2, figsize=(3, 2.5))
plt.clf()
plt.plot(x, np.abs(x), linewidth=2)
plt.text(-1, 0, '$f$', size=20)
plt.ylim(ymin=-.2)
plt.axis('off')
plt.tight_layout()
plt.show()

Total running time of the script: ( 0 minutes 0.057 seconds)

Gallery generated by Sphinx-Gallery