Mercurial > octave-nkf
annotate scripts/statistics/distributions/expcdf.m @ 11523:fd0a3ac60b0e
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 14 Jan 2011 05:47:45 -0500 |
parents | 1740012184f9 |
children | 19b9f17d22af |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1995-2011 Kurt Hornik |
5410 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
5410 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
5410 | 18 |
19 ## -*- texinfo -*- | |
5411 | 20 ## @deftypefn {Function File} {} expcdf (@var{x}, @var{lambda}) |
5410 | 21 ## For each element of @var{x}, compute the cumulative distribution |
22 ## function (CDF) at @var{x} of the exponential distribution with | |
7604
90c9038170bf
doc fix for exp distribution functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
23 ## mean @var{lambda}. |
5410 | 24 ## |
25 ## The arguments can be of common size or scalar. | |
26 ## @end deftypefn | |
27 | |
5428 | 28 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
5410 | 29 ## Description: CDF of the exponential distribution |
30 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
31 function cdf = expcdf (x, lambda) |
5410 | 32 |
33 if (nargin != 2) | |
6046 | 34 print_usage (); |
5410 | 35 endif |
36 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
37 if (!isscalar (x) && !isscalar(lambda)) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
38 [retval, x, lambda] = common_size (x, lambda); |
5410 | 39 if (retval > 0) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
11469
diff
changeset
|
40 error ("expcdf: X and LAMBDA must be of common size or scalar"); |
5410 | 41 endif |
42 endif | |
43 | |
44 if (isscalar (x)) | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
45 sz = size (lambda); |
5410 | 46 else |
47 sz = size (x); | |
48 endif | |
49 | |
50 cdf = zeros (sz); | |
51 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
52 k = find (isnan (x) | !(lambda > 0)); |
5410 | 53 if (any (k)) |
54 cdf(k) = NaN; | |
55 endif | |
56 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
57 k = find ((x == Inf) & (lambda > 0)); |
5410 | 58 if (any (k)) |
59 cdf(k) = 1; | |
60 endif | |
61 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
62 k = find ((x > 0) & (x < Inf) & (lambda > 0)); |
5410 | 63 if (any (k)) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
64 if isscalar (lambda) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
65 cdf (k) = 1 - exp (- x(k) ./ lambda); |
5410 | 66 elseif isscalar (x) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
67 cdf (k) = 1 - exp (- x ./ lambda(k)); |
5410 | 68 else |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
69 cdf (k) = 1 - exp (- x(k) ./ lambda(k)); |
5410 | 70 endif |
71 endif | |
72 | |
73 endfunction |