<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title></title>
</head>
<body style="font-family:Arial;font-size:14px">
<p>Hello Heinz,<br>
<br>
You can have a look at pages 45-49 of my slides on least Squares :<br>
<br>
<a href="http://www.utc.fr/~mottelet/mt94/leastSquares.pdf">http://www.utc.fr/~mottelet/mt94/leastSquares.pdf</a><br>
<br>
Page 48 you have an example where the Covariance matrix is approximated for a fitting problem with an ode defined page 42.<br>
<br>
S.<br>
<br>
<br>
Quoting Heinz Nabielek <<a href="mailto:heinznabielek@me.com">heinznabielek@me.com</a>>:</p>
<blockquote style="border-left:2px solid blue;margin-left:2px;padding-left:12px;" type="cite">
<div><font size="4">Scilab friends: the power of Scilab is amazing and I have used it recently for non-linear least-squares fitting, below example from Scilab help function for "datafit". On occasions, I have also used "leastsq".</font></div>
<div> </div>
<div><font size="4">Question: how do I derive the 1sigma standard error in the three parameters p(1), p(2), and p(3)? And, if it is not too complicated, covariances?</font></div>
<div> </div>
<div><font size="4">I know this is written in dozens of textbooks, but I am always getting lost.</font></div>
<div><font size="4">Please provide a simple recipe written in Scilab.</font></div>
<div><font size="4">Best greetings</font></div>
<div><font size="4">Heinz</font></div>
<div> </div>
<div> </div>
<div> </div>
<div>
<pre style="font-family: Monospaced;">
<span style="color:rgb(100,174,100);font-style:italic;">// -- 04/04/2020 14:57:30 -- //</span>
<span style="color:rgb(100,174,100);font-style:italic;">//generate the data</span>
<span style="color:rgb(176,24,19);">function</span> <span style="color:rgb(131,67,16);font-weight:bold;">y</span><span style="color:rgb(92,92,92);">=</span><span style="text-decoration: underline;">FF</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(131,67,16);font-weight:bold;">x</span>, <span style="color:rgb(131,67,16);font-weight:bold;">p</span><span style="color:rgb(74,85,219);">)</span>
  <span style="color:rgb(131,67,16);font-weight:bold;">y</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(131,67,16);font-weight:bold;">p</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">1</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(92,92,92);">*</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(131,67,16);font-weight:bold;">x</span><span style="color:rgb(92,92,92);">-</span><span style="color:rgb(131,67,16);font-weight:bold;">p</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">2</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(92,92,92);">+</span><span style="color:rgb(131,67,16);font-weight:bold;">p</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">3</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(92,92,92);">*</span><span style="color:rgb(131,67,16);font-weight:bold;">x</span><span style="color:rgb(92,92,92);">.*</span><span style="color:rgb(131,67,16);font-weight:bold;">x</span>
<span style="color:rgb(176,24,19);">endfunction</span>
X<span style="color:rgb(92,92,92);">=</span><span style="color:rgb(74,85,219);">[</span><span style="color:rgb(74,85,219);">]</span>;
Y<span style="color:rgb(92,92,92);">=</span><span style="color:rgb(74,85,219);">[</span><span style="color:rgb(74,85,219);">]</span>;
pg<span style="color:rgb(92,92,92);">=</span><span style="color:rgb(74,85,219);">[</span><span style="color:rgb(188,143,143);">34</span>;<span style="color:rgb(188,143,143);">12</span>;<span style="color:rgb(188,143,143);">14</span><span style="color:rgb(74,85,219);">]</span> <span style="color:rgb(100,174,100);font-style:italic;">//parameter used to generate data</span>
<span style="color:rgb(160,32,240);">for</span> x<span style="color:rgb(92,92,92);">=</span><span style="color:rgb(188,143,143);">0</span><span style="color:rgb(255,170,0);">:</span><span style="color:rgb(188,143,143);">.1</span><span style="color:rgb(255,170,0);">:</span><span style="color:rgb(188,143,143);">3</span>
  Y<span style="color:rgb(92,92,92);">=</span><span style="color:rgb(74,85,219);">[</span>Y,<span style="color:rgb(174,92,176);text-decoration:underline;">FF</span><span style="color:rgb(74,85,219);">(</span>x,pg<span style="color:rgb(74,85,219);">)</span><span style="color:rgb(92,92,92);">+</span><span style="color:rgb(188,143,143);">100</span><span style="color:rgb(92,92,92);">*</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(50,185,185);">rand</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(92,92,92);">-</span><span style="color:rgb(188,143,143);">.5</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(74,85,219);">]</span>;
  X<span style="color:rgb(92,92,92);">=</span><span style="color:rgb(74,85,219);">[</span>X,x<span style="color:rgb(74,85,219);">]</span>;
<span style="color:rgb(160,32,240);">end</span>
Z<span style="color:rgb(92,92,92);">=</span><span style="color:rgb(74,85,219);">[</span>Y;X<span style="color:rgb(74,85,219);">]</span>;
<span style="color:rgb(100,174,100);font-style:italic;">//The criterion function</span>
<span style="color:rgb(176,24,19);">function</span> <span style="color:rgb(131,67,16);font-weight:bold;">e</span><span style="color:rgb(92,92,92);">=</span><span style="text-decoration: underline;">G</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(131,67,16);font-weight:bold;">p</span>, <span style="color:rgb(131,67,16);font-weight:bold;">z</span><span style="color:rgb(74,85,219);">)</span>,
  y<span style="color:rgb(92,92,92);">=</span><span style="color:rgb(131,67,16);font-weight:bold;">z</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">1</span><span style="color:rgb(74,85,219);">)</span>,x<span style="color:rgb(92,92,92);">=</span><span style="color:rgb(131,67,16);font-weight:bold;">z</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">2</span><span style="color:rgb(74,85,219);">)</span>;
  <span style="color:rgb(131,67,16);font-weight:bold;">e</span><span style="color:rgb(92,92,92);">=</span>y<span style="color:rgb(92,92,92);">-</span><span style="color:rgb(174,92,176);text-decoration:underline;">FF</span><span style="color:rgb(74,85,219);">(</span>x,<span style="color:rgb(131,67,16);font-weight:bold;">p</span><span style="color:rgb(74,85,219);">)</span>,
