.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_numerical_methods/general_methods/plot_estimate_integral_iterated_quadrature.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_numerical_methods_general_methods_plot_estimate_integral_iterated_quadrature.py: Estimate an integral ==================== .. GENERATED FROM PYTHON SOURCE LINES 6-13 In this example we are going to evaluate an integral of the form. .. math:: I_f = \int_{a}^{b}\, \int_{l_1(x_0)}^{u_1(x_0)}\, \int_{l_2(x_0, x_1)}^{u_2(x_0,x_1)}\, \int_{l_{n-1}(x_0, \dots, x_{n-2})}^{u_{n-1}(x_0, \dots, x_{n-2})} \, f(x_0, \dots, x_{n-1})\mathrm{d}{x_{n-1}}\dots\mathrm{d}{x_0} with the iterated quadrature algorithm. .. GENERATED FROM PYTHON SOURCE LINES 15-22 .. code-block:: Python import openturns as ot import openturns.viewer as viewer from matplotlib import pylab as plt import math as m ot.Log.Show(ot.Log.NONE) .. GENERATED FROM PYTHON SOURCE LINES 23-24 define the integrand and the bounds .. GENERATED FROM PYTHON SOURCE LINES 24-30 .. code-block:: Python a = -m.pi b = m.pi f = ot.SymbolicFunction(["x", "y"], ["1+cos(x)*sin(y)"]) ll = [ot.SymbolicFunction(["x"], [" 2+cos(x)"])] u = [ot.SymbolicFunction(["x"], ["-2-cos(x)"])] .. GENERATED FROM PYTHON SOURCE LINES 31-32 Draw the graph of the integrand and the bounds .. GENERATED FROM PYTHON SOURCE LINES 32-44 .. code-block:: Python g = ot.Graph("Integration nodes", "x", "y", True, "upper right") g.add(f.draw([a, a], [b, b])) curve = ll[0].draw(a, b).getDrawable(0) curve.setLineWidth(2) curve.setColor("red") g.add(curve) curve = u[0].draw(a, b).getDrawable(0) curve.setLineWidth(2) curve.setColor("red") g.add(curve) view = viewer.View(g) .. image-sg:: /auto_numerical_methods/general_methods/images/sphx_glr_plot_estimate_integral_iterated_quadrature_001.png :alt: Integration nodes :srcset: /auto_numerical_methods/general_methods/images/sphx_glr_plot_estimate_integral_iterated_quadrature_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 45-46 compute the integral value .. GENERATED FROM PYTHON SOURCE LINES 46-49 .. code-block:: Python I2 = ot.IteratedQuadrature().integrate(f, a, b, ll, u) print(I2) plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none [-25.1327] .. _sphx_glr_download_auto_numerical_methods_general_methods_plot_estimate_integral_iterated_quadrature.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_estimate_integral_iterated_quadrature.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_estimate_integral_iterated_quadrature.py `