# Generated Code

The following is matlab code generated by the CellML API from this CellML file. (Back to language selection)

The raw code is available.

```function [VOI, STATES, ALGEBRAIC, CONSTANTS] = mainFunction()
% This is the "main function".  In Matlab, things work best if you rename this function to match the filename.
[VOI, STATES, ALGEBRAIC, CONSTANTS] = solveModel();
end

function [algebraicVariableCount] = getAlgebraicVariableCount()
% Used later when setting a global variable with the number of algebraic variables.
% Note: This is not the "main method".
algebraicVariableCount =24;
end
% There are a total of 33 entries in each of the rate and state variable arrays.
% There are a total of 97 entries in the constant variable array.
%

function [VOI, STATES, ALGEBRAIC, CONSTANTS] = solveModel()
% Create ALGEBRAIC of correct size
global algebraicVariableCount;  algebraicVariableCount = getAlgebraicVariableCount();
% Initialise constants and state variables
[INIT_STATES, CONSTANTS] = initConsts;

% Set timespan to solve over
tspan = [0, 10];

% Set numerical accuracy options for ODE solver
options = odeset('RelTol', 1e-06, 'AbsTol', 1e-06, 'MaxStep', 1);

% Solve model with ODE solver
[VOI, STATES] = ode15s(@(VOI, STATES)computeRates(VOI, STATES, CONSTANTS), tspan, INIT_STATES, options);

% Compute algebraic variables
[RATES, ALGEBRAIC] = computeRates(VOI, STATES, CONSTANTS);
ALGEBRAIC = computeAlgebraic(ALGEBRAIC, CONSTANTS, STATES, VOI);

% Plot state variables against variable of integration
[LEGEND_STATES, LEGEND_ALGEBRAIC, LEGEND_VOI, LEGEND_CONSTANTS] = createLegends();
figure();
plot(VOI, STATES);
xlabel(LEGEND_VOI);
l = legend(LEGEND_STATES);
set(l,'Interpreter','none');
end

function [LEGEND_STATES, LEGEND_ALGEBRAIC, LEGEND_VOI, LEGEND_CONSTANTS] = createLegends()
LEGEND_STATES = ''; LEGEND_ALGEBRAIC = ''; LEGEND_VOI = ''; LEGEND_CONSTANTS = '';
LEGEND_VOI = strpad('time in component environment (hour)');
LEGEND_STATES(:,1) = strpad('ATbl in component ATbl (nanomole)');
LEGEND_CONSTANTS(:,1) = strpad('k2T in component ATbl (nmol_hr)');
LEGEND_ALGEBRAIC(:,18) = strpad('Qb in component model_parameters (l_hr)');
LEGEND_ALGEBRAIC(:,16) = strpad('Qp in component Qp (l_hr)');
LEGEND_CONSTANTS(:,2) = strpad('Ql in component model_parameters (l_hr)');
LEGEND_CONSTANTS(:,3) = strpad('Qt in component model_parameters (l_hr)');
LEGEND_CONSTANTS(:,95) = strpad('CTbf in component model_parameters (nM)');
LEGEND_ALGEBRAIC(:,1) = strpad('CTblf in component CTblf (nM)');
LEGEND_ALGEBRAIC(:,11) = strpad('CTpf in component CTpf (nM)');
LEGEND_CONSTANTS(:,4) = strpad('CTbl in component model_parameters (nM)');
LEGEND_CONSTANTS(:,91) = strpad('CTlf in component CTlf (nM)');
LEGEND_CONSTANTS(:,94) = strpad('CTtv in component CTtv (nM)');
LEGEND_CONSTANTS(:,5) = strpad('ts in component model_parameters (dimensionless)');
LEGEND_ALGEBRAIC(:,19) = strpad('Qbt in component model_parameters (l_hr)');
LEGEND_CONSTANTS(:,96) = strpad('CDbf in component model_parameters (nM)');
LEGEND_ALGEBRAIC(:,5) = strpad('CDblf in component CDblf (nM)');
LEGEND_ALGEBRAIC(:,13) = strpad('CDpf in component CDpf (nM)');
LEGEND_CONSTANTS(:,93) = strpad('CDlf in component CDlf (nM)');
LEGEND_CONSTANTS(:,6) = strpad('CDbl in component model_parameters (nM)');
LEGEND_STATES(:,3) = strpad('CT_A in component CT_A (nM)');
LEGEND_CONSTANTS(:,7) = strpad('kTA_on in component CT_A (second_order_rate_constant)');
LEGEND_CONSTANTS(:,8) = strpad('kTA_off in component CT_A (first_order_rate_constant)');
LEGEND_ALGEBRAIC(:,9) = strpad('CAf in component CAf (nM)');
LEGEND_STATES(:,4) = strpad('CD_A in component CD_A (nM)');
LEGEND_CONSTANTS(:,9) = strpad('kDA_on in component CD_A (second_order_rate_constant)');
LEGEND_CONSTANTS(:,10) = strpad('kDA_off in component CD_A (first_order_rate_constant)');
LEGEND_CONSTANTS(:,11) = strpad('CA in component model_parameters (nM)');
LEGEND_STATES(:,5) = strpad('ATl in component ATl (nanomole)');
LEGEND_CONSTANTS(:,12) = strpad('k1T in component model_parameters (first_order_rate_constant)');
LEGEND_CONSTANTS(:,13) = strpad('km5alpha in component model_parameters (nM)');
LEGEND_CONSTANTS(:,14) = strpad('Vmax1 in component model_parameters (nmol_hr)');
LEGEND_CONSTANTS(:,15) = strpad('PTl in component model_parameters (dimensionless)');
LEGEND_CONSTANTS(:,16) = strpad('k1D in component model_parameters (first_order_rate_constant)');
LEGEND_CONSTANTS(:,17) = strpad('PDl in component model_parameters (dimensionless)');
LEGEND_CONSTANTS(:,18) = strpad('CTl in component model_parameters (nM)');
LEGEND_CONSTANTS(:,19) = strpad('CDl in component model_parameters (nM)');
LEGEND_STATES(:,7) = strpad('ATif in component ATif (nanomole)');
LEGEND_CONSTANTS(:,20) = strpad('mu in component model_parameters (l_hr)');
LEGEND_CONSTANTS(:,21) = strpad('PTif in component model_parameters (dimensionless)');
LEGEND_CONSTANTS(:,22) = strpad('CTif in component model_parameters (nM)');
LEGEND_CONSTANTS(:,23) = strpad('CTst in component model_parameters (nM)');
LEGEND_CONSTANTS(:,24) = strpad('CLH in component model_parameters (nanomole)');
LEGEND_CONSTANTS(:,25) = strpad('PTst in component model_parameters (dimensionless)');
LEGEND_STATES(:,8) = strpad('ATst in component ATst (nanomole)');
LEGEND_STATES(:,9) = strpad('ATp in component ATp (nanomole)');
LEGEND_CONSTANTS(:,26) = strpad('Vmax0 in component model_parameters (nmol_hr)');
LEGEND_STATES(:,11) = strpad('CT_R in component CT_R (nM)');
LEGEND_CONSTANTS(:,27) = strpad('kTR_on in component CT_R (second_order_rate_constant)');
LEGEND_CONSTANTS(:,28) = strpad('kTR_off in component CT_R (first_order_rate_constant)');
LEGEND_ALGEBRAIC(:,24) = strpad('CRf in component CRf (nM)');
LEGEND_STATES(:,12) = strpad('CD_R in component CD_R (nM)');
LEGEND_CONSTANTS(:,29) = strpad('kDR_on in component CD_R (second_order_rate_constant)');
LEGEND_CONSTANTS(:,30) = strpad('kDR_off in component CD_R (first_order_rate_constant)');
LEGEND_STATES(:,13) = strpad('CDT in component CDT (nM)');
LEGEND_CONSTANTS(:,31) = strpad('kDT_on in component CDT (second_order_rate_constant)');
LEGEND_CONSTANTS(:,32) = strpad('kDT_off in component CDT (first_order_rate_constant)');
LEGEND_STATES(:,14) = strpad('CDD in component CDD (nM)');
LEGEND_CONSTANTS(:,33) = strpad('kDD_on in component CDD (second_order_rate_constant)');
LEGEND_CONSTANTS(:,34) = strpad('kDD_off in component CDD (first_order_rate_constant)');
LEGEND_STATES(:,15) = strpad('CTT in component CTT (nM)');
LEGEND_CONSTANTS(:,35) = strpad('kTT_on in component CTT (second_order_rate_constant)');
LEGEND_CONSTANTS(:,36) = strpad('kTT_off in component CTT (first_order_rate_constant)');
LEGEND_STATES(:,16) = strpad('CDD5a in component CDD5a (nM)');
LEGEND_CONSTANTS(:,37) = strpad('kDNA_onDD5a in component CDD5a (second_order_rate_constant)');
LEGEND_CONSTANTS(:,38) = strpad('kDNA_offDD5a in component CDD5a (first_order_rate_constant)');
LEGEND_ALGEBRAIC(:,20) = strpad('CDNA5af in component CDNA5af (nM)');
LEGEND_STATES(:,17) = strpad('CDDcd in component CDDcd (nM)');
LEGEND_CONSTANTS(:,39) = strpad('kDNA_onDDcd in component CDDcd (second_order_rate_constant)');
LEGEND_CONSTANTS(:,40) = strpad('kDNA_offDDcd in component CDDcd (first_order_rate_constant)');
LEGEND_ALGEBRAIC(:,15) = strpad('CDNAcdf in component CDNAcdf (nM)');
LEGEND_STATES(:,18) = strpad('CDDsec in component CDDsec (nM)');
LEGEND_CONSTANTS(:,41) = strpad('kDNA_onDDsec in component CDDsec (second_order_rate_constant)');
LEGEND_CONSTANTS(:,42) = strpad('kDNA_offDDsec in component CDDsec (first_order_rate_constant)');
LEGEND_ALGEBRAIC(:,17) = strpad('CDNAsecf in component CDNAsecf (nM)');
LEGEND_STATES(:,19) = strpad('CDDcp in component CDDcp (nM)');
LEGEND_CONSTANTS(:,43) = strpad('kDNA_onDDcp in component CDDcp (second_order_rate_constant)');
LEGEND_CONSTANTS(:,44) = strpad('kDNA_offDDcp in component CDDcp (first_order_rate_constant)');
LEGEND_ALGEBRAIC(:,21) = strpad('CDNAcpf in component CDNAcpf (nM)');
LEGEND_STATES(:,20) = strpad('CDT5a in component CDT5a (nM)');
LEGEND_CONSTANTS(:,45) = strpad('kDNA_onDT5a in component CDT5a (second_order_rate_constant)');
LEGEND_CONSTANTS(:,46) = strpad('kDNA_offDT5a in component CDT5a (first_order_rate_constant)');
LEGEND_STATES(:,21) = strpad('CDTcd in component CDTcd (nM)');
LEGEND_CONSTANTS(:,47) = strpad('kDNA_onDTcd in component CDTcd (second_order_rate_constant)');
LEGEND_CONSTANTS(:,48) = strpad('kDNA_offDTcd in component CDTcd (first_order_rate_constant)');
LEGEND_STATES(:,22) = strpad('CDTsec in component CDTsec (nM)');
LEGEND_CONSTANTS(:,49) = strpad('kDNA_onDTsec in component CDTsec (second_order_rate_constant)');
LEGEND_CONSTANTS(:,50) = strpad('kDNA_offDTsec in component CDTsec (first_order_rate_constant)');
LEGEND_STATES(:,23) = strpad('CDTcp in component CDTcp (nM)');
LEGEND_CONSTANTS(:,51) = strpad('kDNA_onDTcp in component CDTcp (second_order_rate_constant)');
LEGEND_CONSTANTS(:,52) = strpad('kDNA_offDTcp in component CDTcp (first_order_rate_constant)');
LEGEND_STATES(:,24) = strpad('CTT5a in component CTT5a (nM)');
LEGEND_CONSTANTS(:,53) = strpad('kDNA_onTT5a in component CTT5a (second_order_rate_constant)');
LEGEND_CONSTANTS(:,54) = strpad('kDNA_offTT5a in component CTT5a (first_order_rate_constant)');
LEGEND_STATES(:,25) = strpad('CTTcd in component CTTcd (nM)');
LEGEND_CONSTANTS(:,55) = strpad('kDNA_onTTcd in component CTTcd (second_order_rate_constant)');
LEGEND_CONSTANTS(:,56) = strpad('kDNA_offTTcd in component CTTcd (first_order_rate_constant)');
LEGEND_STATES(:,26) = strpad('CTTsec in component CTTsec (nM)');
LEGEND_CONSTANTS(:,57) = strpad('kDNA_onTTsec in component CTTsec (second_order_rate_constant)');
LEGEND_CONSTANTS(:,58) = strpad('kDNA_offTTsec in component CTTsec (first_order_rate_constant)');
LEGEND_STATES(:,27) = strpad('CTTcp in component CTTcp (nM)');
LEGEND_CONSTANTS(:,59) = strpad('kDNA_onTTcp in component CTTcp (second_order_rate_constant)');
LEGEND_CONSTANTS(:,60) = strpad('kDNA_offTTcp in component CTTcp (first_order_rate_constant)');
LEGEND_ALGEBRAIC(:,8) = strpad('T in component CTpf (nM)');
LEGEND_CONSTANTS(:,61) = strpad('NTp in component CTpf (dimensionless)');
LEGEND_CONSTANTS(:,62) = strpad('CTp in component model_parameters (nM)');
LEGEND_ALGEBRAIC(:,12) = strpad('D in component CDpf (nM)');
LEGEND_CONSTANTS(:,63) = strpad('NDp in component CDpf (dimensionless)');
LEGEND_CONSTANTS(:,64) = strpad('CDp in component model_parameters (nM)');
LEGEND_ALGEBRAIC(:,23) = strpad('CR in component CR (nM)');
LEGEND_CONSTANTS(:,65) = strpad('CDNAcd in component model_parameters (nM)');
LEGEND_CONSTANTS(:,66) = strpad('CDNAsec in component model_parameters (nM)');
LEGEND_CONSTANTS(:,67) = strpad('CDNA5a in component model_parameters (nM)');
LEGEND_CONSTANTS(:,68) = strpad('CDNAcp in component model_parameters (nM)');
LEGEND_ALGEBRAIC(:,2) = strpad('DNAocp in component DNAocp (dimensionless)');
LEGEND_ALGEBRAIC(:,3) = strpad('DNAosec in component DNAosec (dimensionless)');
LEGEND_ALGEBRAIC(:,6) = strpad('DNAocd in component DNAocd (dimensionless)');
LEGEND_ALGEBRAIC(:,4) = strpad('DNAo5a in component DNAo5a (dimensionless)');
LEGEND_STATES(:,28) = strpad('ATb in component ATb (nanomole)');
LEGEND_CONSTANTS(:,69) = strpad('CTb in component model_parameters (nM)');
LEGEND_CONSTANTS(:,70) = strpad('PTb in component model_parameters (dimensionless)');
LEGEND_CONSTANTS(:,71) = strpad('CDb in component model_parameters (nM)');
LEGEND_CONSTANTS(:,72) = strpad('PDb in component model_parameters (dimensionless)');
LEGEND_STATES(:,30) = strpad('ALH in component ALH (nanomole)');
LEGEND_CONSTANTS(:,73) = strpad('kLH1 in component ALH (l_hr)');
LEGEND_CONSTANTS(:,74) = strpad('kLH2 in component ALH (nmol_hr)');
LEGEND_CONSTANTS(:,75) = strpad('kLH3 in component ALH (nmol_hr)');
LEGEND_CONSTANTS(:,76) = strpad('kLH4 in component ALH (first_order_rate_constant)');
LEGEND_CONSTANTS(:,77) = strpad('alpha_T in component ALH (dimensionless)');
LEGEND_CONSTANTS(:,78) = strpad('alpha_D in component ALH (dimensionless)');
LEGEND_ALGEBRAIC(:,10) = strpad('A in component ALH (nmol_hr)');
LEGEND_CONSTANTS(:,92) = strpad('B in component ALH (nmol_hr)');
LEGEND_STATES(:,31) = strpad('AR in component AR (nanomole)');
LEGEND_CONSTANTS(:,79) = strpad('k1R in component AR (nmol_hr)');
LEGEND_CONSTANTS(:,80) = strpad('keR in component AR (l_hr)');
LEGEND_ALGEBRAIC(:,22) = strpad('Vp in component Vp (litre)');
LEGEND_CONSTANTS(:,81) = strpad('kQp in component Qp (first_order_rate_constant)');
LEGEND_ALGEBRAIC(:,14) = strpad('Vpc in component Qp (litre)');
LEGEND_STATES(:,32) = strpad('VPC1 in component VPC1 (litre)');
LEGEND_CONSTANTS(:,82) = strpad('VPC2 in component model_parameters (litre)');
LEGEND_ALGEBRAIC(:,7) = strpad('Vmax in component Vmax (nmol_hr)');
LEGEND_CONSTANTS(:,83) = strpad('k5a in component Vmax (nmol_hr)');
LEGEND_CONSTANTS(:,84) = strpad('kcpl in component VPC1 (kg_hr)');
LEGEND_CONSTANTS(:,85) = strpad('kcd1 in component VPC1 (first_order_rate_constant)');
LEGEND_CONSTANTS(:,86) = strpad('VPC1b in component model_parameters (kg)');
LEGEND_STATES(:,33) = strpad('VPL1 in component VPL1 (litre)');
LEGEND_CONSTANTS(:,87) = strpad('ksec in component VPL1 (kg_hr)');
LEGEND_CONSTANTS(:,88) = strpad('kflo in component VPL1 (first_order_rate_constant)');
LEGEND_CONSTANTS(:,89) = strpad('VPL2 in component model_parameters (litre)');
LEGEND_CONSTANTS(:,90) = strpad('Qc in component model_parameters (l_hr)');
LEGEND_RATES(:,1) = strpad('d/dt ATbl in component ATbl (nanomole)');
LEGEND_RATES(:,3) = strpad('d/dt CT_A in component CT_A (nM)');
LEGEND_RATES(:,4) = strpad('d/dt CD_A in component CD_A (nM)');
LEGEND_RATES(:,5) = strpad('d/dt ATl in component ATl (nanomole)');
LEGEND_RATES(:,7) = strpad('d/dt ATif in component ATif (nanomole)');
LEGEND_RATES(:,8) = strpad('d/dt ATst in component ATst (nanomole)');
LEGEND_RATES(:,9) = strpad('d/dt ATp in component ATp (nanomole)');
LEGEND_RATES(:,11) = strpad('d/dt CT_R in component CT_R (nM)');
LEGEND_RATES(:,12) = strpad('d/dt CD_R in component CD_R (nM)');
LEGEND_RATES(:,13) = strpad('d/dt CDT in component CDT (nM)');
LEGEND_RATES(:,14) = strpad('d/dt CDD in component CDD (nM)');
LEGEND_RATES(:,15) = strpad('d/dt CTT in component CTT (nM)');
LEGEND_RATES(:,16) = strpad('d/dt CDD5a in component CDD5a (nM)');
LEGEND_RATES(:,17) = strpad('d/dt CDDcd in component CDDcd (nM)');
LEGEND_RATES(:,18) = strpad('d/dt CDDsec in component CDDsec (nM)');
LEGEND_RATES(:,19) = strpad('d/dt CDDcp in component CDDcp (nM)');
LEGEND_RATES(:,20) = strpad('d/dt CDT5a in component CDT5a (nM)');
LEGEND_RATES(:,21) = strpad('d/dt CDTcd in component CDTcd (nM)');
LEGEND_RATES(:,22) = strpad('d/dt CDTsec in component CDTsec (nM)');
LEGEND_RATES(:,23) = strpad('d/dt CDTcp in component CDTcp (nM)');
LEGEND_RATES(:,24) = strpad('d/dt CTT5a in component CTT5a (nM)');
LEGEND_RATES(:,25) = strpad('d/dt CTTcd in component CTTcd (nM)');
LEGEND_RATES(:,26) = strpad('d/dt CTTsec in component CTTsec (nM)');
LEGEND_RATES(:,27) = strpad('d/dt CTTcp in component CTTcp (nM)');
LEGEND_RATES(:,28) = strpad('d/dt ATb in component ATb (nanomole)');
LEGEND_RATES(:,30) = strpad('d/dt ALH in component ALH (nanomole)');
LEGEND_RATES(:,31) = strpad('d/dt AR in component AR (nanomole)');
LEGEND_RATES(:,32) = strpad('d/dt VPC1 in component VPC1 (litre)');
LEGEND_RATES(:,33) = strpad('d/dt VPL1 in component VPL1 (litre)');
LEGEND_STATES  = LEGEND_STATES';
LEGEND_ALGEBRAIC = LEGEND_ALGEBRAIC';
LEGEND_RATES = LEGEND_RATES';
LEGEND_CONSTANTS = LEGEND_CONSTANTS';
end

function [STATES, CONSTANTS] = initConsts()
VOI = 0; CONSTANTS = []; STATES = []; ALGEBRAIC = [];
STATES(:,1) = 0.0;
CONSTANTS(:,1) = 0.17;
CONSTANTS(:,2) = 1.06;
CONSTANTS(:,3) = 0.061;
CONSTANTS(:,4) = 7.60;
CONSTANTS(:,5) = 0.56;
STATES(:,2) = 0.0;
CONSTANTS(:,6) = 0.59;
STATES(:,3) = 0.0;
CONSTANTS(:,7) = 0.18;
CONSTANTS(:,8) = 8131.0;
STATES(:,4) = 0.0;
CONSTANTS(:,9) = 0.15;
CONSTANTS(:,10) = 5407.0;
CONSTANTS(:,11) = 5.00E5;
STATES(:,5) = 0.0;
CONSTANTS(:,12) = 87.93;
CONSTANTS(:,13) = 40.00;
CONSTANTS(:,14) = 3.65;
CONSTANTS(:,15) = 2.75;
STATES(:,6) = 0.0;
CONSTANTS(:,16) = 77.20;
CONSTANTS(:,17) = 2.00;
CONSTANTS(:,18) = 9.92;
CONSTANTS(:,19) = 0.92;
STATES(:,7) = 0.0;
CONSTANTS(:,20) = 1000.0;
CONSTANTS(:,21) = 1.96;
CONSTANTS(:,22) = 307.29;
CONSTANTS(:,23) = 307.29;
CONSTANTS(:,24) = 0.104;
CONSTANTS(:,25) = 1.00;
STATES(:,8) = 0.0;
STATES(:,9) = 0.0;
CONSTANTS(:,26) = 2.89;
STATES(:,10) = 0.0;
STATES(:,11) = 0.0;
CONSTANTS(:,27) = 0.14;
CONSTANTS(:,28) = 0.069;
STATES(:,12) = 0.0;
CONSTANTS(:,29) = 0.053;
CONSTANTS(:,30) = 0.018;
STATES(:,13) = 0.0;
CONSTANTS(:,31) = 0.14;
CONSTANTS(:,32) = 3.13;
STATES(:,14) = 0.0;
CONSTANTS(:,33) = 0.14;
CONSTANTS(:,34) = 3.13;
STATES(:,15) = 0.0;
CONSTANTS(:,35) = 0.14;
CONSTANTS(:,36) = 3.13;
STATES(:,16) = 0.0;
CONSTANTS(:,37) = 0.14;
CONSTANTS(:,38) = 0.07;
STATES(:,17) = 0.0;
CONSTANTS(:,39) = 0.14;
CONSTANTS(:,40) = 0.1;
STATES(:,18) = 0.0;
CONSTANTS(:,41) = 0.14;
CONSTANTS(:,42) = 0.2;
STATES(:,19) = 0.0;
CONSTANTS(:,43) = 0.14;
CONSTANTS(:,44) = 0.7;
STATES(:,20) = 0.0;
CONSTANTS(:,45) = 0.14;
CONSTANTS(:,46) = 0.56;
STATES(:,21) = 0.0;
CONSTANTS(:,47) = 0.14;
CONSTANTS(:,48) = 0.8;
STATES(:,22) = 0.0;
CONSTANTS(:,49) = 0.14;
CONSTANTS(:,50) = 1.6;
STATES(:,23) = 0.0;
CONSTANTS(:,51) = 0.14;
CONSTANTS(:,52) = 5.6;
STATES(:,24) = 0.0;
CONSTANTS(:,53) = 0.14;
CONSTANTS(:,54) = 0.84;
STATES(:,25) = 0.0;
CONSTANTS(:,55) = 0.14;
CONSTANTS(:,56) = 1.2;
STATES(:,26) = 0.0;
CONSTANTS(:,57) = 0.14;
CONSTANTS(:,58) = 2.4;
STATES(:,27) = 0.0;
CONSTANTS(:,59) = 0.14;
CONSTANTS(:,60) = 8.4;
CONSTANTS(:,61) = 0.79;
CONSTANTS(:,62) = 11.38;
CONSTANTS(:,63) = 1.00;
CONSTANTS(:,64) = 52.46;
CONSTANTS(:,65) = 0.075;
CONSTANTS(:,66) = 0.075;
CONSTANTS(:,67) = 0.075;
CONSTANTS(:,68) = 0.075;
STATES(:,28) = 0.0;
CONSTANTS(:,69) = 0.6275;
CONSTANTS(:,70) = 1.00;
STATES(:,29) = 0.0;
CONSTANTS(:,71) = 0.019884;
CONSTANTS(:,72) = 0.62;
STATES(:,30) = 0.0;
CONSTANTS(:,73) = 0.13;
CONSTANTS(:,74) = 0.026;
CONSTANTS(:,75) = 1.68E-4;
CONSTANTS(:,76) = 0.80;
CONSTANTS(:,77) = 0.25;
CONSTANTS(:,78) = 0.75;
STATES(:,31) = 0.0;
CONSTANTS(:,79) = 68.15;
CONSTANTS(:,80) = 71.90;
CONSTANTS(:,81) = 73.84;
STATES(:,32) = 0.0;
CONSTANTS(:,82) = 5.08E-5;
CONSTANTS(:,83) = 3.02;
CONSTANTS(:,84) = 1.17E-7;
CONSTANTS(:,85) = 0.014;
CONSTANTS(:,86) = 1E-4;
STATES(:,33) = 0.0;
CONSTANTS(:,87) = 8.44E-6;
CONSTANTS(:,88) = 0.043;
CONSTANTS(:,89) = 3.08E-6;
CONSTANTS(:,90) = 6.08;
CONSTANTS(:,91) = CONSTANTS(:,18)./CONSTANTS(:,15);
CONSTANTS(:,92) = CONSTANTS(:,75);
CONSTANTS(:,96) =  CONSTANTS(:,20).*(CONSTANTS(:,22) - CONSTANTS(:,23)./CONSTANTS(:,25));
CONSTANTS(:,93) = CONSTANTS(:,19)./CONSTANTS(:,17);
CONSTANTS(:,94) = CONSTANTS(:,22)./CONSTANTS(:,21);
CONSTANTS(:,95) = CONSTANTS(:,69)./CONSTANTS(:,70);
CONSTANTS(:,96) = CONSTANTS(:,71)./CONSTANTS(:,72);
if (isempty(STATES)), warning('Initial values for states not set');, end
end

function [RATES, ALGEBRAIC] = computeRates(VOI, STATES, CONSTANTS)
global algebraicVariableCount;
statesSize = size(STATES);
statesColumnCount = statesSize(2);
if ( statesColumnCount == 1)
STATES = STATES';
ALGEBRAIC = zeros(1, algebraicVariableCount);
utilOnes = 1;
else
statesRowCount = statesSize(1);
ALGEBRAIC = zeros(statesRowCount, algebraicVariableCount);
RATES = zeros(statesRowCount, statesColumnCount);
utilOnes = ones(statesRowCount, 1);
end
RATES(:,8) = CONSTANTS(:,96);
RATES(:,5) =  CONSTANTS(:,2).*(CONSTANTS(:,4) - CONSTANTS(:,91)) - (( CONSTANTS(:,14).*CONSTANTS(:,91))./(CONSTANTS(:,13)+CONSTANTS(:,91))+ CONSTANTS(:,12).*(STATES(:,5)./CONSTANTS(:,15)));
RATES(:,6) =  CONSTANTS(:,2).*(CONSTANTS(:,6) - CONSTANTS(:,93)) - (( CONSTANTS(:,14).*CONSTANTS(:,91))./(CONSTANTS(:,13)+CONSTANTS(:,91))+ CONSTANTS(:,16).*(STATES(:,6)./CONSTANTS(:,17)));
RATES(:,13) =  CONSTANTS(:,31).*STATES(:,12).*STATES(:,11) -  CONSTANTS(:,32).*STATES(:,13);
RATES(:,14) =  CONSTANTS(:,33).*power(STATES(:,12), 2.00000) -  CONSTANTS(:,34).*STATES(:,14);
RATES(:,15) =  CONSTANTS(:,35).*power(STATES(:,11), 2.00000) -  CONSTANTS(:,36).*STATES(:,15);
ALGEBRAIC(:,1) = CONSTANTS(:,4) - STATES(:,3);
RATES(:,7) =  CONSTANTS(:,3).*(1.00000 - CONSTANTS(:,5)).*(ALGEBRAIC(:,1) - CONSTANTS(:,22)./CONSTANTS(:,21))+ CONSTANTS(:,20).*(CONSTANTS(:,23)./CONSTANTS(:,25) - CONSTANTS(:,22))+ CONSTANTS(:,12).*CONSTANTS(:,24);
ALGEBRAIC(:,3) = (STATES(:,26)+STATES(:,18)+STATES(:,22))./CONSTANTS(:,66);
RATES(:,33) =  (STATES(:,32)./CONSTANTS(:,86)).*CONSTANTS(:,87).*ALGEBRAIC(:,3) -  CONSTANTS(:,88).*STATES(:,33);
ALGEBRAIC(:,2) = (STATES(:,27)+STATES(:,19)+STATES(:,23))./CONSTANTS(:,68);
ALGEBRAIC(:,6) = (STATES(:,25)+STATES(:,17)+STATES(:,21))./CONSTANTS(:,65);
RATES(:,32) =  (STATES(:,32)./CONSTANTS(:,86)).*CONSTANTS(:,84).*ALGEBRAIC(:,2) -  CONSTANTS(:,85).*(1.00000 - ALGEBRAIC(:,6)).*STATES(:,32);
ALGEBRAIC(:,9) = CONSTANTS(:,11) - (STATES(:,3)+STATES(:,4));
RATES(:,3) =  CONSTANTS(:,7).*ALGEBRAIC(:,1).*ALGEBRAIC(:,9) -  CONSTANTS(:,8).*STATES(:,3);
ALGEBRAIC(:,5) = CONSTANTS(:,6) - STATES(:,4);
RATES(:,4) =  CONSTANTS(:,9).*ALGEBRAIC(:,5).*ALGEBRAIC(:,9) -  CONSTANTS(:,10).*STATES(:,4);
ALGEBRAIC(:,10) =   - CONSTANTS(:,73).*( CONSTANTS(:,77).*ALGEBRAIC(:,1)+ CONSTANTS(:,78).*ALGEBRAIC(:,5))+CONSTANTS(:,74);
RATES(:,30) = piecewise({ALGEBRAIC(:,10)>CONSTANTS(:,92), ALGEBRAIC(:,10) -  CONSTANTS(:,76).*STATES(:,30) }, CONSTANTS(:,92) -  CONSTANTS(:,76).*STATES(:,30));
ALGEBRAIC(:,15) = CONSTANTS(:,65) - (STATES(:,25)+STATES(:,17)+STATES(:,21));
RATES(:,17) =  CONSTANTS(:,39).*STATES(:,14).*ALGEBRAIC(:,15) -  CONSTANTS(:,40).*STATES(:,17);
RATES(:,21) =  CONSTANTS(:,47).*STATES(:,13).*ALGEBRAIC(:,15) -  CONSTANTS(:,48).*STATES(:,21);
RATES(:,25) =  CONSTANTS(:,55).*STATES(:,15).*ALGEBRAIC(:,15) -  CONSTANTS(:,56).*STATES(:,25);
ALGEBRAIC(:,14) = STATES(:,32)+CONSTANTS(:,82);
ALGEBRAIC(:,16) =  CONSTANTS(:,81).*ALGEBRAIC(:,14);
ALGEBRAIC(:,8) = STATES(:,26)+STATES(:,22)+STATES(:,24)+STATES(:,20)+STATES(:,25)+STATES(:,21)+STATES(:,27)+STATES(:,23);
ALGEBRAIC(:,11) = (CONSTANTS(:,62) - (STATES(:,11)+ 2.00000.*STATES(:,15)+STATES(:,13)+ALGEBRAIC(:,8)))./(1.00000+CONSTANTS(:,61));
RATES(:,9) =  ALGEBRAIC(:,16).*(CONSTANTS(:,4) - ALGEBRAIC(:,11)) - ( CONSTANTS(:,26).*ALGEBRAIC(:,11))./(CONSTANTS(:,13)+ALGEBRAIC(:,11));
ALGEBRAIC(:,12) = STATES(:,18)+STATES(:,22)+STATES(:,16)+STATES(:,20)+STATES(:,17)+STATES(:,21)+STATES(:,19)+STATES(:,23);
ALGEBRAIC(:,13) = (CONSTANTS(:,64) - (STATES(:,12)+ 2.00000.*STATES(:,14)+STATES(:,13)+ALGEBRAIC(:,12)))./(1.00000+CONSTANTS(:,63));
RATES(:,10) =  ALGEBRAIC(:,16).*(CONSTANTS(:,6) - ALGEBRAIC(:,13)) - ( CONSTANTS(:,26).*ALGEBRAIC(:,11))./(CONSTANTS(:,13)+ALGEBRAIC(:,11));
ALGEBRAIC(:,17) = CONSTANTS(:,66) - (STATES(:,26)+STATES(:,18)+STATES(:,22));
RATES(:,18) =  CONSTANTS(:,41).*STATES(:,14).*ALGEBRAIC(:,17) -  CONSTANTS(:,42).*STATES(:,18);
RATES(:,22) =  CONSTANTS(:,49).*STATES(:,13).*ALGEBRAIC(:,17) -  CONSTANTS(:,50).*STATES(:,22);
RATES(:,26) =  CONSTANTS(:,57).*STATES(:,15).*ALGEBRAIC(:,17) -  CONSTANTS(:,58).*STATES(:,26);
ALGEBRAIC(:,18) = CONSTANTS(:,90) - (ALGEBRAIC(:,16)+CONSTANTS(:,3)+CONSTANTS(:,2));
RATES(:,1) =  ALGEBRAIC(:,18).*(CONSTANTS(:,95) - ALGEBRAIC(:,1))+ ALGEBRAIC(:,16).*(ALGEBRAIC(:,11) - CONSTANTS(:,4))+ CONSTANTS(:,2).*(CONSTANTS(:,91) - CONSTANTS(:,4))+ CONSTANTS(:,3).*(1.00000 - CONSTANTS(:,5)).*(CONSTANTS(:,94) - ALGEBRAIC(:,1))+CONSTANTS(:,1);
ALGEBRAIC(:,19) = CONSTANTS(:,90) - (ALGEBRAIC(:,16)+CONSTANTS(:,2));
RATES(:,2) =  ALGEBRAIC(:,19).*(CONSTANTS(:,96) - ALGEBRAIC(:,5))+ ALGEBRAIC(:,16).*(ALGEBRAIC(:,13) - ALGEBRAIC(:,5))+ CONSTANTS(:,2).*(CONSTANTS(:,93) - CONSTANTS(:,6));
ALGEBRAIC(:,20) = CONSTANTS(:,67) - (STATES(:,24)+STATES(:,16)+STATES(:,20));
RATES(:,16) =  CONSTANTS(:,37).*STATES(:,14).*ALGEBRAIC(:,20) -  CONSTANTS(:,38).*STATES(:,16);
RATES(:,20) =  CONSTANTS(:,45).*STATES(:,13).*ALGEBRAIC(:,20) -  CONSTANTS(:,46).*STATES(:,20);
RATES(:,24) =  CONSTANTS(:,53).*STATES(:,15).*ALGEBRAIC(:,20) -  CONSTANTS(:,54).*STATES(:,24);
RATES(:,28) =  ALGEBRAIC(:,18).*(ALGEBRAIC(:,1) - CONSTANTS(:,69)./CONSTANTS(:,70));
RATES(:,29) =  ALGEBRAIC(:,19).*(ALGEBRAIC(:,5) - CONSTANTS(:,71)./CONSTANTS(:,72));
ALGEBRAIC(:,21) = CONSTANTS(:,68) - (STATES(:,27)+STATES(:,19)+STATES(:,23));
RATES(:,19) =  CONSTANTS(:,43).*STATES(:,14).*ALGEBRAIC(:,21) -  CONSTANTS(:,44).*STATES(:,19);
RATES(:,23) =  CONSTANTS(:,51).*STATES(:,13).*ALGEBRAIC(:,21) -  CONSTANTS(:,52).*STATES(:,23);
RATES(:,27) =  CONSTANTS(:,59).*STATES(:,15).*ALGEBRAIC(:,21) -  CONSTANTS(:,60).*STATES(:,27);
ALGEBRAIC(:,22) = STATES(:,32)+CONSTANTS(:,82)+STATES(:,33)+CONSTANTS(:,89);
ALGEBRAIC(:,23) = STATES(:,31)./ALGEBRAIC(:,22);
ALGEBRAIC(:,24) = ALGEBRAIC(:,23) - (STATES(:,11)+STATES(:,12)+ 2.00000.*(STATES(:,15)+STATES(:,14)+STATES(:,13))+ 2.00000.*(ALGEBRAIC(:,15)+ALGEBRAIC(:,17)+ALGEBRAIC(:,21)+ALGEBRAIC(:,20)));
RATES(:,11) =  CONSTANTS(:,27).*ALGEBRAIC(:,11).*ALGEBRAIC(:,24) -  CONSTANTS(:,28).*STATES(:,11);
RATES(:,12) =  CONSTANTS(:,29).*ALGEBRAIC(:,13).*ALGEBRAIC(:,24) -  CONSTANTS(:,30).*STATES(:,12);
RATES(:,31) = CONSTANTS(:,79) -  CONSTANTS(:,80).*ALGEBRAIC(:,24);
RATES = RATES';
end

% Calculate algebraic variables
function ALGEBRAIC = computeAlgebraic(ALGEBRAIC, CONSTANTS, STATES, VOI)
statesSize = size(STATES);
statesColumnCount = statesSize(2);
if ( statesColumnCount == 1)
STATES = STATES';
utilOnes = 1;
else
statesRowCount = statesSize(1);
utilOnes = ones(statesRowCount, 1);
end
ALGEBRAIC(:,1) = CONSTANTS(:,4) - STATES(:,3);
ALGEBRAIC(:,3) = (STATES(:,26)+STATES(:,18)+STATES(:,22))./CONSTANTS(:,66);
ALGEBRAIC(:,2) = (STATES(:,27)+STATES(:,19)+STATES(:,23))./CONSTANTS(:,68);
ALGEBRAIC(:,6) = (STATES(:,25)+STATES(:,17)+STATES(:,21))./CONSTANTS(:,65);
ALGEBRAIC(:,9) = CONSTANTS(:,11) - (STATES(:,3)+STATES(:,4));
ALGEBRAIC(:,5) = CONSTANTS(:,6) - STATES(:,4);
ALGEBRAIC(:,10) =   - CONSTANTS(:,73).*( CONSTANTS(:,77).*ALGEBRAIC(:,1)+ CONSTANTS(:,78).*ALGEBRAIC(:,5))+CONSTANTS(:,74);
ALGEBRAIC(:,15) = CONSTANTS(:,65) - (STATES(:,25)+STATES(:,17)+STATES(:,21));
ALGEBRAIC(:,14) = STATES(:,32)+CONSTANTS(:,82);
ALGEBRAIC(:,16) =  CONSTANTS(:,81).*ALGEBRAIC(:,14);
ALGEBRAIC(:,8) = STATES(:,26)+STATES(:,22)+STATES(:,24)+STATES(:,20)+STATES(:,25)+STATES(:,21)+STATES(:,27)+STATES(:,23);
ALGEBRAIC(:,11) = (CONSTANTS(:,62) - (STATES(:,11)+ 2.00000.*STATES(:,15)+STATES(:,13)+ALGEBRAIC(:,8)))./(1.00000+CONSTANTS(:,61));
ALGEBRAIC(:,12) = STATES(:,18)+STATES(:,22)+STATES(:,16)+STATES(:,20)+STATES(:,17)+STATES(:,21)+STATES(:,19)+STATES(:,23);
ALGEBRAIC(:,13) = (CONSTANTS(:,64) - (STATES(:,12)+ 2.00000.*STATES(:,14)+STATES(:,13)+ALGEBRAIC(:,12)))./(1.00000+CONSTANTS(:,63));
ALGEBRAIC(:,17) = CONSTANTS(:,66) - (STATES(:,26)+STATES(:,18)+STATES(:,22));
ALGEBRAIC(:,18) = CONSTANTS(:,90) - (ALGEBRAIC(:,16)+CONSTANTS(:,3)+CONSTANTS(:,2));
ALGEBRAIC(:,19) = CONSTANTS(:,90) - (ALGEBRAIC(:,16)+CONSTANTS(:,2));
ALGEBRAIC(:,20) = CONSTANTS(:,67) - (STATES(:,24)+STATES(:,16)+STATES(:,20));
ALGEBRAIC(:,21) = CONSTANTS(:,68) - (STATES(:,27)+STATES(:,19)+STATES(:,23));
ALGEBRAIC(:,22) = STATES(:,32)+CONSTANTS(:,82)+STATES(:,33)+CONSTANTS(:,89);
ALGEBRAIC(:,23) = STATES(:,31)./ALGEBRAIC(:,22);
ALGEBRAIC(:,24) = ALGEBRAIC(:,23) - (STATES(:,11)+STATES(:,12)+ 2.00000.*(STATES(:,15)+STATES(:,14)+STATES(:,13))+ 2.00000.*(ALGEBRAIC(:,15)+ALGEBRAIC(:,17)+ALGEBRAIC(:,21)+ALGEBRAIC(:,20)));
ALGEBRAIC(:,4) = (STATES(:,24)+STATES(:,16)+STATES(:,20))./CONSTANTS(:,67);
ALGEBRAIC(:,7) =  CONSTANTS(:,83).*ALGEBRAIC(:,4);
end

% Compute result of a piecewise function
function x = piecewise(cases, default)
set = [0];
for i = 1:2:length(cases)
if (length(cases{i+1}) == 1)
x(cases{i} & ~set,:) = cases{i+1};
else
x(cases{i} & ~set,:) = cases{i+1}(cases{i} & ~set);
end
set = set | cases{i};
if(set), break, end
end
if (length(default) == 1)
x(~set,:) = default;
else
x(~set,:) = default(~set);
end
end

% Pad out or shorten strings to a set length
req_length = 160;
insize = size(strin,2);
if insize > req_length
strout = strin(1:req_length);
else
strout = [strin, blanks(req_length - insize)];
end
end

```
Source
Derived from workspace Potter, Zager, Barton, 2006 at changeset 941e8c510816.
Collaboration
To begin collaborating on this work, please use your git client and issue this command: