1 <?xml version="1.0" encoding="UTF-8"?>
3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) 2008 - INRIA
6 * This file must be used under the terms of the CeCILL.
7 * This source file is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at
10 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
13 <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="numdiff" xml:lang="en">
15 <refname>numdiff</refname>
16 <refpurpose>numerical gradient estimation</refpurpose>
19 <title>Calling Sequence</title>
20 <synopsis>g = numdiff(fun, x [,dx])</synopsis>
23 <title>Arguments</title>
28 <para>an external, Scilab function or list. See below for calling
29 sequence, see also <link linkend="external">external</link> for
30 details about external functions.
37 <para>a vector, the argument of the function
38 <varname>fun</varname>.
45 <para>a vector, the finite difference step. Default value is
46 <code>dx=sqrt(%eps)*(1+1d-3*abs(x))</code>.
53 <para>a vector, the estimated gradient.</para>
59 <title>Description</title>
61 Given a function <code>fun(x)</code> from
62 <code>R^n</code> to <code>R^p</code> computes the matrix
63 <varname>g</varname> such as
65 <programlisting role="no-scilab-exec"><![CDATA[
66 g(i,j) = (df_i)/(dx_j)
68 <para>using finite difference methods.
69 Uses an order 1 formula.
72 Without parameters, the function <varname>fun</varname> calling sequence is
73 <code>y=fun(x)</code>, and <function>numdiff</function> can be called as
74 <code>g=numdiff(fun,x)</code>. Else the function <varname>fun</varname> calling
75 sequence must be <literal>y = fun(x, param_1, pararm_2, ..., param_q)</literal>.
76 If parameters <literal>param_1, param_2, ..., param_q</literal> exist then
77 <function>numdiff</function> can be called as follow
78 <literal>g=numdiff(list(fun, param_1, param_2, ..., param_q), x)</literal>.
82 <link linkend="derivative">derivative</link> with respect to numerical accuracy
83 issues and comparison between the two algorithms.
87 <title>Examples</title>
88 <programlisting role="example"><![CDATA[
89 // example 1 (without parameters)
90 // myfun is a function from R^2 to R: (x(1),x(2)) |--> myfun(x)
98 // The exact gradient (i.e derivate belong x(1): first component
99 // and derivate belong x(2): second component) is
100 exact=[2*x(1)+x(2) x(1)]
102 //example 2 (with parameters)
103 // myfun is a function from R to R: x(1) |--> myfun(x)
104 // myfun contains 3 parameters: a, b, c
105 function f=myfun(x,a,b,c)
111 g2=numdiff(list(myfun,a,b,c),x)
113 // The exact gradient, i.e derivate belong x(1), is :
117 <refsection role="see also">
118 <title>See Also</title>
119 <simplelist type="inline">
121 <link linkend="optim">optim</link>
124 <link linkend="derivative">derivative</link>
127 <link linkend="external">external</link>