/usr/share/doc/libplplot11/examples/octave/diffn.m is in octave-plplot 5.9.9-2ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | ## Copyright (C) 1998, 1999, 2000 Joao Cardoso.
##
## This program is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by the
## Free Software Foundation; either version 2 of the License, or (at your
## option) any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## This file is part of plplot_octave.
function datal = diffn(data,step,order)
# data = diffn(data [,step [,order]])
#
# Computes the order (<=4) centered finite derivative of data, with step dx.
# Uses Taylor series expansion up to the second derivative.
# The first/last points are computed with forward/backward finite diferences.
# The step is important for correct scaling.
# step and order default to 1
if (nargin == 1)
step = 1; order = 1;
elseif (nargin == 2)
order = 1;
end
if (order > 4 || order < 1)
usage("order must be: <= 1 order <= 4 ");
endif
if (! isvector(data))
error("diffn only operate on row/column vectors. FIXME");
endif
[nr nc]=size(data);
row_f = 0;
if (nr > nc)
data = data';
row_f = 1;
endif;
n_cols=columns(data);
datal=zeros(1,n_cols);
if (order == 1)
coef = [1;-8;0;8;-1]; div = 12*step; win = 2; # centered difference
h_coef = [-3;4;-1]; h_div = 2*step; h_win = 2; # forward/backward
t_coef = -flipud(h_coef);
elseif (order == 2)
coef = [-1;16;-30;16;-1]; div = 12*step^2; win = 2;
h_coef = [2;-5;4;-1]; h_div = step^2; h_win = 3;
t_coef = flipud(h_coef);
elseif (order == 3)
coef = [1;-8;13;0;-13;8;-1]; div = 8*step^3; win = 3;
h_coef = [-5;18;-24;14;-3]; h_div = 2*step^3; h_win = 4;
t_coef = -flipud(h_coef);
elseif (order == 4)
coef = [-1;12;-39;56;-39;12;-1]; div = 6*step^4; win = 3;
h_coef = [3;-14;26;-24;11;-2]; h_div = step^4; h_win = 5;
t_coef = flipud(h_coef);
endif
for i=win+1:n_cols-win
datal(i) = (data(i-win:i+win) * coef)/div;
endfor
# head: use forward diferences here
for i=1:win
datal(i) = (data(i:h_win+i) * h_coef)/h_div;
# datal(i) = mean(datal(win+1:n_cols-win));
endfor
# tail: and backward differences here
for i=n_cols-win+1:n_cols
datal(i) = (data(i-h_win:i) * t_coef)/h_div;
# datal(i) = mean(datal(win+1:n_cols-win));
endfor
if (row_f)
datal = datal';
endif
endfunction
|