1 % ------------------------------------------------------------------------------
2 % Subroutine for the derivative of Fun with respect to rate coefficients
3 % -----------------------------------------------------------------------------
5 DFDR = function dFun_dRcoeff( V, F, NCOEFF, JCOEFF )
7 % V/F - Concentrations of variable/fixed species
8 % NCOEFF - the number of rate coefficients with respect to which we differentiate
9 % JCOEFF - a vector of integers containing the indices of reactions (rate
10 % coefficients) with respect to which we differentiate
11 % INTEGER JCOEFF(NCOEFF)
12 % DFDR - a matrix containg derivative values; specifically,
13 % column j contains d Fun(1:KPP_NVAR) / d RCT( JCOEFF(j) )
14 % for each 1 <= j <= NCOEFF
15 % This matrix is stored in a column-wise linearized format
16 % KPP_REAL DFDR(KPP_NVAR*NCOEFF)
18 % A_RPROD - Local vector with reactant products
19 % Compute the reactant products of all reactions
20 A_RPROD = ReactantProd ( V, F );
22 % Compute the derivatives by multiplying column JCOEFF(j) of the stoichiometric matrix with A_RPROD
24 % Initialize the j-th column of derivative matrix to zero
26 DFDR(i+KPP_NVAR*(j-1)) = 0.0;
28 % Column JCOEFF(j) in the stoichiometric matrix times the
29 % reactant product of the JCOEFF(j)-th reaction
30 % give the j-th column of the derivative matrix
31 aj = A_RPROD(JCOEFF(j));
32 for k=CCOL_STOICM(JCOEFF(j)):CCOL_STOICM(JCOEFF(j)+1)-1
33 DFDR(IROW_STOICM(k)+KPP_NVAR*(j-1)) = STOICM(k)*aj;