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 =141;
end
% There are a total of 37 entries in each of the rate and state variable arrays.
% There are a total of 101 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 (millisecond)');
    LEGEND_STATES(:,1) = strpad('Vm in component membrane (millivolt)');
    LEGEND_CONSTANTS(:,1) = strpad('R in component membrane (coulomb_millivolt_per_kelvin_millimole)');
    LEGEND_CONSTANTS(:,2) = strpad('T in component membrane (kelvin)');
    LEGEND_CONSTANTS(:,3) = strpad('F in component membrane (coulomb_per_millimole)');
    LEGEND_CONSTANTS(:,4) = strpad('Cm in component membrane (picoF)');
    LEGEND_ALGEBRAIC(:,1) = strpad('i_ext in component membrane (picoA)');
    LEGEND_ALGEBRAIC(:,106) = strpad('i_tot in component membrane (picoA)');
    LEGEND_ALGEBRAIC(:,90) = strpad('i_I in component membrane (picoA)');
    LEGEND_ALGEBRAIC(:,46) = strpad('i_Na in component sodium_current (picoA)');
    LEGEND_ALGEBRAIC(:,51) = strpad('i_Ca_L in component L_type_Ca_channel (picoA)');
    LEGEND_ALGEBRAIC(:,55) = strpad('i_Ca_T in component T_type_Ca_channel (picoA)');
    LEGEND_ALGEBRAIC(:,71) = strpad('i_K1 in component time_independent_potassium_current (picoA)');
    LEGEND_ALGEBRAIC(:,72) = strpad('i_Kr in component rapid_time_dependent_potassium_current (picoA)');
    LEGEND_ALGEBRAIC(:,75) = strpad('i_Ks in component slow_time_dependent_potassium_current (picoA)');
    LEGEND_ALGEBRAIC(:,78) = strpad('i_to in component transient_outward_current (picoA)');
    LEGEND_ALGEBRAIC(:,104) = strpad('i_NaK in component sodium_potassium_pump (picoA)');
    LEGEND_ALGEBRAIC(:,95) = strpad('i_NaCa in component sodium_calcium_exchanger (picoA)');
    LEGEND_ALGEBRAIC(:,81) = strpad('i_bNSC in component background_NSC_current (picoA)');
    LEGEND_ALGEBRAIC(:,89) = strpad('i_Cab in component background_Cab_current (picoA)');
    LEGEND_ALGEBRAIC(:,82) = strpad('i_Kpl in component background_Kpl_current (picoA)');
    LEGEND_ALGEBRAIC(:,86) = strpad('i_lCa in component background_lCa_current (picoA)');
    LEGEND_ALGEBRAIC(:,88) = strpad('i_KATP in component background_KATP_current (picoA)');
    LEGEND_CONSTANTS(:,5) = strpad('stim_start in component membrane (millisecond)');
    LEGEND_CONSTANTS(:,6) = strpad('stim_end in component membrane (millisecond)');
    LEGEND_CONSTANTS(:,7) = strpad('stim_period in component membrane (millisecond)');
    LEGEND_CONSTANTS(:,8) = strpad('stim_duration in component membrane (millisecond)');
    LEGEND_CONSTANTS(:,9) = strpad('stim_amplitude in component membrane (picoA)');
    LEGEND_CONSTANTS(:,10) = strpad('Nao in component external_ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,11) = strpad('Cao in component external_ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,12) = strpad('Ko in component external_ion_concentrations (millimolar)');
    LEGEND_STATES(:,2) = strpad('Nai in component internal_ion_concentrations (millimolar)');
    LEGEND_ALGEBRAIC(:,30) = strpad('Cai in component internal_ion_concentrations (millimolar)');
    LEGEND_STATES(:,3) = strpad('Ki in component internal_ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,13) = strpad('Vi in component internal_ion_concentrations (micrometre3)');
    LEGEND_ALGEBRAIC(:,107) = strpad('i_net_Na in component internal_ion_concentrations (picoA)');
    LEGEND_ALGEBRAIC(:,108) = strpad('i_net_K in component internal_ion_concentrations (picoA)');
    LEGEND_ALGEBRAIC(:,97) = strpad('i_net_Ca in component internal_ion_concentrations (picoA)');
    LEGEND_ALGEBRAIC(:,43) = strpad('i_Na_Na in component sodium_current (picoA)');
    LEGEND_ALGEBRAIC(:,49) = strpad('i_CaL_Na in component L_type_Ca_channel (picoA)');
    LEGEND_ALGEBRAIC(:,80) = strpad('i_bNSC_Na in component background_NSC_current (picoA)');
    LEGEND_ALGEBRAIC(:,85) = strpad('i_lCa_Na in component background_lCa_current (picoA)');
    LEGEND_ALGEBRAIC(:,76) = strpad('i_to_K in component transient_outward_current (picoA)');
    LEGEND_ALGEBRAIC(:,77) = strpad('i_to_Na in component transient_outward_current (picoA)');
    LEGEND_ALGEBRAIC(:,73) = strpad('i_Ks_K in component slow_time_dependent_potassium_current (picoA)');
    LEGEND_ALGEBRAIC(:,74) = strpad('i_Ks_Na in component slow_time_dependent_potassium_current (picoA)');
    LEGEND_ALGEBRAIC(:,45) = strpad('i_Na_K in component sodium_current (picoA)');
    LEGEND_ALGEBRAIC(:,50) = strpad('i_CaL_K in component L_type_Ca_channel (picoA)');
    LEGEND_ALGEBRAIC(:,79) = strpad('i_bNSC_K in component background_NSC_current (picoA)');
    LEGEND_ALGEBRAIC(:,84) = strpad('i_lCa_K in component background_lCa_current (picoA)');
    LEGEND_ALGEBRAIC(:,48) = strpad('i_CaL_Ca in component L_type_Ca_channel (picoA)');
    LEGEND_ALGEBRAIC(:,127) = strpad('i_RyR in component RyR_channel (picoA)');
    LEGEND_ALGEBRAIC(:,116) = strpad('i_SR_U in component SR_calcium_pump (picoA)');
    LEGEND_ALGEBRAIC(:,121) = strpad('i_SR_L in component SR_L_current (picoA)');
    LEGEND_ALGEBRAIC(:,141) = strpad('dCaidt in component NL_model (millimolar_per_millisecond)');
    LEGEND_CONSTANTS(:,14) = strpad('CMDN_max in component internal_ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,15) = strpad('K_mCMDN in component internal_ion_concentrations (millimolar)');
    LEGEND_STATES(:,4) = strpad('Ca_Total in component internal_ion_concentrations (millimolar)');
    LEGEND_ALGEBRAIC(:,14) = strpad('b1 in component internal_ion_concentrations (millimolar)');
    LEGEND_ALGEBRAIC(:,27) = strpad('c1 in component internal_ion_concentrations (millimolar2)');
    LEGEND_ALGEBRAIC(:,33) = strpad('CF_Na in component constant_field_equations (millimolar)');
    LEGEND_ALGEBRAIC(:,37) = strpad('CF_Ca in component constant_field_equations (millimolar)');
    LEGEND_ALGEBRAIC(:,40) = strpad('CF_K in component constant_field_equations (millimolar)');
    LEGEND_STATES(:,5) = strpad('ATPi in component ATP_production (millimolar)');
    LEGEND_ALGEBRAIC(:,118) = strpad('dATPdt in component NL_model (millimolar_per_millisecond)');
    LEGEND_CONSTANTS(:,16) = strpad('ProducingRate_Max in component ATP_production (per_millisecond)');
    LEGEND_CONSTANTS(:,17) = strpad('Adenosine_Total in component ATP_production (millimolar)');
    LEGEND_CONSTANTS(:,18) = strpad('P_Na in component sodium_current (picoA_per_millimolar)');
    LEGEND_STATES(:,6) = strpad('p_AP_Na in component sodium_current_voltage_dependent_gate (dimensionless)');
    LEGEND_STATES(:,7) = strpad('y in component sodium_current_ultra_slow_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,2) = strpad('p_RI_Na in component sodium_current_voltage_dependent_gate (dimensionless)');
    LEGEND_STATES(:,8) = strpad('p_RP_Na in component sodium_current_voltage_dependent_gate (dimensionless)');
    LEGEND_STATES(:,9) = strpad('p_AI_Na in component sodium_current_voltage_dependent_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,15) = strpad('k_RP_AP in component sodium_current_voltage_dependent_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,28) = strpad('k_AP_RP in component sodium_current_voltage_dependent_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,38) = strpad('k_RI_AI in component sodium_current_voltage_dependent_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,34) = strpad('k_AI_RI in component sodium_current_voltage_dependent_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,31) = strpad('k_AP_AI in component sodium_current_voltage_dependent_gate (per_millisecond)');
    LEGEND_CONSTANTS(:,19) = strpad('k_AI_AP in component sodium_current_voltage_dependent_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,41) = strpad('k_RP_RI in component sodium_current_voltage_dependent_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,44) = strpad('k_RI_RP in component sodium_current_voltage_dependent_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,3) = strpad('alpha_y in component sodium_current_ultra_slow_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,16) = strpad('beta_y in component sodium_current_ultra_slow_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,47) = strpad('p_open_CaL in component L_type_Ca_channel (dimensionless)');
    LEGEND_ALGEBRAIC(:,53) = strpad('CaDiadic in component L_type_Ca_channel_Ca_dependent_gate (picoA)');
    LEGEND_CONSTANTS(:,20) = strpad('P_CaL in component L_type_Ca_channel (picoA_per_millimolar)');
    LEGEND_STATES(:,10) = strpad('p_AP_CaL in component L_type_Ca_channel_voltage_dependent_gate (dimensionless)');
    LEGEND_STATES(:,11) = strpad('p_U in component L_type_Ca_channel_Ca_dependent_gate (dimensionless)');
    LEGEND_STATES(:,12) = strpad('p_UCa in component L_type_Ca_channel_Ca_dependent_gate (dimensionless)');
    LEGEND_STATES(:,13) = strpad('y in component L_type_Ca_channel_ultra_slow_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,4) = strpad('p_RI_CaL in component L_type_Ca_channel_voltage_dependent_gate (dimensionless)');
    LEGEND_STATES(:,14) = strpad('p_RP_CaL in component L_type_Ca_channel_voltage_dependent_gate (dimensionless)');
    LEGEND_STATES(:,15) = strpad('p_AI_CaL in component L_type_Ca_channel_voltage_dependent_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,17) = strpad('k_RP_AP in component L_type_Ca_channel_voltage_dependent_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,29) = strpad('k_AP_RP in component L_type_Ca_channel_voltage_dependent_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,32) = strpad('k_RI_AI in component L_type_Ca_channel_voltage_dependent_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,35) = strpad('k_AI_RI in component L_type_Ca_channel_voltage_dependent_gate (per_millisecond)');
    LEGEND_CONSTANTS(:,21) = strpad('k_AP_AI in component L_type_Ca_channel_voltage_dependent_gate (per_millisecond)');
    LEGEND_CONSTANTS(:,22) = strpad('k_AI_AP in component L_type_Ca_channel_voltage_dependent_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,39) = strpad('k_RP_RI in component L_type_Ca_channel_voltage_dependent_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,42) = strpad('k_RI_RP in component L_type_Ca_channel_voltage_dependent_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,52) = strpad('iCaL in component L_type_Ca_channel_Ca_dependent_gate (picoA)');
    LEGEND_ALGEBRAIC(:,54) = strpad('Cacm in component L_type_Ca_channel_Ca_dependent_gate (millimolar)');
    LEGEND_ALGEBRAIC(:,63) = strpad('p_CCa in component L_type_Ca_channel_Ca_dependent_gate (dimensionless)');
    LEGEND_STATES(:,16) = strpad('p_C in component L_type_Ca_channel_Ca_dependent_gate (dimensionless)');
    LEGEND_CONSTANTS(:,23) = strpad('k_CCa_UCa in component L_type_Ca_channel_Ca_dependent_gate (per_millisecond)');
    LEGEND_CONSTANTS(:,24) = strpad('k_UCa_CCa in component L_type_Ca_channel_Ca_dependent_gate (per_millisecond)');
    LEGEND_CONSTANTS(:,25) = strpad('k_C_U in component L_type_Ca_channel_Ca_dependent_gate (per_millisecond)');
    LEGEND_CONSTANTS(:,26) = strpad('k_U_C in component L_type_Ca_channel_Ca_dependent_gate (per_millisecond)');
    LEGEND_CONSTANTS(:,93) = strpad('k_UCa_U in component L_type_Ca_channel_Ca_dependent_gate (per_millisecond)');
    LEGEND_CONSTANTS(:,27) = strpad('k_U_UCa in component L_type_Ca_channel_Ca_dependent_gate (per_millimolar_millisecond)');
    LEGEND_CONSTANTS(:,28) = strpad('k_CCa_C in component L_type_Ca_channel_Ca_dependent_gate (per_millisecond)');
    LEGEND_CONSTANTS(:,29) = strpad('k_C_CCa in component L_type_Ca_channel_Ca_dependent_gate (per_millimolar_millisecond)');
    LEGEND_ALGEBRAIC(:,56) = strpad('CaEffC in component L_type_Ca_channel_Ca_dependent_gate (millimolar)');
    LEGEND_ALGEBRAIC(:,58) = strpad('CaEffU in component L_type_Ca_channel_Ca_dependent_gate (millimolar)');
    LEGEND_ALGEBRAIC(:,61) = strpad('k_UUCa_Ca in component L_type_Ca_channel_Ca_dependent_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,59) = strpad('k_CCCa_Ca in component L_type_Ca_channel_Ca_dependent_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,5) = strpad('alpha_y in component L_type_Ca_channel_ultra_slow_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,18) = strpad('beta_y in component L_type_Ca_channel_ultra_slow_gate (per_millisecond)');
    LEGEND_CONSTANTS(:,30) = strpad('P_CaT in component T_type_Ca_channel (picoA_per_millimolar)');
    LEGEND_STATES(:,17) = strpad('y1 in component T_type_Ca_channel_y1_gate (dimensionless)');
    LEGEND_STATES(:,18) = strpad('y2 in component T_type_Ca_channel_y2_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,6) = strpad('alpha_y1 in component T_type_Ca_channel_y1_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,19) = strpad('beta_y1 in component T_type_Ca_channel_y1_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,7) = strpad('alpha_y2 in component T_type_Ca_channel_y2_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,20) = strpad('beta_y2 in component T_type_Ca_channel_y2_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,57) = strpad('E_K in component time_independent_potassium_current (millivolt)');
    LEGEND_CONSTANTS(:,94) = strpad('g_K1 in component time_independent_potassium_current (nanoS)');
    LEGEND_CONSTANTS(:,31) = strpad('P_K1_0 in component time_independent_potassium_current (nanoS_per_picoF)');
    LEGEND_ALGEBRAIC(:,65) = strpad('fO in component time_independent_potassium_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,66) = strpad('fO2 in component time_independent_potassium_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,68) = strpad('fO3 in component time_independent_potassium_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,70) = strpad('fO4 in component time_independent_potassium_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,64) = strpad('fB in component time_independent_potassium_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,60) = strpad('mu in component time_independent_potassium_current (per_millisecond)');
    LEGEND_ALGEBRAIC(:,62) = strpad('lambda in component time_independent_potassium_current (per_millisecond)');
    LEGEND_STATES(:,19) = strpad('y in component time_independent_potassium_current_y_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,67) = strpad('alpha_y in component time_independent_potassium_current_y_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,69) = strpad('beta_y in component time_independent_potassium_current_y_gate (per_millisecond)');
    LEGEND_CONSTANTS(:,95) = strpad('g_Kr in component rapid_time_dependent_potassium_current (nanoS)');
    LEGEND_CONSTANTS(:,32) = strpad('P_Kr in component rapid_time_dependent_potassium_current (nanoS_per_picoF)');
    LEGEND_STATES(:,20) = strpad('y1 in component rapid_time_dependent_potassium_current_y1_gate (dimensionless)');
    LEGEND_STATES(:,21) = strpad('y2 in component rapid_time_dependent_potassium_current_y2_gate (dimensionless)');
    LEGEND_STATES(:,22) = strpad('y3 in component rapid_time_dependent_potassium_current_y3_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,8) = strpad('alpha_y1 in component rapid_time_dependent_potassium_current_y1_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,21) = strpad('beta_y1 in component rapid_time_dependent_potassium_current_y1_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,9) = strpad('alpha_y2 in component rapid_time_dependent_potassium_current_y2_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,22) = strpad('beta_y2 in component rapid_time_dependent_potassium_current_y2_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,10) = strpad('alpha_y3 in component rapid_time_dependent_potassium_current_y3_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,23) = strpad('beta_y3 in component rapid_time_dependent_potassium_current_y3_gate (per_millisecond)');
    LEGEND_STATES(:,23) = strpad('y1 in component slow_time_dependent_potassium_current_y1_gate (dimensionless)');
    LEGEND_STATES(:,24) = strpad('y2 in component slow_time_dependent_potassium_current_y2_gate (dimensionless)');
    LEGEND_CONSTANTS(:,33) = strpad('P_Ks_K in component slow_time_dependent_potassium_current (picoA_per_millimolar)');
    LEGEND_CONSTANTS(:,34) = strpad('P_Ks_Na in component slow_time_dependent_potassium_current (picoA_per_millimolar)');
    LEGEND_ALGEBRAIC(:,11) = strpad('alpha_y1 in component slow_time_dependent_potassium_current_y1_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,24) = strpad('beta_y1 in component slow_time_dependent_potassium_current_y1_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,36) = strpad('alpha_y2 in component slow_time_dependent_potassium_current_y2_gate (per_millisecond)');
    LEGEND_CONSTANTS(:,35) = strpad('beta_y2 in component slow_time_dependent_potassium_current_y2_gate (per_millisecond)');
    LEGEND_STATES(:,25) = strpad('y1 in component transient_outward_current_y1_gate (dimensionless)');
    LEGEND_STATES(:,26) = strpad('y2 in component transient_outward_current_y2_gate (dimensionless)');
    LEGEND_CONSTANTS(:,36) = strpad('P_to_K in component transient_outward_current (picoA_per_millimolar)');
    LEGEND_CONSTANTS(:,37) = strpad('P_to_Na in component transient_outward_current (picoA_per_millimolar)');
    LEGEND_ALGEBRAIC(:,12) = strpad('alpha_y1 in component transient_outward_current_y1_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,25) = strpad('beta_y1 in component transient_outward_current_y1_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,13) = strpad('alpha_y2 in component transient_outward_current_y2_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,26) = strpad('beta_y2 in component transient_outward_current_y2_gate (per_millisecond)');
    LEGEND_CONSTANTS(:,38) = strpad('P_bNSC in component background_NSC_current (picoA_per_millimolar)');
    LEGEND_CONSTANTS(:,96) = strpad('P_Kpl in component background_Kpl_current (nanoS_per_millimolar)');
    LEGEND_CONSTANTS(:,39) = strpad('P_lCa in component background_lCa_current (picoA_per_millimolar)');
    LEGEND_ALGEBRAIC(:,83) = strpad('p_open in component background_lCa_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,87) = strpad('p_open in component background_KATP_current (dimensionless)');
    LEGEND_CONSTANTS(:,97) = strpad('gamma in component background_KATP_current (nanoS)');
    LEGEND_CONSTANTS(:,40) = strpad('P_KATP in component background_KATP_current (nanoS_per_picoF)');
    LEGEND_CONSTANTS(:,41) = strpad('N in component background_KATP_current (picoF)');
    LEGEND_CONSTANTS(:,42) = strpad('P_Cab in component background_Cab_current (picoA_per_millimolar)');
    LEGEND_CONSTANTS(:,98) = strpad('p_E2Na in component sodium_calcium_exchanger (dimensionless)');
    LEGEND_ALGEBRAIC(:,91) = strpad('p_E1Na in component sodium_calcium_exchanger (dimensionless)');
    LEGEND_ALGEBRAIC(:,92) = strpad('p_E1Ca in component sodium_calcium_exchanger (dimensionless)');
    LEGEND_CONSTANTS(:,101) = strpad('p_E2Ca in component sodium_calcium_exchanger (dimensionless)');
    LEGEND_ALGEBRAIC(:,93) = strpad('k1 in component sodium_calcium_exchanger (per_millisecond)');
    LEGEND_ALGEBRAIC(:,94) = strpad('k2 in component sodium_calcium_exchanger (per_millisecond)');
    LEGEND_CONSTANTS(:,43) = strpad('k3 in component sodium_calcium_exchanger (per_millisecond)');
    LEGEND_CONSTANTS(:,44) = strpad('k4 in component sodium_calcium_exchanger (per_millisecond)');
    LEGEND_CONSTANTS(:,45) = strpad('Km_Nai in component sodium_calcium_exchanger (millimolar)');
    LEGEND_CONSTANTS(:,46) = strpad('Km_Nao in component sodium_calcium_exchanger (millimolar)');
    LEGEND_CONSTANTS(:,47) = strpad('Km_Cai in component sodium_calcium_exchanger (millimolar)');
    LEGEND_CONSTANTS(:,48) = strpad('Km_Cao in component sodium_calcium_exchanger (millimolar)');
    LEGEND_STATES(:,27) = strpad('y in component sodium_calcium_exchanger_y_gate (dimensionless)');
    LEGEND_CONSTANTS(:,49) = strpad('P_NaCa in component sodium_calcium_exchanger (picoA_per_picoF)');
    LEGEND_CONSTANTS(:,50) = strpad('Partition in component sodium_calcium_exchanger (dimensionless)');
    LEGEND_ALGEBRAIC(:,96) = strpad('alpha_y in component sodium_calcium_exchanger_y_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,98) = strpad('beta_y in component sodium_calcium_exchanger_y_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,103) = strpad('p_E2Na in component sodium_potassium_pump (dimensionless)');
    LEGEND_ALGEBRAIC(:,99) = strpad('p_E1Na in component sodium_potassium_pump (dimensionless)');
    LEGEND_ALGEBRAIC(:,100) = strpad('p_E1K in component sodium_potassium_pump (dimensionless)');
    LEGEND_ALGEBRAIC(:,105) = strpad('p_E2K in component sodium_potassium_pump (dimensionless)');
    LEGEND_ALGEBRAIC(:,101) = strpad('k1 in component sodium_potassium_pump (per_millisecond)');
    LEGEND_CONSTANTS(:,51) = strpad('k2 in component sodium_potassium_pump (per_millisecond)');
    LEGEND_CONSTANTS(:,52) = strpad('k3 in component sodium_potassium_pump (per_millisecond)');
    LEGEND_CONSTANTS(:,53) = strpad('k4 in component sodium_potassium_pump (per_millisecond)');
    LEGEND_CONSTANTS(:,54) = strpad('Km_Nai in component sodium_potassium_pump (millimolar)');
    LEGEND_CONSTANTS(:,55) = strpad('Km_Nao in component sodium_potassium_pump (millimolar)');
    LEGEND_CONSTANTS(:,56) = strpad('Km_Ki in component sodium_potassium_pump (millimolar)');
    LEGEND_CONSTANTS(:,57) = strpad('Km_Ko in component sodium_potassium_pump (millimolar)');
    LEGEND_CONSTANTS(:,58) = strpad('Km_ATP in component sodium_potassium_pump (millimolar)');
    LEGEND_ALGEBRAIC(:,102) = strpad('Nao_Eff in component sodium_potassium_pump (millimolar)');
    LEGEND_STATES(:,28) = strpad('y in component sodium_potassium_pump_y_gate (dimensionless)');
    LEGEND_CONSTANTS(:,59) = strpad('P_NaK in component sodium_potassium_pump (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,110) = strpad('alpha_y in component sodium_potassium_pump_y_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,112) = strpad('beta_y in component sodium_potassium_pump_y_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,111) = strpad('p_E2Ca in component SR_calcium_pump (dimensionless)');
    LEGEND_ALGEBRAIC(:,109) = strpad('p_E1Ca in component SR_calcium_pump (dimensionless)');
    LEGEND_ALGEBRAIC(:,113) = strpad('p_E1 in component SR_calcium_pump (dimensionless)');
    LEGEND_ALGEBRAIC(:,114) = strpad('p_E2 in component SR_calcium_pump (dimensionless)');
    LEGEND_CONSTANTS(:,60) = strpad('k1 in component SR_calcium_pump (per_millisecond)');
    LEGEND_ALGEBRAIC(:,115) = strpad('k2 in component SR_calcium_pump (per_millisecond)');
    LEGEND_CONSTANTS(:,61) = strpad('k3 in component SR_calcium_pump (per_millisecond)');
    LEGEND_CONSTANTS(:,62) = strpad('k4 in component SR_calcium_pump (per_millisecond)');
    LEGEND_CONSTANTS(:,63) = strpad('Km_CaSR in component SR_calcium_pump (millimolar)');
    LEGEND_CONSTANTS(:,64) = strpad('Km_CaCyto in component SR_calcium_pump (millimolar)');
    LEGEND_CONSTANTS(:,65) = strpad('Km_ATP in component SR_calcium_pump (millimolar)');
    LEGEND_CONSTANTS(:,66) = strpad('i_max in component SR_calcium_pump (picoA)');
    LEGEND_STATES(:,29) = strpad('Caup in component Ca_concentrations_in_SR (millimolar)');
    LEGEND_STATES(:,30) = strpad('y in component SR_calcium_pump_y_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,117) = strpad('alpha_y in component SR_calcium_pump_y_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,119) = strpad('beta_y in component SR_calcium_pump_y_gate (per_millisecond)');
    LEGEND_CONSTANTS(:,67) = strpad('P_RyR in component RyR_channel (picoA_per_millimolar)');
    LEGEND_ALGEBRAIC(:,120) = strpad('k1 in component RyR_channel (per_millisecond)');
    LEGEND_ALGEBRAIC(:,125) = strpad('k2 in component RyR_channel (per_millisecond)');
    LEGEND_ALGEBRAIC(:,126) = strpad('k3 in component RyR_channel (per_millisecond)');
    LEGEND_CONSTANTS(:,68) = strpad('k4 in component RyR_channel (per_millisecond)');
    LEGEND_STATES(:,31) = strpad('p_open_RyR in component RyR_channel (dimensionless)');
    LEGEND_STATES(:,32) = strpad('p_close_RyR in component RyR_channel (dimensionless)');
    LEGEND_ALGEBRAIC(:,124) = strpad('Carel in component Ca_concentrations_in_SR (millimolar)');
    LEGEND_CONSTANTS(:,69) = strpad('Diadid_Factor in component RyR_channel (per_picoA_millisecond)');
    LEGEND_ALGEBRAIC(:,128) = strpad('i_SR_T in component SR_T_current (picoA)');
    LEGEND_CONSTANTS(:,70) = strpad('P_SR_T in component SR_T_current (picoA_per_millimolar)');
    LEGEND_CONSTANTS(:,71) = strpad('P_SR_L in component SR_L_current (picoA_per_millimolar)');
    LEGEND_STATES(:,33) = strpad('Ca_Total in component Ca_concentrations_in_SR (millimolar)');
    LEGEND_CONSTANTS(:,72) = strpad('V_rel in component Ca_concentrations_in_SR (micrometre3)');
    LEGEND_CONSTANTS(:,73) = strpad('V_up in component Ca_concentrations_in_SR (micrometre3)');
    LEGEND_CONSTANTS(:,74) = strpad('CSQN_max in component Ca_concentrations_in_SR (millimolar)');
    LEGEND_CONSTANTS(:,75) = strpad('K_mCSQN in component Ca_concentrations_in_SR (millimolar)');
    LEGEND_ALGEBRAIC(:,122) = strpad('b1 in component Ca_concentrations_in_SR (millimolar)');
    LEGEND_ALGEBRAIC(:,123) = strpad('c1 in component Ca_concentrations_in_SR (millimolar2)');
    LEGEND_CONSTANTS(:,99) = strpad('EffFraction in component NL_model (dimensionless)');
    LEGEND_STATES(:,34) = strpad('pCa in component NL_model (dimensionless)');
    LEGEND_STATES(:,35) = strpad('pCaCB in component NL_model (dimensionless)');
    LEGEND_STATES(:,36) = strpad('pCB in component NL_model (dimensionless)');
    LEGEND_ALGEBRAIC(:,131) = strpad('p in component NL_model (dimensionless)');
    LEGEND_CONSTANTS(:,76) = strpad('T_t in component NL_model (millimolar)');
    LEGEND_ALGEBRAIC(:,135) = strpad('Q_a in component NL_model (per_millisecond)');
    LEGEND_ALGEBRAIC(:,133) = strpad('Q_b in component NL_model (per_millisecond)');
    LEGEND_ALGEBRAIC(:,137) = strpad('Q_r in component NL_model (per_millisecond)');
    LEGEND_ALGEBRAIC(:,138) = strpad('Q_d in component NL_model (per_millisecond)');
    LEGEND_ALGEBRAIC(:,139) = strpad('Q_d1 in component NL_model (per_millisecond)');
    LEGEND_ALGEBRAIC(:,140) = strpad('Q_d2 in component NL_model (per_millisecond)');
    LEGEND_CONSTANTS(:,77) = strpad('Y_1 in component NL_model (per_millimolar_millisecond)');
    LEGEND_CONSTANTS(:,78) = strpad('Y_2 in component NL_model (per_millisecond)');
    LEGEND_CONSTANTS(:,79) = strpad('Y_3 in component NL_model (per_millisecond)');
    LEGEND_CONSTANTS(:,80) = strpad('Y_4 in component NL_model (per_millisecond)');
    LEGEND_CONSTANTS(:,81) = strpad('Y_d in component NL_model (millisecond_per_micrometre2)');
    LEGEND_CONSTANTS(:,82) = strpad('Z_1 in component NL_model (per_millisecond)');
    LEGEND_CONSTANTS(:,83) = strpad('Z_2 in component NL_model (per_millisecond)');
    LEGEND_CONSTANTS(:,84) = strpad('Z_3 in component NL_model (per_millimolar_millisecond)');
    LEGEND_ALGEBRAIC(:,129) = strpad('h in component NL_model (micrometre)');
    LEGEND_CONSTANTS(:,85) = strpad('L_a in component NL_model (micrometre)');
    LEGEND_CONSTANTS(:,86) = strpad('L in component NL_model (micrometre)');
    LEGEND_ALGEBRAIC(:,134) = strpad('ForceCB in component NL_model (mN_per_mm2)');
    LEGEND_STATES(:,37) = strpad('X in component NL_model (micrometre)');
    LEGEND_ALGEBRAIC(:,132) = strpad('NewCBF in component NL_model (mN_per_mm2_micrometre)');
    LEGEND_ALGEBRAIC(:,130) = strpad('CBBound in component NL_model (millimolar)');
    LEGEND_CONSTANTS(:,87) = strpad('KForceEC in component NL_model (mN_per_mm2_micrometre5)');
    LEGEND_CONSTANTS(:,88) = strpad('ZeroForceEL in component NL_model (micrometre)');
    LEGEND_CONSTANTS(:,89) = strpad('KForceLinearEc in component NL_model (mN_per_mm2_micrometre)');
    LEGEND_CONSTANTS(:,90) = strpad('ForceFactor in component NL_model (mN_per_mm2_micrometre_millimolar)');
    LEGEND_CONSTANTS(:,100) = strpad('ForceEcomp in component NL_model (mN_per_mm2)');
    LEGEND_CONSTANTS(:,91) = strpad('B in component NL_model (per_millisecond)');
    LEGEND_CONSTANTS(:,92) = strpad('h_c in component NL_model (micrometre)');
    LEGEND_ALGEBRAIC(:,136) = strpad('ForceExt in component NL_model (mN_per_mm2)');
    LEGEND_RATES(:,1) = strpad('d/dt Vm in component membrane (millivolt)');
    LEGEND_RATES(:,2) = strpad('d/dt Nai in component internal_ion_concentrations (millimolar)');
    LEGEND_RATES(:,3) = strpad('d/dt Ki in component internal_ion_concentrations (millimolar)');
    LEGEND_RATES(:,4) = strpad('d/dt Ca_Total in component internal_ion_concentrations (millimolar)');
    LEGEND_RATES(:,5) = strpad('d/dt ATPi in component ATP_production (millimolar)');
    LEGEND_RATES(:,8) = strpad('d/dt p_RP_Na in component sodium_current_voltage_dependent_gate (dimensionless)');
    LEGEND_RATES(:,6) = strpad('d/dt p_AP_Na in component sodium_current_voltage_dependent_gate (dimensionless)');
    LEGEND_RATES(:,9) = strpad('d/dt p_AI_Na in component sodium_current_voltage_dependent_gate (dimensionless)');
    LEGEND_RATES(:,7) = strpad('d/dt y in component sodium_current_ultra_slow_gate (dimensionless)');
    LEGEND_RATES(:,14) = strpad('d/dt p_RP_CaL in component L_type_Ca_channel_voltage_dependent_gate (dimensionless)');
    LEGEND_RATES(:,10) = strpad('d/dt p_AP_CaL in component L_type_Ca_channel_voltage_dependent_gate (dimensionless)');
    LEGEND_RATES(:,15) = strpad('d/dt p_AI_CaL in component L_type_Ca_channel_voltage_dependent_gate (dimensionless)');
    LEGEND_RATES(:,11) = strpad('d/dt p_U in component L_type_Ca_channel_Ca_dependent_gate (dimensionless)');
    LEGEND_RATES(:,12) = strpad('d/dt p_UCa in component L_type_Ca_channel_Ca_dependent_gate (dimensionless)');
    LEGEND_RATES(:,16) = strpad('d/dt p_C in component L_type_Ca_channel_Ca_dependent_gate (dimensionless)');
    LEGEND_RATES(:,13) = strpad('d/dt y in component L_type_Ca_channel_ultra_slow_gate (dimensionless)');
    LEGEND_RATES(:,17) = strpad('d/dt y1 in component T_type_Ca_channel_y1_gate (dimensionless)');
    LEGEND_RATES(:,18) = strpad('d/dt y2 in component T_type_Ca_channel_y2_gate (dimensionless)');
    LEGEND_RATES(:,19) = strpad('d/dt y in component time_independent_potassium_current_y_gate (dimensionless)');
    LEGEND_RATES(:,20) = strpad('d/dt y1 in component rapid_time_dependent_potassium_current_y1_gate (dimensionless)');
    LEGEND_RATES(:,21) = strpad('d/dt y2 in component rapid_time_dependent_potassium_current_y2_gate (dimensionless)');
    LEGEND_RATES(:,22) = strpad('d/dt y3 in component rapid_time_dependent_potassium_current_y3_gate (dimensionless)');
    LEGEND_RATES(:,23) = strpad('d/dt y1 in component slow_time_dependent_potassium_current_y1_gate (dimensionless)');
    LEGEND_RATES(:,24) = strpad('d/dt y2 in component slow_time_dependent_potassium_current_y2_gate (dimensionless)');
    LEGEND_RATES(:,25) = strpad('d/dt y1 in component transient_outward_current_y1_gate (dimensionless)');
    LEGEND_RATES(:,26) = strpad('d/dt y2 in component transient_outward_current_y2_gate (dimensionless)');
    LEGEND_RATES(:,27) = strpad('d/dt y in component sodium_calcium_exchanger_y_gate (dimensionless)');
    LEGEND_RATES(:,28) = strpad('d/dt y in component sodium_potassium_pump_y_gate (dimensionless)');
    LEGEND_RATES(:,30) = strpad('d/dt y in component SR_calcium_pump_y_gate (dimensionless)');
    LEGEND_RATES(:,31) = strpad('d/dt p_open_RyR in component RyR_channel (dimensionless)');
    LEGEND_RATES(:,32) = strpad('d/dt p_close_RyR in component RyR_channel (dimensionless)');
    LEGEND_RATES(:,33) = strpad('d/dt Ca_Total in component Ca_concentrations_in_SR (millimolar)');
    LEGEND_RATES(:,29) = strpad('d/dt Caup in component Ca_concentrations_in_SR (millimolar)');
    LEGEND_RATES(:,37) = strpad('d/dt X in component NL_model (micrometre)');
    LEGEND_RATES(:,34) = strpad('d/dt pCa in component NL_model (dimensionless)');
    LEGEND_RATES(:,35) = strpad('d/dt pCaCB in component NL_model (dimensionless)');
    LEGEND_RATES(:,36) = strpad('d/dt pCB in component NL_model (dimensionless)');
    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) = -85.95752434460744;
    CONSTANTS(:,1) = 8.3143;
    CONSTANTS(:,2) = 310;
    CONSTANTS(:,3) = 96.4867;
    CONSTANTS(:,4) = 132;
    CONSTANTS(:,5) = 50;
    CONSTANTS(:,6) = 1000000;
    CONSTANTS(:,7) = 400;
    CONSTANTS(:,8) = 2;
    CONSTANTS(:,9) = -4000;
    CONSTANTS(:,10) = 140;
    CONSTANTS(:,11) = 1.8;
    CONSTANTS(:,12) = 5.4;
    STATES(:,2) = 4.925761439682025;
    STATES(:,3) = 143.1837333000449;
    CONSTANTS(:,13) = 8000;
    CONSTANTS(:,14) = 0.05;
    CONSTANTS(:,15) = 0.00238;
    STATES(:,4) = 4.0180173572968586e-4;
    STATES(:,5) = 4.657102729020499;
    CONSTANTS(:,16) = 0.003;
    CONSTANTS(:,17) = 5;
    CONSTANTS(:,18) = 2860;
    STATES(:,6) = 1.779648367445368e-5;
    STATES(:,7) = 0.5861887862983165;
    STATES(:,8) = 0.3556412697995689;
    STATES(:,9) = 0.40285968661346977;
    CONSTANTS(:,19) = 0.0000875;
    CONSTANTS(:,20) = 8712;
    STATES(:,10) = 1.5445004166497696e-6;
    STATES(:,11) = 0.17246483915629204;
    STATES(:,12) = 6.098246017787626e-5;
    STATES(:,13) = 0.9985266538252986;
    STATES(:,14) = 0.9968480629364956;
    STATES(:,15) = 8.77325391245903e-4;
    CONSTANTS(:,21) = 0.004;
    CONSTANTS(:,22) = 0.001;
    STATES(:,16) = 0.4250747299372254;
    CONSTANTS(:,23) = 0.0003;
    CONSTANTS(:,24) = 0.35;
    CONSTANTS(:,25) = 0.143;
    CONSTANTS(:,26) = 0.35;
    CONSTANTS(:,27) = 6.954;
    CONSTANTS(:,28) = 0.0042;
    CONSTANTS(:,29) = 6.954;
    CONSTANTS(:,30) = 612;
    STATES(:,17) = 1.6882718240109127e-5;
    STATES(:,18) = 0.8585352091865849;
    CONSTANTS(:,31) = 1.146;
    STATES(:,19) = 0.6080573900752752;
    CONSTANTS(:,32) = 0.00864;
    STATES(:,20) = 0.0018339931180983765;
    STATES(:,21) = 0.20443083454225305;
    STATES(:,22) = 0.967887666264921;
    STATES(:,23) = 0.09738789658609195;
    STATES(:,24) = 0.09745345578743213;
    CONSTANTS(:,33) = 5.04;
    CONSTANTS(:,34) = 0.2016;
    CONSTANTS(:,35) = 0.004444;
    STATES(:,25) = 7.956883250874798e-4;
    STATES(:,26) = 0.9999125083105881;
    CONSTANTS(:,36) = 0.033;
    CONSTANTS(:,37) = 0.00297;
    CONSTANTS(:,38) = 0.385;
    CONSTANTS(:,39) = 0.11;
    CONSTANTS(:,40) = 0.0236;
    CONSTANTS(:,41) = 2333;
    CONSTANTS(:,42) = 0.04;
    CONSTANTS(:,43) = 1;
    CONSTANTS(:,44) = 1;
    CONSTANTS(:,45) = 8.75;
    CONSTANTS(:,46) = 87.5;
    CONSTANTS(:,47) = 0.00138;
    CONSTANTS(:,48) = 1.38;
    STATES(:,27) = 0.9891789193465331;
    CONSTANTS(:,49) = 6.81;
    CONSTANTS(:,50) = 0.32;
    CONSTANTS(:,51) = 0.04;
    CONSTANTS(:,52) = 0.01;
    CONSTANTS(:,53) = 0.165;
    CONSTANTS(:,54) = 4.05;
    CONSTANTS(:,55) = 69.8;
    CONSTANTS(:,56) = 32.88;
    CONSTANTS(:,57) = 0.258;
    CONSTANTS(:,58) = 0.094;
    STATES(:,28) = 0.5910747147428818;
    CONSTANTS(:,59) = 21;
    CONSTANTS(:,60) = 0.01;
    CONSTANTS(:,61) = 1;
    CONSTANTS(:,62) = 0.01;
    CONSTANTS(:,63) = 0.08;
    CONSTANTS(:,64) = 0.0008;
    CONSTANTS(:,65) = 0.1;
    CONSTANTS(:,66) = 162500;
    STATES(:,29) = 2.611712901567567;
    STATES(:,30) = 0.46108441538480216;
    CONSTANTS(:,67) = 62000;
    CONSTANTS(:,68) = 0.000849;
    STATES(:,31) = 3.4314360001543243e-4;
    STATES(:,32) = 0.19135178123107768;
    CONSTANTS(:,69) = -150;
    CONSTANTS(:,70) = 386;
    CONSTANTS(:,71) = 459;
    STATES(:,33) = 9.455741736977666;
    CONSTANTS(:,72) = 160;
    CONSTANTS(:,73) = 400;
    CONSTANTS(:,74) = 10;
    CONSTANTS(:,75) = 0.8;
    STATES(:,34) = 0.02490898775497523;
    STATES(:,35) = 0.001990153835322864;
    STATES(:,36) = 4.2941813853474524e-4;
    CONSTANTS(:,76) = 0.07;
    CONSTANTS(:,77) = 39;
    CONSTANTS(:,78) = 0.0039;
    CONSTANTS(:,79) = 0.03;
    CONSTANTS(:,80) = 0.12;
    CONSTANTS(:,81) = 0.027;
    CONSTANTS(:,82) = 0.03;
    CONSTANTS(:,83) = 0.0039;
    CONSTANTS(:,84) = 1560;
    CONSTANTS(:,85) = 1.17;
    CONSTANTS(:,86) = 0.9623799975411884;
    STATES(:,37) = 0.9573749975411884;
    CONSTANTS(:,87) = 140000;
    CONSTANTS(:,88) = 0.97;
    CONSTANTS(:,89) = 200;
    CONSTANTS(:,90) = 1800000;
    CONSTANTS(:,91) = 1.2;
    CONSTANTS(:,92) = 0.005;
    CONSTANTS(:,93) = ( CONSTANTS(:,28).*CONSTANTS(:,25).*CONSTANTS(:,27).*CONSTANTS(:,24))./( CONSTANTS(:,26).*CONSTANTS(:,29).*CONSTANTS(:,23));
    CONSTANTS(:,94) =  CONSTANTS(:,31).*CONSTANTS(:,4).*power(CONSTANTS(:,12)./5.40000, 0.400000);
    CONSTANTS(:,95) =  CONSTANTS(:,32).*CONSTANTS(:,4).*power(CONSTANTS(:,12)./5.40000, 0.200000);
    CONSTANTS(:,96) =  0.000110000.*power(CONSTANTS(:,12)./5.40000, 0.160000);
    CONSTANTS(:,97) =  CONSTANTS(:,40).*CONSTANTS(:,41).*power(CONSTANTS(:,12)./1.00000, 0.240000);
    CONSTANTS(:,98) = 1.00000./(1.00000+ power(CONSTANTS(:,46)./CONSTANTS(:,10), 3.00000).*(1.00000+CONSTANTS(:,11)./CONSTANTS(:,48)));
    CONSTANTS(:,99) = exp(  - 20.0000.*power(CONSTANTS(:,86) - CONSTANTS(:,85), 2.00000));
    CONSTANTS(:,100) =  CONSTANTS(:,87).*power(CONSTANTS(:,88) - CONSTANTS(:,86), 5.00000)+ CONSTANTS(:,89).*(CONSTANTS(:,88) - CONSTANTS(:,86));
    CONSTANTS(:,101) = 1.00000./(1.00000+ (CONSTANTS(:,48)./CONSTANTS(:,11)).*(1.00000+power(CONSTANTS(:,10)./CONSTANTS(:,46), 3.00000)));
    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);
    else
        statesRowCount = statesSize(1);
        ALGEBRAIC = zeros(statesRowCount, algebraicVariableCount);
        RATES = zeros(statesRowCount, statesColumnCount);
    end
    ALGEBRAIC(:,3) = 1.00000./( 9.00000e+09.*exp(STATES(:,1)./5.00000)+ 8000.00.*exp(STATES(:,1)./100.000));
    ALGEBRAIC(:,16) = 1.00000./( 0.0140000.*exp( - STATES(:,1)./5.00000)+ 4000.00.*exp( - STATES(:,1)./100.000));
    RATES(:,7) =  ALGEBRAIC(:,3).*(1.00000 - STATES(:,7)) -  ALGEBRAIC(:,16).*STATES(:,7);
    ALGEBRAIC(:,5) = 1.00000./( 250000..*exp(STATES(:,1)./9.00000)+ 58.0000.*exp(STATES(:,1)./65.0000));
    ALGEBRAIC(:,18) = 1.00000./( 1800.00.*exp( - STATES(:,1)./14.0000)+ 66.0000.*exp( - STATES(:,1)./65.0000));
    RATES(:,13) =  ALGEBRAIC(:,5).*(1.00000 - STATES(:,13)) -  ALGEBRAIC(:,18).*STATES(:,13);
    ALGEBRAIC(:,6) = 1.00000./( 0.0190000.*exp( - STATES(:,1)./5.60000)+ 0.820000.*exp( - STATES(:,1)./250.000));
    ALGEBRAIC(:,19) = 1.00000./( 40.0000.*exp(STATES(:,1)./6.30000)+ 1.50000.*exp(STATES(:,1)./10000.0));
    RATES(:,17) =  ALGEBRAIC(:,6).*(1.00000 - STATES(:,17)) -  ALGEBRAIC(:,19).*STATES(:,17);
    ALGEBRAIC(:,7) = 1.00000./( 62000.0.*exp(STATES(:,1)./10.1000)+ 30.0000.*exp(STATES(:,1)./3000.00));
    ALGEBRAIC(:,20) = 1.00000./( 0.000600000.*exp( - STATES(:,1)./6.70000)+ 1.20000.*exp( - STATES(:,1)./25.0000));
    RATES(:,18) =  ALGEBRAIC(:,7).*(1.00000 - STATES(:,18)) -  ALGEBRAIC(:,20).*STATES(:,18);
    ALGEBRAIC(:,8) = 1.00000./( 20.0000.*exp( - STATES(:,1)./11.5000)+ 5.00000.*exp( - STATES(:,1)./300.000));
    ALGEBRAIC(:,21) = 1.00000./( 160.000.*exp(STATES(:,1)./28.0000)+ 200.000.*exp(STATES(:,1)./1000.00))+1.00000./( 2500.00.*exp(STATES(:,1)./20.0000));
    RATES(:,20) =  ALGEBRAIC(:,8).*(1.00000 - STATES(:,20)) -  ALGEBRAIC(:,21).*STATES(:,20);
    ALGEBRAIC(:,9) = 1.00000./( 200.000.*exp( - STATES(:,1)./13.0000)+ 20.0000.*exp( - STATES(:,1)./300.000));
    ALGEBRAIC(:,22) = 1.00000./( 1600.00.*exp(STATES(:,1)./28.0000)+ 2000.00.*exp(STATES(:,1)./1000.00))+1.00000./( 10000.0.*exp(STATES(:,1)./20.0000));
    RATES(:,21) =  ALGEBRAIC(:,9).*(1.00000 - STATES(:,21)) -  ALGEBRAIC(:,22).*STATES(:,21);
    ALGEBRAIC(:,10) = 1.00000./( 10.0000.*exp(STATES(:,1)./17.0000)+ 2.50000.*exp(STATES(:,1)./300.000));
    ALGEBRAIC(:,23) = 1.00000./( 0.350000.*exp( - STATES(:,1)./17.0000)+ 2.00000.*exp( - STATES(:,1)./150.000));
    RATES(:,22) =  ALGEBRAIC(:,10).*(1.00000 - STATES(:,22)) -  ALGEBRAIC(:,23).*STATES(:,22);
    ALGEBRAIC(:,11) = 1.00000./( 85.0000.*exp( - STATES(:,1)./10.5000)+ 370.000.*exp( - STATES(:,1)./62.0000));
    ALGEBRAIC(:,24) = 1.00000./( 1450.00.*exp(STATES(:,1)./20.0000)+ 260.000.*exp(STATES(:,1)./100.000));
    RATES(:,23) =  ALGEBRAIC(:,11).*(1.00000 - STATES(:,23)) -  ALGEBRAIC(:,24).*STATES(:,23);
    ALGEBRAIC(:,12) = 1.00000./( 11.0000.*exp( - STATES(:,1)./28.0000)+ 0.200000.*exp( - STATES(:,1)./400.000));
    ALGEBRAIC(:,25) = 1.00000./( 4.40000.*exp(STATES(:,1)./16.0000)+ 0.200000.*exp(STATES(:,1)./500.000));
    RATES(:,25) =  ALGEBRAIC(:,12).*(1.00000 - STATES(:,25)) -  ALGEBRAIC(:,25).*STATES(:,25);
    ALGEBRAIC(:,13) = ( 0.00380000.*exp( - (STATES(:,1)+13.5000)./11.3000))./(1.00000+ 0.0513350.*exp( - (STATES(:,1)+13.5000)./11.3000));
    ALGEBRAIC(:,26) = ( 0.00380000.*exp((STATES(:,1)+13.5000)./11.3000))./(1.00000+ 0.0670830.*exp((STATES(:,1)+13.5000)./11.3000));
    RATES(:,26) =  ALGEBRAIC(:,13).*(1.00000 - STATES(:,26)) -  ALGEBRAIC(:,26).*STATES(:,26);
    ALGEBRAIC(:,17) = 1.00000./( 0.270000.*exp( - STATES(:,1)./5.90000)+ 1.50000.*exp( - STATES(:,1)./65.0000));
    ALGEBRAIC(:,29) = 1.00000./( 480.000.*exp(STATES(:,1)./7.00000)+ 2.20000.*exp(STATES(:,1)./65.0000));
    RATES(:,10) = ( STATES(:,14).*ALGEBRAIC(:,17)+ STATES(:,15).*CONSTANTS(:,22)) -  STATES(:,10).*(ALGEBRAIC(:,29)+CONSTANTS(:,21));
    ALGEBRAIC(:,15) = 1.00000./( 0.102700.*exp( - STATES(:,1)./8.00000)+ 0.250000.*exp( - STATES(:,1)./50.0000));
    ALGEBRAIC(:,28) = 1.00000./( 26.0000.*exp(STATES(:,1)./17.0000)+ 0.0200000.*exp(STATES(:,1)./800.000));
    ALGEBRAIC(:,31) = 1.00000./( 0.800000.*exp( - STATES(:,1)./400.000));
    RATES(:,6) = ( STATES(:,8).*ALGEBRAIC(:,15)+ STATES(:,9).*CONSTANTS(:,19)) -  STATES(:,6).*(ALGEBRAIC(:,28)+ALGEBRAIC(:,31));
    ALGEBRAIC(:,4) = ((1.00000 - STATES(:,10)) - STATES(:,14)) - STATES(:,15);
    ALGEBRAIC(:,32) = 1.00000./( 0.00180000.*exp( - STATES(:,1)./7.40000)+ 2.00000.*exp( - STATES(:,1)./100.000));
    ALGEBRAIC(:,35) = 1.00000./( 2.20000e+06.*exp(STATES(:,1)./7.40000)+ 11.0000.*exp(STATES(:,1)./100.000));
    RATES(:,15) = ( ALGEBRAIC(:,4).*ALGEBRAIC(:,32)+ STATES(:,10).*CONSTANTS(:,21)) -  STATES(:,15).*(ALGEBRAIC(:,35)+CONSTANTS(:,22));
    ALGEBRAIC(:,14) = (CONSTANTS(:,14) - STATES(:,4))+CONSTANTS(:,15);
    ALGEBRAIC(:,27) =  CONSTANTS(:,15).*STATES(:,4);
    ALGEBRAIC(:,30) = (power((power(ALGEBRAIC(:,14), 2.00000)+ 4.00000.*ALGEBRAIC(:,27)), 1.0 ./ 2) - ALGEBRAIC(:,14))./2.00000;
    ALGEBRAIC(:,36) =  3.70000.*ALGEBRAIC(:,30);
    RATES(:,24) =  ALGEBRAIC(:,36).*(1.00000 - STATES(:,24)) -  CONSTANTS(:,35).*STATES(:,24);
    ALGEBRAIC(:,2) = ((1.00000 - STATES(:,8)) - STATES(:,6)) - STATES(:,9);
    ALGEBRAIC(:,38) = 1.00000./( 0.000102700.*exp( - STATES(:,1)./8.00000)+ 5.00000.*exp( - STATES(:,1)./400.000));
    ALGEBRAIC(:,34) = 1.00000./( 1300.00.*exp(STATES(:,1)./20.0000)+ 0.0400000.*exp(STATES(:,1)./800.000));
    RATES(:,9) = ( ALGEBRAIC(:,2).*ALGEBRAIC(:,38)+ STATES(:,6).*ALGEBRAIC(:,31)) -  STATES(:,9).*(ALGEBRAIC(:,34)+CONSTANTS(:,19));
    ALGEBRAIC(:,39) = 0.0400000./(1.00000+( CONSTANTS(:,22).*ALGEBRAIC(:,29).*ALGEBRAIC(:,32))./( CONSTANTS(:,21).*ALGEBRAIC(:,17).*ALGEBRAIC(:,35)));
    ALGEBRAIC(:,42) = 0.0400000 - ALGEBRAIC(:,39);
    RATES(:,14) = ( STATES(:,10).*ALGEBRAIC(:,29)+ ALGEBRAIC(:,4).*ALGEBRAIC(:,42)) -  STATES(:,14).*(ALGEBRAIC(:,39)+ALGEBRAIC(:,17));
    ALGEBRAIC(:,41) = 0.0100000./(1.00000+( CONSTANTS(:,19).*ALGEBRAIC(:,28).*ALGEBRAIC(:,38))./( ALGEBRAIC(:,31).*ALGEBRAIC(:,15).*ALGEBRAIC(:,34)));
    ALGEBRAIC(:,44) = 0.0100000 - ALGEBRAIC(:,41);
    RATES(:,8) = ( STATES(:,6).*ALGEBRAIC(:,28)+ ALGEBRAIC(:,2).*ALGEBRAIC(:,44)) -  STATES(:,8).*(ALGEBRAIC(:,41)+ALGEBRAIC(:,15));
    ALGEBRAIC(:,37) = piecewise({STATES(:,1)==0.00000,  - CONSTANTS(:,11) }, ( (( 2.00000.*CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*(ALGEBRAIC(:,30) -  CONSTANTS(:,11).*exp((  - 2.00000.*CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2)))))./(1.00000 - exp((  - 2.00000.*CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2)))));
    ALGEBRAIC(:,52) =  0.0676000.*ALGEBRAIC(:,37);
    ALGEBRAIC(:,54) = ALGEBRAIC(:,30) -  0.300000.*ALGEBRAIC(:,52);
    ALGEBRAIC(:,56) =  ALGEBRAIC(:,54).*STATES(:,10);
    ALGEBRAIC(:,58) = ALGEBRAIC(:,56)+ ALGEBRAIC(:,30).*(1.00000 - STATES(:,10));
    ALGEBRAIC(:,61) =  CONSTANTS(:,27).*ALGEBRAIC(:,58);
    RATES(:,11) = ( STATES(:,16).*CONSTANTS(:,25)+ STATES(:,12).*CONSTANTS(:,93)) -  STATES(:,11).*(ALGEBRAIC(:,61)+CONSTANTS(:,26));
    ALGEBRAIC(:,63) = ((1.00000 - STATES(:,16)) - STATES(:,11)) - STATES(:,12);
    RATES(:,12) = ( STATES(:,11).*ALGEBRAIC(:,61)+ ALGEBRAIC(:,63).*CONSTANTS(:,23)) -  STATES(:,12).*(CONSTANTS(:,24)+CONSTANTS(:,93));
    RATES(:,16) = ( ALGEBRAIC(:,63).*CONSTANTS(:,28)+ STATES(:,11).*CONSTANTS(:,26)) -  STATES(:,16).*(CONSTANTS(:,25)+ CONSTANTS(:,29).*ALGEBRAIC(:,54).*STATES(:,10));
    ALGEBRAIC(:,57) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,12)./STATES(:,3));
    ALGEBRAIC(:,67) = 1.00000./( 8000.00.*exp(((STATES(:,1) - ALGEBRAIC(:,57)) - 97.0000)./8.50000)+ 7.00000.*exp(((STATES(:,1) - ALGEBRAIC(:,57)) - 97.0000)./300.000));
    ALGEBRAIC(:,60) = ( 0.750000.*exp( 0.0350000.*((STATES(:,1) - ALGEBRAIC(:,57)) - 10.0000)))./(1.00000+exp( 0.0150000.*((STATES(:,1) - ALGEBRAIC(:,57)) - 140.000)));
    ALGEBRAIC(:,62) = ( 3.00000.*exp(  - 0.0480000.*((STATES(:,1) - ALGEBRAIC(:,57)) - 10.0000)).*(1.00000+exp( 0.0640000.*((STATES(:,1) - ALGEBRAIC(:,57)) - 38.0000))))./(1.00000+exp( 0.0300000.*((STATES(:,1) - ALGEBRAIC(:,57)) - 70.0000)));
    ALGEBRAIC(:,65) = ALGEBRAIC(:,62)./(ALGEBRAIC(:,60)+ALGEBRAIC(:,62));
    ALGEBRAIC(:,69) = ( power(ALGEBRAIC(:,65), 4.00000).*1.00000)./( 0.000140000.*exp( - ((STATES(:,1) - ALGEBRAIC(:,57)) - 97.0000)./9.10000)+ 0.200000.*exp( - ((STATES(:,1) - ALGEBRAIC(:,57)) - 97.0000)./500.000));
    RATES(:,19) =  ALGEBRAIC(:,67).*(1.00000 - STATES(:,19)) -  ALGEBRAIC(:,69).*STATES(:,19);
    ALGEBRAIC(:,94) =  1.00000.*exp(( (CONSTANTS(:,50) - 1.00000).*CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2)));
    ALGEBRAIC(:,96) =  ALGEBRAIC(:,94).*CONSTANTS(:,98)+ CONSTANTS(:,44).*CONSTANTS(:,101);
    ALGEBRAIC(:,91) = 1.00000./(1.00000+ power(CONSTANTS(:,45)./STATES(:,2), 3.00000).*(1.00000+ALGEBRAIC(:,30)./CONSTANTS(:,47)));
    ALGEBRAIC(:,92) = 1.00000./(1.00000+ (CONSTANTS(:,47)./ALGEBRAIC(:,30)).*(1.00000+power(STATES(:,2)./CONSTANTS(:,45), 3.00000)));
    ALGEBRAIC(:,93) =  1.00000.*exp(( CONSTANTS(:,50).*CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2)));
    ALGEBRAIC(:,98) =  ALGEBRAIC(:,93).*ALGEBRAIC(:,91)+ CONSTANTS(:,43).*ALGEBRAIC(:,92);
    RATES(:,27) =  ALGEBRAIC(:,96).*(1.00000 - STATES(:,27)) -  ALGEBRAIC(:,98).*STATES(:,27);
    ALGEBRAIC(:,1) = piecewise({VOI>=CONSTANTS(:,5)&VOI<=CONSTANTS(:,6)&(VOI - CONSTANTS(:,5)) -  floor((VOI - CONSTANTS(:,5))./CONSTANTS(:,7)).*CONSTANTS(:,7)<=CONSTANTS(:,8), CONSTANTS(:,9) }, 0.00000);
    ALGEBRAIC(:,33) = piecewise({STATES(:,1)==0.00000,  - CONSTANTS(:,10) }, ( (( CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*(STATES(:,2) -  CONSTANTS(:,10).*exp((  - CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2)))))./(1.00000 - exp((  - CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2)))));
    ALGEBRAIC(:,80) =  CONSTANTS(:,38).*ALGEBRAIC(:,33);
    ALGEBRAIC(:,40) = piecewise({STATES(:,1)==0.00000, STATES(:,3) }, ( (( CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*(STATES(:,3) -  CONSTANTS(:,12).*exp((  - CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2)))))./(1.00000 - exp((  - CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2)))));
    ALGEBRAIC(:,79) =  0.400000.*CONSTANTS(:,38).*ALGEBRAIC(:,40);
    ALGEBRAIC(:,81) = ALGEBRAIC(:,79)+ALGEBRAIC(:,80);
    ALGEBRAIC(:,89) =  CONSTANTS(:,42).*ALGEBRAIC(:,37);
    ALGEBRAIC(:,82) = piecewise({STATES(:,1)== - 3.00000,  CONSTANTS(:,96).*ALGEBRAIC(:,40).*13.0077 }, ( CONSTANTS(:,96).*ALGEBRAIC(:,40).*(STATES(:,1)+3.00000))./(1.00000 - exp( - (STATES(:,1)+3.00000)./13.0000)));
    ALGEBRAIC(:,83) = 1.00000./(1.00000+power(0.00120000./ALGEBRAIC(:,30), 3.00000));
    ALGEBRAIC(:,85) =  CONSTANTS(:,39).*ALGEBRAIC(:,33).*ALGEBRAIC(:,83);
    ALGEBRAIC(:,84) =  CONSTANTS(:,39).*ALGEBRAIC(:,40).*ALGEBRAIC(:,83);
    ALGEBRAIC(:,86) = ALGEBRAIC(:,84)+ALGEBRAIC(:,85);
    ALGEBRAIC(:,87) = 0.800000./(1.00000+power(STATES(:,5)./0.100000, 2.00000));
    ALGEBRAIC(:,88) =  CONSTANTS(:,97).*(STATES(:,1) - ALGEBRAIC(:,57)).*ALGEBRAIC(:,87);
    ALGEBRAIC(:,90) = ALGEBRAIC(:,81)+ALGEBRAIC(:,89)+ALGEBRAIC(:,82)+ALGEBRAIC(:,86)+ALGEBRAIC(:,88);
    ALGEBRAIC(:,43) =  CONSTANTS(:,18).*ALGEBRAIC(:,33).*STATES(:,6).*STATES(:,7);
    ALGEBRAIC(:,45) =  0.100000.*CONSTANTS(:,18).*ALGEBRAIC(:,40).*STATES(:,6).*STATES(:,7);
    ALGEBRAIC(:,46) = ALGEBRAIC(:,43)+ALGEBRAIC(:,45);
    ALGEBRAIC(:,47) = ( STATES(:,10).*(STATES(:,11)+STATES(:,12)).*STATES(:,13))./(1.00000+power(1.40000./STATES(:,5), 3.00000));
    ALGEBRAIC(:,49) =  1.85000e-05.*CONSTANTS(:,20).*ALGEBRAIC(:,33).*ALGEBRAIC(:,47);
    ALGEBRAIC(:,50) =  0.000365000.*CONSTANTS(:,20).*ALGEBRAIC(:,40).*ALGEBRAIC(:,47);
    ALGEBRAIC(:,48) =  CONSTANTS(:,20).*ALGEBRAIC(:,37).*ALGEBRAIC(:,47);
    ALGEBRAIC(:,51) = ALGEBRAIC(:,49)+ALGEBRAIC(:,48)+ALGEBRAIC(:,50);
    ALGEBRAIC(:,55) =  CONSTANTS(:,30).*ALGEBRAIC(:,37).*STATES(:,17).*STATES(:,18);
    ALGEBRAIC(:,64) = ALGEBRAIC(:,60)./(ALGEBRAIC(:,60)+ALGEBRAIC(:,62));
    ALGEBRAIC(:,66) =  2.00000.*power(ALGEBRAIC(:,65), 2.00000).*power(ALGEBRAIC(:,64), 2.00000);
    ALGEBRAIC(:,68) =  (8.00000./3.00000).*power(ALGEBRAIC(:,65), 3.00000).*ALGEBRAIC(:,64);
    ALGEBRAIC(:,70) = power(ALGEBRAIC(:,65), 4.00000);
    ALGEBRAIC(:,71) =  CONSTANTS(:,94).*(STATES(:,1) - ALGEBRAIC(:,57)).*(ALGEBRAIC(:,70)+ALGEBRAIC(:,68)+ALGEBRAIC(:,66)).*STATES(:,19);
    ALGEBRAIC(:,72) =  CONSTANTS(:,95).*(STATES(:,1) - ALGEBRAIC(:,57)).*( 0.600000.*STATES(:,20)+ 0.400000.*STATES(:,21)).*STATES(:,22);
    ALGEBRAIC(:,73) =  CONSTANTS(:,33).*ALGEBRAIC(:,40).*power(STATES(:,23), 2.00000).*( 0.900000.*STATES(:,24)+0.100000);
    ALGEBRAIC(:,74) =  CONSTANTS(:,34).*ALGEBRAIC(:,33).*power(STATES(:,23), 2.00000).*( 0.900000.*STATES(:,24)+0.100000);
    ALGEBRAIC(:,75) = ALGEBRAIC(:,74)+ALGEBRAIC(:,73);
    ALGEBRAIC(:,76) =  CONSTANTS(:,36).*ALGEBRAIC(:,40).*power(STATES(:,25), 3.00000).*STATES(:,26);
    ALGEBRAIC(:,77) =  CONSTANTS(:,37).*ALGEBRAIC(:,33).*power(STATES(:,25), 3.00000).*STATES(:,26);
    ALGEBRAIC(:,78) = ALGEBRAIC(:,77)+ALGEBRAIC(:,76);
    ALGEBRAIC(:,102) =  CONSTANTS(:,10).*exp((  - 0.820000.*CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2)));
    ALGEBRAIC(:,103) = 1.00000./(1.00000+ power(CONSTANTS(:,55)./ALGEBRAIC(:,102), 1.06000).*(1.00000+power(CONSTANTS(:,12)./CONSTANTS(:,57), 1.12000)));
    ALGEBRAIC(:,99) = 1.00000./(1.00000+ power(CONSTANTS(:,54)./STATES(:,2), 1.06000).*(1.00000+power(STATES(:,3)./CONSTANTS(:,56), 1.12000)));
    ALGEBRAIC(:,101) = 0.370000./(1.00000+CONSTANTS(:,58)./STATES(:,5));
    ALGEBRAIC(:,104) =  CONSTANTS(:,59).*CONSTANTS(:,4).*1.00000.*( ALGEBRAIC(:,101).*ALGEBRAIC(:,99).*STATES(:,28) -  CONSTANTS(:,51).*ALGEBRAIC(:,103).*(1.00000 - STATES(:,28)));
    ALGEBRAIC(:,95) =  CONSTANTS(:,49).*CONSTANTS(:,4).*1.00000.*( ALGEBRAIC(:,93).*ALGEBRAIC(:,91).*STATES(:,27) -  ALGEBRAIC(:,94).*CONSTANTS(:,98).*(1.00000 - STATES(:,27)));
    ALGEBRAIC(:,106) = ALGEBRAIC(:,46)+ALGEBRAIC(:,51)+ALGEBRAIC(:,55)+ALGEBRAIC(:,71)+ALGEBRAIC(:,72)+ALGEBRAIC(:,75)+ALGEBRAIC(:,78)+ALGEBRAIC(:,90)+ALGEBRAIC(:,104)+ALGEBRAIC(:,95);
    RATES(:,1) =  - (ALGEBRAIC(:,106)+ALGEBRAIC(:,1))./CONSTANTS(:,4);
    ALGEBRAIC(:,107) = ALGEBRAIC(:,43)+ALGEBRAIC(:,74)+ALGEBRAIC(:,77)+ALGEBRAIC(:,49)+ALGEBRAIC(:,80)+ALGEBRAIC(:,85)+ 3.00000.*ALGEBRAIC(:,104)+ 3.00000.*ALGEBRAIC(:,95);
    RATES(:,2) =  - ALGEBRAIC(:,107)./( CONSTANTS(:,3).*CONSTANTS(:,13));
    ALGEBRAIC(:,108) = (ALGEBRAIC(:,71)+ALGEBRAIC(:,72)+ALGEBRAIC(:,76)+ALGEBRAIC(:,88)+ALGEBRAIC(:,73)+ALGEBRAIC(:,45)+ALGEBRAIC(:,50)+ALGEBRAIC(:,79)+ALGEBRAIC(:,84)+ALGEBRAIC(:,82)) -  2.00000.*ALGEBRAIC(:,104);
    RATES(:,3) =  - (ALGEBRAIC(:,108)+ALGEBRAIC(:,1))./( CONSTANTS(:,3).*CONSTANTS(:,13));
    ALGEBRAIC(:,105) = 1.00000./(1.00000+ power(CONSTANTS(:,57)./CONSTANTS(:,12), 1.12000).*(1.00000+power(ALGEBRAIC(:,102)./CONSTANTS(:,55), 1.06000)));
    ALGEBRAIC(:,110) =  CONSTANTS(:,51).*ALGEBRAIC(:,103)+ CONSTANTS(:,53).*ALGEBRAIC(:,105);
    ALGEBRAIC(:,100) = 1.00000./(1.00000+ power(CONSTANTS(:,56)./STATES(:,3), 1.12000).*(1.00000+power(STATES(:,2)./CONSTANTS(:,54), 1.06000)));
    ALGEBRAIC(:,112) =  ALGEBRAIC(:,101).*ALGEBRAIC(:,99)+ CONSTANTS(:,52).*ALGEBRAIC(:,100);
    RATES(:,28) =  ALGEBRAIC(:,110).*(1.00000 - STATES(:,28)) -  ALGEBRAIC(:,112).*STATES(:,28);
    ALGEBRAIC(:,111) = 1.00000./(1.00000+CONSTANTS(:,64)./ALGEBRAIC(:,30));
    ALGEBRAIC(:,109) = 1.00000./(1.00000+CONSTANTS(:,63)./STATES(:,29));
    ALGEBRAIC(:,115) = 1.00000./(1.00000+CONSTANTS(:,65)./STATES(:,5));
    ALGEBRAIC(:,116) =  CONSTANTS(:,66).*1.00000.*( CONSTANTS(:,60).*ALGEBRAIC(:,109).*STATES(:,30) -  ALGEBRAIC(:,115).*ALGEBRAIC(:,111).*(1.00000 - STATES(:,30)));
    ALGEBRAIC(:,118) =   - 0.400000.*STATES(:,35).*CONSTANTS(:,76);
    RATES(:,5) = (( CONSTANTS(:,16).*(CONSTANTS(:,17) - STATES(:,5))+ALGEBRAIC(:,118)) - ALGEBRAIC(:,104)./( CONSTANTS(:,3).*CONSTANTS(:,13)))+ALGEBRAIC(:,116)./( 4.00000.*CONSTANTS(:,3).*CONSTANTS(:,13));
    ALGEBRAIC(:,114) = 1.00000 - ALGEBRAIC(:,111);
    ALGEBRAIC(:,117) =  ALGEBRAIC(:,115).*ALGEBRAIC(:,111)+ CONSTANTS(:,62).*ALGEBRAIC(:,114);
    ALGEBRAIC(:,113) = 1.00000 - ALGEBRAIC(:,109);
    ALGEBRAIC(:,119) =  CONSTANTS(:,60).*ALGEBRAIC(:,109)+ CONSTANTS(:,61).*ALGEBRAIC(:,113);
    RATES(:,30) =  ALGEBRAIC(:,117).*(1.00000 - STATES(:,30)) -  ALGEBRAIC(:,119).*STATES(:,30);
    ALGEBRAIC(:,53) =  ALGEBRAIC(:,52).*ALGEBRAIC(:,47);
    ALGEBRAIC(:,120) =  280000..*power(ALGEBRAIC(:,30)./1.00000, 2.00000)+ CONSTANTS(:,69).*ALGEBRAIC(:,53);
    ALGEBRAIC(:,122) = (CONSTANTS(:,74) - STATES(:,33))+CONSTANTS(:,75);
    ALGEBRAIC(:,123) =  CONSTANTS(:,75).*STATES(:,33);
    ALGEBRAIC(:,124) = (power((power(ALGEBRAIC(:,122), 2.00000)+ 4.00000.*ALGEBRAIC(:,123)), 1.0 ./ 2) - ALGEBRAIC(:,122))./2.00000;
    ALGEBRAIC(:,125) = 0.0800000./(1.00000+0.360000./ALGEBRAIC(:,124));
    RATES(:,31) =  STATES(:,32).*ALGEBRAIC(:,120) -  STATES(:,31).*ALGEBRAIC(:,125);
    ALGEBRAIC(:,126) =  0.000377000.*power(ALGEBRAIC(:,124)./1.00000, 2.00000);
    RATES(:,32) =  ALGEBRAIC(:,126).*(1.00000 - (STATES(:,31)+STATES(:,32))) -  (ALGEBRAIC(:,120)+CONSTANTS(:,68)).*STATES(:,32);
    ALGEBRAIC(:,127) =  CONSTANTS(:,67).*(ALGEBRAIC(:,124) - ALGEBRAIC(:,30)).*STATES(:,31);
    ALGEBRAIC(:,128) =  CONSTANTS(:,70).*(STATES(:,29) - ALGEBRAIC(:,124));
    RATES(:,33) = (ALGEBRAIC(:,128) - ALGEBRAIC(:,127))./( 2.00000.*CONSTANTS(:,3).*CONSTANTS(:,72));
    ALGEBRAIC(:,121) =  CONSTANTS(:,71).*(STATES(:,29) - ALGEBRAIC(:,30));
    RATES(:,29) = (( - ALGEBRAIC(:,116) - ALGEBRAIC(:,128)) - ALGEBRAIC(:,121))./( 2.00000.*CONSTANTS(:,3).*CONSTANTS(:,73));
    ALGEBRAIC(:,135) =  CONSTANTS(:,78).*STATES(:,34).*CONSTANTS(:,99) -  CONSTANTS(:,83).*STATES(:,35);
    ALGEBRAIC(:,131) = ((1.00000 - STATES(:,34)) - STATES(:,35)) - STATES(:,36);
    ALGEBRAIC(:,133) =  CONSTANTS(:,77).*ALGEBRAIC(:,30).*ALGEBRAIC(:,131) -  CONSTANTS(:,82).*STATES(:,34);
    RATES(:,34) = ALGEBRAIC(:,133) - ALGEBRAIC(:,135);
    ALGEBRAIC(:,129) = CONSTANTS(:,86) - STATES(:,37);
    RATES(:,37) =  CONSTANTS(:,91).*(ALGEBRAIC(:,129) - CONSTANTS(:,92));
    ALGEBRAIC(:,137) =  CONSTANTS(:,79).*STATES(:,35) -  CONSTANTS(:,84).*STATES(:,36).*ALGEBRAIC(:,30);
    ALGEBRAIC(:,140) =  CONSTANTS(:,81).*power(RATES(:,37), 2.00000).*STATES(:,35);
    RATES(:,35) = (ALGEBRAIC(:,135) - ALGEBRAIC(:,137)) - ALGEBRAIC(:,140);
    ALGEBRAIC(:,138) =  CONSTANTS(:,80).*STATES(:,36);
    ALGEBRAIC(:,139) =  CONSTANTS(:,81).*power(RATES(:,37), 2.00000).*STATES(:,36);
    RATES(:,36) = (ALGEBRAIC(:,137) - ALGEBRAIC(:,138)) - ALGEBRAIC(:,139);
    ALGEBRAIC(:,97) = (ALGEBRAIC(:,48)+ALGEBRAIC(:,55)+ALGEBRAIC(:,89)) -  2.00000.*ALGEBRAIC(:,95);
    ALGEBRAIC(:,141) =  CONSTANTS(:,76).*((ALGEBRAIC(:,140)+ALGEBRAIC(:,137)) - ALGEBRAIC(:,133));
    RATES(:,4) =  - (((ALGEBRAIC(:,97) - ALGEBRAIC(:,116)) - ALGEBRAIC(:,127)) - ALGEBRAIC(:,121))./( 2.00000.*CONSTANTS(:,3).*CONSTANTS(:,13))+ALGEBRAIC(:,141);
   RATES = RATES';
end

% Calculate algebraic variables
function ALGEBRAIC = computeAlgebraic(ALGEBRAIC, CONSTANTS, STATES, VOI)
    ALGEBRAIC(:,3) = 1.00000./( 9.00000e+09.*exp(STATES(:,1)./5.00000)+ 8000.00.*exp(STATES(:,1)./100.000));
    ALGEBRAIC(:,16) = 1.00000./( 0.0140000.*exp( - STATES(:,1)./5.00000)+ 4000.00.*exp( - STATES(:,1)./100.000));
    ALGEBRAIC(:,5) = 1.00000./( 250000..*exp(STATES(:,1)./9.00000)+ 58.0000.*exp(STATES(:,1)./65.0000));
    ALGEBRAIC(:,18) = 1.00000./( 1800.00.*exp( - STATES(:,1)./14.0000)+ 66.0000.*exp( - STATES(:,1)./65.0000));
    ALGEBRAIC(:,6) = 1.00000./( 0.0190000.*exp( - STATES(:,1)./5.60000)+ 0.820000.*exp( - STATES(:,1)./250.000));
    ALGEBRAIC(:,19) = 1.00000./( 40.0000.*exp(STATES(:,1)./6.30000)+ 1.50000.*exp(STATES(:,1)./10000.0));
    ALGEBRAIC(:,7) = 1.00000./( 62000.0.*exp(STATES(:,1)./10.1000)+ 30.0000.*exp(STATES(:,1)./3000.00));
    ALGEBRAIC(:,20) = 1.00000./( 0.000600000.*exp( - STATES(:,1)./6.70000)+ 1.20000.*exp( - STATES(:,1)./25.0000));
    ALGEBRAIC(:,8) = 1.00000./( 20.0000.*exp( - STATES(:,1)./11.5000)+ 5.00000.*exp( - STATES(:,1)./300.000));
    ALGEBRAIC(:,21) = 1.00000./( 160.000.*exp(STATES(:,1)./28.0000)+ 200.000.*exp(STATES(:,1)./1000.00))+1.00000./( 2500.00.*exp(STATES(:,1)./20.0000));
    ALGEBRAIC(:,9) = 1.00000./( 200.000.*exp( - STATES(:,1)./13.0000)+ 20.0000.*exp( - STATES(:,1)./300.000));
    ALGEBRAIC(:,22) = 1.00000./( 1600.00.*exp(STATES(:,1)./28.0000)+ 2000.00.*exp(STATES(:,1)./1000.00))+1.00000./( 10000.0.*exp(STATES(:,1)./20.0000));
    ALGEBRAIC(:,10) = 1.00000./( 10.0000.*exp(STATES(:,1)./17.0000)+ 2.50000.*exp(STATES(:,1)./300.000));
    ALGEBRAIC(:,23) = 1.00000./( 0.350000.*exp( - STATES(:,1)./17.0000)+ 2.00000.*exp( - STATES(:,1)./150.000));
    ALGEBRAIC(:,11) = 1.00000./( 85.0000.*exp( - STATES(:,1)./10.5000)+ 370.000.*exp( - STATES(:,1)./62.0000));
    ALGEBRAIC(:,24) = 1.00000./( 1450.00.*exp(STATES(:,1)./20.0000)+ 260.000.*exp(STATES(:,1)./100.000));
    ALGEBRAIC(:,12) = 1.00000./( 11.0000.*exp( - STATES(:,1)./28.0000)+ 0.200000.*exp( - STATES(:,1)./400.000));
    ALGEBRAIC(:,25) = 1.00000./( 4.40000.*exp(STATES(:,1)./16.0000)+ 0.200000.*exp(STATES(:,1)./500.000));
    ALGEBRAIC(:,13) = ( 0.00380000.*exp( - (STATES(:,1)+13.5000)./11.3000))./(1.00000+ 0.0513350.*exp( - (STATES(:,1)+13.5000)./11.3000));
    ALGEBRAIC(:,26) = ( 0.00380000.*exp((STATES(:,1)+13.5000)./11.3000))./(1.00000+ 0.0670830.*exp((STATES(:,1)+13.5000)./11.3000));
    ALGEBRAIC(:,17) = 1.00000./( 0.270000.*exp( - STATES(:,1)./5.90000)+ 1.50000.*exp( - STATES(:,1)./65.0000));
    ALGEBRAIC(:,29) = 1.00000./( 480.000.*exp(STATES(:,1)./7.00000)+ 2.20000.*exp(STATES(:,1)./65.0000));
    ALGEBRAIC(:,15) = 1.00000./( 0.102700.*exp( - STATES(:,1)./8.00000)+ 0.250000.*exp( - STATES(:,1)./50.0000));
    ALGEBRAIC(:,28) = 1.00000./( 26.0000.*exp(STATES(:,1)./17.0000)+ 0.0200000.*exp(STATES(:,1)./800.000));
    ALGEBRAIC(:,31) = 1.00000./( 0.800000.*exp( - STATES(:,1)./400.000));
    ALGEBRAIC(:,4) = ((1.00000 - STATES(:,10)) - STATES(:,14)) - STATES(:,15);
    ALGEBRAIC(:,32) = 1.00000./( 0.00180000.*exp( - STATES(:,1)./7.40000)+ 2.00000.*exp( - STATES(:,1)./100.000));
    ALGEBRAIC(:,35) = 1.00000./( 2.20000e+06.*exp(STATES(:,1)./7.40000)+ 11.0000.*exp(STATES(:,1)./100.000));
    ALGEBRAIC(:,14) = (CONSTANTS(:,14) - STATES(:,4))+CONSTANTS(:,15);
    ALGEBRAIC(:,27) =  CONSTANTS(:,15).*STATES(:,4);
    ALGEBRAIC(:,30) = (power((power(ALGEBRAIC(:,14), 2.00000)+ 4.00000.*ALGEBRAIC(:,27)), 1.0 ./ 2) - ALGEBRAIC(:,14))./2.00000;
    ALGEBRAIC(:,36) =  3.70000.*ALGEBRAIC(:,30);
    ALGEBRAIC(:,2) = ((1.00000 - STATES(:,8)) - STATES(:,6)) - STATES(:,9);
    ALGEBRAIC(:,38) = 1.00000./( 0.000102700.*exp( - STATES(:,1)./8.00000)+ 5.00000.*exp( - STATES(:,1)./400.000));
    ALGEBRAIC(:,34) = 1.00000./( 1300.00.*exp(STATES(:,1)./20.0000)+ 0.0400000.*exp(STATES(:,1)./800.000));
    ALGEBRAIC(:,39) = 0.0400000./(1.00000+( CONSTANTS(:,22).*ALGEBRAIC(:,29).*ALGEBRAIC(:,32))./( CONSTANTS(:,21).*ALGEBRAIC(:,17).*ALGEBRAIC(:,35)));
    ALGEBRAIC(:,42) = 0.0400000 - ALGEBRAIC(:,39);
    ALGEBRAIC(:,41) = 0.0100000./(1.00000+( CONSTANTS(:,19).*ALGEBRAIC(:,28).*ALGEBRAIC(:,38))./( ALGEBRAIC(:,31).*ALGEBRAIC(:,15).*ALGEBRAIC(:,34)));
    ALGEBRAIC(:,44) = 0.0100000 - ALGEBRAIC(:,41);
    ALGEBRAIC(:,37) = piecewise({STATES(:,1)==0.00000,  - CONSTANTS(:,11) }, ( (( 2.00000.*CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*(ALGEBRAIC(:,30) -  CONSTANTS(:,11).*exp((  - 2.00000.*CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2)))))./(1.00000 - exp((  - 2.00000.*CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2)))));
    ALGEBRAIC(:,52) =  0.0676000.*ALGEBRAIC(:,37);
    ALGEBRAIC(:,54) = ALGEBRAIC(:,30) -  0.300000.*ALGEBRAIC(:,52);
    ALGEBRAIC(:,56) =  ALGEBRAIC(:,54).*STATES(:,10);
    ALGEBRAIC(:,58) = ALGEBRAIC(:,56)+ ALGEBRAIC(:,30).*(1.00000 - STATES(:,10));
    ALGEBRAIC(:,61) =  CONSTANTS(:,27).*ALGEBRAIC(:,58);
    ALGEBRAIC(:,63) = ((1.00000 - STATES(:,16)) - STATES(:,11)) - STATES(:,12);
    ALGEBRAIC(:,57) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,12)./STATES(:,3));
    ALGEBRAIC(:,67) = 1.00000./( 8000.00.*exp(((STATES(:,1) - ALGEBRAIC(:,57)) - 97.0000)./8.50000)+ 7.00000.*exp(((STATES(:,1) - ALGEBRAIC(:,57)) - 97.0000)./300.000));
    ALGEBRAIC(:,60) = ( 0.750000.*exp( 0.0350000.*((STATES(:,1) - ALGEBRAIC(:,57)) - 10.0000)))./(1.00000+exp( 0.0150000.*((STATES(:,1) - ALGEBRAIC(:,57)) - 140.000)));
    ALGEBRAIC(:,62) = ( 3.00000.*exp(  - 0.0480000.*((STATES(:,1) - ALGEBRAIC(:,57)) - 10.0000)).*(1.00000+exp( 0.0640000.*((STATES(:,1) - ALGEBRAIC(:,57)) - 38.0000))))./(1.00000+exp( 0.0300000.*((STATES(:,1) - ALGEBRAIC(:,57)) - 70.0000)));
    ALGEBRAIC(:,65) = ALGEBRAIC(:,62)./(ALGEBRAIC(:,60)+ALGEBRAIC(:,62));
    ALGEBRAIC(:,69) = ( power(ALGEBRAIC(:,65), 4.00000).*1.00000)./( 0.000140000.*exp( - ((STATES(:,1) - ALGEBRAIC(:,57)) - 97.0000)./9.10000)+ 0.200000.*exp( - ((STATES(:,1) - ALGEBRAIC(:,57)) - 97.0000)./500.000));
    ALGEBRAIC(:,94) =  1.00000.*exp(( (CONSTANTS(:,50) - 1.00000).*CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2)));
    ALGEBRAIC(:,96) =  ALGEBRAIC(:,94).*CONSTANTS(:,98)+ CONSTANTS(:,44).*CONSTANTS(:,101);
    ALGEBRAIC(:,91) = 1.00000./(1.00000+ power(CONSTANTS(:,45)./STATES(:,2), 3.00000).*(1.00000+ALGEBRAIC(:,30)./CONSTANTS(:,47)));
    ALGEBRAIC(:,92) = 1.00000./(1.00000+ (CONSTANTS(:,47)./ALGEBRAIC(:,30)).*(1.00000+power(STATES(:,2)./CONSTANTS(:,45), 3.00000)));
    ALGEBRAIC(:,93) =  1.00000.*exp(( CONSTANTS(:,50).*CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2)));
    ALGEBRAIC(:,98) =  ALGEBRAIC(:,93).*ALGEBRAIC(:,91)+ CONSTANTS(:,43).*ALGEBRAIC(:,92);
    ALGEBRAIC(:,1) = piecewise({VOI>=CONSTANTS(:,5)&VOI<=CONSTANTS(:,6)&(VOI - CONSTANTS(:,5)) -  floor((VOI - CONSTANTS(:,5))./CONSTANTS(:,7)).*CONSTANTS(:,7)<=CONSTANTS(:,8), CONSTANTS(:,9) }, 0.00000);
    ALGEBRAIC(:,33) = piecewise({STATES(:,1)==0.00000,  - CONSTANTS(:,10) }, ( (( CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*(STATES(:,2) -  CONSTANTS(:,10).*exp((  - CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2)))))./(1.00000 - exp((  - CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2)))));
    ALGEBRAIC(:,80) =  CONSTANTS(:,38).*ALGEBRAIC(:,33);
    ALGEBRAIC(:,40) = piecewise({STATES(:,1)==0.00000, STATES(:,3) }, ( (( CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*(STATES(:,3) -  CONSTANTS(:,12).*exp((  - CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2)))))./(1.00000 - exp((  - CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2)))));
    ALGEBRAIC(:,79) =  0.400000.*CONSTANTS(:,38).*ALGEBRAIC(:,40);
    ALGEBRAIC(:,81) = ALGEBRAIC(:,79)+ALGEBRAIC(:,80);
    ALGEBRAIC(:,89) =  CONSTANTS(:,42).*ALGEBRAIC(:,37);
    ALGEBRAIC(:,82) = piecewise({STATES(:,1)== - 3.00000,  CONSTANTS(:,96).*ALGEBRAIC(:,40).*13.0077 }, ( CONSTANTS(:,96).*ALGEBRAIC(:,40).*(STATES(:,1)+3.00000))./(1.00000 - exp( - (STATES(:,1)+3.00000)./13.0000)));
    ALGEBRAIC(:,83) = 1.00000./(1.00000+power(0.00120000./ALGEBRAIC(:,30), 3.00000));
    ALGEBRAIC(:,85) =  CONSTANTS(:,39).*ALGEBRAIC(:,33).*ALGEBRAIC(:,83);
    ALGEBRAIC(:,84) =  CONSTANTS(:,39).*ALGEBRAIC(:,40).*ALGEBRAIC(:,83);
    ALGEBRAIC(:,86) = ALGEBRAIC(:,84)+ALGEBRAIC(:,85);
    ALGEBRAIC(:,87) = 0.800000./(1.00000+power(STATES(:,5)./0.100000, 2.00000));
    ALGEBRAIC(:,88) =  CONSTANTS(:,97).*(STATES(:,1) - ALGEBRAIC(:,57)).*ALGEBRAIC(:,87);
    ALGEBRAIC(:,90) = ALGEBRAIC(:,81)+ALGEBRAIC(:,89)+ALGEBRAIC(:,82)+ALGEBRAIC(:,86)+ALGEBRAIC(:,88);
    ALGEBRAIC(:,43) =  CONSTANTS(:,18).*ALGEBRAIC(:,33).*STATES(:,6).*STATES(:,7);
    ALGEBRAIC(:,45) =  0.100000.*CONSTANTS(:,18).*ALGEBRAIC(:,40).*STATES(:,6).*STATES(:,7);
    ALGEBRAIC(:,46) = ALGEBRAIC(:,43)+ALGEBRAIC(:,45);
    ALGEBRAIC(:,47) = ( STATES(:,10).*(STATES(:,11)+STATES(:,12)).*STATES(:,13))./(1.00000+power(1.40000./STATES(:,5), 3.00000));
    ALGEBRAIC(:,49) =  1.85000e-05.*CONSTANTS(:,20).*ALGEBRAIC(:,33).*ALGEBRAIC(:,47);
    ALGEBRAIC(:,50) =  0.000365000.*CONSTANTS(:,20).*ALGEBRAIC(:,40).*ALGEBRAIC(:,47);
    ALGEBRAIC(:,48) =  CONSTANTS(:,20).*ALGEBRAIC(:,37).*ALGEBRAIC(:,47);
    ALGEBRAIC(:,51) = ALGEBRAIC(:,49)+ALGEBRAIC(:,48)+ALGEBRAIC(:,50);
    ALGEBRAIC(:,55) =  CONSTANTS(:,30).*ALGEBRAIC(:,37).*STATES(:,17).*STATES(:,18);
    ALGEBRAIC(:,64) = ALGEBRAIC(:,60)./(ALGEBRAIC(:,60)+ALGEBRAIC(:,62));
    ALGEBRAIC(:,66) =  2.00000.*power(ALGEBRAIC(:,65), 2.00000).*power(ALGEBRAIC(:,64), 2.00000);
    ALGEBRAIC(:,68) =  (8.00000./3.00000).*power(ALGEBRAIC(:,65), 3.00000).*ALGEBRAIC(:,64);
    ALGEBRAIC(:,70) = power(ALGEBRAIC(:,65), 4.00000);
    ALGEBRAIC(:,71) =  CONSTANTS(:,94).*(STATES(:,1) - ALGEBRAIC(:,57)).*(ALGEBRAIC(:,70)+ALGEBRAIC(:,68)+ALGEBRAIC(:,66)).*STATES(:,19);
    ALGEBRAIC(:,72) =  CONSTANTS(:,95).*(STATES(:,1) - ALGEBRAIC(:,57)).*( 0.600000.*STATES(:,20)+ 0.400000.*STATES(:,21)).*STATES(:,22);
    ALGEBRAIC(:,73) =  CONSTANTS(:,33).*ALGEBRAIC(:,40).*power(STATES(:,23), 2.00000).*( 0.900000.*STATES(:,24)+0.100000);
    ALGEBRAIC(:,74) =  CONSTANTS(:,34).*ALGEBRAIC(:,33).*power(STATES(:,23), 2.00000).*( 0.900000.*STATES(:,24)+0.100000);
    ALGEBRAIC(:,75) = ALGEBRAIC(:,74)+ALGEBRAIC(:,73);
    ALGEBRAIC(:,76) =  CONSTANTS(:,36).*ALGEBRAIC(:,40).*power(STATES(:,25), 3.00000).*STATES(:,26);
    ALGEBRAIC(:,77) =  CONSTANTS(:,37).*ALGEBRAIC(:,33).*power(STATES(:,25), 3.00000).*STATES(:,26);
    ALGEBRAIC(:,78) = ALGEBRAIC(:,77)+ALGEBRAIC(:,76);
    ALGEBRAIC(:,102) =  CONSTANTS(:,10).*exp((  - 0.820000.*CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2)));
    ALGEBRAIC(:,103) = 1.00000./(1.00000+ power(CONSTANTS(:,55)./ALGEBRAIC(:,102), 1.06000).*(1.00000+power(CONSTANTS(:,12)./CONSTANTS(:,57), 1.12000)));
    ALGEBRAIC(:,99) = 1.00000./(1.00000+ power(CONSTANTS(:,54)./STATES(:,2), 1.06000).*(1.00000+power(STATES(:,3)./CONSTANTS(:,56), 1.12000)));
    ALGEBRAIC(:,101) = 0.370000./(1.00000+CONSTANTS(:,58)./STATES(:,5));
    ALGEBRAIC(:,104) =  CONSTANTS(:,59).*CONSTANTS(:,4).*1.00000.*( ALGEBRAIC(:,101).*ALGEBRAIC(:,99).*STATES(:,28) -  CONSTANTS(:,51).*ALGEBRAIC(:,103).*(1.00000 - STATES(:,28)));
    ALGEBRAIC(:,95) =  CONSTANTS(:,49).*CONSTANTS(:,4).*1.00000.*( ALGEBRAIC(:,93).*ALGEBRAIC(:,91).*STATES(:,27) -  ALGEBRAIC(:,94).*CONSTANTS(:,98).*(1.00000 - STATES(:,27)));
    ALGEBRAIC(:,106) = ALGEBRAIC(:,46)+ALGEBRAIC(:,51)+ALGEBRAIC(:,55)+ALGEBRAIC(:,71)+ALGEBRAIC(:,72)+ALGEBRAIC(:,75)+ALGEBRAIC(:,78)+ALGEBRAIC(:,90)+ALGEBRAIC(:,104)+ALGEBRAIC(:,95);
    ALGEBRAIC(:,107) = ALGEBRAIC(:,43)+ALGEBRAIC(:,74)+ALGEBRAIC(:,77)+ALGEBRAIC(:,49)+ALGEBRAIC(:,80)+ALGEBRAIC(:,85)+ 3.00000.*ALGEBRAIC(:,104)+ 3.00000.*ALGEBRAIC(:,95);
    ALGEBRAIC(:,108) = (ALGEBRAIC(:,71)+ALGEBRAIC(:,72)+ALGEBRAIC(:,76)+ALGEBRAIC(:,88)+ALGEBRAIC(:,73)+ALGEBRAIC(:,45)+ALGEBRAIC(:,50)+ALGEBRAIC(:,79)+ALGEBRAIC(:,84)+ALGEBRAIC(:,82)) -  2.00000.*ALGEBRAIC(:,104);
    ALGEBRAIC(:,105) = 1.00000./(1.00000+ power(CONSTANTS(:,57)./CONSTANTS(:,12), 1.12000).*(1.00000+power(ALGEBRAIC(:,102)./CONSTANTS(:,55), 1.06000)));
    ALGEBRAIC(:,110) =  CONSTANTS(:,51).*ALGEBRAIC(:,103)+ CONSTANTS(:,53).*ALGEBRAIC(:,105);
    ALGEBRAIC(:,100) = 1.00000./(1.00000+ power(CONSTANTS(:,56)./STATES(:,3), 1.12000).*(1.00000+power(STATES(:,2)./CONSTANTS(:,54), 1.06000)));
    ALGEBRAIC(:,112) =  ALGEBRAIC(:,101).*ALGEBRAIC(:,99)+ CONSTANTS(:,52).*ALGEBRAIC(:,100);
    ALGEBRAIC(:,111) = 1.00000./(1.00000+CONSTANTS(:,64)./ALGEBRAIC(:,30));
    ALGEBRAIC(:,109) = 1.00000./(1.00000+CONSTANTS(:,63)./STATES(:,29));
    ALGEBRAIC(:,115) = 1.00000./(1.00000+CONSTANTS(:,65)./STATES(:,5));
    ALGEBRAIC(:,116) =  CONSTANTS(:,66).*1.00000.*( CONSTANTS(:,60).*ALGEBRAIC(:,109).*STATES(:,30) -  ALGEBRAIC(:,115).*ALGEBRAIC(:,111).*(1.00000 - STATES(:,30)));
    ALGEBRAIC(:,118) =   - 0.400000.*STATES(:,35).*CONSTANTS(:,76);
    ALGEBRAIC(:,114) = 1.00000 - ALGEBRAIC(:,111);
    ALGEBRAIC(:,117) =  ALGEBRAIC(:,115).*ALGEBRAIC(:,111)+ CONSTANTS(:,62).*ALGEBRAIC(:,114);
    ALGEBRAIC(:,113) = 1.00000 - ALGEBRAIC(:,109);
    ALGEBRAIC(:,119) =  CONSTANTS(:,60).*ALGEBRAIC(:,109)+ CONSTANTS(:,61).*ALGEBRAIC(:,113);
    ALGEBRAIC(:,53) =  ALGEBRAIC(:,52).*ALGEBRAIC(:,47);
    ALGEBRAIC(:,120) =  280000..*power(ALGEBRAIC(:,30)./1.00000, 2.00000)+ CONSTANTS(:,69).*ALGEBRAIC(:,53);
    ALGEBRAIC(:,122) = (CONSTANTS(:,74) - STATES(:,33))+CONSTANTS(:,75);
    ALGEBRAIC(:,123) =  CONSTANTS(:,75).*STATES(:,33);
    ALGEBRAIC(:,124) = (power((power(ALGEBRAIC(:,122), 2.00000)+ 4.00000.*ALGEBRAIC(:,123)), 1.0 ./ 2) - ALGEBRAIC(:,122))./2.00000;
    ALGEBRAIC(:,125) = 0.0800000./(1.00000+0.360000./ALGEBRAIC(:,124));
    ALGEBRAIC(:,126) =  0.000377000.*power(ALGEBRAIC(:,124)./1.00000, 2.00000);
    ALGEBRAIC(:,127) =  CONSTANTS(:,67).*(ALGEBRAIC(:,124) - ALGEBRAIC(:,30)).*STATES(:,31);
    ALGEBRAIC(:,128) =  CONSTANTS(:,70).*(STATES(:,29) - ALGEBRAIC(:,124));
    ALGEBRAIC(:,121) =  CONSTANTS(:,71).*(STATES(:,29) - ALGEBRAIC(:,30));
    ALGEBRAIC(:,135) =  CONSTANTS(:,78).*STATES(:,34).*CONSTANTS(:,99) -  CONSTANTS(:,83).*STATES(:,35);
    ALGEBRAIC(:,131) = ((1.00000 - STATES(:,34)) - STATES(:,35)) - STATES(:,36);
    ALGEBRAIC(:,133) =  CONSTANTS(:,77).*ALGEBRAIC(:,30).*ALGEBRAIC(:,131) -  CONSTANTS(:,82).*STATES(:,34);
    ALGEBRAIC(:,129) = CONSTANTS(:,86) - STATES(:,37);
    ALGEBRAIC(:,137) =  CONSTANTS(:,79).*STATES(:,35) -  CONSTANTS(:,84).*STATES(:,36).*ALGEBRAIC(:,30);
    ALGEBRAIC(:,140) =  CONSTANTS(:,81).*power(RATES(:,37), 2.00000).*STATES(:,35);
    ALGEBRAIC(:,138) =  CONSTANTS(:,80).*STATES(:,36);
    ALGEBRAIC(:,139) =  CONSTANTS(:,81).*power(RATES(:,37), 2.00000).*STATES(:,36);
    ALGEBRAIC(:,97) = (ALGEBRAIC(:,48)+ALGEBRAIC(:,55)+ALGEBRAIC(:,89)) -  2.00000.*ALGEBRAIC(:,95);
    ALGEBRAIC(:,141) =  CONSTANTS(:,76).*((ALGEBRAIC(:,140)+ALGEBRAIC(:,137)) - ALGEBRAIC(:,133));
    ALGEBRAIC(:,59) =  CONSTANTS(:,29).*ALGEBRAIC(:,56);
    ALGEBRAIC(:,130) =  CONSTANTS(:,76).*(STATES(:,35)+STATES(:,36));
    ALGEBRAIC(:,132) =  CONSTANTS(:,90).*ALGEBRAIC(:,130);
    ALGEBRAIC(:,134) =  ALGEBRAIC(:,132).*ALGEBRAIC(:,129);
    ALGEBRAIC(:,136) =  - CONSTANTS(:,100)+ALGEBRAIC(:,134);
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