[Scilab-users] Numerical Differentiation

Radovan Omorjan omorr at uns.ac.rs
Mon Mar 24 10:59:26 CET 2014


Thank you Cristophe for your comments and your link for the 
Savitzky-Golay smoothing ,

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.

Regards,
Radovan

//-----------------------
xd=Xinit;  yd=Yinit;
a=min(xd);  b=max(xd);

n  =  20;  // change the number for better smoothing
x  =  linspace(a,b,n)';

// use spline
[y,  d]  =  lsq_splin(xd,  yd,  x);

// plot - points, smoothing line
ys  =  interp(xd,  x,  y,  d);
scf(1001);
plot2d(xd,[yd  ys],style=[-2  5],  ...
        leg="gausian peek at smoothing curve")
p=get("hdl");   
p.children.thickness  =  3;      
xtitle("smoothing curve")
show_window()
// plot derivatives
scf(1002);
plot2d(x,d,style=5,leg="derivatives")
p=get("hdl");   
p.children.thickness  =  3;      
xtitle("derivatives")
show_window()
//end


On 3/24/2014 9:41 AM, Dang, Christophe wrote:
> Hello,
>
>> 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.
> 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.
> https://commons.wikimedia.org/wiki/File:Savitzky-golay_pic_gaussien_bruite.svg?uselang=en
>
> 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.
>



---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20140324/ffc64b76/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fig1.png
Type: image/png
Size: 8552 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20140324/ffc64b76/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fig2a.png
Type: image/png
Size: 10379 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20140324/ffc64b76/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fig2b.png
Type: image/png
Size: 6147 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20140324/ffc64b76/attachment-0002.png>


More information about the users mailing list