Mercurial > octave-nkf
annotate scripts/statistics/distributions/tcdf.m @ 20209:d9341b422488 stable
doc: Update more docstrings to have one sentence summary as first line.
Reviewed statistics/ and @ftp/ in scripts directory.
* scripts/@ftp/ascii.m, scripts/@ftp/binary.m, scripts/@ftp/cd.m,
scripts/@ftp/dir.m, scripts/@ftp/ftp.m, scripts/@ftp/mget.m,
scripts/@ftp/mput.m, scripts/statistics/base/center.m,
scripts/statistics/base/cloglog.m, scripts/statistics/base/cov.m,
scripts/statistics/base/gls.m, scripts/statistics/base/histc.m,
scripts/statistics/base/iqr.m, scripts/statistics/base/kendall.m,
scripts/statistics/base/kurtosis.m, scripts/statistics/base/logit.m,
scripts/statistics/base/lscov.m, scripts/statistics/base/mahalanobis.m,
scripts/statistics/base/mean.m, scripts/statistics/base/meansq.m,
scripts/statistics/base/median.m, scripts/statistics/base/mode.m,
scripts/statistics/base/moment.m, scripts/statistics/base/ols.m,
scripts/statistics/base/ppplot.m, scripts/statistics/base/prctile.m,
scripts/statistics/base/probit.m, scripts/statistics/base/range.m,
scripts/statistics/base/ranks.m, scripts/statistics/base/run_count.m,
scripts/statistics/base/runlength.m, scripts/statistics/base/skewness.m,
scripts/statistics/base/spearman.m, scripts/statistics/base/statistics.m,
scripts/statistics/base/std.m, scripts/statistics/base/table.m,
scripts/statistics/base/var.m, scripts/statistics/base/zscore.m,
scripts/statistics/distributions/betainv.m,
scripts/statistics/distributions/binoinv.m,
scripts/statistics/distributions/binopdf.m,
scripts/statistics/distributions/cauchy_cdf.m,
scripts/statistics/distributions/cauchy_inv.m,
scripts/statistics/distributions/cauchy_pdf.m,
scripts/statistics/distributions/chi2cdf.m,
scripts/statistics/distributions/chi2inv.m,
scripts/statistics/distributions/chi2pdf.m,
scripts/statistics/distributions/discrete_cdf.m,
scripts/statistics/distributions/discrete_inv.m,
scripts/statistics/distributions/discrete_pdf.m,
scripts/statistics/distributions/empirical_cdf.m,
scripts/statistics/distributions/empirical_inv.m,
scripts/statistics/distributions/empirical_pdf.m,
scripts/statistics/distributions/expcdf.m,
scripts/statistics/distributions/expinv.m,
scripts/statistics/distributions/exppdf.m,
scripts/statistics/distributions/finv.m,
scripts/statistics/distributions/fpdf.m,
scripts/statistics/distributions/gamcdf.m,
scripts/statistics/distributions/gaminv.m,
scripts/statistics/distributions/gampdf.m,
scripts/statistics/distributions/geoinv.m,
scripts/statistics/distributions/geopdf.m,
scripts/statistics/distributions/hygecdf.m,
scripts/statistics/distributions/hygeinv.m,
scripts/statistics/distributions/hygepdf.m,
scripts/statistics/distributions/kolmogorov_smirnov_cdf.m,
scripts/statistics/distributions/laplace_cdf.m,
scripts/statistics/distributions/laplace_inv.m,
scripts/statistics/distributions/laplace_pdf.m,
scripts/statistics/distributions/logistic_inv.m,
scripts/statistics/distributions/logncdf.m,
scripts/statistics/distributions/logninv.m,
scripts/statistics/distributions/lognpdf.m,
scripts/statistics/distributions/nbincdf.m,
scripts/statistics/distributions/nbininv.m,
scripts/statistics/distributions/nbinpdf.m,
scripts/statistics/distributions/nbinrnd.m,
scripts/statistics/distributions/normcdf.m,
scripts/statistics/distributions/norminv.m,
scripts/statistics/distributions/normpdf.m,
scripts/statistics/distributions/poisscdf.m,
scripts/statistics/distributions/poissinv.m,
scripts/statistics/distributions/poisspdf.m,
scripts/statistics/distributions/stdnormal_cdf.m,
scripts/statistics/distributions/stdnormal_pdf.m,
scripts/statistics/distributions/tcdf.m,
scripts/statistics/distributions/tinv.m,
scripts/statistics/distributions/tpdf.m,
scripts/statistics/distributions/unidcdf.m,
scripts/statistics/distributions/unidinv.m,
scripts/statistics/distributions/unidpdf.m,
scripts/statistics/distributions/unidrnd.m,
scripts/statistics/distributions/unifcdf.m,
scripts/statistics/distributions/unifinv.m,
scripts/statistics/distributions/wblcdf.m,
scripts/statistics/distributions/wblinv.m,
scripts/statistics/distributions/wblpdf.m,
scripts/statistics/distributions/wienrnd.m,
scripts/statistics/models/private/logistic_regression_derivatives.m,
scripts/statistics/models/private/logistic_regression_likelihood.m,
scripts/statistics/tests/anova.m,
scripts/statistics/tests/chisquare_test_homogeneity.m,
scripts/statistics/tests/chisquare_test_independence.m,
scripts/statistics/tests/cor_test.m,
scripts/statistics/tests/f_test_regression.m,
scripts/statistics/tests/hotelling_test.m,
scripts/statistics/tests/kolmogorov_smirnov_test.m,
scripts/statistics/tests/kolmogorov_smirnov_test_2.m,
scripts/statistics/tests/kruskal_wallis_test.m,
scripts/statistics/tests/manova.m, scripts/statistics/tests/mcnemar_test.m,
scripts/statistics/tests/prop_test_2.m, scripts/statistics/tests/run_test.m,
scripts/statistics/tests/sign_test.m, scripts/statistics/tests/t_test.m,
scripts/statistics/tests/t_test_2.m,
scripts/statistics/tests/t_test_regression.m,
scripts/statistics/tests/u_test.m, scripts/statistics/tests/var_test.m,
scripts/statistics/tests/welch_test.m,
scripts/statistics/tests/wilcoxon_test.m, scripts/statistics/tests/z_test.m,
scripts/statistics/tests/z_test_2.m:
Update more docstrings to have one sentence summary as first line.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 10 May 2015 16:07:41 -0700 |
parents | 9fc020886ae9 |
children |
rev | line source |
---|---|
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1 ## Copyright (C) 2013-2015 Julien Bect |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13171
diff
changeset
|
2 ## Copyright (C) 2012 Rik Wehbring |
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
3 ## Copyright (C) 1995-2015 Kurt Hornik |
5410 | 4 ## |
5 ## This file is part of Octave. | |
6 ## | |
7 ## Octave is free software; you can redistribute it and/or modify it | |
8 ## under the terms of the GNU General Public License as published by | |
7016 | 9 ## the Free Software Foundation; either version 3 of the License, or (at |
10 ## your option) any later version. | |
5410 | 11 ## |
12 ## Octave is distributed in the hope that it will be useful, but | |
13 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 ## General Public License for more details. | |
16 ## | |
17 ## You should have received a copy of the GNU General Public License | |
7016 | 18 ## along with Octave; see the file COPYING. If not, see |
19 ## <http://www.gnu.org/licenses/>. | |
5410 | 20 |
21 ## -*- texinfo -*- | |
5411 | 22 ## @deftypefn {Function File} {} tcdf (@var{x}, @var{n}) |
20209
d9341b422488
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19867
diff
changeset
|
23 ## For each element of @var{x}, compute the cumulative distribution function |
d9341b422488
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19867
diff
changeset
|
24 ## (CDF) at @var{x} of the t (Student) distribution with |
d9341b422488
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19867
diff
changeset
|
25 ## @var{n} degrees of freedom. |
5410 | 26 ## @end deftypefn |
27 | |
5428 | 28 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
5410 | 29 ## Description: CDF of the t distribution |
30 | |
5411 | 31 function cdf = tcdf (x, n) |
5410 | 32 |
33 if (nargin != 2) | |
6046 | 34 print_usage (); |
5410 | 35 endif |
36 | |
19867
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
37 if (! isscalar (n)) |
5410 | 38 [retval, x, n] = common_size (x, n); |
39 if (retval > 0) | |
13171
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
40 error ("tcdf: X and N must be of common size or scalars"); |
5410 | 41 endif |
42 endif | |
43 | |
13171
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
44 if (iscomplex (x) || iscomplex (n)) |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
45 error ("tcdf: X and N must not be complex"); |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
46 endif |
5410 | 47 |
13171
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
48 if (isa (x, "single") || isa (n, "single")) |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
49 cdf = zeros (size (x), "single"); |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
50 else |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
51 cdf = zeros (size (x)); |
5410 | 52 endif |
53 | |
19867
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
54 k = ! isinf (x) & (n > 0); |
17218
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
55 |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
56 xx = x .^ 2; |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
57 x_big_abs = (xx > n); |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
58 |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
59 ## deal with the case "abs(x) big" |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
60 kk = k & x_big_abs; |
13171
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
61 if (isscalar (n)) |
17218
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
62 cdf(kk) = betainc (n ./ (n + xx(kk)), n/2, 1/2) / 2; |
13171
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
63 else |
17218
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
64 cdf(kk) = betainc (n(kk) ./ (n(kk) + xx(kk)), n(kk)/2, 1/2) / 2; |
13171
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
65 endif |
17218
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
66 |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
67 ## deal with the case "abs(x) small" |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
68 kk = k & !x_big_abs; |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
69 if (isscalar (n)) |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
70 cdf(kk) = 0.5 * (1 - betainc (xx(kk) ./ (n + xx(kk)), 1/2, n/2)); |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
71 else |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
72 cdf(kk) = 0.5 * (1 - betainc (xx(kk) ./ (n(kk) + xx(kk)), 1/2, n(kk)/2)); |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
73 endif |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
74 |
13171
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
75 k &= (x > 0); |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
76 if (any (k(:))) |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
77 cdf(k) = 1 - cdf(k); |
5410 | 78 endif |
79 | |
13171
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
80 k = isnan (x) | !(n > 0); |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
81 cdf(k) = NaN; |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
82 |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
83 k = (x == Inf) & (n > 0); |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
84 cdf(k) = 1; |
5410 | 85 |
86 endfunction | |
13171
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
87 |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
88 |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
89 %!shared x,y |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
90 %! x = [-Inf 0 1 Inf]; |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
91 %! y = [0 1/2 3/4 1]; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
92 %!assert (tcdf (x, ones (1,4)), y, eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
93 %!assert (tcdf (x, 1), y, eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
94 %!assert (tcdf (x, [0 1 NaN 1]), [NaN 1/2 NaN 1], eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
95 %!assert (tcdf ([x(1:2) NaN x(4)], 1), [y(1:2) NaN y(4)], eps) |
13171
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
96 |
19867
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
97 ## Test class of input preserved |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
98 %!assert (tcdf ([x, NaN], 1), [y, NaN], eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
99 %!assert (tcdf (single ([x, NaN]), 1), single ([y, NaN]), eps ("single")) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
100 %!assert (tcdf ([x, NaN], single (1)), single ([y, NaN]), eps ("single")) |
13171
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
101 |
19867
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
102 ## Test input validation |
13171
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
103 %!error tcdf () |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
104 %!error tcdf (1) |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
105 %!error tcdf (1,2,3) |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
106 %!error tcdf (ones (3), ones (2)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
107 %!error tcdf (ones (2), ones (3)) |
13171
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
108 %!error tcdf (i, 2) |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
109 %!error tcdf (2, i) |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
110 |
17218
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
111 ## Check some reference values |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
112 |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
113 %!shared tol_rel |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
114 %! tol_rel = 10 * eps; |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
115 |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
116 ## check accuracy for small positive values |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
117 %!assert (tcdf (10^(-10), 2.5), 0.50000000003618087, -tol_rel) |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
118 %!assert (tcdf (10^(-11), 2.5), 0.50000000000361809, -tol_rel) |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
119 %!assert (tcdf (10^(-12), 2.5), 0.50000000000036181, -tol_rel) |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
120 %!assert (tcdf (10^(-13), 2.5), 0.50000000000003618, -tol_rel) |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
121 %!assert (tcdf (10^(-14), 2.5), 0.50000000000000362, -tol_rel) |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
122 %!assert (tcdf (10^(-15), 2.5), 0.50000000000000036, -tol_rel) |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
123 %!assert (tcdf (10^(-16), 2.5), 0.50000000000000004, -tol_rel) |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
124 |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
125 ## check accuracy for large negative values |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
126 %!assert (tcdf (-10^1, 2.5), 2.2207478836537124e-03, -tol_rel) |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
127 %!assert (tcdf (-10^2, 2.5), 7.1916492116661878e-06, -tol_rel) |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
128 %!assert (tcdf (-10^3, 2.5), 2.2747463948307452e-08, -tol_rel) |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
129 %!assert (tcdf (-10^4, 2.5), 7.1933970159922115e-11, -tol_rel) |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
130 %!assert (tcdf (-10^5, 2.5), 2.2747519231756221e-13, -tol_rel) |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
131 |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
132 ## # Reference values obtained using Python 2.7.4 and mpmath 0.17 |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
133 ## |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
134 ## from mpmath import * |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
135 ## |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
136 ## mp.dps = 100 |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
137 ## |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
138 ## def F(x_in, nu_in): |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
139 ## x = mpf(x_in); |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
140 ## nu = mpf(nu_in); |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
141 ## t = nu / (nu + x*x) |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
142 ## a = nu / 2 |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
143 ## b = mpf(0.5) |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
144 ## F = betainc(a, b, 0, t, regularized=True) / 2 |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
145 ## if (x > 0): |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
146 ## F = 1 - F |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
147 ## return F |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
148 ## |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
149 ## nu = 2.5 |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
150 ## |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
151 ## for i in range(1, 6): |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
152 ## x = - power(mpf(10), mpf(i)) |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
153 ## print "%%!assert (tcdf (-10^%d, 2.5), %s, -eps)" \ |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
154 ## % (i, nstr(F(x, nu), 17)) |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
155 ## |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
156 ## for i in range(10, 17): |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
157 ## x = power(mpf(10), -mpf(i)) |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
158 ## print "%%!assert (tcdf (10^(-%d), 2.5), %s, -eps)" \ |
251807f3cdc1
tcdf.m: Improve accuracy around zero and add tests.
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
159 ## % (i, nstr(F(x, nu), 17)) |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
17218
diff
changeset
|
160 |