File: numdiff.xml

package info (click to toggle)
scilab 5.2.2-9
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 334,832 kB
  • ctags: 52,586
  • sloc: xml: 526,945; ansic: 223,590; fortran: 163,080; java: 56,934; cpp: 33,840; tcl: 27,936; sh: 20,397; makefile: 9,908; ml: 9,451; perl: 1,323; cs: 614; lisp: 30
file content (152 lines) | stat: -rw-r--r-- 4,258 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) 2008 - INRIA
 * 
 * This file must be used under the terms of the CeCILL.
 * This source file is licensed as described in the file COPYING, which
 * you should have received as part of this distribution.  The terms
 * are also available at    
 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 *
 -->
<refentry version="5.0-subset Scilab" xml:id="numdiff" xml:lang="en"
          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">
  <info>
    <pubdate>$LastChangedDate$</pubdate>
  </info>

  <refnamediv>
    <refname>numdiff</refname>

    <refpurpose>numerical gradient estimation</refpurpose>
  </refnamediv>

  <refsynopsisdiv>
    <title>Calling Sequence</title>

    <synopsis>g=numdiff(fun,x [,dx])</synopsis>
  </refsynopsisdiv>

  <refsection>
    <title>Parameters</title>

    <variablelist>
      <varlistentry>
        <term>fun</term>

        <listitem>
          <para>an external, Scilab function or list. See below for calling
          sequence, see also <link linkend="external">external</link> for
          details about external functions.</para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term>x</term>

        <listitem>
          <para>vector, the argument of the function
          <literal>fun</literal></para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term>dx</term>

        <listitem>
          <para>vector, the finite difference step. Default value is
          <literal>dx=sqrt(%eps)*(1+1d-3*abs(x))</literal></para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term>g</term>

        <listitem>
          <para>vector, the estimated gradient</para>
        </listitem>
      </varlistentry>
    </variablelist>
  </refsection>

  <refsection>
    <title>Description</title>

    <para>given a function <literal>fun(x)</literal> from
    <literal>R^n</literal> to <literal>R^p</literal> computes the matrix
    <literal>g</literal> such as</para>

    <programlisting role = ""><![CDATA[ 
g(i,j) = (df_i)/(dx_j)
 ]]></programlisting>

    <para>using finite difference methods.</para>

    <para>
	Without parameters, the function fun calling sequence is
    <literal>y=fun(x)</literal>, and numdiff can be called as
    <literal>g=numdiff(fun,x)</literal>. Else the function fun calling
    sequence must be <literal>y=fun(x,param_1,pararm_2,..,param_q)</literal>.
    If parameters <literal>param_1,param_2,..param_q</literal> exist then
    <literal>numdiff</literal> can be called as follow
    <literal>g=numdiff(list(fun,param_1,param_2,..param_q),x)</literal>.
	</para>
    
    <para>
    See the 
  <link linkend="derivative">derivative</link> with respect to numerical accuracy 
  issues and comparison between the two algorithms.
	</para>

</refsection>

  <refsection>
    <title>Examples</title>

    <programlisting role="example"><![CDATA[ 
// example 1 (without parameters)
// myfun is a function from R^2 to R :   (x(1),x(2)) |--> myfun(x) 
function f=myfun(x)
  f=x(1)*x(1)+x(1)*x(2)
endfunction

x=[5 8]
g=numdiff(myfun,x)

// The exact gradient (i.e derivate belong x(1) :first component and derivate belong x(2): second component) is  
exact=[2*x(1)+x(2)  x(1)]

//example 2 (with parameters)
// myfun is a function from R to R:  x(1) |--> myfun(x) 
// myfun contains 3 parameters, a, b, c
function  f=myfun(x,a,b,c)
  f=(x+a)^c+b
endfunction

a=3; b=4; c=2;
x=1
g2=numdiff(list(myfun,a,b,c),x)

// The exact gradient, i.e derivate belong x(1), is :
exact2=c*(x+a)^(c-1)
 ]]></programlisting>
  </refsection>

  <refsection>
    <title>See Also</title>

    <simplelist type="inline">
      <member><link linkend="optim">optim</link></member>

      <member><link linkend="derivative">derivative</link></member>

      <member><link linkend="external">external</link></member>
    </simplelist>
  </refsection>
</refentry>