comparison scripts/statistics/distributions/fpdf.m @ 19833:9fc020886ae9

maint: Clean up m-files to follow Octave coding conventions. Try to trim long lines to < 80 chars. Use '##' for single line comments. Use '(...)' around tests for if/elseif/switch/while. Abut cell indexing operator '{' next to variable. Abut array indexing operator '(' next to variable. Use space between negation operator '!' and following expression. Use two newlines between endfunction and start of %!test or %!demo code. Remove unnecessary parens grouping between short-circuit operators. Remove stray extra spaces (typos) between variables and assignment operators. Remove stray extra spaces from ends of lines.
author Rik <rik@octave.org>
date Mon, 23 Feb 2015 14:54:39 -0800
parents 4197fc428c7d
children d9341b422488
comparison
equal deleted inserted replaced
19832:a1acca0c2216 19833:9fc020886ae9
31 31
32 if (nargin != 3) 32 if (nargin != 3)
33 print_usage (); 33 print_usage ();
34 endif 34 endif
35 35
36 if (!isscalar (m) || !isscalar (n)) 36 if (! isscalar (m) || ! isscalar (n))
37 [retval, x, m, n] = common_size (x, m, n); 37 [retval, x, m, n] = common_size (x, m, n);
38 if (retval > 0) 38 if (retval > 0)
39 error ("fpdf: X, M, and N must be of common size or scalars"); 39 error ("fpdf: X, M, and N must be of common size or scalars");
40 endif 40 endif
41 endif 41 endif
67 endif 67 endif
68 68
69 endfunction 69 endfunction
70 70
71 71
72 %% F (x, 1, m) == T distribution (sqrt (x), m) / sqrt (x) 72 ## F (x, 1, m) == T distribution (sqrt (x), m) / sqrt (x)
73 %!test 73 %!test
74 %! x = rand (10,1); 74 %! x = rand (10,1);
75 %! x = x(x > 0.1 & x < 0.9); 75 %! x = x(x > 0.1 & x < 0.9);
76 %! y = tpdf (sqrt (x), 2) ./ sqrt (x); 76 %! y = tpdf (sqrt (x), 2) ./ sqrt (x);
77 %! assert (fpdf (x, 1, 2), y, 5*eps); 77 %! assert (fpdf (x, 1, 2), y, 5*eps);
84 %!assert (fpdf (x, 2*ones (1,5), 2), y, eps) 84 %!assert (fpdf (x, 2*ones (1,5), 2), y, eps)
85 %!assert (fpdf (x, [0 NaN Inf 2 2], 2), [NaN NaN NaN y(4:5)], eps) 85 %!assert (fpdf (x, [0 NaN Inf 2 2], 2), [NaN NaN NaN y(4:5)], eps)
86 %!assert (fpdf (x, 2, [0 NaN Inf 2 2]), [NaN NaN NaN y(4:5)], eps) 86 %!assert (fpdf (x, 2, [0 NaN Inf 2 2]), [NaN NaN NaN y(4:5)], eps)
87 %!assert (fpdf ([x, NaN], 2, 2), [y, NaN], eps) 87 %!assert (fpdf ([x, NaN], 2, 2), [y, NaN], eps)
88 88
89 %% Test class of input preserved 89 ## Test class of input preserved
90 %!assert (fpdf (single ([x, NaN]), 2, 2), single ([y, NaN]), eps ("single")) 90 %!assert (fpdf (single ([x, NaN]), 2, 2), single ([y, NaN]), eps ("single"))
91 %!assert (fpdf ([x, NaN], single (2), 2), single ([y, NaN]), eps ("single")) 91 %!assert (fpdf ([x, NaN], single (2), 2), single ([y, NaN]), eps ("single"))
92 %!assert (fpdf ([x, NaN], 2, single (2)), single ([y, NaN]), eps ("single")) 92 %!assert (fpdf ([x, NaN], 2, single (2)), single ([y, NaN]), eps ("single"))
93 93
94 %% Test input validation 94 ## Test input validation
95 %!error fpdf () 95 %!error fpdf ()
96 %!error fpdf (1) 96 %!error fpdf (1)
97 %!error fpdf (1,2) 97 %!error fpdf (1,2)
98 %!error fpdf (1,2,3,4) 98 %!error fpdf (1,2,3,4)
99 %!error fpdf (ones (3), ones (2), ones (2)) 99 %!error fpdf (ones (3), ones (2), ones (2))