| 1 |
function f = gampar(ab, XLO, XUP, PLO, PUP); |
| 2 |
|
| 3 |
% The function takes as inputs the parameters ab=[a, b] of the gamma |
| 4 |
% distribution, the bounds of the support [XLO, XUP], the the corresponding |
| 5 |
% probability of the bounds [PLO, PUP] and returns the residual value f. |
| 6 |
% |
| 7 |
% Copyright (C) 1997-2012 Tao Zha |
| 8 |
% |
| 9 |
% This free software: you can redistribute it and/or modify |
| 10 |
% it under the terms of the GNU General Public License as published by |
| 11 |
% the Free Software Foundation, either version 3 of the License, or |
| 12 |
% (at your option) any later version. |
| 13 |
% |
| 14 |
% It is distributed in the hope that it will be useful, |
| 15 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
% GNU General Public License for more details. |
| 18 |
% |
| 19 |
% If you did not received a copy of the GNU General Public License |
| 20 |
% with this software, see <http://www.gnu.org/licenses/>. |
| 21 |
% |
| 22 |
|
| 23 |
a = abs(ab(1)); b = abs(ab(2)); % abs() is used to allow continuous search for the fsolve function find_gampar.m. |
| 24 |
f1 = PLO - gamcdf(XLO, a, 1/b); %Note that in Matlab, it is 1/b, NOT b. |
| 25 |
f2 = PUP - gamcdf(XUP, a, 1/b); %Note that in Matlab, it is 1/b, NOT b. |
| 26 |
% Equivalently, one can use the gaminv function to define the zero |
| 27 |
% conditions: |
| 28 |
% f1 = XLO - gaminv(PLO, a, b); |
| 29 |
% f2 = XUP - gaminv(PUP, a, b); |
| 30 |
|
| 31 |
f = [f1, f2]; |