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" version="5.0-subset Scilab" 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>vector, the argument of the function
38
<literal>fun</literal>
45
<para>vector, the finite difference step. Default value is
46
<literal>dx=sqrt(%eps)*(1+1d-3*abs(x))</literal>
53
<para>vector, the estimated gradient</para>
59
<title>Description</title>
61
given a function <literal>fun(x)</literal> from
62
<literal>R^n</literal> to <literal>R^p</literal> computes the matrix
63
<literal>g</literal> such as
65
<programlisting role=""><![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 fun calling sequence is
73
<literal>y=fun(x)</literal>, and numdiff can be called as
74
<literal>g=numdiff(fun,x)</literal>. Else the function fun 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
<literal>numdiff</literal> 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 and derivate belong x(2): second component) is
99
exact=[2*x(1)+x(2) x(1)]
101
//example 2 (with parameters)
102
// myfun is a function from R to R: x(1) |--> myfun(x)
103
// myfun contains 3 parameters, a, b, c
104
function f=myfun(x,a,b,c)
110
g2=numdiff(list(myfun,a,b,c),x)
112
// The exact gradient, i.e derivate belong x(1), is :
116
<refsection role="see also">
117
<title>See Also</title>
118
<simplelist type="inline">
120
<link linkend="optim">optim</link>
123
<link linkend="derivative">derivative</link>
126
<link linkend="external">external</link>