Skip to content

Commit 3a8e31b

Browse files
committed
Required by plot_ellipse() but was left in RTB, move it here
1 parent 41b240e commit 3a8e31b

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

chi2inv_rtb.m

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
%CHI2INV_RTB Inverse chi-squared function
2+
%
3+
% X = CHI2INV_RTB(P, N) is the inverse chi-squared cdf function of N-degrees of freedom.
4+
%
5+
% Notes::
6+
% - only works for N=2
7+
% - uses a table lookup with around 6 figure accuracy
8+
% - an approximation to chi2inv() from the Statistics & Machine Learning Toolbox
9+
%
10+
% See also chi2inv.
11+
12+
% Copyright (C) 1993-2017, by Peter I. Corke
13+
%
14+
% This file is part of The Robotics Toolbox for MATLAB (RTB).
15+
%
16+
% RTB is free software: you can redistribute it and/or modify
17+
% it under the terms of the GNU Lesser General Public License as published by
18+
% the Free Software Foundation, either version 3 of the License, or
19+
% (at your option) any later version.
20+
%
21+
% RTB is distributed in the hope that it will be useful,
22+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
23+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24+
% GNU Lesser General Public License for more details.
25+
%
26+
% You should have received a copy of the GNU Leser General Public License
27+
% along with RTB. If not, see <http://www.gnu.org/licenses/>.
28+
%
29+
% http://www.petercorke.com
30+
31+
function f = chi2inv_rtb(confidence, n)
32+
33+
assert(n == 2, 'chi2inv_rtb: only valid for 2DOF');
34+
35+
c = linspace(0,1,101);
36+
37+
% build a lookup table:
38+
%x = chi2inv(c,2)
39+
%fprintf('%f ');
40+
41+
% use the lookup table
42+
x = [0.000000 0.020101 0.040405 0.060918 0.081644 0.102587 0.123751 0.145141 0.166763 0.188621 0.210721 0.233068 0.255667 0.278524 0.301646 0.325038 0.348707 0.372659 0.396902 0.421442 0.446287 0.471445 0.496923 0.522730 0.548874 0.575364 0.602210 0.629421 0.657008 0.684981 0.713350 0.742127 0.771325 0.800955 0.831031 0.861566 0.892574 0.924071 0.956072 0.988593 1.021651 1.055265 1.089454 1.124238 1.159637 1.195674 1.232372 1.269757 1.307853 1.346689 1.386294 1.426700 1.467938 1.510045 1.553058 1.597015 1.641961 1.687940 1.735001 1.783196 1.832581 1.883217 1.935168 1.988505 2.043302 2.099644 2.157619 2.217325 2.278869 2.342366 2.407946 2.475749 2.545931 2.618667 2.694147 2.772589 2.854233 2.939352 3.028255 3.121295 3.218876 3.321462 3.429597 3.543914 3.665163 3.794240 3.932226 4.080442 4.240527 4.414550 4.605170 4.815891 5.051457 5.318520 5.626821 5.991465 6.437752 7.013116 7.824046 9.210340 Inf];
43+
44+
f = interp1(c, x, confidence);

0 commit comments

Comments
 (0)