
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 =78;
end
% There are a total of 24 entries in each of the rate and state variable arrays.
% There are a total of 159 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, 60];

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

    % Solve model with ODE solver
    [VOI, STATES] = ode23(@(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();
    ia = [1];
    plot(VOI, ALGEBRAIC(:,ia));
    xlabel(LEGEND_VOI);
    l = legend(LEGEND_ALGEBRAIC(ia,:));
    figure();
    isp = [6,12,23];
    plot(VOI, STATES(:,isp));
    xlabel(LEGEND_VOI);
    l = legend(LEGEND_STATES(isp,:));
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 env (second)');
    LEGEND_ALGEBRAIC(:,1) = strpad('NE in component env (mM)');
    LEGEND_STATES(:,1) = strpad('B1AR in component env (mM)');
    LEGEND_STATES(:,2) = strpad('GRK in component env (mM)');
    LEGEND_STATES(:,3) = strpad('B1ARPG in component env (mM)');
    LEGEND_STATES(:,4) = strpad('B1ARPA in component env (mM)');
    LEGEND_STATES(:,5) = strpad('Gsabg in component env (mM)');
    LEGEND_STATES(:,6) = strpad('Gsa in component env (mM)');
    LEGEND_STATES(:,7) = strpad('Gsbg in component env (mM)');
    LEGEND_STATES(:,8) = strpad('FSK in component env (mM)');
    LEGEND_STATES(:,9) = strpad('AC in component env (mM)');
    LEGEND_STATES(:,10) = strpad('IBMX in component env (mM)');
    LEGEND_STATES(:,11) = strpad('PDE in component env (mM)');
    LEGEND_STATES(:,12) = strpad('cAMP in component env (mM)');
    LEGEND_STATES(:,13) = strpad('PKA in component env (mM)');
    LEGEND_STATES(:,14) = strpad('PKAR in component env (mM)');
    LEGEND_STATES(:,15) = strpad('PKI in component env (mM)');
    LEGEND_STATES(:,16) = strpad('PKAC in component env (mM)');
    LEGEND_STATES(:,17) = strpad('PP2A in component env (mM)');
    LEGEND_STATES(:,18) = strpad('IKs in component env (mM)');
    LEGEND_STATES(:,19) = strpad('ICa in component env (mM)');
    LEGEND_STATES(:,20) = strpad('RyR in component env (mM)');
    LEGEND_STATES(:,21) = strpad('Inhib1 in component env (mM)');
    LEGEND_STATES(:,22) = strpad('TnI in component env (mM)');
    LEGEND_STATES(:,23) = strpad('PLB in component env (mM)');
    LEGEND_STATES(:,24) = strpad('PP1 in component env (mM)');
    LEGEND_CONSTANTS(:,1) = strpad('tau_NE in component env (second)');
    LEGEND_CONSTANTS(:,2) = strpad('tau_B1AR in component env (second)');
    LEGEND_CONSTANTS(:,3) = strpad('tau_GRK in component env (second)');
    LEGEND_CONSTANTS(:,4) = strpad('tau_B1ARPG in component env (second)');
    LEGEND_CONSTANTS(:,5) = strpad('tau_B1ARPA in component env (second)');
    LEGEND_CONSTANTS(:,6) = strpad('tau_Gsabg in component env (second)');
    LEGEND_CONSTANTS(:,7) = strpad('tau_Gsa in component env (second)');
    LEGEND_CONSTANTS(:,8) = strpad('tau_Gsbg in component env (second)');
    LEGEND_CONSTANTS(:,9) = strpad('tau_FSK in component env (second)');
    LEGEND_CONSTANTS(:,10) = strpad('tau_AC in component env (second)');
    LEGEND_CONSTANTS(:,11) = strpad('tau_IBMX in component env (second)');
    LEGEND_CONSTANTS(:,12) = strpad('tau_PDE in component env (second)');
    LEGEND_CONSTANTS(:,13) = strpad('tau_cAMP in component env (second)');
    LEGEND_CONSTANTS(:,14) = strpad('tau_PKA in component env (second)');
    LEGEND_CONSTANTS(:,15) = strpad('tau_PKAR in component env (second)');
    LEGEND_CONSTANTS(:,16) = strpad('tau_PKI in component env (second)');
    LEGEND_CONSTANTS(:,17) = strpad('tau_PKAC in component env (second)');
    LEGEND_CONSTANTS(:,18) = strpad('tau_PP2A in component env (second)');
    LEGEND_CONSTANTS(:,19) = strpad('tau_IKs in component env (second)');
    LEGEND_CONSTANTS(:,20) = strpad('tau_ICa in component env (second)');
    LEGEND_CONSTANTS(:,21) = strpad('tau_RyR in component env (second)');
    LEGEND_CONSTANTS(:,22) = strpad('tau_Inhib1 in component env (second)');
    LEGEND_CONSTANTS(:,23) = strpad('tau_TnI in component env (second)');
    LEGEND_CONSTANTS(:,24) = strpad('tau_PLB in component env (second)');
    LEGEND_CONSTANTS(:,25) = strpad('tau_PP1 in component env (second)');
    LEGEND_CONSTANTS(:,26) = strpad('Ymax in component env (mM)');
    LEGEND_CONSTANTS(:,27) = strpad('EC50_NE_B1AR in component env (dimensionless)');
    LEGEND_CONSTANTS(:,28) = strpad('EC50_B1ARPA_B1AR in component env (dimensionless)');
    LEGEND_CONSTANTS(:,29) = strpad('EC50_B1ARPG_B1AR in component env (dimensionless)');
    LEGEND_CONSTANTS(:,30) = strpad('EC50_B1AR_GRK in component env (dimensionless)');
    LEGEND_CONSTANTS(:,31) = strpad('EC50_B1AR_Gsabg in component env (dimensionless)');
    LEGEND_CONSTANTS(:,32) = strpad('EC50_GRK_B1ARPG in component env (dimensionless)');
    LEGEND_CONSTANTS(:,33) = strpad('EC50_Gsabg_Gsbg in component env (dimensionless)');
    LEGEND_CONSTANTS(:,34) = strpad('EC50_Gsabg_Gsa in component env (dimensionless)');
    LEGEND_CONSTANTS(:,35) = strpad('EC50_Gsa_AC in component env (dimensionless)');
    LEGEND_CONSTANTS(:,36) = strpad('EC50_AC_cAMP in component env (dimensionless)');
    LEGEND_CONSTANTS(:,37) = strpad('EC50_FSK_AC in component env (dimensionless)');
    LEGEND_CONSTANTS(:,38) = strpad('EC50_IBMX_PDE in component env (dimensionless)');
    LEGEND_CONSTANTS(:,39) = strpad('EC50_PDE_cAMP in component env (dimensionless)');
    LEGEND_CONSTANTS(:,40) = strpad('EC50_cAMP_PKA in component env (dimensionless)');
    LEGEND_CONSTANTS(:,41) = strpad('EC50_PKA_PKAR in component env (dimensionless)');
    LEGEND_CONSTANTS(:,42) = strpad('EC50_PKA_PKAC in component env (dimensionless)');
    LEGEND_CONSTANTS(:,43) = strpad('EC50_PKI_PKAC in component env (dimensionless)');
    LEGEND_CONSTANTS(:,44) = strpad('EC50_PP2A_TnI in component env (dimensionless)');
    LEGEND_CONSTANTS(:,45) = strpad('EC50_PP2A_Inhib1 in component env (dimensionless)');
    LEGEND_CONSTANTS(:,46) = strpad('EC50_PP2A_ICa in component env (dimensionless)');
    LEGEND_CONSTANTS(:,47) = strpad('EC50_PP2A_RyR in component env (dimensionless)');
    LEGEND_CONSTANTS(:,48) = strpad('EC50_PKAC_B1ARPA in component env (dimensionless)');
    LEGEND_CONSTANTS(:,49) = strpad('EC50_PKAC_PLB in component env (dimensionless)');
    LEGEND_CONSTANTS(:,50) = strpad('EC50_PKAC_IKs in component env (dimensionless)');
    LEGEND_CONSTANTS(:,51) = strpad('EC50_PKAC_ICa in component env (dimensionless)');
    LEGEND_CONSTANTS(:,52) = strpad('EC50_PKAC_RyR in component env (dimensionless)');
    LEGEND_CONSTANTS(:,53) = strpad('EC50_PKAC_TnI in component env (dimensionless)');
    LEGEND_CONSTANTS(:,54) = strpad('EC50_PKAC_Inhib1 in component env (dimensionless)');
    LEGEND_CONSTANTS(:,55) = strpad('EC50_Inhib1_PP1 in component env (dimensionless)');
    LEGEND_CONSTANTS(:,56) = strpad('EC50_PP1_RyR in component env (dimensionless)');
    LEGEND_CONSTANTS(:,57) = strpad('EC50_PP1_ICa in component env (dimensionless)');
    LEGEND_CONSTANTS(:,58) = strpad('EC50_PP1_IKs in component env (dimensionless)');
    LEGEND_CONSTANTS(:,59) = strpad('EC50_PP1_PLB in component env (dimensionless)');
    LEGEND_CONSTANTS(:,60) = strpad('W_NE_B1AR in component env (dimensionless)');
    LEGEND_CONSTANTS(:,61) = strpad('W_B1ARPA_B1AR in component env (dimensionless)');
    LEGEND_CONSTANTS(:,62) = strpad('W_B1ARPG_B1AR in component env (dimensionless)');
    LEGEND_CONSTANTS(:,63) = strpad('W_B1AR_GRK in component env (dimensionless)');
    LEGEND_CONSTANTS(:,64) = strpad('W_B1AR_Gsabg in component env (dimensionless)');
    LEGEND_CONSTANTS(:,65) = strpad('W_GRK_B1ARPG in component env (dimensionless)');
    LEGEND_CONSTANTS(:,66) = strpad('W_Gsabg_Gsbg in component env (dimensionless)');
    LEGEND_CONSTANTS(:,67) = strpad('W_Gsabg_Gsa in component env (dimensionless)');
    LEGEND_CONSTANTS(:,68) = strpad('W_Gsa_AC in component env (dimensionless)');
    LEGEND_CONSTANTS(:,69) = strpad('W_AC_cAMP in component env (dimensionless)');
    LEGEND_CONSTANTS(:,70) = strpad('W_FSK_AC in component env (dimensionless)');
    LEGEND_CONSTANTS(:,71) = strpad('W_IBMX_PDE in component env (dimensionless)');
    LEGEND_CONSTANTS(:,72) = strpad('W_PDE_cAMP in component env (dimensionless)');
    LEGEND_CONSTANTS(:,73) = strpad('W_cAMP_PKA in component env (dimensionless)');
    LEGEND_CONSTANTS(:,74) = strpad('W_PKA_PKAR in component env (dimensionless)');
    LEGEND_CONSTANTS(:,75) = strpad('W_PKA_PKAC in component env (dimensionless)');
    LEGEND_CONSTANTS(:,76) = strpad('W_PKI_PKAC in component env (dimensionless)');
    LEGEND_CONSTANTS(:,77) = strpad('W_PP2A_TnI in component env (dimensionless)');
    LEGEND_CONSTANTS(:,78) = strpad('W_PP2A_Inhib1 in component env (dimensionless)');
    LEGEND_CONSTANTS(:,79) = strpad('W_PP2A_ICa in component env (dimensionless)');
    LEGEND_CONSTANTS(:,80) = strpad('W_PP2A_RyR in component env (dimensionless)');
    LEGEND_CONSTANTS(:,81) = strpad('W_PKAC_B1ARPA in component env (dimensionless)');
    LEGEND_CONSTANTS(:,82) = strpad('W_PKAC_PLB in component env (dimensionless)');
    LEGEND_CONSTANTS(:,83) = strpad('W_PKAC_IKs in component env (dimensionless)');
    LEGEND_CONSTANTS(:,84) = strpad('W_PKAC_ICa in component env (dimensionless)');
    LEGEND_CONSTANTS(:,85) = strpad('W_PKAC_RyR in component env (dimensionless)');
    LEGEND_CONSTANTS(:,86) = strpad('W_PKAC_TnI in component env (dimensionless)');
    LEGEND_CONSTANTS(:,87) = strpad('W_PKAC_Inhib1 in component env (dimensionless)');
    LEGEND_CONSTANTS(:,88) = strpad('W_Inhib1_PP1 in component env (dimensionless)');
    LEGEND_CONSTANTS(:,89) = strpad('W_PP1_RyR in component env (dimensionless)');
    LEGEND_CONSTANTS(:,90) = strpad('W_PP1_ICa in component env (dimensionless)');
    LEGEND_CONSTANTS(:,91) = strpad('W_PP1_IKs in component env (dimensionless)');
    LEGEND_CONSTANTS(:,92) = strpad('W_PP1_PLB in component env (dimensionless)');
    LEGEND_CONSTANTS(:,93) = strpad('n in component env (dimensionless)');
    LEGEND_ALGEBRAIC(:,21) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,2) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,3) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,4) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,5) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,6) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,7) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,8) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,22) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,9) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,10) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,11) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,12) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,13) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,14) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,52) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,51) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,46) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,47) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,58) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,74) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,25) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,49) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,50) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,23) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,24) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,28) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,29) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,30) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,72) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,73) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,53) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,54) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,55) = strpad('OR_AC_GSA_FSK in component env (dimensionless)');
    LEGEND_ALGEBRAIC(:,61) = strpad('OR_cAMP_AC_PDE in component env (dimensionless)');
    LEGEND_ALGEBRAIC(:,62) = strpad('OR_PKAC_PKA_PKI in component env (dimensionless)');
    LEGEND_ALGEBRAIC(:,63) = strpad('OR_IKs_PKAC_PP1 in component env (dimensionless)');
    LEGEND_ALGEBRAIC(:,75) = strpad('OR_ICa_PP2A_PP1 in component env (dimensionless)');
    LEGEND_ALGEBRAIC(:,77) = strpad('OR_ICa_PKAC_OR_ICa_PP2A_PP1 in component env (dimensionless)');
    LEGEND_ALGEBRAIC(:,76) = strpad('OR_RyR_PP2A_PP1 in component env (dimensionless)');
    LEGEND_ALGEBRAIC(:,78) = strpad('OR_RyR_PKAC_OR_RyR_PP2A_PP1 in component env (dimensionless)');
    LEGEND_ALGEBRAIC(:,64) = strpad('OR_Inhib1_PKAC_PP2A in component env (dimensionless)');
    LEGEND_ALGEBRAIC(:,65) = strpad('OR_TnI_PKAC_PP2A in component env (dimensionless)');
    LEGEND_ALGEBRAIC(:,66) = strpad('OR_PLB_PKAC_PP1 in component env (dimensionless)');
    LEGEND_CONSTANTS(:,94) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,127) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,56) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,95) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,128) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,48) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,96) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,129) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,71) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,97) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,130) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,33) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,98) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,131) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,34) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,99) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,132) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,35) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,100) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,133) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,36) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,101) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,134) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,37) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,102) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,135) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,38) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,103) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,136) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,39) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,104) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,137) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,57) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,105) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,138) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,17) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,106) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,139) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,26) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,107) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,140) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,40) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,108) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,141) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,41) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,109) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,142) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,42) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,110) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,143) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,27) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,111) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,144) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,15) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,112) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,145) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,16) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,113) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,146) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,18) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,114) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,147) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,19) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,115) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,148) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,43) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,116) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,149) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,44) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,117) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,150) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,45) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,118) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,151) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,67) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,119) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,152) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,68) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,120) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,153) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,69) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,121) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,154) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,70) = strpad('f_inhib in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,122) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,155) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,20) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,123) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,156) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,59) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,124) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,157) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,60) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,125) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,158) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,31) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,126) = strpad('beta in component f_module (dimensionless)');
    LEGEND_CONSTANTS(:,159) = strpad('K in component f_module (dimensionless)');
    LEGEND_ALGEBRAIC(:,32) = strpad('f_act in component f_module (dimensionless)');
    LEGEND_RATES(:,1) = strpad('d/dt B1AR in component env (mM)');
    LEGEND_RATES(:,2) = strpad('d/dt GRK in component env (mM)');
    LEGEND_RATES(:,3) = strpad('d/dt B1ARPG in component env (mM)');
    LEGEND_RATES(:,4) = strpad('d/dt B1ARPA in component env (mM)');
    LEGEND_RATES(:,5) = strpad('d/dt Gsabg in component env (mM)');
    LEGEND_RATES(:,6) = strpad('d/dt Gsa in component env (mM)');
    LEGEND_RATES(:,7) = strpad('d/dt Gsbg in component env (mM)');
    LEGEND_RATES(:,8) = strpad('d/dt FSK in component env (mM)');
    LEGEND_RATES(:,9) = strpad('d/dt AC in component env (mM)');
    LEGEND_RATES(:,10) = strpad('d/dt IBMX in component env (mM)');
    LEGEND_RATES(:,11) = strpad('d/dt PDE in component env (mM)');
    LEGEND_RATES(:,12) = strpad('d/dt cAMP in component env (mM)');
    LEGEND_RATES(:,13) = strpad('d/dt PKA in component env (mM)');
    LEGEND_RATES(:,14) = strpad('d/dt PKAR in component env (mM)');
    LEGEND_RATES(:,15) = strpad('d/dt PKI in component env (mM)');
    LEGEND_RATES(:,16) = strpad('d/dt PKAC in component env (mM)');
    LEGEND_RATES(:,17) = strpad('d/dt PP2A in component env (mM)');
    LEGEND_RATES(:,18) = strpad('d/dt IKs in component env (mM)');
    LEGEND_RATES(:,19) = strpad('d/dt ICa in component env (mM)');
    LEGEND_RATES(:,20) = strpad('d/dt RyR in component env (mM)');
    LEGEND_RATES(:,21) = strpad('d/dt Inhib1 in component env (mM)');
    LEGEND_RATES(:,22) = strpad('d/dt TnI in component env (mM)');
    LEGEND_RATES(:,23) = strpad('d/dt PLB in component env (mM)');
    LEGEND_RATES(:,24) = strpad('d/dt PP1 in component env (mM)');
    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;
    STATES(:,5) = 0;
    STATES(:,6) = 0;
    STATES(:,7) = 0;
    STATES(:,8) = 0;
    STATES(:,9) = 0;
    STATES(:,10) = 0;
    STATES(:,11) = 0;
    STATES(:,12) = 0;
    STATES(:,13) = 0;
    STATES(:,14) = 0;
    STATES(:,15) = 0;
    STATES(:,16) = 0;
    STATES(:,17) = 0;
    STATES(:,18) = 0;
    STATES(:,19) = 0;
    STATES(:,20) = 0;
    STATES(:,21) = 0;
    STATES(:,22) = 0;
    STATES(:,23) = 0;
    STATES(:,24) = 0;
    CONSTANTS(:,1) = 1;
    CONSTANTS(:,2) = 1;
    CONSTANTS(:,3) = 1;
    CONSTANTS(:,4) = 1;
    CONSTANTS(:,5) = 1;
    CONSTANTS(:,6) = 1;
    CONSTANTS(:,7) = 1;
    CONSTANTS(:,8) = 1;
    CONSTANTS(:,9) = 1;
    CONSTANTS(:,10) = 1;
    CONSTANTS(:,11) = 1;
    CONSTANTS(:,12) = 1;
    CONSTANTS(:,13) = 1;
    CONSTANTS(:,14) = 1;
    CONSTANTS(:,15) = 1;
    CONSTANTS(:,16) = 1;
    CONSTANTS(:,17) = 1;
    CONSTANTS(:,18) = 1;
    CONSTANTS(:,19) = 1;
    CONSTANTS(:,20) = 1;
    CONSTANTS(:,21) = 1;
    CONSTANTS(:,22) = 1;
    CONSTANTS(:,23) = 1;
    CONSTANTS(:,24) = 1;
    CONSTANTS(:,25) = 1;
    CONSTANTS(:,26) = 1;
    CONSTANTS(:,27) = 0.5;
    CONSTANTS(:,28) = 0.5;
    CONSTANTS(:,29) = 0.5;
    CONSTANTS(:,30) = 0.5;
    CONSTANTS(:,31) = 0.5;
    CONSTANTS(:,32) = 0.5;
    CONSTANTS(:,33) = 0.5;
    CONSTANTS(:,34) = 0.5;
    CONSTANTS(:,35) = 0.5;
    CONSTANTS(:,36) = 0.5;
    CONSTANTS(:,37) = 0.5;
    CONSTANTS(:,38) = 0.5;
    CONSTANTS(:,39) = 0.5;
    CONSTANTS(:,40) = 0.5;
    CONSTANTS(:,41) = 0.5;
    CONSTANTS(:,42) = 0.5;
    CONSTANTS(:,43) = 0.5;
    CONSTANTS(:,44) = 0.5;
    CONSTANTS(:,45) = 0.5;
    CONSTANTS(:,46) = 0.5;
    CONSTANTS(:,47) = 0.5;
    CONSTANTS(:,48) = 0.5;
    CONSTANTS(:,49) = 0.5;
    CONSTANTS(:,50) = 0.5;
    CONSTANTS(:,51) = 0.5;
    CONSTANTS(:,52) = 0.5;
    CONSTANTS(:,53) = 0.5;
    CONSTANTS(:,54) = 0.5;
    CONSTANTS(:,55) = 0.5;
    CONSTANTS(:,56) = 0.5;
    CONSTANTS(:,57) = 0.5;
    CONSTANTS(:,58) = 0.5;
    CONSTANTS(:,59) = 0.5;
    CONSTANTS(:,60) = 1;
    CONSTANTS(:,61) = 1;
    CONSTANTS(:,62) = 1;
    CONSTANTS(:,63) = 1;
    CONSTANTS(:,64) = 1;
    CONSTANTS(:,65) = 1;
    CONSTANTS(:,66) = 1;
    CONSTANTS(:,67) = 1;
    CONSTANTS(:,68) = 1;
    CONSTANTS(:,69) = 1;
    CONSTANTS(:,70) = 1;
    CONSTANTS(:,71) = 1;
    CONSTANTS(:,72) = 1;
    CONSTANTS(:,73) = 1;
    CONSTANTS(:,74) = 1;
    CONSTANTS(:,75) = 1;
    CONSTANTS(:,76) = 1;
    CONSTANTS(:,77) = 1;
    CONSTANTS(:,78) = 1;
    CONSTANTS(:,79) = 1;
    CONSTANTS(:,80) = 1;
    CONSTANTS(:,81) = 1;
    CONSTANTS(:,82) = 1;
    CONSTANTS(:,83) = 1;
    CONSTANTS(:,84) = 1;
    CONSTANTS(:,85) = 1;
    CONSTANTS(:,86) = 1;
    CONSTANTS(:,87) = 1;
    CONSTANTS(:,88) = 1;
    CONSTANTS(:,89) = 1;
    CONSTANTS(:,90) = 1;
    CONSTANTS(:,91) = 1;
    CONSTANTS(:,92) = 1;
    CONSTANTS(:,93) = 1.4;
    CONSTANTS(:,94) = (power(CONSTANTS(:,27), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,27), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,95) = (power(CONSTANTS(:,28), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,28), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,96) = (power(CONSTANTS(:,29), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,29), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,97) = (power(CONSTANTS(:,30), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,30), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,98) = (power(CONSTANTS(:,31), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,31), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,99) = (power(CONSTANTS(:,32), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,32), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,100) = (power(CONSTANTS(:,33), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,33), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,101) = (power(CONSTANTS(:,34), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,34), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,102) = (power(CONSTANTS(:,35), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,35), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,103) = (power(CONSTANTS(:,36), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,36), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,104) = (power(CONSTANTS(:,37), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,37), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,105) = (power(CONSTANTS(:,38), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,38), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,106) = (power(CONSTANTS(:,39), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,39), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,107) = (power(CONSTANTS(:,40), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,40), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,108) = (power(CONSTANTS(:,41), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,41), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,109) = (power(CONSTANTS(:,42), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,42), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,110) = (power(CONSTANTS(:,43), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,43), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,111) = (power(CONSTANTS(:,44), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,44), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,112) = (power(CONSTANTS(:,45), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,45), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,113) = (power(CONSTANTS(:,46), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,46), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,114) = (power(CONSTANTS(:,47), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,47), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,115) = (power(CONSTANTS(:,48), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,48), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,116) = (power(CONSTANTS(:,49), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,49), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,117) = (power(CONSTANTS(:,50), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,50), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,118) = (power(CONSTANTS(:,51), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,51), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,119) = (power(CONSTANTS(:,52), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,52), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,120) = (power(CONSTANTS(:,53), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,53), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,121) = (power(CONSTANTS(:,54), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,54), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,122) = (power(CONSTANTS(:,55), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,55), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,123) = (power(CONSTANTS(:,56), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,56), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,124) = (power(CONSTANTS(:,57), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,57), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,125) = (power(CONSTANTS(:,58), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,58), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,126) = (power(CONSTANTS(:,59), CONSTANTS(:,93)) - 1.00000)./( 2.00000.*power(CONSTANTS(:,59), CONSTANTS(:,93)) - 1.00000);
    CONSTANTS(:,127) = power(CONSTANTS(:,94) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,128) = power(CONSTANTS(:,95) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,129) = power(CONSTANTS(:,96) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,130) = power(CONSTANTS(:,97) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,131) = power(CONSTANTS(:,98) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,132) = power(CONSTANTS(:,99) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,133) = power(CONSTANTS(:,100) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,134) = power(CONSTANTS(:,101) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,135) = power(CONSTANTS(:,102) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,136) = power(CONSTANTS(:,103) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,137) = power(CONSTANTS(:,104) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,138) = power(CONSTANTS(:,105) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,139) = power(CONSTANTS(:,106) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,140) = power(CONSTANTS(:,107) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,141) = power(CONSTANTS(:,108) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,142) = power(CONSTANTS(:,109) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,143) = power(CONSTANTS(:,110) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,144) = power(CONSTANTS(:,111) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,145) = power(CONSTANTS(:,112) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,146) = power(CONSTANTS(:,113) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,147) = power(CONSTANTS(:,114) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,148) = power(CONSTANTS(:,115) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,149) = power(CONSTANTS(:,116) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,150) = power(CONSTANTS(:,117) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,151) = power(CONSTANTS(:,118) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,152) = power(CONSTANTS(:,119) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,153) = power(CONSTANTS(:,120) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,154) = power(CONSTANTS(:,121) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,155) = power(CONSTANTS(:,122) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,156) = power(CONSTANTS(:,123) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,157) = power(CONSTANTS(:,124) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,158) = power(CONSTANTS(:,125) - 1.00000, 1.00000./CONSTANTS(:,93));
    CONSTANTS(:,159) = power(CONSTANTS(:,126) - 1.00000, 1.00000./CONSTANTS(:,93));
    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(:,70).*CONSTANTS(:,26) - STATES(:,8))./CONSTANTS(:,9);
    RATES(:,10) = ( CONSTANTS(:,71).*CONSTANTS(:,26) - STATES(:,10))./CONSTANTS(:,11);
    RATES(:,15) = ( CONSTANTS(:,76).*CONSTANTS(:,26) - STATES(:,15))./CONSTANTS(:,16);
    RATES(:,17) = ( CONSTANTS(:,77).*CONSTANTS(:,26) - STATES(:,17))./CONSTANTS(:,18);
    ALGEBRAIC(:,2) = ( CONSTANTS(:,63).*CONSTANTS(:,97).*power(STATES(:,1), CONSTANTS(:,93)))./(power(CONSTANTS(:,130), CONSTANTS(:,93))+power(STATES(:,1), CONSTANTS(:,93)));
    RATES(:,2) = ( ALGEBRAIC(:,2).*CONSTANTS(:,26) - STATES(:,2))./CONSTANTS(:,3);
    ALGEBRAIC(:,4) = ( CONSTANTS(:,65).*CONSTANTS(:,99).*power(STATES(:,2), CONSTANTS(:,93)))./(power(CONSTANTS(:,132), CONSTANTS(:,93))+power(STATES(:,2), CONSTANTS(:,93)));
    RATES(:,3) = ( ALGEBRAIC(:,4).*CONSTANTS(:,26) - STATES(:,3))./CONSTANTS(:,4);
    ALGEBRAIC(:,12) = ( CONSTANTS(:,81).*CONSTANTS(:,115).*power(STATES(:,16), CONSTANTS(:,93)))./(power(CONSTANTS(:,148), CONSTANTS(:,93))+power(STATES(:,16), CONSTANTS(:,93)));
    RATES(:,4) = ( ALGEBRAIC(:,12).*CONSTANTS(:,26) - STATES(:,4))./CONSTANTS(:,5);
    ALGEBRAIC(:,3) = ( CONSTANTS(:,64).*CONSTANTS(:,98).*power(STATES(:,1), CONSTANTS(:,93)))./(power(CONSTANTS(:,131), CONSTANTS(:,93))+power(STATES(:,1), CONSTANTS(:,93)));
    RATES(:,5) = ( ALGEBRAIC(:,3).*CONSTANTS(:,26) - STATES(:,5))./CONSTANTS(:,6);
    ALGEBRAIC(:,6) = ( CONSTANTS(:,67).*CONSTANTS(:,101).*power(STATES(:,5), CONSTANTS(:,93)))./(power(CONSTANTS(:,134), CONSTANTS(:,93))+power(STATES(:,5), CONSTANTS(:,93)));
    RATES(:,6) = ( ALGEBRAIC(:,6).*CONSTANTS(:,26) - STATES(:,6))./CONSTANTS(:,7);
    ALGEBRAIC(:,5) = ( CONSTANTS(:,66).*CONSTANTS(:,100).*power(STATES(:,5), CONSTANTS(:,93)))./(power(CONSTANTS(:,133), CONSTANTS(:,93))+power(STATES(:,5), CONSTANTS(:,93)));
    RATES(:,7) = ( ALGEBRAIC(:,5).*CONSTANTS(:,26) - STATES(:,7))./CONSTANTS(:,8);
    ALGEBRAIC(:,9) = ( CONSTANTS(:,73).*CONSTANTS(:,107).*power(STATES(:,12), CONSTANTS(:,93)))./(power(CONSTANTS(:,140), CONSTANTS(:,93))+power(STATES(:,12), CONSTANTS(:,93)));
    RATES(:,13) = ( ALGEBRAIC(:,9).*CONSTANTS(:,26) - STATES(:,13))./CONSTANTS(:,14);
    ALGEBRAIC(:,10) = ( CONSTANTS(:,74).*CONSTANTS(:,108).*power(STATES(:,13), CONSTANTS(:,93)))./(power(CONSTANTS(:,141), CONSTANTS(:,93))+power(STATES(:,13), CONSTANTS(:,93)));
    RATES(:,14) = ( ALGEBRAIC(:,10).*CONSTANTS(:,26) - STATES(:,14))./CONSTANTS(:,15);
    ALGEBRAIC(:,17) = ( CONSTANTS(:,71).*CONSTANTS(:,105).*power(STATES(:,10), CONSTANTS(:,93)))./(power(CONSTANTS(:,138), CONSTANTS(:,93))+power(STATES(:,10), CONSTANTS(:,93)));
    ALGEBRAIC(:,25) = CONSTANTS(:,71) - ALGEBRAIC(:,17);
    RATES(:,11) = ( ALGEBRAIC(:,25).*CONSTANTS(:,26) - STATES(:,11))./CONSTANTS(:,12);
    ALGEBRAIC(:,20) = ( CONSTANTS(:,88).*CONSTANTS(:,122).*power(STATES(:,21), CONSTANTS(:,93)))./(power(CONSTANTS(:,155), CONSTANTS(:,93))+power(STATES(:,21), CONSTANTS(:,93)));
    ALGEBRAIC(:,30) = CONSTANTS(:,88) - ALGEBRAIC(:,20);
    RATES(:,24) = ( ALGEBRAIC(:,30).*CONSTANTS(:,26) - STATES(:,24))./CONSTANTS(:,25);
    ALGEBRAIC(:,7) = ( CONSTANTS(:,68).*CONSTANTS(:,102).*power(STATES(:,6), CONSTANTS(:,93)))./(power(CONSTANTS(:,135), CONSTANTS(:,93))+power(STATES(:,6), CONSTANTS(:,93)));
    ALGEBRAIC(:,22) = ( CONSTANTS(:,70).*CONSTANTS(:,104).*power(STATES(:,8), CONSTANTS(:,93)))./(power(CONSTANTS(:,137), CONSTANTS(:,93))+power(STATES(:,8), CONSTANTS(:,93)));
    ALGEBRAIC(:,55) = (ALGEBRAIC(:,7)+ALGEBRAIC(:,22)) -  ALGEBRAIC(:,7).*ALGEBRAIC(:,22);
    RATES(:,9) = ( ALGEBRAIC(:,55).*CONSTANTS(:,26) - STATES(:,9))./CONSTANTS(:,10);
    ALGEBRAIC(:,8) = ( CONSTANTS(:,69).*CONSTANTS(:,103).*power(STATES(:,9), CONSTANTS(:,93)))./(power(CONSTANTS(:,136), CONSTANTS(:,93))+power(STATES(:,9), CONSTANTS(:,93)));
    ALGEBRAIC(:,26) = ( CONSTANTS(:,72).*CONSTANTS(:,106).*power(STATES(:,11), CONSTANTS(:,93)))./(power(CONSTANTS(:,139), CONSTANTS(:,93))+power(STATES(:,11), CONSTANTS(:,93)));
    ALGEBRAIC(:,49) = CONSTANTS(:,72) - ALGEBRAIC(:,26);
    ALGEBRAIC(:,61) = (ALGEBRAIC(:,8)+ALGEBRAIC(:,49)) -  ALGEBRAIC(:,8).*ALGEBRAIC(:,49);
    RATES(:,12) = ( ALGEBRAIC(:,61).*CONSTANTS(:,26) - STATES(:,12))./CONSTANTS(:,13);
    ALGEBRAIC(:,11) = ( CONSTANTS(:,75).*CONSTANTS(:,109).*power(STATES(:,13), CONSTANTS(:,93)))./(power(CONSTANTS(:,142), CONSTANTS(:,93))+power(STATES(:,13), CONSTANTS(:,93)));
    ALGEBRAIC(:,27) = ( CONSTANTS(:,76).*CONSTANTS(:,110).*power(STATES(:,15), CONSTANTS(:,93)))./(power(CONSTANTS(:,143), CONSTANTS(:,93))+power(STATES(:,15), CONSTANTS(:,93)));
    ALGEBRAIC(:,50) = CONSTANTS(:,76) - ALGEBRAIC(:,27);
    ALGEBRAIC(:,62) = (ALGEBRAIC(:,11)+ALGEBRAIC(:,50)) -  ALGEBRAIC(:,11).*ALGEBRAIC(:,50);
    RATES(:,16) = ( ALGEBRAIC(:,62).*CONSTANTS(:,26) - STATES(:,16))./CONSTANTS(:,17);
    ALGEBRAIC(:,14) = ( CONSTANTS(:,83).*CONSTANTS(:,117).*power(STATES(:,16), CONSTANTS(:,93)))./(power(CONSTANTS(:,150), CONSTANTS(:,93))+power(STATES(:,16), CONSTANTS(:,93)));
    ALGEBRAIC(:,31) = ( CONSTANTS(:,91).*CONSTANTS(:,125).*power(STATES(:,24), CONSTANTS(:,93)))./(power(CONSTANTS(:,158), CONSTANTS(:,93))+power(STATES(:,24), CONSTANTS(:,93)));
    ALGEBRAIC(:,53) = CONSTANTS(:,91) - ALGEBRAIC(:,31);
    ALGEBRAIC(:,63) = (ALGEBRAIC(:,14)+ALGEBRAIC(:,53)) -  ALGEBRAIC(:,14).*ALGEBRAIC(:,53);
    RATES(:,18) = ( ALGEBRAIC(:,63).*CONSTANTS(:,26) - STATES(:,18))./CONSTANTS(:,19);
    ALGEBRAIC(:,47) = ( CONSTANTS(:,87).*CONSTANTS(:,121).*power(STATES(:,16), CONSTANTS(:,93)))./(power(CONSTANTS(:,154), CONSTANTS(:,93))+power(STATES(:,16), CONSTANTS(:,93)));
    ALGEBRAIC(:,16) = ( CONSTANTS(:,78).*CONSTANTS(:,112).*power(STATES(:,17), CONSTANTS(:,93)))./(power(CONSTANTS(:,145), CONSTANTS(:,93))+power(STATES(:,17), CONSTANTS(:,93)));
    ALGEBRAIC(:,24) = CONSTANTS(:,78) - ALGEBRAIC(:,16);
    ALGEBRAIC(:,64) = (ALGEBRAIC(:,47)+ALGEBRAIC(:,24)) -  ALGEBRAIC(:,47).*ALGEBRAIC(:,24);
    RATES(:,21) = ( ALGEBRAIC(:,64).*CONSTANTS(:,26) - STATES(:,21))./CONSTANTS(:,22);
    ALGEBRAIC(:,46) = ( CONSTANTS(:,86).*CONSTANTS(:,120).*power(STATES(:,16), CONSTANTS(:,93)))./(power(CONSTANTS(:,153), CONSTANTS(:,93))+power(STATES(:,16), CONSTANTS(:,93)));
    ALGEBRAIC(:,15) = ( CONSTANTS(:,77).*CONSTANTS(:,111).*power(STATES(:,17), CONSTANTS(:,93)))./(power(CONSTANTS(:,144), CONSTANTS(:,93))+power(STATES(:,17), CONSTANTS(:,93)));
    ALGEBRAIC(:,23) = CONSTANTS(:,77) - ALGEBRAIC(:,15);
    ALGEBRAIC(:,65) = (ALGEBRAIC(:,46)+ALGEBRAIC(:,23)) -  ALGEBRAIC(:,46).*ALGEBRAIC(:,23);
    RATES(:,22) = ( ALGEBRAIC(:,65).*CONSTANTS(:,26) - STATES(:,22))./CONSTANTS(:,23);
    ALGEBRAIC(:,13) = ( CONSTANTS(:,82).*CONSTANTS(:,116).*power(STATES(:,16), CONSTANTS(:,93)))./(power(CONSTANTS(:,149), CONSTANTS(:,93))+power(STATES(:,16), CONSTANTS(:,93)));
    ALGEBRAIC(:,32) = ( CONSTANTS(:,92).*CONSTANTS(:,126).*power(STATES(:,24), CONSTANTS(:,93)))./(power(CONSTANTS(:,159), CONSTANTS(:,93))+power(STATES(:,24), CONSTANTS(:,93)));
    ALGEBRAIC(:,54) = CONSTANTS(:,92) - ALGEBRAIC(:,32);
    ALGEBRAIC(:,66) = (ALGEBRAIC(:,13)+ALGEBRAIC(:,54)) -  ALGEBRAIC(:,13).*ALGEBRAIC(:,54);
    RATES(:,23) = ( ALGEBRAIC(:,66).*CONSTANTS(:,26) - STATES(:,23))./CONSTANTS(:,24);
    ALGEBRAIC(:,1) = piecewise({VOI>5.00000&VOI<=45.0000, 1.00000 }, 0.000000);
    ALGEBRAIC(:,21) = ( CONSTANTS(:,60).*CONSTANTS(:,94).*power(ALGEBRAIC(:,1), CONSTANTS(:,93)))./(power(CONSTANTS(:,127), CONSTANTS(:,93))+power(ALGEBRAIC(:,1), CONSTANTS(:,93)));
    ALGEBRAIC(:,48) = ( CONSTANTS(:,61).*CONSTANTS(:,95).*power(STATES(:,4), CONSTANTS(:,93)))./(power(CONSTANTS(:,128), CONSTANTS(:,93))+power(STATES(:,4), CONSTANTS(:,93)));
    ALGEBRAIC(:,58) = CONSTANTS(:,61) - ALGEBRAIC(:,48);
    ALGEBRAIC(:,71) = ( CONSTANTS(:,62).*CONSTANTS(:,96).*power(STATES(:,3), CONSTANTS(:,93)))./(power(CONSTANTS(:,129), CONSTANTS(:,93))+power(STATES(:,3), CONSTANTS(:,93)));
    ALGEBRAIC(:,74) = CONSTANTS(:,62) - ALGEBRAIC(:,71);
    RATES(:,1) = ( ALGEBRAIC(:,21).*ALGEBRAIC(:,74).*ALGEBRAIC(:,58).*CONSTANTS(:,26) - STATES(:,1))./CONSTANTS(:,2);
    ALGEBRAIC(:,52) = ( CONSTANTS(:,84).*CONSTANTS(:,118).*power(STATES(:,16), CONSTANTS(:,93)))./(power(CONSTANTS(:,151), CONSTANTS(:,93))+power(STATES(:,16), CONSTANTS(:,93)));
    ALGEBRAIC(:,18) = ( CONSTANTS(:,79).*CONSTANTS(:,113).*power(STATES(:,17), CONSTANTS(:,93)))./(power(CONSTANTS(:,146), CONSTANTS(:,93))+power(STATES(:,17), CONSTANTS(:,93)));
    ALGEBRAIC(:,28) = CONSTANTS(:,79) - ALGEBRAIC(:,18);
    ALGEBRAIC(:,60) = ( CONSTANTS(:,90).*CONSTANTS(:,124).*power(STATES(:,24), CONSTANTS(:,93)))./(power(CONSTANTS(:,157), CONSTANTS(:,93))+power(STATES(:,24), CONSTANTS(:,93)));
    ALGEBRAIC(:,73) = CONSTANTS(:,90) - ALGEBRAIC(:,60);
    ALGEBRAIC(:,75) = (ALGEBRAIC(:,28)+ALGEBRAIC(:,73)) -  ALGEBRAIC(:,28).*ALGEBRAIC(:,73);
    ALGEBRAIC(:,77) = (ALGEBRAIC(:,52)+ALGEBRAIC(:,75)) -  ALGEBRAIC(:,52).*ALGEBRAIC(:,75);
    RATES(:,19) = ( ALGEBRAIC(:,77).*CONSTANTS(:,26) - STATES(:,19))./CONSTANTS(:,20);
    ALGEBRAIC(:,51) = ( CONSTANTS(:,85).*CONSTANTS(:,119).*power(STATES(:,16), CONSTANTS(:,93)))./(power(CONSTANTS(:,152), CONSTANTS(:,93))+power(STATES(:,16), CONSTANTS(:,93)));
    ALGEBRAIC(:,19) = ( CONSTANTS(:,80).*CONSTANTS(:,114).*power(STATES(:,17), CONSTANTS(:,93)))./(power(CONSTANTS(:,147), CONSTANTS(:,93))+power(STATES(:,17), CONSTANTS(:,93)));
    ALGEBRAIC(:,29) = CONSTANTS(:,80) - ALGEBRAIC(:,19);
    ALGEBRAIC(:,59) = ( CONSTANTS(:,89).*CONSTANTS(:,123).*power(STATES(:,24), CONSTANTS(:,93)))./(power(CONSTANTS(:,156), CONSTANTS(:,93))+power(STATES(:,24), CONSTANTS(:,93)));
    ALGEBRAIC(:,72) = CONSTANTS(:,89) - ALGEBRAIC(:,59);
    ALGEBRAIC(:,76) = (ALGEBRAIC(:,29)+ALGEBRAIC(:,72)) -  ALGEBRAIC(:,29).*ALGEBRAIC(:,72);
    ALGEBRAIC(:,78) = (ALGEBRAIC(:,51)+ALGEBRAIC(:,76)) -  ALGEBRAIC(:,51).*ALGEBRAIC(:,76);
    RATES(:,20) = ( ALGEBRAIC(:,78).*CONSTANTS(:,26) - STATES(:,20))./CONSTANTS(:,21);
   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(:,2) = ( CONSTANTS(:,63).*CONSTANTS(:,97).*power(STATES(:,1), CONSTANTS(:,93)))./(power(CONSTANTS(:,130), CONSTANTS(:,93))+power(STATES(:,1), CONSTANTS(:,93)));
    ALGEBRAIC(:,4) = ( CONSTANTS(:,65).*CONSTANTS(:,99).*power(STATES(:,2), CONSTANTS(:,93)))./(power(CONSTANTS(:,132), CONSTANTS(:,93))+power(STATES(:,2), CONSTANTS(:,93)));
    ALGEBRAIC(:,12) = ( CONSTANTS(:,81).*CONSTANTS(:,115).*power(STATES(:,16), CONSTANTS(:,93)))./(power(CONSTANTS(:,148), CONSTANTS(:,93))+power(STATES(:,16), CONSTANTS(:,93)));
    ALGEBRAIC(:,3) = ( CONSTANTS(:,64).*CONSTANTS(:,98).*power(STATES(:,1), CONSTANTS(:,93)))./(power(CONSTANTS(:,131), CONSTANTS(:,93))+power(STATES(:,1), CONSTANTS(:,93)));
    ALGEBRAIC(:,6) = ( CONSTANTS(:,67).*CONSTANTS(:,101).*power(STATES(:,5), CONSTANTS(:,93)))./(power(CONSTANTS(:,134), CONSTANTS(:,93))+power(STATES(:,5), CONSTANTS(:,93)));
    ALGEBRAIC(:,5) = ( CONSTANTS(:,66).*CONSTANTS(:,100).*power(STATES(:,5), CONSTANTS(:,93)))./(power(CONSTANTS(:,133), CONSTANTS(:,93))+power(STATES(:,5), CONSTANTS(:,93)));
    ALGEBRAIC(:,9) = ( CONSTANTS(:,73).*CONSTANTS(:,107).*power(STATES(:,12), CONSTANTS(:,93)))./(power(CONSTANTS(:,140), CONSTANTS(:,93))+power(STATES(:,12), CONSTANTS(:,93)));
    ALGEBRAIC(:,10) = ( CONSTANTS(:,74).*CONSTANTS(:,108).*power(STATES(:,13), CONSTANTS(:,93)))./(power(CONSTANTS(:,141), CONSTANTS(:,93))+power(STATES(:,13), CONSTANTS(:,93)));
    ALGEBRAIC(:,17) = ( CONSTANTS(:,71).*CONSTANTS(:,105).*power(STATES(:,10), CONSTANTS(:,93)))./(power(CONSTANTS(:,138), CONSTANTS(:,93))+power(STATES(:,10), CONSTANTS(:,93)));
    ALGEBRAIC(:,25) = CONSTANTS(:,71) - ALGEBRAIC(:,17);
    ALGEBRAIC(:,20) = ( CONSTANTS(:,88).*CONSTANTS(:,122).*power(STATES(:,21), CONSTANTS(:,93)))./(power(CONSTANTS(:,155), CONSTANTS(:,93))+power(STATES(:,21), CONSTANTS(:,93)));
    ALGEBRAIC(:,30) = CONSTANTS(:,88) - ALGEBRAIC(:,20);
    ALGEBRAIC(:,7) = ( CONSTANTS(:,68).*CONSTANTS(:,102).*power(STATES(:,6), CONSTANTS(:,93)))./(power(CONSTANTS(:,135), CONSTANTS(:,93))+power(STATES(:,6), CONSTANTS(:,93)));
    ALGEBRAIC(:,22) = ( CONSTANTS(:,70).*CONSTANTS(:,104).*power(STATES(:,8), CONSTANTS(:,93)))./(power(CONSTANTS(:,137), CONSTANTS(:,93))+power(STATES(:,8), CONSTANTS(:,93)));
    ALGEBRAIC(:,55) = (ALGEBRAIC(:,7)+ALGEBRAIC(:,22)) -  ALGEBRAIC(:,7).*ALGEBRAIC(:,22);
    ALGEBRAIC(:,8) = ( CONSTANTS(:,69).*CONSTANTS(:,103).*power(STATES(:,9), CONSTANTS(:,93)))./(power(CONSTANTS(:,136), CONSTANTS(:,93))+power(STATES(:,9), CONSTANTS(:,93)));
    ALGEBRAIC(:,26) = ( CONSTANTS(:,72).*CONSTANTS(:,106).*power(STATES(:,11), CONSTANTS(:,93)))./(power(CONSTANTS(:,139), CONSTANTS(:,93))+power(STATES(:,11), CONSTANTS(:,93)));
    ALGEBRAIC(:,49) = CONSTANTS(:,72) - ALGEBRAIC(:,26);
    ALGEBRAIC(:,61) = (ALGEBRAIC(:,8)+ALGEBRAIC(:,49)) -  ALGEBRAIC(:,8).*ALGEBRAIC(:,49);
    ALGEBRAIC(:,11) = ( CONSTANTS(:,75).*CONSTANTS(:,109).*power(STATES(:,13), CONSTANTS(:,93)))./(power(CONSTANTS(:,142), CONSTANTS(:,93))+power(STATES(:,13), CONSTANTS(:,93)));
    ALGEBRAIC(:,27) = ( CONSTANTS(:,76).*CONSTANTS(:,110).*power(STATES(:,15), CONSTANTS(:,93)))./(power(CONSTANTS(:,143), CONSTANTS(:,93))+power(STATES(:,15), CONSTANTS(:,93)));
    ALGEBRAIC(:,50) = CONSTANTS(:,76) - ALGEBRAIC(:,27);
    ALGEBRAIC(:,62) = (ALGEBRAIC(:,11)+ALGEBRAIC(:,50)) -  ALGEBRAIC(:,11).*ALGEBRAIC(:,50);
    ALGEBRAIC(:,14) = ( CONSTANTS(:,83).*CONSTANTS(:,117).*power(STATES(:,16), CONSTANTS(:,93)))./(power(CONSTANTS(:,150), CONSTANTS(:,93))+power(STATES(:,16), CONSTANTS(:,93)));
    ALGEBRAIC(:,31) = ( CONSTANTS(:,91).*CONSTANTS(:,125).*power(STATES(:,24), CONSTANTS(:,93)))./(power(CONSTANTS(:,158), CONSTANTS(:,93))+power(STATES(:,24), CONSTANTS(:,93)));
    ALGEBRAIC(:,53) = CONSTANTS(:,91) - ALGEBRAIC(:,31);
    ALGEBRAIC(:,63) = (ALGEBRAIC(:,14)+ALGEBRAIC(:,53)) -  ALGEBRAIC(:,14).*ALGEBRAIC(:,53);
    ALGEBRAIC(:,47) = ( CONSTANTS(:,87).*CONSTANTS(:,121).*power(STATES(:,16), CONSTANTS(:,93)))./(power(CONSTANTS(:,154), CONSTANTS(:,93))+power(STATES(:,16), CONSTANTS(:,93)));
    ALGEBRAIC(:,16) = ( CONSTANTS(:,78).*CONSTANTS(:,112).*power(STATES(:,17), CONSTANTS(:,93)))./(power(CONSTANTS(:,145), CONSTANTS(:,93))+power(STATES(:,17), CONSTANTS(:,93)));
    ALGEBRAIC(:,24) = CONSTANTS(:,78) - ALGEBRAIC(:,16);
    ALGEBRAIC(:,64) = (ALGEBRAIC(:,47)+ALGEBRAIC(:,24)) -  ALGEBRAIC(:,47).*ALGEBRAIC(:,24);
    ALGEBRAIC(:,46) = ( CONSTANTS(:,86).*CONSTANTS(:,120).*power(STATES(:,16), CONSTANTS(:,93)))./(power(CONSTANTS(:,153), CONSTANTS(:,93))+power(STATES(:,16), CONSTANTS(:,93)));
    ALGEBRAIC(:,15) = ( CONSTANTS(:,77).*CONSTANTS(:,111).*power(STATES(:,17), CONSTANTS(:,93)))./(power(CONSTANTS(:,144), CONSTANTS(:,93))+power(STATES(:,17), CONSTANTS(:,93)));
    ALGEBRAIC(:,23) = CONSTANTS(:,77) - ALGEBRAIC(:,15);
    ALGEBRAIC(:,65) = (ALGEBRAIC(:,46)+ALGEBRAIC(:,23)) -  ALGEBRAIC(:,46).*ALGEBRAIC(:,23);
    ALGEBRAIC(:,13) = ( CONSTANTS(:,82).*CONSTANTS(:,116).*power(STATES(:,16), CONSTANTS(:,93)))./(power(CONSTANTS(:,149), CONSTANTS(:,93))+power(STATES(:,16), CONSTANTS(:,93)));
    ALGEBRAIC(:,32) = ( CONSTANTS(:,92).*CONSTANTS(:,126).*power(STATES(:,24), CONSTANTS(:,93)))./(power(CONSTANTS(:,159), CONSTANTS(:,93))+power(STATES(:,24), CONSTANTS(:,93)));
    ALGEBRAIC(:,54) = CONSTANTS(:,92) - ALGEBRAIC(:,32);
    ALGEBRAIC(:,66) = (ALGEBRAIC(:,13)+ALGEBRAIC(:,54)) -  ALGEBRAIC(:,13).*ALGEBRAIC(:,54);
    ALGEBRAIC(:,1) = piecewise({VOI>5.00000&VOI<=45.0000, 1.00000 }, 0.000000);
    ALGEBRAIC(:,21) = ( CONSTANTS(:,60).*CONSTANTS(:,94).*power(ALGEBRAIC(:,1), CONSTANTS(:,93)))./(power(CONSTANTS(:,127), CONSTANTS(:,93))+power(ALGEBRAIC(:,1), CONSTANTS(:,93)));
    ALGEBRAIC(:,48) = ( CONSTANTS(:,61).*CONSTANTS(:,95).*power(STATES(:,4), CONSTANTS(:,93)))./(power(CONSTANTS(:,128), CONSTANTS(:,93))+power(STATES(:,4), CONSTANTS(:,93)));
    ALGEBRAIC(:,58) = CONSTANTS(:,61) - ALGEBRAIC(:,48);
    ALGEBRAIC(:,71) = ( CONSTANTS(:,62).*CONSTANTS(:,96).*power(STATES(:,3), CONSTANTS(:,93)))./(power(CONSTANTS(:,129), CONSTANTS(:,93))+power(STATES(:,3), CONSTANTS(:,93)));
    ALGEBRAIC(:,74) = CONSTANTS(:,62) - ALGEBRAIC(:,71);
    ALGEBRAIC(:,52) = ( CONSTANTS(:,84).*CONSTANTS(:,118).*power(STATES(:,16), CONSTANTS(:,93)))./(power(CONSTANTS(:,151), CONSTANTS(:,93))+power(STATES(:,16), CONSTANTS(:,93)));
    ALGEBRAIC(:,18) = ( CONSTANTS(:,79).*CONSTANTS(:,113).*power(STATES(:,17), CONSTANTS(:,93)))./(power(CONSTANTS(:,146), CONSTANTS(:,93))+power(STATES(:,17), CONSTANTS(:,93)));
    ALGEBRAIC(:,28) = CONSTANTS(:,79) - ALGEBRAIC(:,18);
    ALGEBRAIC(:,60) = ( CONSTANTS(:,90).*CONSTANTS(:,124).*power(STATES(:,24), CONSTANTS(:,93)))./(power(CONSTANTS(:,157), CONSTANTS(:,93))+power(STATES(:,24), CONSTANTS(:,93)));
    ALGEBRAIC(:,73) = CONSTANTS(:,90) - ALGEBRAIC(:,60);
    ALGEBRAIC(:,75) = (ALGEBRAIC(:,28)+ALGEBRAIC(:,73)) -  ALGEBRAIC(:,28).*ALGEBRAIC(:,73);
    ALGEBRAIC(:,77) = (ALGEBRAIC(:,52)+ALGEBRAIC(:,75)) -  ALGEBRAIC(:,52).*ALGEBRAIC(:,75);
    ALGEBRAIC(:,51) = ( CONSTANTS(:,85).*CONSTANTS(:,119).*power(STATES(:,16), CONSTANTS(:,93)))./(power(CONSTANTS(:,152), CONSTANTS(:,93))+power(STATES(:,16), CONSTANTS(:,93)));
    ALGEBRAIC(:,19) = ( CONSTANTS(:,80).*CONSTANTS(:,114).*power(STATES(:,17), CONSTANTS(:,93)))./(power(CONSTANTS(:,147), CONSTANTS(:,93))+power(STATES(:,17), CONSTANTS(:,93)));
    ALGEBRAIC(:,29) = CONSTANTS(:,80) - ALGEBRAIC(:,19);
    ALGEBRAIC(:,59) = ( CONSTANTS(:,89).*CONSTANTS(:,123).*power(STATES(:,24), CONSTANTS(:,93)))./(power(CONSTANTS(:,156), CONSTANTS(:,93))+power(STATES(:,24), CONSTANTS(:,93)));
    ALGEBRAIC(:,72) = CONSTANTS(:,89) - ALGEBRAIC(:,59);
    ALGEBRAIC(:,76) = (ALGEBRAIC(:,29)+ALGEBRAIC(:,72)) -  ALGEBRAIC(:,29).*ALGEBRAIC(:,72);
    ALGEBRAIC(:,78) = (ALGEBRAIC(:,51)+ALGEBRAIC(:,76)) -  ALGEBRAIC(:,51).*ALGEBRAIC(:,76);
    ALGEBRAIC(:,33) = CONSTANTS(:,63) - ALGEBRAIC(:,2);
    ALGEBRAIC(:,34) = CONSTANTS(:,64) - ALGEBRAIC(:,3);
    ALGEBRAIC(:,35) = CONSTANTS(:,65) - ALGEBRAIC(:,4);
    ALGEBRAIC(:,36) = CONSTANTS(:,66) - ALGEBRAIC(:,5);
    ALGEBRAIC(:,37) = CONSTANTS(:,67) - ALGEBRAIC(:,6);
    ALGEBRAIC(:,38) = CONSTANTS(:,68) - ALGEBRAIC(:,7);
    ALGEBRAIC(:,39) = CONSTANTS(:,69) - ALGEBRAIC(:,8);
    ALGEBRAIC(:,40) = CONSTANTS(:,73) - ALGEBRAIC(:,9);
    ALGEBRAIC(:,41) = CONSTANTS(:,74) - ALGEBRAIC(:,10);
    ALGEBRAIC(:,42) = CONSTANTS(:,75) - ALGEBRAIC(:,11);
    ALGEBRAIC(:,43) = CONSTANTS(:,81) - ALGEBRAIC(:,12);
    ALGEBRAIC(:,44) = CONSTANTS(:,82) - ALGEBRAIC(:,13);
    ALGEBRAIC(:,45) = CONSTANTS(:,83) - ALGEBRAIC(:,14);
    ALGEBRAIC(:,56) = CONSTANTS(:,60) - ALGEBRAIC(:,21);
    ALGEBRAIC(:,57) = CONSTANTS(:,70) - ALGEBRAIC(:,22);
    ALGEBRAIC(:,67) = CONSTANTS(:,84) - ALGEBRAIC(:,52);
    ALGEBRAIC(:,68) = CONSTANTS(:,85) - ALGEBRAIC(:,51);
    ALGEBRAIC(:,69) = CONSTANTS(:,86) - ALGEBRAIC(:,46);
    ALGEBRAIC(:,70) = CONSTANTS(:,87) - ALGEBRAIC(:,47);
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
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

