/usr/share/octave/packages/statistics-1.3.0/tripdf.m is in octave-statistics 1.3.0-1.
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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | ## Copyright (C) 2016 Dag Lyberg
## Copyright (C) 1997-2015 Kurt Hornik
##
## This file is part of Octave.
##
## Octave 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 3 of the License, or (at
## your option) any later version.
##
## Octave 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.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING. If not, see
## <http://www.gnu.org/licenses/>.
## -*- texinfo -*-
## @deftypefn {} {} tripdf (@var{x}, @var{a}, @var{b}, @var{c})
## Compute the probability density function (PDF) at @var{x} of the triangular
## distribution with parameters @var{a}, @var{b}, and @var{c} on the interval
## [@var{a}, @var{b}].
## @end deftypefn
## Author: Dag Lyberg <daglyberg80@gmail.com>
## Description: PDF of the triangular distribution
function pdf = tripdf (x, a, b, c)
if (nargin != 4)
print_usage ();
endif
if (! isscalar (a) || ! isscalar (b) || ! isscalar (c))
[retval, x, a, b, c] = common_size (x, a, b, c);
if (retval > 0)
error ("tripdf: X, A, B, and C must be of common size or scalars");
endif
endif
if (iscomplex (x) || iscomplex (a) || iscomplex (b) || iscomplex (c))
error ("tripdf: X, A, B, and C must not be complex");
endif
if (isa (x, "single") || isa (a, "single") ...
|| isa (b, "single") || isa (c, "single"))
pdf = zeros (size (x), "single");
else
pdf = zeros (size (x));
endif
k = isnan (x) | !(a < b) | !(c >= a) | !(c <= b) ;
pdf(k) = NaN;
k = (x >= a) & (x <= b) & (a < b) & (a <= c) & (c <= b);
h = 2 ./ (b-a);
if (isscalar (a) && isscalar (b) && isscalar (c))
j = k & (a <= x) & (x < c);
pdf(j) = h * (x(j)-a) / (c-a);
j = k & (x == c);
pdf(j) = h;
j = k & (c < x) & (x <= b);
pdf(j) = h * (b-x(j)) / (b-c);
else
j = k & (a <= x) & (x < c);
pdf(j) = h(j) .* (x(j)-a(j)) ./ (c(j)-a(j));
j = k & (x == c);
pdf(j) = h(j);
j = k & (c < x) & (x <= b);
pdf(j) = h(j) .* (b(j)-x(j)) ./ (b(j)-c(j));
endif
endfunction
%!shared x,y,deps
%! x = [-1, 0, 0.1, 0.5, 0.9, 1, 2] + 1;
%! y = [0, 0, 0.4, 2, 0.4, 0, 0];
%! deps = 2*eps;
%!assert (tripdf (x, ones (1,7), 2*ones (1,7), 1.5*ones (1,7)), y, deps)
%!assert (tripdf (x, 1*ones (1,7), 2, 1.5), y, deps)
%!assert (tripdf (x, 1, 2*ones (1,7), 1.5), y, deps)
%!assert (tripdf (x, 1, 2, 1.5*ones (1,7)), y, deps)
%!assert (tripdf (x, 1, 2, 1.5), y, deps)
%!assert (tripdf (x, [1, 1, NaN, 1, 1, 1, 1], 2, 1.5), [y(1:2), NaN, y(4:7)], deps)
%!assert (tripdf (x, 1, 2*[1, 1, NaN, 1, 1, 1, 1], 1.5), [y(1:2), NaN, y(4:7)], deps)
%!assert (tripdf (x, 1, 2, 1.5*[1, 1, NaN, 1, 1, 1, 1]), [y(1:2), NaN, y(4:7)], deps)
%!assert (tripdf ([x, NaN], 1, 2, 1.5), [y, NaN], deps)
## Test class of input preserved
%!assert (tripdf (single ([x, NaN]), 1, 2, 1.5), single ([y, NaN]), eps('single'))
%!assert (tripdf ([x, NaN], single (1), 2, 1.5), single ([y, NaN]), eps('single'))
%!assert (tripdf ([x, NaN], 1, single (2), 1.5), single ([y, NaN]), eps('single'))
%!assert (tripdf ([x, NaN], 1, 2, single (1.5)), single ([y, NaN]), eps('single'))
## Test input validation
%!error tripdf ()
%!error tripdf (1)
%!error tripdf (1,2)
%!error tripdf (1,2,3)
%!error tripdf (1,2,3,4,5)
%!error tripdf (1, ones (3), ones (2), ones (2))
%!error tripdf (1, ones (2), ones (3), ones (2))
%!error tripdf (1, ones (2), ones (2), ones (3))
%!error tripdf (i, 2, 2, 2)
%!error tripdf (2, i, 2, 2)
%!error tripdf (2, 2, i, 2)
%!error tripdf (2, 2, 2, i)
|