<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Scilab ( https://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) 2008 - INRIA
 * Copyright (C) 2012 - 2016 - Scilab Enterprises
 * Copyright (C) 2020 - Samuel GOUGEON
 *
 * This file is hereby licensed under the terms of the GNU GPL v2.0,
 * pursuant to article 5.3.4 of the CeCILL v.2.1.
 * This file was originally licensed under the terms of the CeCILL v2.1,
 * and continues to be available under such terms.
 * For more information, see the COPYING file which you should have received
 * along with this program.
 *
 -->
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
          xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns3="http://www.w3.org/1999/xhtml"
          xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook"
          xmlns:scilab="http://www.scilab.org" xml:id="integrate" xml:lang="en">
    <refnamediv>
        <refname>integrate</refname>
        <refpurpose>integration of an expression by quadrature</refpurpose>
    </refnamediv>
    <refsynopsisdiv>
        <title>Syntax</title>
        <synopsis>
           y = integrate(expr, v, x0, x1)
           y = integrate(expr, v, x0, x1, atol)
           y = integrate(expr, v, x0, x1, atol, rtol)
        </synopsis>
    </refsynopsisdiv>
    <refsection>
        <title>Arguments</title>
        <variablelist>
            <varlistentry>
                <term>expr</term>
                <listitem>
                    a character string defining a Scilab expression.
                    <para/>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>v</term>
                <listitem>
                    a character string, the integration variable name.
                    <para/>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>x0</term>
                <listitem>
                    a real number, the lower bound of integration.
                    <para/>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>x1</term>
                <listitem>
                    a vector of real numbers, upper bounds of integration.
                    <para/>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>atol</term>
                <listitem>
                    a real number (absolute error bound). Default value: 1e-13.
                    <para/>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>rtol</term>
                <listitem>
                    a real number, (relative error bound). Default value: 1e-8.
                    <para/>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>y</term>
                <listitem>
                    a vector of real numbers, the integral value for each <literal>x1(i)</literal>.
                    <para/>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection>
        <title>Description</title>
        <para>
            <literal>y = integrate(expr, v, x0, x1 [,atol [,rtol]])</literal> computes
            <latex alt="y(i) = integral_{x_0}^{x_1(i)} f(v).dv">
                y(i) = \int_{x_0}^{x_1(i)} f(v)\,dv
            </latex>
            for <literal>i=1:size(x1,'*')</literal>, where <emphasis>f(v)</emphasis>
            is given by the expression <literal>expr</literal>.
        </para>
        <para>The evaluation hopefully satisfies following claim for accuracy:
            <literal>abs(I - y) &lt;= max(atol, rtol*abs(I))</literal> where
            <literal>I</literal> stands for the exact value of the integral.
        </para>
        <para>
            <warning>
                Restriction: The given expression must not use variable names with a leading
                <literal>%</literal>.
            </warning>
        </para>
    </refsection>
    <refsection>
        <title>Examples</title>
        <programlisting role="example"><![CDATA[
x1 = 0:0.1:2*%pi;
Y = integrate('sin(x)', 'x', 0, x1);
norm(cos(x1)-(1-Y))

x1 = -10:0.1:10;
Y = integrate(['if x==0 then 1,';
               'else sin(x)/x,end'], 'x', 0, x1)
     ]]></programlisting>
    </refsection>
    <refsection role="see also">
        <title>See also</title>
        <simplelist type="inline">
            <member>
                <link linkend="intg">intg</link>
            </member>
            <member>
                <link linkend="inttrap">inttrap</link>
            </member>
            <member>
                <link linkend="intsplin">intsplin</link>
            </member>
            <member>
                <link linkend="ode">ode</link>
            </member>
        </simplelist>
    </refsection>
    <refsection role="history">
        <title>History</title>
        <revhistory>
            <revision>
                <revnumber>6.1.0</revnumber>
                <revdescription>
                    Default atol value increased from
                    10<superscript>-14</superscript> to 10<superscript>-13</superscript>.
                </revdescription>
            </revision>
        </revhistory>
    </refsection>
</refentry>
