e67e66bfe251f50fb02086f08d376c636f862ca3
[scilab.git] / scilab / modules / optimization / help / en_US / nonlinearleastsquares / fit_dat.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4  * Copyright (C) 2008 - INRIA
5  * Copyright (C) 2011 - DIGITEO - Michael Baudin
6  * 
7  * This file must be used under the terms of the CeCILL.
8  * This source file is licensed as described in the file COPYING, which
9  * you should have received as part of this distribution.  The terms
10  * are also available at    
11  * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
12  *
13  -->
14 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="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="fit_dat" xml:lang="en">
15     <refnamediv>
16         <refname>fit_dat</refname>
17         <refpurpose>
18             Parameter identification based on measured data 
19             <emphasis role="bold">
20                 This function is obsolete. Please use <link linkend="datafit">datafit</link>.
21             </emphasis>
22         </refpurpose>
23     </refnamediv>
24     <refsynopsisdiv>
25         <title>Calling Sequence</title>
26         <synopsis>[p,err]=fit_dat(G,p0,Z [,W] [,pmin,pmax] [,DG])</synopsis>
27     </refsynopsisdiv>
28     <refsection>
29         <title>Arguments</title>
30         <variablelist>
31             <varlistentry>
32                 <term>G</term>
33                 <listitem>
34                     <para>Scilab function (e=G(p,z), e: nex1, p: npx1, z: nzx1)</para>
35                 </listitem>
36             </varlistentry>
37             <varlistentry>
38                 <term>p0</term>
39                 <listitem>
40                     <para>initial guess (size npx1)</para>
41                 </listitem>
42             </varlistentry>
43             <varlistentry>
44                 <term>Z</term>
45                 <listitem>
46                     <para>matrix [z_1,z_2,...z_n] where z_i (nzx1) is the ith
47                         measurement
48                     </para>
49                 </listitem>
50             </varlistentry>
51             <varlistentry>
52                 <term>W</term>
53                 <listitem>
54                     <para>weighting matrix of size nexne (optional; default 1)</para>
55                 </listitem>
56             </varlistentry>
57             <varlistentry>
58                 <term>pmin</term>
59                 <listitem>
60                     <para>lower bound on p (optional; size npx1)</para>
61                 </listitem>
62             </varlistentry>
63             <varlistentry>
64                 <term>pmax</term>
65                 <listitem>
66                     <para>upper bound on p (optional; size npx1)</para>
67                 </listitem>
68             </varlistentry>
69             <varlistentry>
70                 <term>DG</term>
71                 <listitem>
72                     <para>partial of G wrt p (optional; S=DG(p,z), S: nexnp)</para>
73                 </listitem>
74             </varlistentry>
75         </variablelist>
76     </refsection>
77     <refsection>
78         <title>Description</title>
79         <para>
80             <literal>fit_dat</literal> is used for fitting data to a model. For
81             a given function G(p,z), this function finds the best vector of parameters
82             p for approximating G(p,z_i)=0 for a set of measurement vectors z_i.
83             Vector p is found by minimizing
84             <literal>G(p,z_1)'WG(p,z_1)+G(p,z_2)'WG(p,z_2)+...+G(p,z_n)'WG(p,z_n)</literal>
85         </para>
86     </refsection>
87     <refsection>
88         <title>Examples</title>
89         <programlisting role="example"><![CDATA[ 
90 function y=FF(x)
91   y=a*(x-b)+c*x.*x;
92 endfunction
93 X=[];
94 Y=[];
95 a=34;
96 b=12;
97 c=14;
98 for x=0:.1:3
99   Y=[Y,FF(x)+100*(rand()-.5)];
100   X=[X,x];
101 end
102 Z=[Y;X];
103 function e=G(p,z)
104   a=p(1)
105   b=p(2)
106   c=p(3)
107   y=z(1)
108   x=z(2)
109   e=y-FF(x)
110 endfunction
111
112 [p,err]=fit_dat(G,[3;5;10],Z)
113
114 xset('window',0)
115 clf();
116 plot2d(X',Y',-1) 
117 plot2d(X',FF(X)',5,'002')
118 a=p(1);
119 b=p(2);
120 c=p(3);
121 plot2d(X',FF(X)',12,'002')
122
123 a=34;
124 b=12;
125 c=14;
126 function s=DG(p,z)
127   y=z(1),
128   x=z(2),
129   s=-[x-p(2),-p(1),x*x]
130 endfunction
131
132 [p,err]=fit_dat(G,[3;5;10],Z,DG)
133
134 xset('window',1)
135 clf();
136 plot2d(X',Y',-1)
137 plot2d(X',FF(X)',5,'002')
138 a=p(1);
139 b=p(2);
140 c=p(3);
141 plot2d(X',FF(X)',12,'002')
142  ]]></programlisting>
143     </refsection>
144     <refsection role="see also">
145         <title>See Also</title>
146         <simplelist type="inline">
147             <member>
148                 <link linkend="optim">optim</link>
149             </member>
150             <member>
151                 <link linkend="datafit">datafit</link>
152             </member>
153         </simplelist>
154     </refsection>
155     <refsection>
156         <title>History</title>
157         <revhistory>
158             <revision>
159                 <revnumber>5.4.1</revnumber>
160                 <revdescription>
161                     Function tagged obsolete. Will be removed in 5.5.0. Please use <link linkend="datafit">datafit</link> instead.
162                 </revdescription>
163             </revision>
164         </revhistory>
165     </refsection>
166 </refentry>