<span style="color:rgb(176,24,19);">endfunction</span>
<span style="color:rgb(100,174,100);font-style:italic;">//Solve the problem</span>
p0<span style="color:rgb(92,92,92);">=</span><span style="color:rgb(74,85,219);">[</span><span style="color:rgb(188,143,143);">3</span>;<span style="color:rgb(188,143,143);">5</span>;<span style="color:rgb(188,143,143);">10</span><span style="color:rgb(74,85,219);">]</span>
<span style="color:rgb(74,85,219);">[</span>p,err<span style="color:rgb(74,85,219);">]</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(174,92,176);text-decoration:underline;">datafit</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(174,92,176);text-decoration:underline;">G</span>,Z,p0<span style="color:rgb(74,85,219);">)</span>;
<span style="color:rgb(174,92,176);text-decoration:underline;">scf</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">0</span><span style="color:rgb(74,85,219);">)</span>;<span style="color:rgb(174,92,176);text-decoration:underline;">clf</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(74,85,219);">)</span>
<span style="color:rgb(50,185,185);">plot2d</span><span style="color:rgb(74,85,219);">(</span>X,<span style="color:rgb(174,92,176);text-decoration:underline;">FF</span><span style="color:rgb(74,85,219);">(</span>X,pg<span style="color:rgb(74,85,219);">)</span>,<span style="color:rgb(188,143,143);">5</span><span style="color:rgb(74,85,219);">)</span> <span style="color:rgb(100,174,100);font-style:italic;">//the curve without noise</span>
<span style="color:rgb(50,185,185);">plot2d</span><span style="color:rgb(74,85,219);">(</span>X,Y,<span style="color:rgb(92,92,92);">-</span><span style="color:rgb(188,143,143);">1</span><span style="color:rgb(74,85,219);">)</span>  <span style="color:rgb(100,174,100);font-style:italic;">// the noisy data</span>
<span style="color:rgb(50,185,185);">plot2d</span><span style="color:rgb(74,85,219);">(</span>X,<span style="color:rgb(174,92,176);text-decoration:underline;">FF</span><span style="color:rgb(74,85,219);">(</span>X,p<span style="color:rgb(74,85,219);">)</span>,<span style="color:rgb(188,143,143);">12</span><span style="color:rgb(74,85,219);">)</span> <span style="color:rgb(100,174,100);font-style:italic;">//the solution</span>
<span style="color:rgb(50,185,185);">xgrid</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(74,85,219);">)</span>;<span style="color:rgb(174,92,176);text-decoration:underline;">legend</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(188,143,143);">the curve without noise</span><span style="color:rgb(188,143,143);">"</span>,<span style="color:rgb(188,143,143);">"</span><span style="color:rgb(188,143,143);"> the noisy data</span><span style="color:rgb(188,143,143);">"</span>, <span style="color:rgb(188,143,143);">"</span><span style="color:rgb(188,143,143);">THE FINAL SOLUTION</span><span style="color:rgb(188,143,143);">.</span><span style="color:rgb(188,143,143);">.</span><span style="color:rgb(188,143,143);">.</span><span style="color:rgb(188,143,143);">.</span><span style="color:rgb(188,143,143);">.</span><span style="color:rgb(188,143,143);">"</span>,<span style="color:rgb(188,143,143);">4</span><span style="color:rgb(74,85,219);">)</span>;
<span style="color:rgb(174,92,176);text-decoration:underline;">title</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(188,143,143);">solution set   39.868419    10.312053    11.482521</span><span style="color:rgb(188,143,143);">"</span>,<span style="color:rgb(188,143,143);">"</span><span style="color:rgb(188,143,143);">fontsize</span><span style="color:rgb(188,143,143);">"</span>,<span style="color:rgb(188,143,143);">4</span><span style="color:rgb(74,85,219);">)</span>;</pre>
<div><img apple-inline="yes" id="383993A6-92A2-49B1-8197-1E47B42182AF" src="cid:ykF-KXpZkQTyf4_RvfR_TUp@webmail1"></div>
</div>
</blockquote>
<p><br>
<br></p>
</body>
</html>