<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix"><tt>Thank you Cristophe for your
comments and your link for the</tt> Savitzky-Golay smoothing
<tt>,<br>
<br>
Here is a simple code using lsq-splin() on your example data I
played with. Nothing spectacular - just followed the Scilab
Help, but I hope someone will find it useful.<br>
<br>
Regards,<br>
Radovan<br>
</tt><br>
<pre style="font-family:Monospaced;font-style:normal;font-size:13.0;"><big><big><span style="color:rgb(100,174,100);font-style:italic;">//-----------------------</span>
<span style="color:rgb(0,0,0);">xd</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(0,0,0);">Xinit</span><span style="color:rgb(0,0,0);">;</span> <span style="color:rgb(0,0,0);">yd</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(0,0,0);">Yinit</span><span style="color:rgb(0,0,0);">;</span>
<span style="color:rgb(0,0,0);">a</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(50,185,185);">min</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(0,0,0);">xd</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(0,0,0);">;</span> <span style="color:rgb(0,0,0);">b</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(50,185,185);">max</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(0,0,0);">xd</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(0,0,0);">;</span>
<span style="color:rgb(0,0,0);">n</span> <span style="color:rgb(92,92,92);">=</span> <span style="color:rgb(188,143,143);">20</span><span style="color:rgb(0,0,0);">;</span> <span style="color:rgb(100,174,100);font-style:italic;">// change the number for better smoothing</span>
<span style="color:rgb(0,0,0);">x</span> <span style="color:rgb(92,92,92);">=</span> <span style="color:rgb(174,92,176);text-decoration:underline;">linspace</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(0,0,0);">a</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(0,0,0);">b</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(0,0,0);">n</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(92,92,92);">'</span><span style="color:rgb(0,0,0);">;</span>
<span style="color:rgb(100,174,100);font-style:italic;">// use spline</span>
<span style="color:rgb(74,85,219);">[</span><span style="color:rgb(0,0,0);">y</span><span style="color:rgb(0,0,0);">,</span> <span style="color:rgb(0,0,0);">d</span><span style="color:rgb(74,85,219);">]</span> <span style="color:rgb(92,92,92);">=</span> <span style="color:rgb(50,185,185);">lsq_splin</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(0,0,0);">xd</span><span style="color:rgb(0,0,0);">,</span> <span style="color:rgb(0,0,0);">yd</span><span style="color:rgb(0,0,0);">,</span> <span style="color:rgb(0,0,0);">x</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(0,0,0);">;</span>
<span style="color:rgb(100,174,100);font-style:italic;">// plot - points, smoothing line</span>
<span style="color:rgb(0,0,0);">ys</span> <span style="color:rgb(92,92,92);">=</span> <span style="color:rgb(50,185,185);">interp</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(0,0,0);">xd</span><span style="color:rgb(0,0,0);">,</span> <span style="color:rgb(0,0,0);">x</span><span style="color:rgb(0,0,0);">,</span> <span style="color:rgb(0,0,0);">y</span><span style="color:rgb(0,0,0);">,</span> <span style="color:rgb(0,0,0);">d</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(0,0,0);">;</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);">1001</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(0,0,0);">;</span>
<span style="color:rgb(50,185,185);">plot2d</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(0,0,0);">xd</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(74,85,219);">[</span><span style="color:rgb(0,0,0);">yd</span> <span style="color:rgb(0,0,0);">ys</span><span style="color:rgb(74,85,219);">]</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(0,0,0);">style</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(74,85,219);">[</span><span style="color:rgb(92,92,92);">-</span><span style="color:rgb(188,143,143);">2</span> <span style="color:rgb(188,143,143);">5</span><span style="color:rgb(74,85,219);">]</span><span style="color:rgb(0,0,0);">,</span> <span style="color:rgb(255,170,0);">...</span>
<span style="color:rgb(0,0,0);">leg</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(188,143,143);">gausian peek@smoothing curve</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(74,85,219);">)</span>
<span style="color:rgb(0,0,0);">p</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(50,185,185);">get</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(188,143,143);">hdl</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(0,0,0);">;</span>
<span style="color:rgb(0,0,0);">p</span><span style="color:rgb(92,92,92);">.</span><span style="color:rgb(170,170,170);">children</span><span style="color:rgb(92,92,92);">.</span><span style="color:rgb(170,170,170);">thickness</span> <span style="color:rgb(92,92,92);">=</span> <span style="color:rgb(188,143,143);">3</span><span style="color:rgb(0,0,0);">;</span>
<span style="color:rgb(50,185,185);">xtitle</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(188,143,143);">smoothing curve</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(74,85,219);">)</span>
<span style="color:rgb(50,185,185);">show_window</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(74,85,219);">)</span>
<span style="color:rgb(100,174,100);font-style:italic;">// plot derivatives</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);">1002</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(0,0,0);">;</span>
<span style="color:rgb(50,185,185);">plot2d</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(0,0,0);">x</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(0,0,0);">d</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(0,0,0);">style</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(188,143,143);">5</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(0,0,0);">leg</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(188,143,143);">derivatives</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(74,85,219);">)</span>
<span style="color:rgb(0,0,0);">p</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(50,185,185);">get</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(188,143,143);">hdl</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(0,0,0);">;</span>
<span style="color:rgb(0,0,0);">p</span><span style="color:rgb(92,92,92);">.</span><span style="color:rgb(170,170,170);">children</span><span style="color:rgb(92,92,92);">.</span><span style="color:rgb(170,170,170);">thickness</span> <span style="color:rgb(92,92,92);">=</span> <span style="color:rgb(188,143,143);">3</span><span style="color:rgb(0,0,0);">;</span>
<span style="color:rgb(50,185,185);">xtitle</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(188,143,143);">derivatives</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(74,85,219);">)</span>
<span style="color:rgb(50,185,185);">show_window</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(74,85,219);">)</span>
<span style="color:rgb(100,174,100);font-style:italic;">//end</span></big></big></pre>
<tt><br>
</tt>On 3/24/2014 9:41 AM, Dang, Christophe wrote:<br>
</div>
<blockquote
cite="mid:3B5FFC67498DFF49AE7271A584867D16F328AB4F57@301EX00100.sidel.com"
type="cite">
<pre wrap="">Hello,
</pre>
<blockquote type="cite">
<pre wrap="">De la part de Samuel Enibe
Envoyé : samedi 22 mars 2014 19:01
May I know the best way to determine dy/dx for the data set.
</pre>
</blockquote>
<pre wrap="">
The best way is the way that gives you accurate results in the minimal time.
If you have an analytical model, the best is to fit it and then derive the function, with numdiff().
You can otherwise perform a Savitzky-Golay smoothing, which also gives you the derivative, see e.g.
<a class="moz-txt-link-freetext" href="https://commons.wikimedia.org/wiki/File:Savitzky-golay_pic_gaussien_bruite.svg?uselang=en">https://commons.wikimedia.org/wiki/File:Savitzky-golay_pic_gaussien_bruite.svg?uselang=en</a>
If you excpect a very low noise, then you can assume the points are at their "exact" position. Then, if you suppose the second derivative is small, you can use a simple slope calculation such as
yprime = diff(y)./diff(x)
plot(x(1, $-1), yprime)
which is the fastest method, but also the most sensitive to noise.
If the second deriative is not negligible, you may use the spline interpolation proposed by Radovan, but you may just use the step
yprime = splin(x, y)
plot(x, yprime)
Best regards.
</pre>
</blockquote>
<br>
<br /><br />
<hr style='border:none; color:#909090; background-color:#B0B0B0; height: 1px; width: 99%;' />
<table style='border-collapse:collapse;border:none;'>
<tr>
<td style='border:none;padding:0px 15px 0px 8px'>
<a href="http://www.avast.com/">
<img border=0 src="http://static.avast.com/emails/avast-mail-stamp.png" />
</a>
</td>
<td>
<p style='color:#3d4d5a; font-family:"Calibri","Verdana","Arial","Helvetica"; font-size:12pt;'>
This email is free from viruses and malware because <a href="http://www.avast.com/">avast! Antivirus</a> protection is active.
</p>
</td>
</tr>
</table>
<br />
</body>
</html>