.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_advanced_mathematical_optimization_auto_examples_plot_smooth.py: Smooth vs non-smooth ===================== Draws a figure to explain smooth versus non smooth optimization. .. rst-class:: sphx-glr-horizontal * .. image:: /advanced/mathematical_optimization/auto_examples/images/sphx_glr_plot_smooth_001.png :class: sphx-glr-multi-img * .. image:: /advanced/mathematical_optimization/auto_examples/images/sphx_glr_plot_smooth_002.png :class: sphx-glr-multi-img .. code-block:: python 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) .. _sphx_glr_download_advanced_mathematical_optimization_auto_examples_plot_smooth.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: plot_smooth.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_smooth.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_