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 =66;
end
% There are a total of 42 entries in each of the rate and state variable arrays.
% There are a total of 94 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 (second)');
    LEGEND_STATES(:,1) = strpad('Casp8 in component Casp8 (micromolar)');
    LEGEND_STATES(:,2) = strpad('Casp8Bid in component Casp8 (micromolar)');
    LEGEND_STATES(:,3) = strpad('FeLnNO in component FeLn (micromolar)');
    LEGEND_STATES(:,4) = strpad('Bid in component Bid (micromolar)');
    LEGEND_ALGEBRAIC(:,3) = strpad('J_0 in component Casp8 (flux)');
    LEGEND_ALGEBRAIC(:,1) = strpad('J_f0 in component Casp8 (flux)');
    LEGEND_ALGEBRAIC(:,2) = strpad('J_Casp8 in component Casp8 (flux)');
    LEGEND_ALGEBRAIC(:,4) = strpad('r_20NO in component Casp8 (flux)');
    LEGEND_ALGEBRAIC(:,62) = strpad('r_19NO in component PTPC (flux)');
    LEGEND_CONSTANTS(:,1) = strpad('k_f0 in component model_constant (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,2) = strpad('k_10 in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,3) = strpad('k_00 in component model_constant (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,4) = strpad('u in component model_constant (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,5) = strpad('k_20NO in component model_constant (second_order_rate_constant)');
    LEGEND_STATES(:,5) = strpad('Apaf_1 in component Apaf_1 (micromolar)');
    LEGEND_STATES(:,6) = strpad('CytcApaf_1 in component CytcApaf_1 (micromolar)');
    LEGEND_STATES(:,7) = strpad('Cytc in component Cytc (micromolar)');
    LEGEND_ALGEBRAIC(:,5) = strpad('J_Apaf_1 in component Apaf_1 (flux)');
    LEGEND_ALGEBRAIC(:,6) = strpad('J_1 in component Apaf_1 (flux)');
    LEGEND_CONSTANTS(:,6) = strpad('P_Apaf_1 in component model_constant (flux)');
    LEGEND_CONSTANTS(:,7) = strpad('k_11 in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,8) = strpad('k_01 in component model_constant (first_order_rate_constant)');
    LEGEND_STATES(:,8) = strpad('Apop in component Apop (micromolar)');
    LEGEND_ALGEBRAIC(:,8) = strpad('J_1b in component CytcApaf_1 (flux)');
    LEGEND_CONSTANTS(:,9) = strpad('k_11b in component model_constant (rate)');
    LEGEND_CONSTANTS(:,10) = strpad('k_01b in component model_constant (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,11) = strpad('p in component model_constant (dimensionless)');
    LEGEND_STATES(:,9) = strpad('Cytc_mito in component Cytc_mito (micromolar)');
    LEGEND_STATES(:,10) = strpad('PTPC in component PTPC (micromolar)');
    LEGEND_ALGEBRAIC(:,9) = strpad('PTPC_act in component Cytc (micromolar)');
    LEGEND_CONSTANTS(:,12) = strpad('PTPC_0 in component model_constant (micromolar)');
    LEGEND_ALGEBRAIC(:,13) = strpad('J_14 in component Cytc_mito (flux)');
    LEGEND_ALGEBRAIC(:,7) = strpad('J_Cytc in component Cytc (flux)');
    LEGEND_CONSTANTS(:,13) = strpad('k_1 in component model_constant (second_order_rate_constant)');
    LEGEND_STATES(:,11) = strpad('Bax_2 in component Bax_2 (micromolar)');
    LEGEND_ALGEBRAIC(:,11) = strpad('J_Cytc_mito in component Cytc_mito (flux)');
    LEGEND_CONSTANTS(:,14) = strpad('P_Cytc_mito in component model_constant (flux)');
    LEGEND_CONSTANTS(:,15) = strpad('k14 in component model_constant (second_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,18) = strpad('J_12b in component tBidBax (flux)');
    LEGEND_ALGEBRAIC(:,10) = strpad('J_Bax_2 in component Bax_2 (flux)');
    LEGEND_STATES(:,12) = strpad('tBid_mito in component tBid_mito (micromolar)');
    LEGEND_STATES(:,13) = strpad('Bax in component Bax (micromolar)');
    LEGEND_ALGEBRAIC(:,15) = strpad('J_11 in component tBid (flux)');
    LEGEND_ALGEBRAIC(:,14) = strpad('J_12a in component tBid_mito (flux)');
    LEGEND_ALGEBRAIC(:,12) = strpad('J_tBid_mito in component tBid_mito (flux)');
    LEGEND_CONSTANTS(:,16) = strpad('k12a in component model_constant (second_order_rate_constant)');
    LEGEND_STATES(:,14) = strpad('tBid in component tBid (micromolar)');
    LEGEND_ALGEBRAIC(:,26) = strpad('J_f8 in component Casp3Bid (flux)');
    LEGEND_ALGEBRAIC(:,16) = strpad('J_tBid in component tBid (flux)');
    LEGEND_CONSTANTS(:,17) = strpad('k11 in component model_constant (first_order_rate_constant)');
    LEGEND_STATES(:,15) = strpad('tBidBax in component tBidBax (micromolar)');
    LEGEND_ALGEBRAIC(:,17) = strpad('J_tBidBax in component tBidBax (flux)');
    LEGEND_CONSTANTS(:,18) = strpad('k12b in component model_constant (second_order_rate_constant)');
    LEGEND_STATES(:,16) = strpad('Bcl_2 in component Bcl_2 (micromolar)');
    LEGEND_ALGEBRAIC(:,20) = strpad('J_13 in component Bax (flux)');
    LEGEND_ALGEBRAIC(:,19) = strpad('J_Bax in component Bax (flux)');
    LEGEND_CONSTANTS(:,92) = strpad('P_Bax in component Bax (flux)');
    LEGEND_CONSTANTS(:,19) = strpad('k13 in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,20) = strpad('P_oBax in component model_constant (flux)');
    LEGEND_CONSTANTS(:,21) = strpad('p53 in component model_constant (micromolar)');
    LEGEND_CONSTANTS(:,22) = strpad('p53_thresh in component model_constant (micromolar)');
    LEGEND_CONSTANTS(:,23) = strpad('u_Bax in component model_constant (first_order_rate_constant)');
    LEGEND_STATES(:,17) = strpad('Casp3 in component Casp3 (micromolar)');
    LEGEND_STATES(:,18) = strpad('Casp3Bcl_2 in component Casp3Bcl_2 (micromolar)');
    LEGEND_ALGEBRAIC(:,21) = strpad('J_9 in component Bcl_2 (flux)');
    LEGEND_ALGEBRAIC(:,23) = strpad('J_Bcl_2 in component Bcl_2 (flux)');
    LEGEND_CONSTANTS(:,24) = strpad('k_19 in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,25) = strpad('k_09 in component model_constant (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,93) = strpad('P_Bcl_2 in component Bcl_2 (flux)');
    LEGEND_CONSTANTS(:,26) = strpad('P_oBcl_2 in component model_constant (flux)');
    LEGEND_CONSTANTS(:,27) = strpad('u_Bcl_2 in component model_constant (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,22) = strpad('J_f9 in component Casp3Bcl_2 (flux)');
    LEGEND_CONSTANTS(:,28) = strpad('k_f9 in component model_constant (first_order_rate_constant)');
    LEGEND_STATES(:,19) = strpad('Casp3Bid in component Casp3Bid (micromolar)');
    LEGEND_ALGEBRAIC(:,24) = strpad('J_8 in component Casp3Bid (flux)');
    LEGEND_CONSTANTS(:,29) = strpad('k_18 in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,30) = strpad('k_08 in component model_constant (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,31) = strpad('k_f8 in component model_constant (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,25) = strpad('J_Bid in component Bid (flux)');
    LEGEND_CONSTANTS(:,32) = strpad('P_Bid in component model_constant (flux)');
    LEGEND_STATES(:,20) = strpad('IAP in component IAP (micromolar)');
    LEGEND_STATES(:,21) = strpad('Casp3IAP in component Casp3 (micromolar)');
    LEGEND_ALGEBRAIC(:,35) = strpad('J_f6 in component Casp9Pro3 (flux)');
    LEGEND_ALGEBRAIC(:,34) = strpad('J_f6b in component ApopCasp9_2Pro3 (flux)');
    LEGEND_ALGEBRAIC(:,28) = strpad('J_7 in component Casp3 (flux)');
    LEGEND_ALGEBRAIC(:,27) = strpad('J_Casp3 in component Casp3 (flux)');
    LEGEND_ALGEBRAIC(:,66) = strpad('r_22NO in component FeLn (flux)');
    LEGEND_CONSTANTS(:,33) = strpad('k_17 in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,34) = strpad('k_07 in component model_constant (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,30) = strpad('J_2 in component Pro9 (flux)');
    LEGEND_ALGEBRAIC(:,43) = strpad('J_4b in component ApopCasp9 (flux)');
    LEGEND_STATES(:,22) = strpad('Pro9 in component Pro9 (micromolar)');
    LEGEND_STATES(:,23) = strpad('ApopPro9 in component Pro9 (micromolar)');
    LEGEND_STATES(:,24) = strpad('ApopPro9_2 in component ApopPro9_2 (micromolar)');
    LEGEND_ALGEBRAIC(:,31) = strpad('J_3 in component Pro9 (flux)');
    LEGEND_ALGEBRAIC(:,29) = strpad('J_Pro9 in component Pro9 (flux)');
    LEGEND_CONSTANTS(:,35) = strpad('k_12 in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,36) = strpad('k_02 in component model_constant (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,37) = strpad('k_13 in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,38) = strpad('k_03 in component model_constant (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,39) = strpad('P_Pro9 in component model_constant (flux)');
    LEGEND_ALGEBRAIC(:,32) = strpad('J_f3 in component ApopPro9_2 (flux)');
    LEGEND_CONSTANTS(:,40) = strpad('k_f3 in component model_constant (first_order_rate_constant)');
    LEGEND_STATES(:,25) = strpad('ApopCasp9_2Pro3 in component ApopCasp9_2Pro3 (micromolar)');
    LEGEND_STATES(:,26) = strpad('ApopCasp9_2 in component ApopCasp9_2 (micromolar)');
    LEGEND_STATES(:,27) = strpad('Pro3 in component Pro3 (micromolar)');
    LEGEND_ALGEBRAIC(:,33) = strpad('J_6b in component ApopCasp9_2Pro3 (flux)');
    LEGEND_CONSTANTS(:,41) = strpad('k_16b in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,42) = strpad('k_06b in component model_constant (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,43) = strpad('k_f6b in component model_constant (first_order_rate_constant)');
    LEGEND_STATES(:,28) = strpad('Casp9Pro3 in component Casp9Pro3 (micromolar)');
    LEGEND_ALGEBRAIC(:,36) = strpad('J_6 in component Pro3 (flux)');
    LEGEND_CONSTANTS(:,44) = strpad('k_f6 in component model_constant (first_order_rate_constant)');
    LEGEND_STATES(:,29) = strpad('Casp9 in component Casp9 (micromolar)');
    LEGEND_ALGEBRAIC(:,37) = strpad('J_Pro3 in component Pro3 (flux)');
    LEGEND_CONSTANTS(:,45) = strpad('k_16 in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,46) = strpad('k_06 in component model_constant (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,47) = strpad('P_Pro3 in component model_constant (flux)');
    LEGEND_STATES(:,30) = strpad('Casp9IAP in component IAP (micromolar)');
    LEGEND_STATES(:,31) = strpad('ApopCasp9IAP in component IAP (micromolar)');
    LEGEND_STATES(:,32) = strpad('ApopCasp9_2IAP in component IAP (micromolar)');
    LEGEND_STATES(:,33) = strpad('ApopCasp9 in component ApopCasp9 (micromolar)');
    LEGEND_ALGEBRAIC(:,38) = strpad('J_5 in component IAP (flux)');
    LEGEND_ALGEBRAIC(:,39) = strpad('J_5b in component IAP (flux)');
    LEGEND_ALGEBRAIC(:,40) = strpad('J_5c in component IAP (flux)');
    LEGEND_ALGEBRAIC(:,42) = strpad('J_IAP in component IAP (flux)');
    LEGEND_CONSTANTS(:,48) = strpad('P_IAP in component model_constant (flux)');
    LEGEND_CONSTANTS(:,49) = strpad('k_15 in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,50) = strpad('k_05 in component model_constant (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,51) = strpad('k_15b in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,52) = strpad('k_05b in component model_constant (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,53) = strpad('k_15c in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,54) = strpad('k_05c in component model_constant (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,41) = strpad('J_4 in component ApopCasp9 (flux)');
    LEGEND_CONSTANTS(:,55) = strpad('k_14 in component model_constant (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,56) = strpad('k_04 in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,57) = strpad('k_14b in component model_constant (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,58) = strpad('k_04b in component model_constant (second_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,44) = strpad('J_Casp9 in component Casp9 (flux)');
    LEGEND_ALGEBRAIC(:,65) = strpad('r_21NO in component FeLn (flux)');
    LEGEND_STATES(:,34) = strpad('NO in component NO (micromolar)');
    LEGEND_STATES(:,35) = strpad('O_2m in component O_2m (micromolar)');
    LEGEND_CONSTANTS(:,59) = strpad('O_2 in component NO (micromolar)');
    LEGEND_STATES(:,36) = strpad('NO_2 in component NO (micromolar)');
    LEGEND_STATES(:,37) = strpad('N2O3 in component N2O3 (micromolar)');
    LEGEND_STATES(:,38) = strpad('GSNO in component GSNO (micromolar)');
    LEGEND_STATES(:,39) = strpad('CcOX in component NO (micromolar)');
    LEGEND_STATES(:,40) = strpad('FeLn in component FeLn (micromolar)');
    LEGEND_CONSTANTS(:,91) = strpad('r_1NO in component NO (flux)');
    LEGEND_ALGEBRAIC(:,45) = strpad('r_4NO in component NO (flux)');
    LEGEND_ALGEBRAIC(:,46) = strpad('r_12aNO in component NO (flux)');
    LEGEND_ALGEBRAIC(:,47) = strpad('r_12bNOp in component NO (flux)');
    LEGEND_ALGEBRAIC(:,48) = strpad('r_12bNOm in component NO (flux)');
    LEGEND_ALGEBRAIC(:,49) = strpad('r_14NO in component NO (flux)');
    LEGEND_ALGEBRAIC(:,50) = strpad('r_15NO in component NO (flux)');
    LEGEND_ALGEBRAIC(:,51) = strpad('r_16NO in component NO (flux)');
    LEGEND_CONSTANTS(:,60) = strpad('k_1NO in component model_constant (flux)');
    LEGEND_CONSTANTS(:,61) = strpad('k_4NO in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,62) = strpad('k_12aNO in component model_constant (rate2)');
    LEGEND_CONSTANTS(:,63) = strpad('k_12bNOp in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,64) = strpad('k_12bNOm in component model_constant (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,65) = strpad('k_14NO in component model_constant (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,66) = strpad('k_15NO in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,67) = strpad('k_16NO in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,68) = strpad('SOD in component O_2m (micromolar)');
    LEGEND_CONSTANTS(:,94) = strpad('r_2NO in component O_2m (flux)');
    LEGEND_ALGEBRAIC(:,52) = strpad('r_5NO in component O_2m (flux)');
    LEGEND_ALGEBRAIC(:,53) = strpad('r_10NO in component O_2m (flux)');
    LEGEND_CONSTANTS(:,69) = strpad('k_2NO in component model_constant (flux)');
    LEGEND_CONSTANTS(:,70) = strpad('k_5NO in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,71) = strpad('k_10NO in component model_constant (rate2)');
    LEGEND_STATES(:,41) = strpad('ONOO_m in component ONOO_m (micromolar)');
    LEGEND_STATES(:,42) = strpad('GSH in component GSH (micromolar)');
    LEGEND_CONSTANTS(:,72) = strpad('GPX in component ONOO_m (micromolar)');
    LEGEND_CONSTANTS(:,73) = strpad('CO_2 in component ONOO_m (micromolar)');
    LEGEND_CONSTANTS(:,74) = strpad('Cyt_c in component ONOO_m (micromolar)');
    LEGEND_ALGEBRAIC(:,54) = strpad('r_6NO in component ONOO_m (flux)');
    LEGEND_ALGEBRAIC(:,55) = strpad('r_7NO in component ONOO_m (flux)');
    LEGEND_ALGEBRAIC(:,58) = strpad('r_8NO in component ONOO_m (flux)');
    LEGEND_ALGEBRAIC(:,61) = strpad('r_9NO in component ONOO_m (flux)');
    LEGEND_ALGEBRAIC(:,64) = strpad('r_18NO in component ONOO_m (flux)');
    LEGEND_CONSTANTS(:,75) = strpad('k_6NO in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,76) = strpad('k_7NO in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,77) = strpad('k_8NO in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,78) = strpad('k_9NO in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,79) = strpad('k_18NO in component model_constant (second_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,56) = strpad('GSSG in component GSH (micromolar)');
    LEGEND_CONSTANTS(:,80) = strpad('FeLn_0 in component model_constant (micromolar)');
    LEGEND_CONSTANTS(:,81) = strpad('GSH_0 in component model_constant (micromolar)');
    LEGEND_ALGEBRAIC(:,57) = strpad('r_11NO in component GSH (flux)');
    LEGEND_ALGEBRAIC(:,60) = strpad('r_m in component GSH (flux)');
    LEGEND_ALGEBRAIC(:,63) = strpad('r_17NO in component GSH (flux)');
    LEGEND_CONSTANTS(:,82) = strpad('k_11NO in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,83) = strpad('v_m in component model_constant (flux)');
    LEGEND_CONSTANTS(:,84) = strpad('k_m in component model_constant (micromolar)');
    LEGEND_CONSTANTS(:,85) = strpad('k_17NO in component model_constant (second_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,59) = strpad('r_13NO in component N2O3 (flux)');
    LEGEND_CONSTANTS(:,86) = strpad('k_13NO in component model_constant (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,87) = strpad('k_21NO in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,88) = strpad('k_22NO in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,89) = strpad('k_19NO in component model_constant (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,90) = strpad('k_17bNO in component model_constant (second_order_rate_constant)');
    LEGEND_RATES(:,1) = strpad('d/dt Casp8 in component Casp8 (micromolar)');
    LEGEND_RATES(:,2) = strpad('d/dt Casp8Bid in component Casp8 (micromolar)');
    LEGEND_RATES(:,5) = strpad('d/dt Apaf_1 in component Apaf_1 (micromolar)');
    LEGEND_RATES(:,6) = strpad('d/dt CytcApaf_1 in component CytcApaf_1 (micromolar)');
    LEGEND_RATES(:,7) = strpad('d/dt Cytc in component Cytc (micromolar)');
    LEGEND_RATES(:,9) = strpad('d/dt Cytc_mito in component Cytc_mito (micromolar)');
    LEGEND_RATES(:,11) = strpad('d/dt Bax_2 in component Bax_2 (micromolar)');
    LEGEND_RATES(:,12) = strpad('d/dt tBid_mito in component tBid_mito (micromolar)');
    LEGEND_RATES(:,14) = strpad('d/dt tBid in component tBid (micromolar)');
    LEGEND_RATES(:,15) = strpad('d/dt tBidBax in component tBidBax (micromolar)');
    LEGEND_RATES(:,13) = strpad('d/dt Bax in component Bax (micromolar)');
    LEGEND_RATES(:,16) = strpad('d/dt Bcl_2 in component Bcl_2 (micromolar)');
    LEGEND_RATES(:,18) = strpad('d/dt Casp3Bcl_2 in component Casp3Bcl_2 (micromolar)');
    LEGEND_RATES(:,19) = strpad('d/dt Casp3Bid in component Casp3Bid (micromolar)');
    LEGEND_RATES(:,4) = strpad('d/dt Bid in component Bid (micromolar)');
    LEGEND_RATES(:,21) = strpad('d/dt Casp3IAP in component Casp3 (micromolar)');
    LEGEND_RATES(:,17) = strpad('d/dt Casp3 in component Casp3 (micromolar)');
    LEGEND_RATES(:,8) = strpad('d/dt Apop in component Apop (micromolar)');
    LEGEND_RATES(:,22) = strpad('d/dt Pro9 in component Pro9 (micromolar)');
    LEGEND_RATES(:,23) = strpad('d/dt ApopPro9 in component Pro9 (micromolar)');
    LEGEND_RATES(:,24) = strpad('d/dt ApopPro9_2 in component ApopPro9_2 (micromolar)');
    LEGEND_RATES(:,25) = strpad('d/dt ApopCasp9_2Pro3 in component ApopCasp9_2Pro3 (micromolar)');
    LEGEND_RATES(:,28) = strpad('d/dt Casp9Pro3 in component Casp9Pro3 (micromolar)');
    LEGEND_RATES(:,27) = strpad('d/dt Pro3 in component Pro3 (micromolar)');
    LEGEND_RATES(:,30) = strpad('d/dt Casp9IAP in component IAP (micromolar)');
    LEGEND_RATES(:,31) = strpad('d/dt ApopCasp9IAP in component IAP (micromolar)');
    LEGEND_RATES(:,32) = strpad('d/dt ApopCasp9_2IAP in component IAP (micromolar)');
    LEGEND_RATES(:,20) = strpad('d/dt IAP in component IAP (micromolar)');
    LEGEND_RATES(:,33) = strpad('d/dt ApopCasp9 in component ApopCasp9 (micromolar)');
    LEGEND_RATES(:,29) = strpad('d/dt Casp9 in component Casp9 (micromolar)');
    LEGEND_RATES(:,26) = strpad('d/dt ApopCasp9_2 in component ApopCasp9_2 (micromolar)');
    LEGEND_RATES(:,34) = strpad('d/dt NO in component NO (micromolar)');
    LEGEND_RATES(:,39) = strpad('d/dt CcOX in component NO (micromolar)');
    LEGEND_RATES(:,36) = strpad('d/dt NO_2 in component NO (micromolar)');
    LEGEND_RATES(:,35) = strpad('d/dt O_2m in component O_2m (micromolar)');
    LEGEND_RATES(:,41) = strpad('d/dt ONOO_m in component ONOO_m (micromolar)');
    LEGEND_RATES(:,42) = strpad('d/dt GSH in component GSH (micromolar)');
    LEGEND_RATES(:,38) = strpad('d/dt GSNO in component GSNO (micromolar)');
    LEGEND_RATES(:,37) = strpad('d/dt N2O3 in component N2O3 (micromolar)');
    LEGEND_RATES(:,40) = strpad('d/dt FeLn in component FeLn (micromolar)');
    LEGEND_RATES(:,3) = strpad('d/dt FeLnNO in component FeLn (micromolar)');
    LEGEND_RATES(:,10) = strpad('d/dt PTPC in component PTPC (micromolar)');
    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;
    STATES(:,2) = 0;
    STATES(:,3) = 0;
    STATES(:,4) = 0.004;
    CONSTANTS(:,1) = 0.1;
    CONSTANTS(:,2) = 10;
    CONSTANTS(:,3) = 0.5;
    CONSTANTS(:,4) = 0.006;
    CONSTANTS(:,5) = 66;
    STATES(:,5) = 0.004;
    STATES(:,6) = 0;
    STATES(:,7) = 0;
    CONSTANTS(:,6) = 0.0003;
    CONSTANTS(:,7) = 5;
    CONSTANTS(:,8) = 0.5;
    STATES(:,8) = 0;
    CONSTANTS(:,9) = 50000;
    CONSTANTS(:,10) = 0.5;
    CONSTANTS(:,11) = 4;
    STATES(:,9) = 0.004;
    STATES(:,10) = 0;
    CONSTANTS(:,12) = 0;
    CONSTANTS(:,13) = 1;
    STATES(:,11) = 0;
    CONSTANTS(:,14) = 0.0003;
    CONSTANTS(:,15) = 10;
    STATES(:,12) = 0;
    STATES(:,13) = 0.004;
    CONSTANTS(:,16) = 10;
    STATES(:,14) = 0;
    CONSTANTS(:,17) = 10;
    STATES(:,15) = 0;
    CONSTANTS(:,18) = 10;
    STATES(:,16) = 0.004;
    CONSTANTS(:,19) = 10;
    CONSTANTS(:,20) = 0.00003;
    CONSTANTS(:,21) = 0.0066;
    CONSTANTS(:,22) = 0.004;
    CONSTANTS(:,23) = 0.006;
    STATES(:,17) = 0;
    STATES(:,18) = 0;
    CONSTANTS(:,24) = 10;
    CONSTANTS(:,25) = 0.5;
    CONSTANTS(:,26) = 0.00008;
    CONSTANTS(:,27) = 0.006;
    CONSTANTS(:,28) = 0.1;
    STATES(:,19) = 0;
    CONSTANTS(:,29) = 10;
    CONSTANTS(:,30) = 0.5;
    CONSTANTS(:,31) = 0.1;
    CONSTANTS(:,32) = 0.00003;
    STATES(:,20) = 0.004;
    STATES(:,21) = 0;
    CONSTANTS(:,33) = 5;
    CONSTANTS(:,34) = 0.0035;
    STATES(:,22) = 0.004;
    STATES(:,23) = 0;
    STATES(:,24) = 0;
    CONSTANTS(:,35) = 10;
    CONSTANTS(:,36) = 0.5;
    CONSTANTS(:,37) = 10;
    CONSTANTS(:,38) = 0.5;
    CONSTANTS(:,39) = 0.0003;
    CONSTANTS(:,40) = 0.1;
    STATES(:,25) = 0;
    STATES(:,26) = 0;
    STATES(:,27) = 0.004;
    CONSTANTS(:,41) = 10;
    CONSTANTS(:,42) = 0.5;
    CONSTANTS(:,43) = 0.1;
    STATES(:,28) = 0;
    CONSTANTS(:,44) = 0.001;
    STATES(:,29) = 0;
    CONSTANTS(:,45) = 10;
    CONSTANTS(:,46) = 0.5;
    CONSTANTS(:,47) = 0.0003;
    STATES(:,30) = 0;
    STATES(:,31) = 0;
    STATES(:,32) = 0;
    STATES(:,33) = 0;
    CONSTANTS(:,48) = 0.00003;
    CONSTANTS(:,49) = 5;
    CONSTANTS(:,50) = 0.0035;
    CONSTANTS(:,51) = 5;
    CONSTANTS(:,52) = 0.0035;
    CONSTANTS(:,53) = 5;
    CONSTANTS(:,54) = 0.0035;
    CONSTANTS(:,55) = 5;
    CONSTANTS(:,56) = 0.5;
    CONSTANTS(:,57) = 5;
    CONSTANTS(:,58) = 0.5;
    STATES(:,34) = 0;
    STATES(:,35) = 35;
    CONSTANTS(:,59) = 35;
    STATES(:,36) = 0;
    STATES(:,37) = 0;
    STATES(:,38) = 0;
    STATES(:,39) = 0.1;
    STATES(:,40) = 0.05;
    CONSTANTS(:,60) = 1;
    CONSTANTS(:,61) = 6700;
    CONSTANTS(:,62) = 0.000006;
    CONSTANTS(:,63) = 1100;
    CONSTANTS(:,64) = 81000;
    CONSTANTS(:,65) = 0.0002;
    CONSTANTS(:,66) = 100;
    CONSTANTS(:,67) = 1.21;
    CONSTANTS(:,68) = 10;
    CONSTANTS(:,69) = 0.1;
    CONSTANTS(:,70) = 2400;
    CONSTANTS(:,71) = 0.0006;
    STATES(:,41) = 0;
    STATES(:,42) = 10000;
    CONSTANTS(:,72) = 5.8;
    CONSTANTS(:,73) = 1000;
    CONSTANTS(:,74) = 400;
    CONSTANTS(:,75) = 0.00135;
    CONSTANTS(:,76) = 2;
    CONSTANTS(:,77) = 0.058;
    CONSTANTS(:,78) = 0.025;
    CONSTANTS(:,79) = 1;
    CONSTANTS(:,80) = 0.05;
    CONSTANTS(:,81) = 10000;
    CONSTANTS(:,82) = 66;
    CONSTANTS(:,83) = 320;
    CONSTANTS(:,84) = 50;
    CONSTANTS(:,85) = 66;
    CONSTANTS(:,86) = 1600;
    CONSTANTS(:,87) = 66;
    CONSTANTS(:,88) = 66;
    CONSTANTS(:,89) = 10;
    CONSTANTS(:,90) = 0.0002;
    CONSTANTS(:,91) = CONSTANTS(:,60);
    CONSTANTS(:,92) =  CONSTANTS(:,20).*(1.00000+power(CONSTANTS(:,21), 4.00000)./(power(CONSTANTS(:,21), 4.00000)+power(CONSTANTS(:,22), 4.00000)));
    CONSTANTS(:,93) = ( CONSTANTS(:,26).*power(CONSTANTS(:,22), 4.00000))./(power(CONSTANTS(:,21), 4.00000)+power(CONSTANTS(:,22), 4.00000));
    CONSTANTS(:,94) = CONSTANTS(:,69);
    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
    ALGEBRAIC(:,3) =  CONSTANTS(:,2).*STATES(:,1).*STATES(:,4) -  CONSTANTS(:,3).*STATES(:,2);
    ALGEBRAIC(:,1) =  CONSTANTS(:,1).*STATES(:,2);
    RATES(:,2) = ALGEBRAIC(:,3) - ALGEBRAIC(:,1);
    ALGEBRAIC(:,5) = CONSTANTS(:,6) -  CONSTANTS(:,4).*STATES(:,5);
    ALGEBRAIC(:,6) =  CONSTANTS(:,7).*STATES(:,7).*STATES(:,5) -  CONSTANTS(:,8).*STATES(:,6);
    RATES(:,5) =  - ALGEBRAIC(:,6)+ALGEBRAIC(:,5);
    ALGEBRAIC(:,8) =  CONSTANTS(:,9).*power(STATES(:,6), CONSTANTS(:,11)) -  CONSTANTS(:,10).*STATES(:,8);
    RATES(:,6) = ALGEBRAIC(:,6) -  7.00000.*ALGEBRAIC(:,8);
    ALGEBRAIC(:,9) = CONSTANTS(:,12) - STATES(:,10);
    ALGEBRAIC(:,13) =  CONSTANTS(:,15).*STATES(:,11).*STATES(:,9);
    ALGEBRAIC(:,7) =   - CONSTANTS(:,4).*STATES(:,7);
    RATES(:,7) = (ALGEBRAIC(:,13) - ALGEBRAIC(:,6))+ALGEBRAIC(:,7)+ CONSTANTS(:,13).*ALGEBRAIC(:,9).*STATES(:,9);
    ALGEBRAIC(:,11) = CONSTANTS(:,14) -  CONSTANTS(:,4).*STATES(:,9);
    RATES(:,9) =  - ALGEBRAIC(:,13)+ALGEBRAIC(:,11);
    ALGEBRAIC(:,15) =  CONSTANTS(:,17).*STATES(:,14);
    ALGEBRAIC(:,14) =  CONSTANTS(:,16).*STATES(:,12).*STATES(:,13);
    ALGEBRAIC(:,12) =   - CONSTANTS(:,4).*STATES(:,12);
    RATES(:,12) = (ALGEBRAIC(:,15) - ALGEBRAIC(:,14))+ALGEBRAIC(:,12);
    ALGEBRAIC(:,18) =  CONSTANTS(:,18).*STATES(:,15).*STATES(:,13);
    ALGEBRAIC(:,10) =   - CONSTANTS(:,4).*STATES(:,11);
    RATES(:,11) = ALGEBRAIC(:,18)+ALGEBRAIC(:,10);
    ALGEBRAIC(:,17) =   - CONSTANTS(:,4).*STATES(:,15);
    RATES(:,15) = (ALGEBRAIC(:,14) - ALGEBRAIC(:,18))+ALGEBRAIC(:,17);
    ALGEBRAIC(:,20) =  CONSTANTS(:,19).*STATES(:,16).*STATES(:,13);
    ALGEBRAIC(:,19) = CONSTANTS(:,92) -  CONSTANTS(:,23).*STATES(:,13);
    RATES(:,13) = (( - ALGEBRAIC(:,14) - ALGEBRAIC(:,18)) - ALGEBRAIC(:,20))+ALGEBRAIC(:,19);
    ALGEBRAIC(:,21) =  CONSTANTS(:,24).*STATES(:,17).*STATES(:,16) -  CONSTANTS(:,25).*STATES(:,18);
    ALGEBRAIC(:,23) = CONSTANTS(:,93) -  CONSTANTS(:,27).*STATES(:,16);
    RATES(:,16) = ( - ALGEBRAIC(:,21) - ALGEBRAIC(:,20))+ALGEBRAIC(:,23);
    ALGEBRAIC(:,22) =  CONSTANTS(:,28).*STATES(:,18);
    RATES(:,18) = ALGEBRAIC(:,21) - ALGEBRAIC(:,22);
    ALGEBRAIC(:,26) =  CONSTANTS(:,31).*STATES(:,19);
    ALGEBRAIC(:,16) =   - CONSTANTS(:,4).*STATES(:,14);
    RATES(:,14) = ((ALGEBRAIC(:,1)+ALGEBRAIC(:,26)) - ALGEBRAIC(:,15))+ALGEBRAIC(:,18)+ALGEBRAIC(:,16);
    ALGEBRAIC(:,24) =  CONSTANTS(:,29).*STATES(:,17).*STATES(:,4) -  CONSTANTS(:,30).*STATES(:,19);
    RATES(:,19) = ALGEBRAIC(:,24) - ALGEBRAIC(:,26);
    ALGEBRAIC(:,25) = CONSTANTS(:,32) -  CONSTANTS(:,4).*STATES(:,4);
    RATES(:,4) = ( - ALGEBRAIC(:,3) - ALGEBRAIC(:,24))+ALGEBRAIC(:,25);
    ALGEBRAIC(:,28) =  CONSTANTS(:,33).*STATES(:,17).*STATES(:,20) -  CONSTANTS(:,34).*STATES(:,21);
    RATES(:,21) = ALGEBRAIC(:,28);
    ALGEBRAIC(:,30) =  CONSTANTS(:,35).*STATES(:,8).*STATES(:,22) -  CONSTANTS(:,36).*STATES(:,23);
    ALGEBRAIC(:,31) =  CONSTANTS(:,37).*STATES(:,23).*STATES(:,22) -  CONSTANTS(:,38).*STATES(:,24);
    ALGEBRAIC(:,29) = CONSTANTS(:,39) -  CONSTANTS(:,4).*STATES(:,22);
    RATES(:,22) = ( - ALGEBRAIC(:,30) - ALGEBRAIC(:,31))+ALGEBRAIC(:,29);
    RATES(:,23) = ALGEBRAIC(:,30) - ALGEBRAIC(:,31);
    ALGEBRAIC(:,32) =  CONSTANTS(:,40).*STATES(:,24);
    RATES(:,24) = ALGEBRAIC(:,31) - ALGEBRAIC(:,32);
    ALGEBRAIC(:,34) =  CONSTANTS(:,43).*STATES(:,25);
    ALGEBRAIC(:,33) =  CONSTANTS(:,41).*STATES(:,26).*STATES(:,27) -  CONSTANTS(:,42).*STATES(:,25);
    RATES(:,25) = ALGEBRAIC(:,33) - ALGEBRAIC(:,34);
    ALGEBRAIC(:,35) =  CONSTANTS(:,44).*STATES(:,28);
    ALGEBRAIC(:,36) =  CONSTANTS(:,45).*STATES(:,29).*STATES(:,27) -  CONSTANTS(:,46).*STATES(:,28);
    RATES(:,28) = ALGEBRAIC(:,36) - ALGEBRAIC(:,35);
    ALGEBRAIC(:,37) = CONSTANTS(:,47) -  CONSTANTS(:,4).*STATES(:,27);
    RATES(:,27) = ( - ALGEBRAIC(:,36) - ALGEBRAIC(:,33))+ALGEBRAIC(:,37);
    ALGEBRAIC(:,38) =  CONSTANTS(:,49).*STATES(:,29).*STATES(:,20) -  CONSTANTS(:,50).*STATES(:,30);
    RATES(:,30) = ALGEBRAIC(:,38);
    ALGEBRAIC(:,39) =  CONSTANTS(:,51).*STATES(:,33).*STATES(:,20) -  CONSTANTS(:,52).*STATES(:,31);
    RATES(:,31) = ALGEBRAIC(:,39);
    ALGEBRAIC(:,40) =  CONSTANTS(:,53).*STATES(:,26).*STATES(:,20) -  CONSTANTS(:,54).*STATES(:,32);
    RATES(:,32) = ALGEBRAIC(:,40);
    ALGEBRAIC(:,42) = CONSTANTS(:,48) -  CONSTANTS(:,4).*STATES(:,20);
    RATES(:,20) = ((( - ALGEBRAIC(:,38) - ALGEBRAIC(:,39)) - ALGEBRAIC(:,40)) - ALGEBRAIC(:,28))+ALGEBRAIC(:,42);
    ALGEBRAIC(:,41) =  CONSTANTS(:,55).*STATES(:,26) -  CONSTANTS(:,56).*STATES(:,33).*STATES(:,29);
    RATES(:,26) = (((ALGEBRAIC(:,32) - ALGEBRAIC(:,41)) - ALGEBRAIC(:,40)) - ALGEBRAIC(:,33))+ALGEBRAIC(:,34);
    ALGEBRAIC(:,43) =  CONSTANTS(:,57).*STATES(:,33) -  CONSTANTS(:,58).*STATES(:,8).*STATES(:,29);
    RATES(:,8) = (ALGEBRAIC(:,8) - ALGEBRAIC(:,30))+ALGEBRAIC(:,43);
    RATES(:,33) = (ALGEBRAIC(:,41) - ALGEBRAIC(:,43)) - ALGEBRAIC(:,39);
    ALGEBRAIC(:,46) =  CONSTANTS(:,62).*power(STATES(:,34), 2.00000).*CONSTANTS(:,59);
    ALGEBRAIC(:,47) =  CONSTANTS(:,63).*STATES(:,36).*STATES(:,34);
    ALGEBRAIC(:,48) =  CONSTANTS(:,64).*STATES(:,37);
    RATES(:,36) = ( 2.00000.*ALGEBRAIC(:,46) - ALGEBRAIC(:,47))+ALGEBRAIC(:,48);
    ALGEBRAIC(:,50) =  CONSTANTS(:,66).*STATES(:,39).*STATES(:,34);
    RATES(:,39) =  - ALGEBRAIC(:,50);
    ALGEBRAIC(:,45) =  CONSTANTS(:,61).*STATES(:,34).*STATES(:,35);
    ALGEBRAIC(:,49) =  CONSTANTS(:,65).*STATES(:,38);
    ALGEBRAIC(:,51) =  CONSTANTS(:,67).*STATES(:,40).*STATES(:,34);
    RATES(:,34) = (((((CONSTANTS(:,91) - ALGEBRAIC(:,45)) -  2.00000.*ALGEBRAIC(:,46)) - ALGEBRAIC(:,47))+ALGEBRAIC(:,48)+ALGEBRAIC(:,49)) - ALGEBRAIC(:,50)) - ALGEBRAIC(:,51);
    ALGEBRAIC(:,52) =  CONSTANTS(:,70).*CONSTANTS(:,68).*STATES(:,35);
    ALGEBRAIC(:,53) =  CONSTANTS(:,71).*power(STATES(:,38), 2.00000).*STATES(:,35);
    RATES(:,35) = ((CONSTANTS(:,94) - ALGEBRAIC(:,45)) - ALGEBRAIC(:,52)) - ALGEBRAIC(:,53);
    ALGEBRAIC(:,2) =   - CONSTANTS(:,4).*STATES(:,1);
    ALGEBRAIC(:,4) =  CONSTANTS(:,5).*STATES(:,3).*STATES(:,1);
    ALGEBRAIC(:,62) =  CONSTANTS(:,89).*STATES(:,37).*STATES(:,1);
    RATES(:,1) = (( - ALGEBRAIC(:,3)+ALGEBRAIC(:,1)+ALGEBRAIC(:,2)) - ALGEBRAIC(:,62)) - ALGEBRAIC(:,4);
    ALGEBRAIC(:,54) =  CONSTANTS(:,75).*STATES(:,41).*STATES(:,42);
    ALGEBRAIC(:,55) =  CONSTANTS(:,76).*STATES(:,41).*CONSTANTS(:,72);
    ALGEBRAIC(:,58) =  CONSTANTS(:,77).*STATES(:,41).*CONSTANTS(:,73);
    ALGEBRAIC(:,61) =  CONSTANTS(:,78).*STATES(:,41).*CONSTANTS(:,74);
    ALGEBRAIC(:,64) =  CONSTANTS(:,79).*STATES(:,41).*STATES(:,10);
    RATES(:,41) = ((((ALGEBRAIC(:,45) - ALGEBRAIC(:,54)) - ALGEBRAIC(:,55)) - ALGEBRAIC(:,58)) - ALGEBRAIC(:,61)) - ALGEBRAIC(:,64);
    ALGEBRAIC(:,57) =  CONSTANTS(:,82).*STATES(:,37).*STATES(:,42);
    ALGEBRAIC(:,56) = ((CONSTANTS(:,81) - STATES(:,42)) - STATES(:,38))./2.00000;
    ALGEBRAIC(:,60) = ( CONSTANTS(:,83).*ALGEBRAIC(:,56))./(CONSTANTS(:,84)+ALGEBRAIC(:,56));
    ALGEBRAIC(:,63) =  CONSTANTS(:,85).*STATES(:,3).*STATES(:,42);
    RATES(:,42) = (( - ALGEBRAIC(:,54) - ALGEBRAIC(:,57))+ 2.00000.*ALGEBRAIC(:,60)) - ALGEBRAIC(:,63);
    RATES(:,38) = (((ALGEBRAIC(:,54) -  2.00000.*ALGEBRAIC(:,53))+ALGEBRAIC(:,57)) - ALGEBRAIC(:,49))+ALGEBRAIC(:,63);
    ALGEBRAIC(:,59) =  CONSTANTS(:,86).*STATES(:,37);
    RATES(:,37) = ((( - ALGEBRAIC(:,57)+ALGEBRAIC(:,47)) - ALGEBRAIC(:,48)) - ALGEBRAIC(:,59)) - ALGEBRAIC(:,62);
    RATES(:,10) =  - ALGEBRAIC(:,62);
    ALGEBRAIC(:,44) =   - CONSTANTS(:,4).*STATES(:,29);
    ALGEBRAIC(:,65) =  CONSTANTS(:,87).*STATES(:,3).*STATES(:,29);
    RATES(:,29) = ((((ALGEBRAIC(:,41)+ALGEBRAIC(:,43)) - ALGEBRAIC(:,38)) - ALGEBRAIC(:,36))+ALGEBRAIC(:,35)+ALGEBRAIC(:,44)) - ALGEBRAIC(:,65);
    ALGEBRAIC(:,27) =   - CONSTANTS(:,4).*STATES(:,17);
    ALGEBRAIC(:,66) =  CONSTANTS(:,88).*STATES(:,3).*STATES(:,17);
    RATES(:,17) = ((((((ALGEBRAIC(:,35)+ALGEBRAIC(:,34)) - ALGEBRAIC(:,28)) - ALGEBRAIC(:,24))+ALGEBRAIC(:,26)) - ALGEBRAIC(:,21))+ALGEBRAIC(:,22)+ALGEBRAIC(:,27)) - ALGEBRAIC(:,66);
    RATES(:,40) =  - ALGEBRAIC(:,51)+ALGEBRAIC(:,63)+ALGEBRAIC(:,4)+ALGEBRAIC(:,65)+ALGEBRAIC(:,66);
    RATES(:,3) = (((ALGEBRAIC(:,51) - ALGEBRAIC(:,63)) - ALGEBRAIC(:,4)) - ALGEBRAIC(:,65)) - ALGEBRAIC(:,66);
   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(:,3) =  CONSTANTS(:,2).*STATES(:,1).*STATES(:,4) -  CONSTANTS(:,3).*STATES(:,2);
    ALGEBRAIC(:,1) =  CONSTANTS(:,1).*STATES(:,2);
    ALGEBRAIC(:,5) = CONSTANTS(:,6) -  CONSTANTS(:,4).*STATES(:,5);
    ALGEBRAIC(:,6) =  CONSTANTS(:,7).*STATES(:,7).*STATES(:,5) -  CONSTANTS(:,8).*STATES(:,6);
    ALGEBRAIC(:,8) =  CONSTANTS(:,9).*power(STATES(:,6), CONSTANTS(:,11)) -  CONSTANTS(:,10).*STATES(:,8);
    ALGEBRAIC(:,9) = CONSTANTS(:,12) - STATES(:,10);
    ALGEBRAIC(:,13) =  CONSTANTS(:,15).*STATES(:,11).*STATES(:,9);
    ALGEBRAIC(:,7) =   - CONSTANTS(:,4).*STATES(:,7);
    ALGEBRAIC(:,11) = CONSTANTS(:,14) -  CONSTANTS(:,4).*STATES(:,9);
    ALGEBRAIC(:,15) =  CONSTANTS(:,17).*STATES(:,14);
    ALGEBRAIC(:,14) =  CONSTANTS(:,16).*STATES(:,12).*STATES(:,13);
    ALGEBRAIC(:,12) =   - CONSTANTS(:,4).*STATES(:,12);
    ALGEBRAIC(:,18) =  CONSTANTS(:,18).*STATES(:,15).*STATES(:,13);
    ALGEBRAIC(:,10) =   - CONSTANTS(:,4).*STATES(:,11);
    ALGEBRAIC(:,17) =   - CONSTANTS(:,4).*STATES(:,15);
    ALGEBRAIC(:,20) =  CONSTANTS(:,19).*STATES(:,16).*STATES(:,13);
    ALGEBRAIC(:,19) = CONSTANTS(:,92) -  CONSTANTS(:,23).*STATES(:,13);
    ALGEBRAIC(:,21) =  CONSTANTS(:,24).*STATES(:,17).*STATES(:,16) -  CONSTANTS(:,25).*STATES(:,18);
    ALGEBRAIC(:,23) = CONSTANTS(:,93) -  CONSTANTS(:,27).*STATES(:,16);
    ALGEBRAIC(:,22) =  CONSTANTS(:,28).*STATES(:,18);
    ALGEBRAIC(:,26) =  CONSTANTS(:,31).*STATES(:,19);
    ALGEBRAIC(:,16) =   - CONSTANTS(:,4).*STATES(:,14);
    ALGEBRAIC(:,24) =  CONSTANTS(:,29).*STATES(:,17).*STATES(:,4) -  CONSTANTS(:,30).*STATES(:,19);
    ALGEBRAIC(:,25) = CONSTANTS(:,32) -  CONSTANTS(:,4).*STATES(:,4);
    ALGEBRAIC(:,28) =  CONSTANTS(:,33).*STATES(:,17).*STATES(:,20) -  CONSTANTS(:,34).*STATES(:,21);
    ALGEBRAIC(:,30) =  CONSTANTS(:,35).*STATES(:,8).*STATES(:,22) -  CONSTANTS(:,36).*STATES(:,23);
    ALGEBRAIC(:,31) =  CONSTANTS(:,37).*STATES(:,23).*STATES(:,22) -  CONSTANTS(:,38).*STATES(:,24);
    ALGEBRAIC(:,29) = CONSTANTS(:,39) -  CONSTANTS(:,4).*STATES(:,22);
    ALGEBRAIC(:,32) =  CONSTANTS(:,40).*STATES(:,24);
    ALGEBRAIC(:,34) =  CONSTANTS(:,43).*STATES(:,25);
    ALGEBRAIC(:,33) =  CONSTANTS(:,41).*STATES(:,26).*STATES(:,27) -  CONSTANTS(:,42).*STATES(:,25);
    ALGEBRAIC(:,35) =  CONSTANTS(:,44).*STATES(:,28);
    ALGEBRAIC(:,36) =  CONSTANTS(:,45).*STATES(:,29).*STATES(:,27) -  CONSTANTS(:,46).*STATES(:,28);
    ALGEBRAIC(:,37) = CONSTANTS(:,47) -  CONSTANTS(:,4).*STATES(:,27);
    ALGEBRAIC(:,38) =  CONSTANTS(:,49).*STATES(:,29).*STATES(:,20) -  CONSTANTS(:,50).*STATES(:,30);
    ALGEBRAIC(:,39) =  CONSTANTS(:,51).*STATES(:,33).*STATES(:,20) -  CONSTANTS(:,52).*STATES(:,31);
    ALGEBRAIC(:,40) =  CONSTANTS(:,53).*STATES(:,26).*STATES(:,20) -  CONSTANTS(:,54).*STATES(:,32);
    ALGEBRAIC(:,42) = CONSTANTS(:,48) -  CONSTANTS(:,4).*STATES(:,20);
    ALGEBRAIC(:,41) =  CONSTANTS(:,55).*STATES(:,26) -  CONSTANTS(:,56).*STATES(:,33).*STATES(:,29);
    ALGEBRAIC(:,43) =  CONSTANTS(:,57).*STATES(:,33) -  CONSTANTS(:,58).*STATES(:,8).*STATES(:,29);
    ALGEBRAIC(:,46) =  CONSTANTS(:,62).*power(STATES(:,34), 2.00000).*CONSTANTS(:,59);
    ALGEBRAIC(:,47) =  CONSTANTS(:,63).*STATES(:,36).*STATES(:,34);
    ALGEBRAIC(:,48) =  CONSTANTS(:,64).*STATES(:,37);
    ALGEBRAIC(:,50) =  CONSTANTS(:,66).*STATES(:,39).*STATES(:,34);
    ALGEBRAIC(:,45) =  CONSTANTS(:,61).*STATES(:,34).*STATES(:,35);
    ALGEBRAIC(:,49) =  CONSTANTS(:,65).*STATES(:,38);
    ALGEBRAIC(:,51) =  CONSTANTS(:,67).*STATES(:,40).*STATES(:,34);
    ALGEBRAIC(:,52) =  CONSTANTS(:,70).*CONSTANTS(:,68).*STATES(:,35);
    ALGEBRAIC(:,53) =  CONSTANTS(:,71).*power(STATES(:,38), 2.00000).*STATES(:,35);
    ALGEBRAIC(:,2) =   - CONSTANTS(:,4).*STATES(:,1);
    ALGEBRAIC(:,4) =  CONSTANTS(:,5).*STATES(:,3).*STATES(:,1);
    ALGEBRAIC(:,62) =  CONSTANTS(:,89).*STATES(:,37).*STATES(:,1);
    ALGEBRAIC(:,54) =  CONSTANTS(:,75).*STATES(:,41).*STATES(:,42);
    ALGEBRAIC(:,55) =  CONSTANTS(:,76).*STATES(:,41).*CONSTANTS(:,72);
    ALGEBRAIC(:,58) =  CONSTANTS(:,77).*STATES(:,41).*CONSTANTS(:,73);
    ALGEBRAIC(:,61) =  CONSTANTS(:,78).*STATES(:,41).*CONSTANTS(:,74);
    ALGEBRAIC(:,64) =  CONSTANTS(:,79).*STATES(:,41).*STATES(:,10);
    ALGEBRAIC(:,57) =  CONSTANTS(:,82).*STATES(:,37).*STATES(:,42);
    ALGEBRAIC(:,56) = ((CONSTANTS(:,81) - STATES(:,42)) - STATES(:,38))./2.00000;
    ALGEBRAIC(:,60) = ( CONSTANTS(:,83).*ALGEBRAIC(:,56))./(CONSTANTS(:,84)+ALGEBRAIC(:,56));
    ALGEBRAIC(:,63) =  CONSTANTS(:,85).*STATES(:,3).*STATES(:,42);
    ALGEBRAIC(:,59) =  CONSTANTS(:,86).*STATES(:,37);
    ALGEBRAIC(:,44) =   - CONSTANTS(:,4).*STATES(:,29);
    ALGEBRAIC(:,65) =  CONSTANTS(:,87).*STATES(:,3).*STATES(:,29);
    ALGEBRAIC(:,27) =   - CONSTANTS(:,4).*STATES(:,17);
    ALGEBRAIC(:,66) =  CONSTANTS(:,88).*STATES(:,3).*STATES(:,17);
end

% Pad out or shorten strings to a set length
function strout = strpad(strin)
    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