.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_functional_modeling/vectorial_functions/plot_linear_combination_function.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_functional_modeling_vectorial_functions_plot_linear_combination_function.py: Create a linear combination of functions ======================================== .. GENERATED FROM PYTHON SOURCE LINES 6-22 In this example we are going to build a linear combination of several functions. .. math:: f = \sum \alpha_i f_i Here .. math:: f_1(x) = [x_1^2+x_2,x_1+x_2+x_3] f_2(x) = [x_1 + 2 * x_2 + x_3,x_1+x_2+x_3] with coefficients .. math:: a_1 = 2, a_2 = 4 .. GENERATED FROM PYTHON SOURCE LINES 24-28 .. code-block:: Python import openturns as ot ot.Log.Show(ot.Log.NONE) .. GENERATED FROM PYTHON SOURCE LINES 29-30 assume a list of functions to combine .. GENERATED FROM PYTHON SOURCE LINES 30-36 .. code-block:: Python functions = list() functions.append(ot.SymbolicFunction(["x1", "x2", "x3"], ["x1^2 + x2", "x1 + x2 + x3"])) functions.append( ot.SymbolicFunction(["x1", "x2", "x3"], ["x1 + 2 * x2 + x3", "x1 + x2 - x3"]) ) .. GENERATED FROM PYTHON SOURCE LINES 37-38 create the combination function .. GENERATED FROM PYTHON SOURCE LINES 38-41 .. code-block:: Python coefficients = [2.0, 4.0] function = ot.LinearCombinationFunction(functions, coefficients) .. GENERATED FROM PYTHON SOURCE LINES 42-43 evaluate the function .. GENERATED FROM PYTHON SOURCE LINES 43-46 .. code-block:: Python x = [1.0, 2.0, 3.0] y = function(x) print("x=", x, "y=", y) .. rst-class:: sphx-glr-script-out .. code-block:: none x= [1.0, 2.0, 3.0] y= [38,12] .. _sphx_glr_download_auto_functional_modeling_vectorial_functions_plot_linear_combination_function.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_linear_combination_function.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_linear_combination_function.py `