1function nu_p = stoich_p(a, species, rxns)
2% STOICH_P  Get the product stoichiometric coefficients.
3% nu_p = stoich_p(a,species,rxns)
4%
5% See also: :mat:func:`stoich_r`, :mat:func:`stoich_net`
6%
7% :param a:
8%     Instance of class :mat:func:`Kinetics` (or another
9%     object deriving from Kinetics)
10%     for which the product stoichiometric coefficients are desired.
11% :param species:
12%     Species indices for which product stoichiometric coefficients
13%     should be retrieved. Optional argument; if specified, ``rxns``
14%     must be specified as well.
15% :param rxns:
16%     Reaction indices for which product stoichiometric coefficients
17%     should be retrieved. Optional argument; if specified, ``species``
18%     must be specified as well.
19% :return:
20%     Returns a sparse matrix of all product stoichiometric
21%     coefficients. The matrix element ``nu(k,i)`` is the
22%     stoichiometric coefficient of species k as a product in
23%     reaction i. If ``species`` and ``rxns`` are specified, the matrix
24%     will contain only entries for the specified species and
25%     reactions. For example, ``stoich_p(a,3,[1 3 5 7])`` returns a
26%     sparse matrix containing only the coefficients for species 3
27%     in reactions 1, 3, 5, and 7.
28%
29
30nsp = nTotalSpecies(a);
31nr = nReactions(a);
32b = sparse(nsp, nr);
33if nargin == 1
34    kvals = 1:nsp;
35    ivals = 1:nr;
36elseif nargin == 3
37    kvals = species;
38    ivals = rxns;
39else
40    error('stoich_p requires 1 or 3 arguments.')
41end
42
43for k = kvals
44    for i = ivals
45        nu = kinetics_get(a.id, 6, i, k);
46        if nu ~= 0.0
47            b(k, i) = nu;
48        end
49    end
50end
51nu_p = b;
52