<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) 2008 - INRIA
 *
 * Copyright (C) 2012 - 2016 - Scilab Enterprises
 *
 * 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:ns5="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="diff" xml:lang="en">
    <refnamediv>
        <refname>diff</refname>
        <refpurpose>Difference and discrete derivative</refpurpose>
    </refnamediv>
    <refsynopsisdiv>
        <title>Syntax</title>
        <synopsis>
            y = diff(x)
            y = diff(x, n)
            y = diff(x, n, dim)
        </synopsis>
    </refsynopsisdiv>
    <refsection>
        <title>Arguments</title>
        <variablelist>
            <varlistentry>
                <term>x</term>
                <listitem>
                    <para>vector or matrix (real, complex, sparse or polynomial)</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>n</term>
                <listitem>
                    <para>integer the order of differentiation</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>dim</term>
                <listitem>
                    <para>integer or character string with values "r","c" and "*"</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>y</term>
                <listitem>
                    <para>scalar or vector/matrix</para>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection>
        <title>Description</title>
        <para>
            <literal>y=diff(x)</literal> compute the difference function
            <literal>y=x(2:$)-x(1:$-1)</literal>
        </para>
        <para>
            <literal>diff(x,n,dim)</literal> is the <literal>n</literal>th
            difference function along dimension <literal>dim</literal>.
        </para>
        <para>
            <literal>diff(x,n,"*")</literal> is equivalent to
            <literal>diff(x(:),n)</literal>.
        </para>
        <para>
            Default value for <literal>n</literal> is 1. Default value for
            <literal>dim</literal> is <literal>"*"</literal>.
        </para>
        <para>
            <literal>dim='r'</literal> is equivalent to <literal>dim=1</literal>
            and <literal>dim='c'</literal> is equivalent to
            <literal>dim=2</literal>.
        </para>
    </refsection>
    <refsection>
        <title>Examples</title>
        <programlisting role="example">
            <![CDATA[
v = (1:8)^3;
diff(v)
diff(v,3)

A=[(1:8)^2
   (1:8)^3
   (1:8)^4];

diff(A,3,2)

// approximate differentiation
step = 0.001
t = 0:step:10;
y = sin(t);
dy = diff(sin(t)) / step; //approximate differentiation of sine function
norm(dy-cos(t(1:$-1)), %inf)
 ]]>
        </programlisting>
    </refsection>
    <refsection role="see also">
        <title>See also</title>
        <simplelist type="inline">
            <member>
                <link linkend="interp">interp</link>
            </member>
            <member>
                <link linkend="interp2d">interp2d</link>
            </member>
            <member>
                <link linkend="splin">splin</link>
            </member>
            <member>
                <link linkend="eval_cshep2d">eval_cshep2d</link>
            </member>
            <member>
                <link linkend="numderivative">numderivative</link>
            </member>
            <member>
                <link linkend="sgolaydiff">sgolaydiff</link>
            </member>
        </simplelist>
    </refsection>

</refentry>
