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 =93;
end
% There are a total of 41 entries in each of the rate and state variable arrays.
% There are a total of 148 entries in the constant variable array.
%

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

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

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

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

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

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

function [LEGEND_STATES, LEGEND_ALGEBRAIC, LEGEND_VOI, LEGEND_CONSTANTS] = createLegends()
    LEGEND_STATES = ''; LEGEND_ALGEBRAIC = ''; LEGEND_VOI = ''; LEGEND_CONSTANTS = '';
    LEGEND_VOI = strpad('time in component environment (second)');
    LEGEND_CONSTANTS(:,1) = strpad('R in component model_parameters (joule_per_kilomole_kelvin)');
    LEGEND_CONSTANTS(:,2) = strpad('T in component model_parameters (kelvin)');
    LEGEND_CONSTANTS(:,3) = strpad('F in component model_parameters (coulomb_per_mole)');
    LEGEND_CONSTANTS(:,4) = strpad('Na_e in component model_parameters (millimolar)');
    LEGEND_CONSTANTS(:,5) = strpad('Ca_e in component model_parameters (millimolar)');
    LEGEND_CONSTANTS(:,6) = strpad('K_e in component model_parameters (millimolar)');
    LEGEND_CONSTANTS(:,146) = strpad('Vt in component model_parameters (cm3)');
    LEGEND_CONSTANTS(:,113) = strpad('Vd in component model_parameters (cm3)');
    LEGEND_CONSTANTS(:,114) = strpad('Vmyo in component model_parameters (cm3)');
    LEGEND_CONSTANTS(:,117) = strpad('Sms in component model_parameters (cm2)');
    LEGEND_CONSTANTS(:,118) = strpad('Smt in component model_parameters (cm2)');
    LEGEND_CONSTANTS(:,148) = strpad('Cms in component model_parameters (microF)');
    LEGEND_CONSTANTS(:,147) = strpad('Cmt in component model_parameters (microF)');
    LEGEND_CONSTANTS(:,107) = strpad('Vc in component model_parameters (cm3)');
    LEGEND_CONSTANTS(:,115) = strpad('VSRup in component model_parameters (cm3)');
    LEGEND_CONSTANTS(:,116) = strpad('VSRrel in component model_parameters (cm3)');
    LEGEND_CONSTANTS(:,119) = strpad('pt in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,144) = strpad('Lt in component model_parameters (cm)');
    LEGEND_CONSTANTS(:,145) = strpad('Rst in component model_parameters (ohm)');
    LEGEND_CONSTANTS(:,7) = strpad('Rot in component model_parameters (ohm_per_cm2)');
    LEGEND_CONSTANTS(:,8) = strpad('radiust in component model_parameters (cm)');
    LEGEND_CONSTANTS(:,9) = strpad('ptcm in component model_parameters (per_cm)');
    LEGEND_CONSTANTS(:,10) = strpad('Smtot in component model_parameters (cm2)');
    LEGEND_ALGEBRAIC(:,2) = strpad('i_circ in component common_current (microA)');
    LEGEND_CONSTANTS(:,11) = strpad('R_st in component common_current (kilo_ohm)');
    LEGEND_STATES(:,1) = strpad('Vm_s in component membrane (millivolt)');
    LEGEND_STATES(:,2) = strpad('Vm_t in component membrane (millivolt)');
    LEGEND_ALGEBRAIC(:,27) = strpad('J_CaSRrel in component SR_Ca_release_channel (millimolar_per_second)');
    LEGEND_CONSTANTS(:,12) = strpad('kap in component SR_Ca_release_channel (per_millimolar4_per_second)');
    LEGEND_CONSTANTS(:,13) = strpad('kam in component SR_Ca_release_channel (per_second)');
    LEGEND_CONSTANTS(:,14) = strpad('kbp in component SR_Ca_release_channel (per_millimolar3_per_second)');
    LEGEND_CONSTANTS(:,15) = strpad('kbm in component SR_Ca_release_channel (per_second)');
    LEGEND_CONSTANTS(:,16) = strpad('kcp in component SR_Ca_release_channel (per_second)');
    LEGEND_CONSTANTS(:,17) = strpad('kcm in component SR_Ca_release_channel (per_second)');
    LEGEND_STATES(:,3) = strpad('F2 in component SR_Ca_release_channel (dimensionless)');
    LEGEND_STATES(:,4) = strpad('F3 in component SR_Ca_release_channel (dimensionless)');
    LEGEND_STATES(:,5) = strpad('F1 in component SR_Ca_release_channel (dimensionless)');
    LEGEND_STATES(:,6) = strpad('F4 in component SR_Ca_release_channel (dimensionless)');
    LEGEND_STATES(:,7) = strpad('Ca_ss in component ion_concentrations (millimolar)');
    LEGEND_STATES(:,8) = strpad('CaSRrel in component ion_concentrations (millimolar)');
    LEGEND_ALGEBRAIC(:,50) = strpad('J_CaSRup in component SERCA2a_pump (millimolar_per_second)');
    LEGEND_CONSTANTS(:,18) = strpad('K_fb in component SERCA2a_pump (millimolar)');
    LEGEND_CONSTANTS(:,19) = strpad('K_rb in component SERCA2a_pump (millimolar)');
    LEGEND_ALGEBRAIC(:,48) = strpad('fb in component SERCA2a_pump (dimensionless)');
    LEGEND_ALGEBRAIC(:,49) = strpad('rb in component SERCA2a_pump (dimensionless)');
    LEGEND_CONSTANTS(:,20) = strpad('Vmaxf in component SERCA2a_pump (millimolar_per_second)');
    LEGEND_CONSTANTS(:,21) = strpad('Vmaxr in component SERCA2a_pump (millimolar_per_second)');
    LEGEND_CONSTANTS(:,22) = strpad('K_SR in component SERCA2a_pump (dimensionless)');
    LEGEND_CONSTANTS(:,23) = strpad('N_fb in component SERCA2a_pump (dimensionless)');
    LEGEND_CONSTANTS(:,24) = strpad('N_rb in component SERCA2a_pump (dimensionless)');
    LEGEND_STATES(:,9) = strpad('Ca_i in component ion_concentrations (millimolar)');
    LEGEND_STATES(:,10) = strpad('CaSRup in component ion_concentrations (millimolar)');
    LEGEND_ALGEBRAIC(:,51) = strpad('J_tr in component intracellular_and_SR_Ca_fluxes (millimolar_per_second)');
    LEGEND_ALGEBRAIC(:,1) = strpad('J_xfer in component intracellular_and_SR_Ca_fluxes (millimolar_per_second)');
    LEGEND_ALGEBRAIC(:,54) = strpad('J_trpn in component intracellular_and_SR_Ca_fluxes (millimolar_per_second)');
    LEGEND_ALGEBRAIC(:,52) = strpad('J_BTRH in component intracellular_and_SR_Ca_fluxes (millimolar_per_second)');
    LEGEND_ALGEBRAIC(:,53) = strpad('J_BTRL in component intracellular_and_SR_Ca_fluxes (millimolar_per_second)');
    LEGEND_CONSTANTS(:,25) = strpad('BTRHmax in component intracellular_and_SR_Ca_fluxes (millimolar)');
    LEGEND_CONSTANTS(:,26) = strpad('BTRLmax in component intracellular_and_SR_Ca_fluxes (millimolar)');
    LEGEND_CONSTANTS(:,27) = strpad('tau_tr in component intracellular_and_SR_Ca_fluxes (second)');
    LEGEND_CONSTANTS(:,28) = strpad('tau_xfer in component intracellular_and_SR_Ca_fluxes (second)');
    LEGEND_STATES(:,11) = strpad('BTRH in component intracellular_and_SR_Ca_fluxes (millimolar)');
    LEGEND_STATES(:,12) = strpad('BTRL in component intracellular_and_SR_Ca_fluxes (millimolar)');
    LEGEND_CONSTANTS(:,29) = strpad('k_htrpn_plus in component intracellular_and_SR_Ca_fluxes (per_millimolar_per_second)');
    LEGEND_CONSTANTS(:,30) = strpad('k_htrpn_minus in component intracellular_and_SR_Ca_fluxes (per_second)');
    LEGEND_CONSTANTS(:,31) = strpad('k_ltrpn_plus in component intracellular_and_SR_Ca_fluxes (per_millimolar_per_second)');
    LEGEND_CONSTANTS(:,32) = strpad('k_ltrpn_minus in component intracellular_and_SR_Ca_fluxes (per_second)');
    LEGEND_STATES(:,13) = strpad('Na_i in component ion_concentrations (millimolar)');
    LEGEND_STATES(:,14) = strpad('K_i in component ion_concentrations (millimolar)');
    LEGEND_STATES(:,15) = strpad('Na_t in component ion_concentrations (millimolar)');
    LEGEND_STATES(:,16) = strpad('Ca_t in component ion_concentrations (millimolar)');
    LEGEND_STATES(:,17) = strpad('K_t in component ion_concentrations (millimolar)');
    LEGEND_ALGEBRAIC(:,55) = strpad('i_Kext in component ion_concentrations (microA)');
    LEGEND_CONSTANTS(:,33) = strpad('K_mCMDN in component ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,34) = strpad('K_mCSQN in component ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,35) = strpad('K_mEGTA in component ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,36) = strpad('CMDN_tot in component ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,37) = strpad('CSQN_tot in component ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,38) = strpad('EGTA_tot in component ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,39) = strpad('tau_d in component ion_concentrations (second)');
    LEGEND_CONSTANTS(:,40) = strpad('STIMULATION in component ion_concentrations (dimensionless)');
    LEGEND_CONSTANTS(:,41) = strpad('time0 in component ion_concentrations (second)');
    LEGEND_ALGEBRAIC(:,60) = strpad('i_Na_s in component sodium_current (microA)');
    LEGEND_ALGEBRAIC(:,62) = strpad('i_Ca_s in component calcium_current (microA)');
    LEGEND_ALGEBRAIC(:,69) = strpad('i_BNa_s in component background_currents (microA)');
    LEGEND_ALGEBRAIC(:,75) = strpad('i_NaCa_s in component Na_Ca_ion_exchanger_current (microA)');
    LEGEND_ALGEBRAIC(:,73) = strpad('i_NaK_s in component sodium_potassium_pump (microA)');
    LEGEND_ALGEBRAIC(:,61) = strpad('i_fNa_s in component hyperpolarisation_activated_current (microA)');
    LEGEND_ALGEBRAIC(:,67) = strpad('i_fK_s in component hyperpolarisation_activated_current (microA)');
    LEGEND_ALGEBRAIC(:,71) = strpad('i_BK_s in component background_currents (microA)');
    LEGEND_ALGEBRAIC(:,66) = strpad('i_K1_s in component inward_rectifier (microA)');
    LEGEND_ALGEBRAIC(:,64) = strpad('i_Kto_s in component Ca_independent_transient_outward_K_current (microA)');
    LEGEND_ALGEBRAIC(:,65) = strpad('i_Kss_s in component steady_state_outward_K_current (microA)');
    LEGEND_ALGEBRAIC(:,74) = strpad('i_CaP_s in component sarcolemmal_calcium_pump_current (microA)');
    LEGEND_ALGEBRAIC(:,70) = strpad('i_BCa_s in component background_currents (microA)');
    LEGEND_ALGEBRAIC(:,77) = strpad('i_Na_t in component sodium_current (microA)');
    LEGEND_ALGEBRAIC(:,79) = strpad('i_Ca_t in component calcium_current (microA)');
    LEGEND_ALGEBRAIC(:,86) = strpad('i_BNa_t in component background_currents (microA)');
    LEGEND_ALGEBRAIC(:,93) = strpad('i_NaCa_t in component Na_Ca_ion_exchanger_current (microA)');
    LEGEND_ALGEBRAIC(:,91) = strpad('i_NaK_t in component sodium_potassium_pump (microA)');
    LEGEND_ALGEBRAIC(:,78) = strpad('i_fNa_t in component hyperpolarisation_activated_current (microA)');
    LEGEND_ALGEBRAIC(:,84) = strpad('i_fK_t in component hyperpolarisation_activated_current (microA)');
    LEGEND_ALGEBRAIC(:,88) = strpad('i_BK_t in component background_currents (microA)');
    LEGEND_ALGEBRAIC(:,83) = strpad('i_K1_t in component inward_rectifier (microA)');
    LEGEND_ALGEBRAIC(:,81) = strpad('i_Kto_t in component Ca_independent_transient_outward_K_current (microA)');
    LEGEND_ALGEBRAIC(:,82) = strpad('i_Kss_t in component steady_state_outward_K_current (microA)');
    LEGEND_ALGEBRAIC(:,92) = strpad('i_CaP_t in component sarcolemmal_calcium_pump_current (microA)');
    LEGEND_ALGEBRAIC(:,87) = strpad('i_BCa_t in component background_currents (microA)');
    LEGEND_ALGEBRAIC(:,56) = strpad('Jte_Na in component t_tubular_ion_fluxes (millimolar_per_second)');
    LEGEND_ALGEBRAIC(:,57) = strpad('Jte_Ca in component t_tubular_ion_fluxes (millimolar_per_second)');
    LEGEND_ALGEBRAIC(:,58) = strpad('Jte_K in component t_tubular_ion_fluxes (millimolar_per_second)');
    LEGEND_CONSTANTS(:,42) = strpad('tau_Na in component t_tubular_ion_fluxes (second)');
    LEGEND_CONSTANTS(:,43) = strpad('tau_Ca in component t_tubular_ion_fluxes (second)');
    LEGEND_CONSTANTS(:,44) = strpad('tau_K in component t_tubular_ion_fluxes (second)');
    LEGEND_ALGEBRAIC(:,68) = strpad('i_f_s in component hyperpolarisation_activated_current (microA)');
    LEGEND_ALGEBRAIC(:,72) = strpad('i_B_s in component background_currents (microA)');
    LEGEND_ALGEBRAIC(:,59) = strpad('E_Na in component sodium_current (millivolt)');
    LEGEND_CONSTANTS(:,45) = strpad('g_Na in component sodium_current (milliS_per_cm2)');
    LEGEND_CONSTANTS(:,120) = strpad('g_Nas in component sodium_current (milliS)');
    LEGEND_CONSTANTS(:,46) = strpad('fNat in component sodium_current (dimensionless)');
    LEGEND_STATES(:,18) = strpad('m in component sodium_current_m_gate (dimensionless)');
    LEGEND_STATES(:,19) = strpad('h in component sodium_current_h_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,3) = strpad('alpha_m in component sodium_current_m_gate (per_second)');
    LEGEND_ALGEBRAIC(:,28) = strpad('beta_m in component sodium_current_m_gate (per_second)');
    LEGEND_ALGEBRAIC(:,4) = strpad('alpha_h in component sodium_current_h_gate (per_second)');
    LEGEND_ALGEBRAIC(:,29) = strpad('beta_h in component sodium_current_h_gate (per_second)');
    LEGEND_STATES(:,20) = strpad('Co in component calcium_current (dimensionless)');
    LEGEND_STATES(:,21) = strpad('C_cast in component calcium_current (dimensionless)');
    LEGEND_STATES(:,22) = strpad('C1 in component calcium_current (dimensionless)');
    LEGEND_STATES(:,23) = strpad('C2 in component calcium_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,30) = strpad('tauCo in component calcium_current (second)');
    LEGEND_CONSTANTS(:,47) = strpad('tauC_cast in component calcium_current (second)');
    LEGEND_ALGEBRAIC(:,31) = strpad('tauC1 in component calcium_current (second)');
    LEGEND_ALGEBRAIC(:,32) = strpad('tauC2 in component calcium_current (second)');
    LEGEND_ALGEBRAIC(:,5) = strpad('Co_inf in component calcium_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,6) = strpad('C_cast_inf in component calcium_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,7) = strpad('C1_inf in component calcium_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,8) = strpad('C2_inf in component calcium_current (dimensionless)');
    LEGEND_CONSTANTS(:,48) = strpad('g_Ca in component calcium_current (cm_per_second)');
    LEGEND_CONSTANTS(:,121) = strpad('g_Cas in component calcium_current (cm3_per_second)');
    LEGEND_CONSTANTS(:,49) = strpad('fCat in component calcium_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,63) = strpad('E_K in component Ca_independent_transient_outward_K_current (millivolt)');
    LEGEND_CONSTANTS(:,50) = strpad('a in component Ca_independent_transient_outward_K_current (dimensionless)');
    LEGEND_CONSTANTS(:,51) = strpad('b in component Ca_independent_transient_outward_K_current (dimensionless)');
    LEGEND_CONSTANTS(:,52) = strpad('g_Kto in component Ca_independent_transient_outward_K_current (milliS_per_cm2)');
    LEGEND_CONSTANTS(:,122) = strpad('g_Ktos in component Ca_independent_transient_outward_K_current (milliS)');
    LEGEND_CONSTANTS(:,53) = strpad('fKtot in component Ca_independent_transient_outward_K_current (dimensionless)');
    LEGEND_STATES(:,24) = strpad('r in component Ca_independent_transient_outward_K_current_r_gate (dimensionless)');
    LEGEND_STATES(:,25) = strpad('s in component Ca_independent_transient_outward_K_current_s_gate (dimensionless)');
    LEGEND_STATES(:,26) = strpad('s_slow in component Ca_independent_transient_outward_K_current_s_slow_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,33) = strpad('tau_r in component Ca_independent_transient_outward_K_current_r_gate (second)');
    LEGEND_ALGEBRAIC(:,9) = strpad('r_max in component Ca_independent_transient_outward_K_current_r_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,34) = strpad('tau_s in component Ca_independent_transient_outward_K_current_s_gate (second)');
    LEGEND_ALGEBRAIC(:,10) = strpad('s_max in component Ca_independent_transient_outward_K_current_s_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,35) = strpad('tau_s_slow in component Ca_independent_transient_outward_K_current_s_slow_gate (second)');
    LEGEND_ALGEBRAIC(:,11) = strpad('s_slow_max in component Ca_independent_transient_outward_K_current_s_slow_gate (dimensionless)');
    LEGEND_CONSTANTS(:,54) = strpad('g_Kss in component steady_state_outward_K_current (milliS_per_cm2)');
    LEGEND_CONSTANTS(:,123) = strpad('g_Ksss in component steady_state_outward_K_current (milliS)');
    LEGEND_CONSTANTS(:,55) = strpad('fKsst in component steady_state_outward_K_current (dimensionless)');
    LEGEND_STATES(:,27) = strpad('r_ss in component steady_state_outward_K_current_r_ss_gate (dimensionless)');
    LEGEND_STATES(:,28) = strpad('s_ss in component steady_state_outward_K_current_s_ss_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,36) = strpad('tau_r_ss in component steady_state_outward_K_current_r_ss_gate (second)');
    LEGEND_ALGEBRAIC(:,12) = strpad('r_ss_max in component steady_state_outward_K_current_r_ss_gate (dimensionless)');
    LEGEND_CONSTANTS(:,108) = strpad('tau_s_ss in component steady_state_outward_K_current_s_ss_gate (second)');
    LEGEND_ALGEBRAIC(:,13) = strpad('s_ss_max in component steady_state_outward_K_current_s_ss_gate (dimensionless)');
    LEGEND_CONSTANTS(:,56) = strpad('g_K1 in component inward_rectifier (milliS_per_cm2)');
    LEGEND_CONSTANTS(:,124) = strpad('g_K1s in component inward_rectifier (milliS)');
    LEGEND_CONSTANTS(:,57) = strpad('fK1t in component inward_rectifier (dimensionless)');
    LEGEND_CONSTANTS(:,58) = strpad('g_f in component hyperpolarisation_activated_current (milliS_per_cm2)');
    LEGEND_CONSTANTS(:,125) = strpad('g_fs in component hyperpolarisation_activated_current (milliS)');
    LEGEND_CONSTANTS(:,59) = strpad('fft in component hyperpolarisation_activated_current (dimensionless)');
    LEGEND_CONSTANTS(:,60) = strpad('f_Na in component hyperpolarisation_activated_current (dimensionless)');
    LEGEND_CONSTANTS(:,109) = strpad('f_K in component hyperpolarisation_activated_current (dimensionless)');
    LEGEND_STATES(:,29) = strpad('y in component hyperpolarisation_activated_current_y_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,37) = strpad('tau_y in component hyperpolarisation_activated_current_y_gate (second)');
    LEGEND_ALGEBRAIC(:,14) = strpad('y_infinity in component hyperpolarisation_activated_current_y_gate (dimensionless)');
    LEGEND_CONSTANTS(:,61) = strpad('g_B_Ca in component background_currents (milliS_per_cm2)');
    LEGEND_CONSTANTS(:,62) = strpad('g_B_Na in component background_currents (milliS_per_cm2)');
    LEGEND_CONSTANTS(:,63) = strpad('g_B_K in component background_currents (milliS_per_cm2)');
    LEGEND_CONSTANTS(:,126) = strpad('g_B_Cas in component background_currents (milliS)');
    LEGEND_CONSTANTS(:,127) = strpad('g_B_Nas in component background_currents (milliS)');
    LEGEND_CONSTANTS(:,128) = strpad('g_B_Ks in component background_currents (milliS)');
    LEGEND_CONSTANTS(:,64) = strpad('fCabt in component background_currents (dimensionless)');
    LEGEND_CONSTANTS(:,65) = strpad('fNabt in component background_currents (dimensionless)');
    LEGEND_CONSTANTS(:,66) = strpad('fKbt in component background_currents (dimensionless)');
    LEGEND_CONSTANTS(:,67) = strpad('E_Ca in component background_currents (millivolt)');
    LEGEND_CONSTANTS(:,68) = strpad('i_NaK_max in component sodium_potassium_pump (microA_per_cm2)');
    LEGEND_CONSTANTS(:,129) = strpad('i_NaK_max_s in component sodium_potassium_pump (microA)');
    LEGEND_CONSTANTS(:,69) = strpad('fNaKt in component sodium_potassium_pump (dimensionless)');
    LEGEND_CONSTANTS(:,70) = strpad('K_m_K in component sodium_potassium_pump (millimolar)');
    LEGEND_CONSTANTS(:,71) = strpad('K_m_Na in component sodium_potassium_pump (millimolar)');
    LEGEND_CONSTANTS(:,110) = strpad('sigma in component sodium_potassium_pump (dimensionless)');
    LEGEND_CONSTANTS(:,72) = strpad('i_CaP_max in component sarcolemmal_calcium_pump_current (microA_per_cm2)');
    LEGEND_CONSTANTS(:,130) = strpad('i_CaP_max_s in component sarcolemmal_calcium_pump_current (microA)');
    LEGEND_CONSTANTS(:,73) = strpad('fCaPt in component sarcolemmal_calcium_pump_current (dimensionless)');
    LEGEND_CONSTANTS(:,74) = strpad('i_NaCa_max in component Na_Ca_ion_exchanger_current (microA_per_cm2)');
    LEGEND_CONSTANTS(:,131) = strpad('i_NaCa_max_s in component Na_Ca_ion_exchanger_current (microA)');
    LEGEND_CONSTANTS(:,75) = strpad('fNaCat in component Na_Ca_ion_exchanger_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,85) = strpad('i_f_t in component hyperpolarisation_activated_current (microA)');
    LEGEND_ALGEBRAIC(:,89) = strpad('i_B_t in component background_currents (microA)');
    LEGEND_ALGEBRAIC(:,76) = strpad('E_Na in component sodium_current (millivolt)');
    LEGEND_CONSTANTS(:,76) = strpad('g_Na in component sodium_current (milliS_per_cm2)');
    LEGEND_CONSTANTS(:,132) = strpad('g_Nat in component sodium_current (milliS)');
    LEGEND_CONSTANTS(:,77) = strpad('fNat in component sodium_current (dimensionless)');
    LEGEND_STATES(:,30) = strpad('m in component sodium_current_m_gate (dimensionless)');
    LEGEND_STATES(:,31) = strpad('h in component sodium_current_h_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,15) = strpad('alpha_m in component sodium_current_m_gate (per_second)');
    LEGEND_ALGEBRAIC(:,38) = strpad('beta_m in component sodium_current_m_gate (per_second)');
    LEGEND_ALGEBRAIC(:,16) = strpad('alpha_h in component sodium_current_h_gate (per_second)');
    LEGEND_ALGEBRAIC(:,39) = strpad('beta_h in component sodium_current_h_gate (per_second)');
    LEGEND_STATES(:,32) = strpad('Co in component calcium_current (dimensionless)');
    LEGEND_STATES(:,33) = strpad('C_cast in component calcium_current (dimensionless)');
    LEGEND_STATES(:,34) = strpad('C1 in component calcium_current (dimensionless)');
    LEGEND_STATES(:,35) = strpad('C2 in component calcium_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,40) = strpad('tauCo in component calcium_current (second)');
    LEGEND_CONSTANTS(:,78) = strpad('tauC_cast in component calcium_current (second)');
    LEGEND_ALGEBRAIC(:,41) = strpad('tauC1 in component calcium_current (second)');
    LEGEND_ALGEBRAIC(:,42) = strpad('tauC2 in component calcium_current (second)');
    LEGEND_ALGEBRAIC(:,17) = strpad('Co_inf in component calcium_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,18) = strpad('C_cast_inf in component calcium_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,19) = strpad('C1_inf in component calcium_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,20) = strpad('C2_inf in component calcium_current (dimensionless)');
    LEGEND_CONSTANTS(:,79) = strpad('g_Ca in component calcium_current (cm_per_second)');
    LEGEND_CONSTANTS(:,133) = strpad('g_Cat in component calcium_current (cm3_per_second)');
    LEGEND_CONSTANTS(:,80) = strpad('fCat in component calcium_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,80) = strpad('E_K in component Ca_independent_transient_outward_K_current (millivolt)');
    LEGEND_CONSTANTS(:,81) = strpad('a in component Ca_independent_transient_outward_K_current (dimensionless)');
    LEGEND_CONSTANTS(:,82) = strpad('b in component Ca_independent_transient_outward_K_current (dimensionless)');
    LEGEND_CONSTANTS(:,83) = strpad('g_Kto in component Ca_independent_transient_outward_K_current (milliS_per_cm2)');
    LEGEND_CONSTANTS(:,134) = strpad('g_Ktot in component Ca_independent_transient_outward_K_current (milliS)');
    LEGEND_CONSTANTS(:,84) = strpad('fKtot in component Ca_independent_transient_outward_K_current (dimensionless)');
    LEGEND_STATES(:,36) = strpad('r in component Ca_independent_transient_outward_K_current_r_gate (dimensionless)');
    LEGEND_STATES(:,37) = strpad('s in component Ca_independent_transient_outward_K_current_s_gate (dimensionless)');
    LEGEND_STATES(:,38) = strpad('s_slow in component Ca_independent_transient_outward_K_current_s_slow_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,43) = strpad('tau_r in component Ca_independent_transient_outward_K_current_r_gate (second)');
    LEGEND_ALGEBRAIC(:,21) = strpad('r_max in component Ca_independent_transient_outward_K_current_r_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,44) = strpad('tau_t in component Ca_independent_transient_outward_K_current_s_gate (second)');
    LEGEND_ALGEBRAIC(:,22) = strpad('s_max in component Ca_independent_transient_outward_K_current_s_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,45) = strpad('tau_s_slow in component Ca_independent_transient_outward_K_current_s_slow_gate (second)');
    LEGEND_ALGEBRAIC(:,23) = strpad('s_slow_max in component Ca_independent_transient_outward_K_current_s_slow_gate (dimensionless)');
    LEGEND_CONSTANTS(:,85) = strpad('g_Kss in component steady_state_outward_K_current (milliS_per_cm2)');
    LEGEND_CONSTANTS(:,135) = strpad('g_Ksst in component steady_state_outward_K_current (milliS)');
    LEGEND_CONSTANTS(:,86) = strpad('fKsst in component steady_state_outward_K_current (dimensionless)');
    LEGEND_STATES(:,39) = strpad('r_ss in component steady_state_outward_K_current_r_ss_gate (dimensionless)');
    LEGEND_STATES(:,40) = strpad('s_ss in component steady_state_outward_K_current_s_ss_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,46) = strpad('tau_r_ss in component steady_state_outward_K_current_r_ss_gate (second)');
    LEGEND_ALGEBRAIC(:,24) = strpad('r_ss_max in component steady_state_outward_K_current_r_ss_gate (dimensionless)');
    LEGEND_CONSTANTS(:,111) = strpad('tau_s_ss in component steady_state_outward_K_current_s_ss_gate (second)');
    LEGEND_ALGEBRAIC(:,25) = strpad('s_ss_max in component steady_state_outward_K_current_s_ss_gate (dimensionless)');
    LEGEND_CONSTANTS(:,87) = strpad('g_K1 in component inward_rectifier (milliS_per_cm2)');
    LEGEND_CONSTANTS(:,136) = strpad('g_K1t in component inward_rectifier (milliS)');
    LEGEND_CONSTANTS(:,88) = strpad('fK1t in component inward_rectifier (dimensionless)');
    LEGEND_CONSTANTS(:,89) = strpad('g_f in component hyperpolarisation_activated_current (milliS_per_cm2)');
    LEGEND_CONSTANTS(:,137) = strpad('g_ft in component hyperpolarisation_activated_current (milliS)');
    LEGEND_CONSTANTS(:,90) = strpad('fft in component hyperpolarisation_activated_current (dimensionless)');
    LEGEND_CONSTANTS(:,91) = strpad('f_Na in component hyperpolarisation_activated_current (dimensionless)');
    LEGEND_CONSTANTS(:,112) = strpad('f_K in component hyperpolarisation_activated_current (dimensionless)');
    LEGEND_STATES(:,41) = strpad('y in component hyperpolarisation_activated_current_y_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,47) = strpad('tau_y in component hyperpolarisation_activated_current_y_gate (second)');
    LEGEND_ALGEBRAIC(:,26) = strpad('y_infinity in component hyperpolarisation_activated_current_y_gate (dimensionless)');
    LEGEND_CONSTANTS(:,92) = strpad('g_B_Ca in component background_currents (milliS_per_cm2)');
    LEGEND_CONSTANTS(:,93) = strpad('g_B_Na in component background_currents (milliS_per_cm2)');
    LEGEND_CONSTANTS(:,94) = strpad('g_B_K in component background_currents (milliS_per_cm2)');
    LEGEND_CONSTANTS(:,138) = strpad('g_B_Cat in component background_currents (milliS)');
    LEGEND_CONSTANTS(:,139) = strpad('g_B_Nat in component background_currents (milliS)');
    LEGEND_CONSTANTS(:,140) = strpad('g_B_Kt in component background_currents (milliS)');
    LEGEND_CONSTANTS(:,95) = strpad('fCabt in component background_currents (dimensionless)');
    LEGEND_CONSTANTS(:,96) = strpad('fNabt in component background_currents (dimensionless)');
    LEGEND_CONSTANTS(:,97) = strpad('fKbt in component background_currents (dimensionless)');
    LEGEND_CONSTANTS(:,98) = strpad('E_Ca in component background_currents (millivolt)');
    LEGEND_CONSTANTS(:,99) = strpad('i_NaK_max in component sodium_potassium_pump (microA_per_cm2)');
    LEGEND_CONSTANTS(:,141) = strpad('i_NaK_max_t in component sodium_potassium_pump (microA)');
    LEGEND_CONSTANTS(:,100) = strpad('fNaKt in component sodium_potassium_pump (dimensionless)');
    LEGEND_CONSTANTS(:,101) = strpad('K_m_K in component sodium_potassium_pump (millimolar)');
    LEGEND_CONSTANTS(:,102) = strpad('K_m_Na in component sodium_potassium_pump (millimolar)');
    LEGEND_ALGEBRAIC(:,90) = strpad('sigma in component sodium_potassium_pump (dimensionless)');
    LEGEND_CONSTANTS(:,103) = strpad('i_CaP_max in component sarcolemmal_calcium_pump_current (microA_per_cm2)');
    LEGEND_CONSTANTS(:,142) = strpad('i_CaP_max_t in component sarcolemmal_calcium_pump_current (microA)');
    LEGEND_CONSTANTS(:,104) = strpad('fCaPt in component sarcolemmal_calcium_pump_current (dimensionless)');
    LEGEND_CONSTANTS(:,105) = strpad('i_NaCa_max in component Na_Ca_ion_exchanger_current (microA_per_cm2)');
    LEGEND_CONSTANTS(:,143) = strpad('i_NaCa_max_t in component Na_Ca_ion_exchanger_current (microA)');
    LEGEND_CONSTANTS(:,106) = strpad('fNaCat in component Na_Ca_ion_exchanger_current (dimensionless)');
    LEGEND_RATES(:,5) = strpad('d/dt F1 in component SR_Ca_release_channel (dimensionless)');
    LEGEND_RATES(:,3) = strpad('d/dt F2 in component SR_Ca_release_channel (dimensionless)');
    LEGEND_RATES(:,4) = strpad('d/dt F3 in component SR_Ca_release_channel (dimensionless)');
    LEGEND_RATES(:,6) = strpad('d/dt F4 in component SR_Ca_release_channel (dimensionless)');
    LEGEND_RATES(:,11) = strpad('d/dt BTRH in component intracellular_and_SR_Ca_fluxes (millimolar)');
    LEGEND_RATES(:,12) = strpad('d/dt BTRL in component intracellular_and_SR_Ca_fluxes (millimolar)');
    LEGEND_RATES(:,13) = strpad('d/dt Na_i in component ion_concentrations (millimolar)');
    LEGEND_RATES(:,15) = strpad('d/dt Na_t in component ion_concentrations (millimolar)');
    LEGEND_RATES(:,14) = strpad('d/dt K_i in component ion_concentrations (millimolar)');
    LEGEND_RATES(:,17) = strpad('d/dt K_t in component ion_concentrations (millimolar)');
    LEGEND_RATES(:,9) = strpad('d/dt Ca_i in component ion_concentrations (millimolar)');
    LEGEND_RATES(:,16) = strpad('d/dt Ca_t in component ion_concentrations (millimolar)');
    LEGEND_RATES(:,7) = strpad('d/dt Ca_ss in component ion_concentrations (millimolar)');
    LEGEND_RATES(:,8) = strpad('d/dt CaSRrel in component ion_concentrations (millimolar)');
    LEGEND_RATES(:,10) = strpad('d/dt CaSRup in component ion_concentrations (millimolar)');
    LEGEND_RATES(:,1) = strpad('d/dt Vm_s in component membrane (millivolt)');
    LEGEND_RATES(:,18) = strpad('d/dt m in component sodium_current_m_gate (dimensionless)');
    LEGEND_RATES(:,19) = strpad('d/dt h in component sodium_current_h_gate (dimensionless)');
    LEGEND_RATES(:,20) = strpad('d/dt Co in component calcium_current (dimensionless)');
    LEGEND_RATES(:,22) = strpad('d/dt C1 in component calcium_current (dimensionless)');
    LEGEND_RATES(:,23) = strpad('d/dt C2 in component calcium_current (dimensionless)');
    LEGEND_RATES(:,21) = strpad('d/dt C_cast in component calcium_current (dimensionless)');
    LEGEND_RATES(:,24) = strpad('d/dt r in component Ca_independent_transient_outward_K_current_r_gate (dimensionless)');
    LEGEND_RATES(:,25) = strpad('d/dt s in component Ca_independent_transient_outward_K_current_s_gate (dimensionless)');
    LEGEND_RATES(:,26) = strpad('d/dt s_slow in component Ca_independent_transient_outward_K_current_s_slow_gate (dimensionless)');
    LEGEND_RATES(:,27) = strpad('d/dt r_ss in component steady_state_outward_K_current_r_ss_gate (dimensionless)');
    LEGEND_RATES(:,28) = strpad('d/dt s_ss in component steady_state_outward_K_current_s_ss_gate (dimensionless)');
    LEGEND_RATES(:,29) = strpad('d/dt y in component hyperpolarisation_activated_current_y_gate (dimensionless)');
    LEGEND_RATES(:,2) = strpad('d/dt Vm_t in component membrane (millivolt)');
    LEGEND_RATES(:,30) = strpad('d/dt m in component sodium_current_m_gate (dimensionless)');
    LEGEND_RATES(:,31) = strpad('d/dt h in component sodium_current_h_gate (dimensionless)');
    LEGEND_RATES(:,32) = strpad('d/dt Co in component calcium_current (dimensionless)');
    LEGEND_RATES(:,34) = strpad('d/dt C1 in component calcium_current (dimensionless)');
    LEGEND_RATES(:,35) = strpad('d/dt C2 in component calcium_current (dimensionless)');
    LEGEND_RATES(:,33) = strpad('d/dt C_cast in component calcium_current (dimensionless)');
    LEGEND_RATES(:,36) = strpad('d/dt r in component Ca_independent_transient_outward_K_current_r_gate (dimensionless)');
    LEGEND_RATES(:,37) = strpad('d/dt s in component Ca_independent_transient_outward_K_current_s_gate (dimensionless)');
    LEGEND_RATES(:,38) = strpad('d/dt s_slow in component Ca_independent_transient_outward_K_current_s_slow_gate (dimensionless)');
    LEGEND_RATES(:,39) = strpad('d/dt r_ss in component steady_state_outward_K_current_r_ss_gate (dimensionless)');
    LEGEND_RATES(:,40) = strpad('d/dt s_ss in component steady_state_outward_K_current_s_ss_gate (dimensionless)');
    LEGEND_RATES(:,41) = strpad('d/dt y in component hyperpolarisation_activated_current_y_gate (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 = [];
    CONSTANTS(:,1) = 8310;
    CONSTANTS(:,2) = 295;
    CONSTANTS(:,3) = 96500;
    CONSTANTS(:,4) = 140;
    CONSTANTS(:,5) = 1.2;
    CONSTANTS(:,6) = 5.4;
    CONSTANTS(:,7) = 83.33;
    CONSTANTS(:,8) = 150e-7;
    CONSTANTS(:,9) = 30000000;
    CONSTANTS(:,10) = 0.0001;
    CONSTANTS(:,11) = 20.0;
    STATES(:,1) = -7.9709547e1;
    STATES(:,2) = -7.9709536e1;
    CONSTANTS(:,12) = 12.15e12;
    CONSTANTS(:,13) = 576;
    CONSTANTS(:,14) = 4.05e9;
    CONSTANTS(:,15) = 1930;
    CONSTANTS(:,16) = 100;
    CONSTANTS(:,17) = 0.8;
    STATES(:,3) = 3.8333331e-4;
    STATES(:,4) = 6.4516879e-11;
    STATES(:,5) = 6.7606483e-1;
    STATES(:,6) = 3.2355462e-1;
    STATES(:,7) = 4.3112114e-5;
    STATES(:,8) = 2.2638169e-1;
    CONSTANTS(:,18) = 0.000168;
    CONSTANTS(:,19) = 3.29;
    CONSTANTS(:,20) = 0.4;
    CONSTANTS(:,21) = 0.9;
    CONSTANTS(:,22) = 1;
    CONSTANTS(:,23) = 1.2;
    CONSTANTS(:,24) = 1;
    STATES(:,9) = 3.5486498e-5;
    STATES(:,10) = 2.2755058e-1;
    CONSTANTS(:,25) = 0.14;
    CONSTANTS(:,26) = 0.07;
    CONSTANTS(:,27) = 0.02;
    CONSTANTS(:,28) = 0.008;
    STATES(:,11) = 9.2804169e-1;
    STATES(:,12) = 3.4317829e-2;
    CONSTANTS(:,29) = 20000;
    CONSTANTS(:,30) = 0.07;
    CONSTANTS(:,31) = 40000;
    CONSTANTS(:,32) = 40;
    STATES(:,13) = 6.9435814e0;
    STATES(:,14) = 1.3753311e2;
    STATES(:,15) = 1.4001386e2;
    STATES(:,16) = 1.2271399e0;
    STATES(:,17) = 5.3627676e0;
    CONSTANTS(:,33) = 0.00238;
    CONSTANTS(:,34) = 0.8;
    CONSTANTS(:,35) = 0.00015;
    CONSTANTS(:,36) = 0.05;
    CONSTANTS(:,37) = 15;
    CONSTANTS(:,38) = 10;
    CONSTANTS(:,39) = 0.008;
    CONSTANTS(:,40) = 1;
    CONSTANTS(:,41) = 0;
    CONSTANTS(:,42) = 0.15;
    CONSTANTS(:,43) = 0.5;
    CONSTANTS(:,44) = 0.15;
    CONSTANTS(:,45) = 10.0;
    CONSTANTS(:,46) = 0.56;
    STATES(:,18) = 2.1832558e-6;
    STATES(:,19) = 5.8232781e-1;
    STATES(:,20) = 2.5436465e-6;
    STATES(:,21) = 9.9570063e-1;
    STATES(:,22) = 9.9994546e-1;
    STATES(:,23) = 9.9994546e-1;
    CONSTANTS(:,47) = 0.009;
    CONSTANTS(:,48) = 0.00021;
    CONSTANTS(:,49) = 0.87;
    CONSTANTS(:,50) = 0.886;
    CONSTANTS(:,51) = 0.114;
    CONSTANTS(:,52) = 0.35;
    CONSTANTS(:,53) = 0.56;
    STATES(:,24) = 2.3485072e-3;
    STATES(:,25) = 9.8315843e-1;
    STATES(:,26) = 6.7483370e-1;
    CONSTANTS(:,54) = 0.07;
    CONSTANTS(:,55) = 0.76;
    STATES(:,27) = 3.1079213e-3;
    STATES(:,28) = 3.0773393e-1;
    CONSTANTS(:,56) = 0.24;
    CONSTANTS(:,57) = 0.56;
    CONSTANTS(:,58) = 0.0145;
    CONSTANTS(:,59) = 0.56;
    CONSTANTS(:,60) = 0.2;
    STATES(:,29) = 3.4357356e-3;
    CONSTANTS(:,61) = 0.000648;
    CONSTANTS(:,62) = 0.0008015;
    CONSTANTS(:,63) = 0.00138;
    CONSTANTS(:,64) = 0.56;
    CONSTANTS(:,65) = 0.56;
    CONSTANTS(:,66) = 0.56;
    CONSTANTS(:,67) = 65;
    CONSTANTS(:,68) = 1;
    CONSTANTS(:,69) = 0.59;
    CONSTANTS(:,70) = 1.5;
    CONSTANTS(:,71) = 10;
    CONSTANTS(:,72) = 0.85;
    CONSTANTS(:,73) = 0.56;
    CONSTANTS(:,74) = 1.8e-4;
    CONSTANTS(:,75) = 0.81;
    CONSTANTS(:,76) = 10.0;
    CONSTANTS(:,77) = 0.56;
    STATES(:,30) = 2.1832694e-6;
    STATES(:,31) = 5.8232717e-1;
    STATES(:,32) = 2.5436520e-6;
    STATES(:,33) = 9.9570063e-1;
    STATES(:,34) = 9.9785393e-1;
    STATES(:,35) = 9.9994546e-1;
    CONSTANTS(:,78) = 0.009;
    CONSTANTS(:,79) = 0.00021;
    CONSTANTS(:,80) = 0.87;
    CONSTANTS(:,81) = 0.886;
    CONSTANTS(:,82) = 0.114;
    CONSTANTS(:,83) = 0.35;
    CONSTANTS(:,84) = 0.56;
    STATES(:,36) = 2.3485094e-3;
    STATES(:,37) = 9.8315865e-1;
    STATES(:,38) = 6.7478532e-1;
    CONSTANTS(:,85) = 0.07;
    CONSTANTS(:,86) = 0.76;
    STATES(:,39) = 3.1079241e-3;
    STATES(:,40) = 3.0773368e-1;
    CONSTANTS(:,87) = 0.24;
    CONSTANTS(:,88) = 0.56;
    CONSTANTS(:,89) = 0.0145;
    CONSTANTS(:,90) = 0.56;
    CONSTANTS(:,91) = 0.2;
    STATES(:,41) = 3.4357175e-3;
    CONSTANTS(:,92) = 0.000648;
    CONSTANTS(:,93) = 0.0008015;
    CONSTANTS(:,94) = 0.00138;
    CONSTANTS(:,95) = 0.56;
    CONSTANTS(:,96) = 0.56;
    CONSTANTS(:,97) = 0.56;
    CONSTANTS(:,98) = 65;
    CONSTANTS(:,99) = 1;
    CONSTANTS(:,100) = 0.59;
    CONSTANTS(:,101) = 1.5;
    CONSTANTS(:,102) = 10;
    CONSTANTS(:,103) = 0.85;
    CONSTANTS(:,104) = 0.56;
    CONSTANTS(:,105) = 1.8e-4;
    CONSTANTS(:,106) = 0.81;
    CONSTANTS(:,107) = CONSTANTS(:,10)./7850.00;
    CONSTANTS(:,108) = 2.10000;
    CONSTANTS(:,109) = 1.00000 - CONSTANTS(:,60);
    CONSTANTS(:,110) = (exp(CONSTANTS(:,4)./67.3000) - 1.00000)./7.00000;
    CONSTANTS(:,111) = 2.10000;
    CONSTANTS(:,112) = 1.00000 - CONSTANTS(:,91);
    CONSTANTS(:,113) =  CONSTANTS(:,107).*7.50000e-05;
    CONSTANTS(:,114) =  CONSTANTS(:,107).*0.585000;
    CONSTANTS(:,115) =  CONSTANTS(:,107).*0.0315000;
    CONSTANTS(:,116) =  CONSTANTS(:,107).*0.00350000;
    CONSTANTS(:,117) = CONSTANTS(:,10) -  4400.00.*CONSTANTS(:,107);
    CONSTANTS(:,118) = CONSTANTS(:,10) - CONSTANTS(:,117);
    CONSTANTS(:,119) =  CONSTANTS(:,9).*CONSTANTS(:,117);
    CONSTANTS(:,120) =  CONSTANTS(:,45).*(CONSTANTS(:,117)+CONSTANTS(:,118)).*(1.00000 - CONSTANTS(:,46));
    CONSTANTS(:,121) =  CONSTANTS(:,48).*(CONSTANTS(:,117)+CONSTANTS(:,118)).*(1.00000 - CONSTANTS(:,49));
    CONSTANTS(:,122) =  CONSTANTS(:,52).*(CONSTANTS(:,117)+CONSTANTS(:,118)).*(1.00000 - CONSTANTS(:,53));
    CONSTANTS(:,123) =  CONSTANTS(:,54).*(CONSTANTS(:,117)+CONSTANTS(:,118)).*(1.00000 - CONSTANTS(:,55));
    CONSTANTS(:,124) =  CONSTANTS(:,56).*(CONSTANTS(:,117)+CONSTANTS(:,118)).*(1.00000 - CONSTANTS(:,57));
    CONSTANTS(:,125) =  CONSTANTS(:,58).*(CONSTANTS(:,117)+CONSTANTS(:,118)).*(1.00000 - CONSTANTS(:,59));
    CONSTANTS(:,126) =  CONSTANTS(:,61).*(CONSTANTS(:,117)+CONSTANTS(:,118)).*(1.00000 - CONSTANTS(:,64));
    CONSTANTS(:,127) =  CONSTANTS(:,62).*(CONSTANTS(:,117)+CONSTANTS(:,118)).*(1.00000 - CONSTANTS(:,65));
    CONSTANTS(:,128) =  CONSTANTS(:,63).*(CONSTANTS(:,117)+CONSTANTS(:,118)).*(1.00000 - CONSTANTS(:,66));
    CONSTANTS(:,129) =  CONSTANTS(:,68).*(CONSTANTS(:,117)+CONSTANTS(:,118)).*(1.00000 - CONSTANTS(:,69));
    CONSTANTS(:,130) =  CONSTANTS(:,72).*(CONSTANTS(:,117)+CONSTANTS(:,118)).*(1.00000 - CONSTANTS(:,73));
    CONSTANTS(:,131) =  CONSTANTS(:,74).*(CONSTANTS(:,117)+CONSTANTS(:,118)).*(1.00000 - CONSTANTS(:,75));
    CONSTANTS(:,132) =  CONSTANTS(:,76).*(CONSTANTS(:,117)+CONSTANTS(:,118)).*CONSTANTS(:,77);
    CONSTANTS(:,133) =  CONSTANTS(:,79).*(CONSTANTS(:,117)+CONSTANTS(:,118)).*CONSTANTS(:,80);
    CONSTANTS(:,134) =  CONSTANTS(:,83).*(CONSTANTS(:,117)+CONSTANTS(:,118)).*CONSTANTS(:,84);
    CONSTANTS(:,135) =  CONSTANTS(:,85).*(CONSTANTS(:,117)+CONSTANTS(:,118)).*CONSTANTS(:,86);
    CONSTANTS(:,136) =  CONSTANTS(:,87).*(CONSTANTS(:,117)+CONSTANTS(:,118)).*CONSTANTS(:,88);
    CONSTANTS(:,137) =  CONSTANTS(:,89).*(CONSTANTS(:,117)+CONSTANTS(:,118)).*CONSTANTS(:,90);
    CONSTANTS(:,138) =  CONSTANTS(:,92).*(CONSTANTS(:,117)+CONSTANTS(:,118)).*CONSTANTS(:,95);
    CONSTANTS(:,139) =  CONSTANTS(:,93).*(CONSTANTS(:,117)+CONSTANTS(:,118)).*CONSTANTS(:,96);
    CONSTANTS(:,140) =  CONSTANTS(:,94).*(CONSTANTS(:,117)+CONSTANTS(:,118)).*CONSTANTS(:,97);
    CONSTANTS(:,141) =  CONSTANTS(:,99).*(CONSTANTS(:,117)+CONSTANTS(:,118)).*CONSTANTS(:,100);
    CONSTANTS(:,142) =  CONSTANTS(:,103).*(CONSTANTS(:,117)+CONSTANTS(:,118)).*CONSTANTS(:,104);
    CONSTANTS(:,143) =  CONSTANTS(:,105).*(CONSTANTS(:,117)+CONSTANTS(:,118)).*CONSTANTS(:,106);
    CONSTANTS(:,144) = CONSTANTS(:,118)./( 2.00000.*3.14159.*CONSTANTS(:,8).*CONSTANTS(:,119));
    CONSTANTS(:,145) = ( CONSTANTS(:,7).*(CONSTANTS(:,144)./2.00000))./( 3.14159.*power(CONSTANTS(:,8), 2.00000).*CONSTANTS(:,119));
    CONSTANTS(:,146) =  3.14159.*power(CONSTANTS(:,8), 2.00000).*CONSTANTS(:,144).*CONSTANTS(:,119);
    CONSTANTS(:,147) =  CONSTANTS(:,118).*1.00000;
    CONSTANTS(:,148) =  CONSTANTS(:,117).*1.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);
        utilOnes = 1;
    else
        statesRowCount = statesSize(1);
        ALGEBRAIC = zeros(statesRowCount, algebraicVariableCount);
        RATES = zeros(statesRowCount, statesColumnCount);
        utilOnes = ones(statesRowCount, 1);
    end
    RATES(:,5) =   - CONSTANTS(:,12).*power(STATES(:,7), 4.00000).*STATES(:,5)+ CONSTANTS(:,13).*STATES(:,3);
    RATES(:,3) = ( CONSTANTS(:,12).*power(STATES(:,7), 4.00000).*STATES(:,5) - ( CONSTANTS(:,13).*STATES(:,3)+ CONSTANTS(:,14).*power(STATES(:,7), 3.00000).*STATES(:,3)+ CONSTANTS(:,16).*STATES(:,3)))+ CONSTANTS(:,15).*STATES(:,4)+ CONSTANTS(:,17).*STATES(:,6);
    RATES(:,4) =  CONSTANTS(:,14).*power(STATES(:,7), 3.00000).*STATES(:,3) -  CONSTANTS(:,15).*STATES(:,4);
    RATES(:,6) =  CONSTANTS(:,16).*STATES(:,3) -  CONSTANTS(:,17).*STATES(:,6);
    ALGEBRAIC(:,6) = 1.00000./(1.00000+STATES(:,7)./0.0100000);
    RATES(:,21) = (ALGEBRAIC(:,6) - STATES(:,21))./CONSTANTS(:,47);
    ALGEBRAIC(:,13) = 1.00000./(1.00000+exp((STATES(:,1)+87.5000)./10.3000));
    RATES(:,28) = (ALGEBRAIC(:,13) - STATES(:,28))./CONSTANTS(:,108);
    ALGEBRAIC(:,18) = 1.00000./(1.00000+STATES(:,7)./0.0100000);
    RATES(:,33) = (ALGEBRAIC(:,18) - STATES(:,33))./CONSTANTS(:,78);
    ALGEBRAIC(:,25) = 1.00000./(1.00000+exp((STATES(:,2)+87.5000)./10.3000));
    RATES(:,40) = (ALGEBRAIC(:,25) - STATES(:,40))./CONSTANTS(:,111);
    ALGEBRAIC(:,3) = ( 117.260.*(STATES(:,1)+59.3000))./(1.00000 - exp(  - 0.550000.*(STATES(:,1)+59.3000)));
    ALGEBRAIC(:,28) =  3800.00.*exp(  - 0.0720000.*(STATES(:,1)+61.0000));
    RATES(:,18) =  ALGEBRAIC(:,3).*(1.00000 - STATES(:,18)) -  ALGEBRAIC(:,28).*STATES(:,18);
    ALGEBRAIC(:,4) = 284.400./(1.00000+exp( 0.0812000.*(STATES(:,1)+115.900)));
    ALGEBRAIC(:,29) = ( 18.7700.*(STATES(:,1)+64.4000))./(1.00000 - exp(  - 0.220000.*(STATES(:,1)+64.4000)));
    RATES(:,19) =  ALGEBRAIC(:,4).*(1.00000 - STATES(:,19)) -  ALGEBRAIC(:,29).*STATES(:,19);
    ALGEBRAIC(:,30) =  0.00305000.*exp(  - 0.00450000.*power(STATES(:,1)+7.00000, 2.00000))+ 0.00105000.*exp(  - 0.00200000.*power(STATES(:,1) - 18.0000, 2.00000))+0.000250000;
    ALGEBRAIC(:,5) = 1.00000./(1.00000+exp((STATES(:,1)+15.3000)./ - 5.00000));
    RATES(:,20) = (ALGEBRAIC(:,5) - STATES(:,20))./ALGEBRAIC(:,30);
    ALGEBRAIC(:,31) =  0.105000.*exp( - power((STATES(:,1)+45.0000)./12.0000, 2.00000))+0.0400000./(1.00000+exp(( - STATES(:,1)+25.0000)./25.0000))+0.0150000./(1.00000+exp((STATES(:,1)+75.0000)./25.0000))+0.00170000;
    ALGEBRAIC(:,7) = 1.00000./(1.00000+exp((STATES(:,1)+26.7000)./5.40000));
    RATES(:,22) = (ALGEBRAIC(:,7) - STATES(:,22))./ALGEBRAIC(:,31);
    ALGEBRAIC(:,32) =  0.0410000.*exp( - power((STATES(:,1)+47.0000)./12.0000, 2.00000))+0.0800000./(1.00000+exp((STATES(:,1)+55.0000)./ - 5.00000))+0.0150000./(1.00000+exp((STATES(:,1)+75.0000)./25.0000))+0.00170000;
    ALGEBRAIC(:,8) = 1.00000./(1.00000+exp((STATES(:,1)+26.7000)./5.40000));
    RATES(:,23) = (ALGEBRAIC(:,8) - STATES(:,23))./ALGEBRAIC(:,32);
    ALGEBRAIC(:,33) = 1.00000./( 45.1600.*exp( 0.0357700.*(STATES(:,1)+50.0000))+ 98.9000.*exp(  - 0.100000.*(STATES(:,1)+38.0000)));
    ALGEBRAIC(:,9) = 1.00000./(1.00000+exp((STATES(:,1)+10.6000)./ - 11.4200));
    RATES(:,24) = (ALGEBRAIC(:,9) - STATES(:,24))./ALGEBRAIC(:,33);
    ALGEBRAIC(:,34) =  0.350000.*exp( - power( 0.0666000.*(STATES(:,1)+70.0000), 2.00000))+0.0350000;
    ALGEBRAIC(:,10) = 1.00000./(1.00000+exp((STATES(:,1)+45.3000)./6.88410));
    RATES(:,25) = (ALGEBRAIC(:,10) - STATES(:,25))./ALGEBRAIC(:,34);
    ALGEBRAIC(:,35) =  3.70000.*exp( - power( 0.0333000.*(STATES(:,1)+70.0000), 2.00000))+0.0350000;
    ALGEBRAIC(:,11) = 1.00000./(1.00000+exp((STATES(:,1)+45.3000)./6.88410));
    RATES(:,26) = (ALGEBRAIC(:,11) - STATES(:,26))./ALGEBRAIC(:,35);
    ALGEBRAIC(:,36) = 10.0000./( 45.1600.*exp( 0.0357700.*(STATES(:,1)+50.0000))+ 98.9000.*exp(  - 0.100000.*(STATES(:,1)+38.0000)));
    ALGEBRAIC(:,12) = 1.00000./(1.00000+exp( - (STATES(:,1)+11.5000)./11.8200));
    RATES(:,27) = (ALGEBRAIC(:,12) - STATES(:,27))./ALGEBRAIC(:,36);
    ALGEBRAIC(:,37) = 1.00000./( 0.118850.*exp((STATES(:,1)+80.0000)./28.3700)+ 0.562300.*exp((STATES(:,1)+80.0000)./ - 14.1900));
    ALGEBRAIC(:,14) = 1.00000./(1.00000+exp((STATES(:,1)+138.600)./10.4800));
    RATES(:,29) = (ALGEBRAIC(:,14) - STATES(:,29))./ALGEBRAIC(:,37);
    ALGEBRAIC(:,15) = ( 117.260.*(STATES(:,2)+59.3000))./(1.00000 - exp(  - 0.550000.*(STATES(:,2)+59.3000)));
    ALGEBRAIC(:,38) =  3800.00.*exp(  - 0.0720000.*(STATES(:,2)+61.0000));
    RATES(:,30) =  ALGEBRAIC(:,15).*(1.00000 - STATES(:,30)) -  ALGEBRAIC(:,38).*STATES(:,30);
    ALGEBRAIC(:,16) = 284.400./(1.00000+exp( 0.0812000.*(STATES(:,2)+115.900)));
    ALGEBRAIC(:,39) = ( 18.7700.*(STATES(:,2)+64.4000))./(1.00000 - exp(  - 0.220000.*(STATES(:,2)+64.4000)));
    RATES(:,31) =  ALGEBRAIC(:,16).*(1.00000 - STATES(:,31)) -  ALGEBRAIC(:,39).*STATES(:,31);
    ALGEBRAIC(:,40) =  0.00305000.*exp(  - 0.00450000.*power(STATES(:,2)+7.00000, 2.00000))+ 0.00105000.*exp(  - 0.00200000.*power(STATES(:,2) - 18.0000, 2.00000))+0.000250000;
    ALGEBRAIC(:,17) = 1.00000./(1.00000+exp((STATES(:,2)+15.3000)./ - 5.00000));
    RATES(:,32) = (ALGEBRAIC(:,17) - STATES(:,32))./ALGEBRAIC(:,40);
    ALGEBRAIC(:,41) =  0.105000.*exp( - power((STATES(:,2)+45.0000)./12.0000, 2.00000))+0.0400000./(1.00000+exp(( - STATES(:,2)+25.0000)./25.0000))+0.0150000./(1.00000+exp((STATES(:,2)+75.0000)./25.0000))+0.00170000;
    ALGEBRAIC(:,19) = 1.00000./(1.00000+exp((STATES(:,2)+26.7000)./5.40000));
    RATES(:,34) = (ALGEBRAIC(:,19) - STATES(:,34))./ALGEBRAIC(:,41);
    ALGEBRAIC(:,42) =  0.0410000.*exp( - power((STATES(:,2)+47.0000)./12.0000, 2.00000))+0.0800000./(1.00000+exp((STATES(:,2)+55.0000)./ - 5.00000))+0.0150000./(1.00000+exp((STATES(:,2)+75.0000)./25.0000))+0.00170000;
    ALGEBRAIC(:,20) = 1.00000./(1.00000+exp((STATES(:,2)+26.7000)./5.40000));
    RATES(:,35) = (ALGEBRAIC(:,20) - STATES(:,35))./ALGEBRAIC(:,42);
    ALGEBRAIC(:,43) = 1.00000./( 45.1600.*exp( 0.0357700.*(STATES(:,2)+50.0000))+ 98.9000.*exp(  - 0.100000.*(STATES(:,2)+38.0000)));
    ALGEBRAIC(:,21) = 1.00000./(1.00000+exp((STATES(:,2)+10.6000)./ - 11.4200));
    RATES(:,36) = (ALGEBRAIC(:,21) - STATES(:,36))./ALGEBRAIC(:,43);
    ALGEBRAIC(:,44) =  0.350000.*exp( - power( 0.0666000.*(STATES(:,2)+70.0000), 2.00000))+0.0350000;
    ALGEBRAIC(:,22) = 1.00000./(1.00000+exp((STATES(:,2)+45.3000)./6.88410));
    RATES(:,37) = (ALGEBRAIC(:,22) - STATES(:,37))./ALGEBRAIC(:,44);
    ALGEBRAIC(:,45) =  3.70000.*exp( - power( 0.0333000.*(STATES(:,2)+70.0000), 2.00000))+0.0350000;
    ALGEBRAIC(:,23) = 1.00000./(1.00000+exp((STATES(:,2)+45.3000)./6.88410));
    RATES(:,38) = (ALGEBRAIC(:,23) - STATES(:,38))./ALGEBRAIC(:,45);
    ALGEBRAIC(:,46) = 10.0000./( 45.1600.*exp( 0.0357700.*(STATES(:,2)+50.0000))+ 98.9000.*exp(  - 0.100000.*(STATES(:,2)+38.0000)));
    ALGEBRAIC(:,24) = 1.00000./(1.00000+exp( - (STATES(:,2)+11.5000)./11.8200));
    RATES(:,39) = (ALGEBRAIC(:,24) - STATES(:,39))./ALGEBRAIC(:,46);
    ALGEBRAIC(:,47) = 1.00000./( 0.118850.*exp((STATES(:,2)+80.0000)./28.3700)+ 0.562300.*exp((STATES(:,2)+80.0000)./ - 14.1900));
    ALGEBRAIC(:,26) = 1.00000./(1.00000+exp((STATES(:,2)+138.600)./10.4800));
    RATES(:,41) = (ALGEBRAIC(:,26) - STATES(:,41))./ALGEBRAIC(:,47);
    ALGEBRAIC(:,52) =  CONSTANTS(:,29).*STATES(:,9).*(1.00000 - STATES(:,11)) -  CONSTANTS(:,30).*STATES(:,11);
    RATES(:,11) = ALGEBRAIC(:,52);
    ALGEBRAIC(:,27) =  1800.00.*(STATES(:,3)+STATES(:,4)).*(STATES(:,8) - STATES(:,7));
    ALGEBRAIC(:,51) = (STATES(:,10) - STATES(:,8))./CONSTANTS(:,27);
    RATES(:,8) =  (1.00000./(1.00000+( CONSTANTS(:,37).*CONSTANTS(:,34))./power(CONSTANTS(:,34)+STATES(:,8), 2.00000))).*(ALGEBRAIC(:,51) - ALGEBRAIC(:,27));
    ALGEBRAIC(:,48) = power(STATES(:,9)./CONSTANTS(:,18), CONSTANTS(:,23));
    ALGEBRAIC(:,49) = power(STATES(:,10)./CONSTANTS(:,19), CONSTANTS(:,24));
    ALGEBRAIC(:,50) = ( CONSTANTS(:,22).*( CONSTANTS(:,20).*ALGEBRAIC(:,48) -  CONSTANTS(:,21).*ALGEBRAIC(:,49)))./(1.00000+ALGEBRAIC(:,48)+ALGEBRAIC(:,49));
    RATES(:,10) = ALGEBRAIC(:,50) - ALGEBRAIC(:,51);
    ALGEBRAIC(:,53) =  CONSTANTS(:,31).*STATES(:,9).*(1.00000 - STATES(:,12)) -  CONSTANTS(:,32).*STATES(:,12);
    RATES(:,12) = ALGEBRAIC(:,53);
    ALGEBRAIC(:,2) =  1000.00.*((STATES(:,1) - STATES(:,2))./CONSTANTS(:,11));
    ALGEBRAIC(:,55) = piecewise({CONSTANTS(:,40)==1.00000&VOI - CONSTANTS(:,41)<0.00100000,  52.0000.*(CONSTANTS(:,117)+CONSTANTS(:,118)) }, 0.00000);
    ALGEBRAIC(:,60) =  CONSTANTS(:,120).*power(STATES(:,18), 3.00000).*STATES(:,19).*(STATES(:,1) -  arbitrary_log((CONSTANTS(:,4)+ 0.120000.*CONSTANTS(:,6))./(STATES(:,13)+ 0.120000.*STATES(:,14)), 10).*(( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)));
    ALGEBRAIC(:,62) =  CONSTANTS(:,121).*4.00000.*(( STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*(( STATES(:,7).*exp(( 2.00000.*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  0.341000.*CONSTANTS(:,5))./(exp(( 2.00000.*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000)).*STATES(:,20).*( (0.900000+STATES(:,21)./10.0000).*STATES(:,22)+ (0.100000+STATES(:,21)./10.0000).*STATES(:,23));
    ALGEBRAIC(:,75) = ( CONSTANTS(:,131).*( exp( 0.0187000.*STATES(:,1)).*power(STATES(:,13), 3.00000).*CONSTANTS(:,5) -  exp( -0.0187000.*STATES(:,1)).*power(CONSTANTS(:,4), 3.00000).*STATES(:,9)))./(1.00000+ 0.000100000.*( STATES(:,9).*power(CONSTANTS(:,4), 3.00000)+ CONSTANTS(:,5).*power(STATES(:,13), 3.00000)));
    ALGEBRAIC(:,73) = (( (CONSTANTS(:,129)./(1.00000+ 0.124500.*exp((  - 0.100000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))+ 0.0365000.*CONSTANTS(:,110).*exp((  - STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*CONSTANTS(:,6))./(CONSTANTS(:,6)+CONSTANTS(:,70)))./(1.00000+power(CONSTANTS(:,71)./STATES(:,13), 1.50000));
    ALGEBRAIC(:,63) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,6)./STATES(:,14));
    ALGEBRAIC(:,66) =  (( CONSTANTS(:,124).*(STATES(:,1) - (ALGEBRAIC(:,63)+1.73000)))./(1.00000+exp( (( 1.61300.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*(STATES(:,1) - (ALGEBRAIC(:,63)+1.73000))))).*(1.00000+exp( - (CONSTANTS(:,6) - 0.998800)./0.124000));
    ALGEBRAIC(:,64) =  CONSTANTS(:,122).*STATES(:,24).*( CONSTANTS(:,50).*STATES(:,25)+ CONSTANTS(:,51).*STATES(:,26)).*(STATES(:,1) - ALGEBRAIC(:,63));
    ALGEBRAIC(:,65) =  CONSTANTS(:,123).*STATES(:,27).*STATES(:,28).*(STATES(:,1) - ALGEBRAIC(:,63));
    ALGEBRAIC(:,74) = ( CONSTANTS(:,130).*STATES(:,9))./(STATES(:,9)+0.000400000);
    ALGEBRAIC(:,59) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,4)./STATES(:,13));
    ALGEBRAIC(:,68) =  CONSTANTS(:,125).*STATES(:,29).*( 0.200000.*(STATES(:,1) - ALGEBRAIC(:,59))+ 0.800000.*(STATES(:,1) - ALGEBRAIC(:,63)));
    ALGEBRAIC(:,69) =  CONSTANTS(:,127).*(STATES(:,1) - ALGEBRAIC(:,59));
    ALGEBRAIC(:,71) =  CONSTANTS(:,128).*(STATES(:,1) - ALGEBRAIC(:,63));
    ALGEBRAIC(:,70) =  CONSTANTS(:,126).*(STATES(:,1) - CONSTANTS(:,67));
    ALGEBRAIC(:,72) = ALGEBRAIC(:,69)+ALGEBRAIC(:,70)+ALGEBRAIC(:,71);
    RATES(:,1) =  1000.00.*(((ALGEBRAIC(:,55)+ALGEBRAIC(:,2)) - (ALGEBRAIC(:,60)+ALGEBRAIC(:,62)+ALGEBRAIC(:,64)+ALGEBRAIC(:,65)+ALGEBRAIC(:,68)+ALGEBRAIC(:,66)+ALGEBRAIC(:,72)+ALGEBRAIC(:,73)+ALGEBRAIC(:,75)+ALGEBRAIC(:,74)))./CONSTANTS(:,148));
    ALGEBRAIC(:,79) =  CONSTANTS(:,133).*4.00000.*(( STATES(:,2).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*(( STATES(:,7).*exp(( 2.00000.*STATES(:,2).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  0.341000.*STATES(:,16))./(exp(( 2.00000.*STATES(:,2).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000)).*STATES(:,32).*( (0.900000+STATES(:,33)./10.0000).*STATES(:,34)+ (0.100000+STATES(:,33)./10.0000).*STATES(:,35));
    RATES(:,7) =  (1.00000./(1.00000+ CONSTANTS(:,36).*(CONSTANTS(:,33)./power(CONSTANTS(:,33)+STATES(:,7), 2.00000)))).*( - (ALGEBRAIC(:,62)+ALGEBRAIC(:,79))./(( 2.00000.*CONSTANTS(:,113).*CONSTANTS(:,3)+ALGEBRAIC(:,27)./CONSTANTS(:,113)) - (( (STATES(:,7) - STATES(:,9)).*CONSTANTS(:,114))./CONSTANTS(:,39))./CONSTANTS(:,113)));
    ALGEBRAIC(:,67) =  CONSTANTS(:,125).*STATES(:,29).*CONSTANTS(:,109).*(STATES(:,1) - ALGEBRAIC(:,63));
    ALGEBRAIC(:,90) = (exp(STATES(:,15)./67.3000) - 1.00000)./7.00000;
    ALGEBRAIC(:,91) = (( (CONSTANTS(:,141)./(1.00000+ 0.124500.*exp((  - 0.100000.*STATES(:,2).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))+ 0.0365000.*ALGEBRAIC(:,90).*exp((  - STATES(:,2).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*STATES(:,17))./(STATES(:,17)+CONSTANTS(:,101)))./(1.00000+power(CONSTANTS(:,102)./STATES(:,13), 1.50000));
    ALGEBRAIC(:,80) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(STATES(:,17)./STATES(:,14));
    ALGEBRAIC(:,84) =  CONSTANTS(:,137).*STATES(:,41).*CONSTANTS(:,112).*(STATES(:,2) - ALGEBRAIC(:,80));
    ALGEBRAIC(:,88) =  CONSTANTS(:,140).*(STATES(:,2) - ALGEBRAIC(:,80));
    ALGEBRAIC(:,83) =  (( CONSTANTS(:,136).*(STATES(:,2) - (ALGEBRAIC(:,80)+1.73000)))./(1.00000+exp( (( 1.61300.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*(STATES(:,2) - (ALGEBRAIC(:,80)+1.73000))))).*(1.00000+exp( - (STATES(:,17) - 0.998800)./0.124000));
    ALGEBRAIC(:,81) =  CONSTANTS(:,134).*STATES(:,36).*( CONSTANTS(:,81).*STATES(:,37)+ CONSTANTS(:,82).*STATES(:,38)).*(STATES(:,2) - ALGEBRAIC(:,80));
    ALGEBRAIC(:,82) =  CONSTANTS(:,135).*STATES(:,39).*STATES(:,40).*(STATES(:,2) - ALGEBRAIC(:,80));
    RATES(:,14) =  - ( - ALGEBRAIC(:,55)+ALGEBRAIC(:,67)+ALGEBRAIC(:,84)+ALGEBRAIC(:,65)+ALGEBRAIC(:,82)+ALGEBRAIC(:,66)+ALGEBRAIC(:,83)+ALGEBRAIC(:,71)+ALGEBRAIC(:,88)+ ALGEBRAIC(:,73).* - 2.00000+ ALGEBRAIC(:,91).* - 2.00000+ALGEBRAIC(:,64)+ALGEBRAIC(:,81))./( CONSTANTS(:,114).*CONSTANTS(:,3));
    ALGEBRAIC(:,58) = ( 1.00000.*CONSTANTS(:,146))./( CONSTANTS(:,44).*(STATES(:,17) - CONSTANTS(:,6)));
    RATES(:,17) = ((ALGEBRAIC(:,84)+ALGEBRAIC(:,82)+ALGEBRAIC(:,83)+ALGEBRAIC(:,88)+ ALGEBRAIC(:,91).* - 2.00000+ALGEBRAIC(:,81))./(CONSTANTS(:,3) - ALGEBRAIC(:,58)))./CONSTANTS(:,146);
    ALGEBRAIC(:,77) =  CONSTANTS(:,132).*power(STATES(:,30), 3.00000).*STATES(:,31).*(STATES(:,2) -  arbitrary_log((STATES(:,15)+ 0.120000.*STATES(:,17))./(STATES(:,13)+ 0.120000.*STATES(:,14)), 10).*(( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)));
    ALGEBRAIC(:,76) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(STATES(:,15)./STATES(:,13));
    ALGEBRAIC(:,86) =  CONSTANTS(:,139).*(STATES(:,2) - ALGEBRAIC(:,76));
    ALGEBRAIC(:,93) = ( CONSTANTS(:,143).*( exp( 0.0187000.*STATES(:,2)).*power(STATES(:,13), 3.00000).*STATES(:,16) -  exp( -0.0187000.*STATES(:,2)).*power(STATES(:,15), 3.00000).*STATES(:,9)))./(1.00000+ 0.000100000.*( STATES(:,9).*power(STATES(:,15), 3.00000)+ STATES(:,16).*power(STATES(:,13), 3.00000)));
    RATES(:,13) =  - (ALGEBRAIC(:,60)+ALGEBRAIC(:,77)+ALGEBRAIC(:,69)+ALGEBRAIC(:,86)+ ALGEBRAIC(:,75).*3.00000+ ALGEBRAIC(:,93).*3.00000+ ALGEBRAIC(:,73).*3.00000+ ALGEBRAIC(:,91).*3.00000)./( CONSTANTS(:,114).*CONSTANTS(:,3));
    ALGEBRAIC(:,56) = ( 1.00000.*CONSTANTS(:,146))./( CONSTANTS(:,42).*(STATES(:,15) - CONSTANTS(:,4)));
    RATES(:,15) = ((ALGEBRAIC(:,77)+ALGEBRAIC(:,86)+ ALGEBRAIC(:,93).*3.00000+ ALGEBRAIC(:,91).*3.00000)./(CONSTANTS(:,3) - ALGEBRAIC(:,56)))./CONSTANTS(:,146);
    ALGEBRAIC(:,92) = ( CONSTANTS(:,142).*STATES(:,9))./(STATES(:,9)+0.000400000);
    ALGEBRAIC(:,87) =  CONSTANTS(:,138).*(STATES(:,2) - CONSTANTS(:,98));
    RATES(:,9) =  (1.00000./(1.00000+ CONSTANTS(:,36).*(CONSTANTS(:,33)./power(CONSTANTS(:,33)+STATES(:,9), 2.00000)))).*((( -2.00000.*(ALGEBRAIC(:,75)+ALGEBRAIC(:,93))+(ALGEBRAIC(:,70)+ALGEBRAIC(:,87)+ALGEBRAIC(:,74)+ALGEBRAIC(:,92)))./( -2.00000.*CONSTANTS(:,114).*CONSTANTS(:,3))+((( (STATES(:,7) - STATES(:,9)).*CONSTANTS(:,114))./CONSTANTS(:,39)+ALGEBRAIC(:,27)) - ALGEBRAIC(:,50))./CONSTANTS(:,114)) - ( ALGEBRAIC(:,52).*CONSTANTS(:,25)+ ALGEBRAIC(:,53).*CONSTANTS(:,26)));
    ALGEBRAIC(:,57) = ( 1.00000.*CONSTANTS(:,146))./( CONSTANTS(:,43).*(STATES(:,16) - CONSTANTS(:,5)));
    RATES(:,16) = ((ALGEBRAIC(:,79)+ALGEBRAIC(:,92)+ALGEBRAIC(:,87)+ ALGEBRAIC(:,93).* - 2.00000)./( 2.00000.*CONSTANTS(:,3) - ALGEBRAIC(:,57)))./CONSTANTS(:,146);
    ALGEBRAIC(:,85) =  CONSTANTS(:,137).*STATES(:,41).*( 0.200000.*(STATES(:,2) - ALGEBRAIC(:,76))+ 0.800000.*(STATES(:,2) - ALGEBRAIC(:,80)));
    ALGEBRAIC(:,89) = ALGEBRAIC(:,86)+ALGEBRAIC(:,87)+ALGEBRAIC(:,88);
    RATES(:,2) =  1000.00.*( - (ALGEBRAIC(:,2)+ALGEBRAIC(:,77)+ALGEBRAIC(:,79)+ALGEBRAIC(:,81)+ALGEBRAIC(:,82)+ALGEBRAIC(:,85)+ALGEBRAIC(:,83)+ALGEBRAIC(:,89)+ALGEBRAIC(:,91)+ALGEBRAIC(:,93)+ALGEBRAIC(:,92))./CONSTANTS(:,147));
   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(:,6) = 1.00000./(1.00000+STATES(:,7)./0.0100000);
    ALGEBRAIC(:,13) = 1.00000./(1.00000+exp((STATES(:,1)+87.5000)./10.3000));
    ALGEBRAIC(:,18) = 1.00000./(1.00000+STATES(:,7)./0.0100000);
    ALGEBRAIC(:,25) = 1.00000./(1.00000+exp((STATES(:,2)+87.5000)./10.3000));
    ALGEBRAIC(:,3) = ( 117.260.*(STATES(:,1)+59.3000))./(1.00000 - exp(  - 0.550000.*(STATES(:,1)+59.3000)));
    ALGEBRAIC(:,28) =  3800.00.*exp(  - 0.0720000.*(STATES(:,1)+61.0000));
    ALGEBRAIC(:,4) = 284.400./(1.00000+exp( 0.0812000.*(STATES(:,1)+115.900)));
    ALGEBRAIC(:,29) = ( 18.7700.*(STATES(:,1)+64.4000))./(1.00000 - exp(  - 0.220000.*(STATES(:,1)+64.4000)));
    ALGEBRAIC(:,30) =  0.00305000.*exp(  - 0.00450000.*power(STATES(:,1)+7.00000, 2.00000))+ 0.00105000.*exp(  - 0.00200000.*power(STATES(:,1) - 18.0000, 2.00000))+0.000250000;
    ALGEBRAIC(:,5) = 1.00000./(1.00000+exp((STATES(:,1)+15.3000)./ - 5.00000));
    ALGEBRAIC(:,31) =  0.105000.*exp( - power((STATES(:,1)+45.0000)./12.0000, 2.00000))+0.0400000./(1.00000+exp(( - STATES(:,1)+25.0000)./25.0000))+0.0150000./(1.00000+exp((STATES(:,1)+75.0000)./25.0000))+0.00170000;
    ALGEBRAIC(:,7) = 1.00000./(1.00000+exp((STATES(:,1)+26.7000)./5.40000));
    ALGEBRAIC(:,32) =  0.0410000.*exp( - power((STATES(:,1)+47.0000)./12.0000, 2.00000))+0.0800000./(1.00000+exp((STATES(:,1)+55.0000)./ - 5.00000))+0.0150000./(1.00000+exp((STATES(:,1)+75.0000)./25.0000))+0.00170000;
    ALGEBRAIC(:,8) = 1.00000./(1.00000+exp((STATES(:,1)+26.7000)./5.40000));
    ALGEBRAIC(:,33) = 1.00000./( 45.1600.*exp( 0.0357700.*(STATES(:,1)+50.0000))+ 98.9000.*exp(  - 0.100000.*(STATES(:,1)+38.0000)));
    ALGEBRAIC(:,9) = 1.00000./(1.00000+exp((STATES(:,1)+10.6000)./ - 11.4200));
    ALGEBRAIC(:,34) =  0.350000.*exp( - power( 0.0666000.*(STATES(:,1)+70.0000), 2.00000))+0.0350000;
    ALGEBRAIC(:,10) = 1.00000./(1.00000+exp((STATES(:,1)+45.3000)./6.88410));
    ALGEBRAIC(:,35) =  3.70000.*exp( - power( 0.0333000.*(STATES(:,1)+70.0000), 2.00000))+0.0350000;
    ALGEBRAIC(:,11) = 1.00000./(1.00000+exp((STATES(:,1)+45.3000)./6.88410));
    ALGEBRAIC(:,36) = 10.0000./( 45.1600.*exp( 0.0357700.*(STATES(:,1)+50.0000))+ 98.9000.*exp(  - 0.100000.*(STATES(:,1)+38.0000)));
    ALGEBRAIC(:,12) = 1.00000./(1.00000+exp( - (STATES(:,1)+11.5000)./11.8200));
    ALGEBRAIC(:,37) = 1.00000./( 0.118850.*exp((STATES(:,1)+80.0000)./28.3700)+ 0.562300.*exp((STATES(:,1)+80.0000)./ - 14.1900));
    ALGEBRAIC(:,14) = 1.00000./(1.00000+exp((STATES(:,1)+138.600)./10.4800));
    ALGEBRAIC(:,15) = ( 117.260.*(STATES(:,2)+59.3000))./(1.00000 - exp(  - 0.550000.*(STATES(:,2)+59.3000)));
    ALGEBRAIC(:,38) =  3800.00.*exp(  - 0.0720000.*(STATES(:,2)+61.0000));
    ALGEBRAIC(:,16) = 284.400./(1.00000+exp( 0.0812000.*(STATES(:,2)+115.900)));
    ALGEBRAIC(:,39) = ( 18.7700.*(STATES(:,2)+64.4000))./(1.00000 - exp(  - 0.220000.*(STATES(:,2)+64.4000)));
    ALGEBRAIC(:,40) =  0.00305000.*exp(  - 0.00450000.*power(STATES(:,2)+7.00000, 2.00000))+ 0.00105000.*exp(  - 0.00200000.*power(STATES(:,2) - 18.0000, 2.00000))+0.000250000;
    ALGEBRAIC(:,17) = 1.00000./(1.00000+exp((STATES(:,2)+15.3000)./ - 5.00000));
    ALGEBRAIC(:,41) =  0.105000.*exp( - power((STATES(:,2)+45.0000)./12.0000, 2.00000))+0.0400000./(1.00000+exp(( - STATES(:,2)+25.0000)./25.0000))+0.0150000./(1.00000+exp((STATES(:,2)+75.0000)./25.0000))+0.00170000;
    ALGEBRAIC(:,19) = 1.00000./(1.00000+exp((STATES(:,2)+26.7000)./5.40000));
    ALGEBRAIC(:,42) =  0.0410000.*exp( - power((STATES(:,2)+47.0000)./12.0000, 2.00000))+0.0800000./(1.00000+exp((STATES(:,2)+55.0000)./ - 5.00000))+0.0150000./(1.00000+exp((STATES(:,2)+75.0000)./25.0000))+0.00170000;
    ALGEBRAIC(:,20) = 1.00000./(1.00000+exp((STATES(:,2)+26.7000)./5.40000));
    ALGEBRAIC(:,43) = 1.00000./( 45.1600.*exp( 0.0357700.*(STATES(:,2)+50.0000))+ 98.9000.*exp(  - 0.100000.*(STATES(:,2)+38.0000)));
    ALGEBRAIC(:,21) = 1.00000./(1.00000+exp((STATES(:,2)+10.6000)./ - 11.4200));
    ALGEBRAIC(:,44) =  0.350000.*exp( - power( 0.0666000.*(STATES(:,2)+70.0000), 2.00000))+0.0350000;
    ALGEBRAIC(:,22) = 1.00000./(1.00000+exp((STATES(:,2)+45.3000)./6.88410));
    ALGEBRAIC(:,45) =  3.70000.*exp( - power( 0.0333000.*(STATES(:,2)+70.0000), 2.00000))+0.0350000;
    ALGEBRAIC(:,23) = 1.00000./(1.00000+exp((STATES(:,2)+45.3000)./6.88410));
    ALGEBRAIC(:,46) = 10.0000./( 45.1600.*exp( 0.0357700.*(STATES(:,2)+50.0000))+ 98.9000.*exp(  - 0.100000.*(STATES(:,2)+38.0000)));
    ALGEBRAIC(:,24) = 1.00000./(1.00000+exp( - (STATES(:,2)+11.5000)./11.8200));
    ALGEBRAIC(:,47) = 1.00000./( 0.118850.*exp((STATES(:,2)+80.0000)./28.3700)+ 0.562300.*exp((STATES(:,2)+80.0000)./ - 14.1900));
    ALGEBRAIC(:,26) = 1.00000./(1.00000+exp((STATES(:,2)+138.600)./10.4800));
    ALGEBRAIC(:,52) =  CONSTANTS(:,29).*STATES(:,9).*(1.00000 - STATES(:,11)) -  CONSTANTS(:,30).*STATES(:,11);
    ALGEBRAIC(:,27) =  1800.00.*(STATES(:,3)+STATES(:,4)).*(STATES(:,8) - STATES(:,7));
    ALGEBRAIC(:,51) = (STATES(:,10) - STATES(:,8))./CONSTANTS(:,27);
    ALGEBRAIC(:,48) = power(STATES(:,9)./CONSTANTS(:,18), CONSTANTS(:,23));
    ALGEBRAIC(:,49) = power(STATES(:,10)./CONSTANTS(:,19), CONSTANTS(:,24));
    ALGEBRAIC(:,50) = ( CONSTANTS(:,22).*( CONSTANTS(:,20).*ALGEBRAIC(:,48) -  CONSTANTS(:,21).*ALGEBRAIC(:,49)))./(1.00000+ALGEBRAIC(:,48)+ALGEBRAIC(:,49));
    ALGEBRAIC(:,53) =  CONSTANTS(:,31).*STATES(:,9).*(1.00000 - STATES(:,12)) -  CONSTANTS(:,32).*STATES(:,12);
    ALGEBRAIC(:,2) =  1000.00.*((STATES(:,1) - STATES(:,2))./CONSTANTS(:,11));
    ALGEBRAIC(:,55) = piecewise({CONSTANTS(:,40)==1.00000&VOI - CONSTANTS(:,41)<0.00100000,  52.0000.*(CONSTANTS(:,117)+CONSTANTS(:,118)) }, 0.00000);
    ALGEBRAIC(:,60) =  CONSTANTS(:,120).*power(STATES(:,18), 3.00000).*STATES(:,19).*(STATES(:,1) -  arbitrary_log((CONSTANTS(:,4)+ 0.120000.*CONSTANTS(:,6))./(STATES(:,13)+ 0.120000.*STATES(:,14)), 10).*(( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)));
    ALGEBRAIC(:,62) =  CONSTANTS(:,121).*4.00000.*(( STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*(( STATES(:,7).*exp(( 2.00000.*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  0.341000.*CONSTANTS(:,5))./(exp(( 2.00000.*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000)).*STATES(:,20).*( (0.900000+STATES(:,21)./10.0000).*STATES(:,22)+ (0.100000+STATES(:,21)./10.0000).*STATES(:,23));
    ALGEBRAIC(:,75) = ( CONSTANTS(:,131).*( exp( 0.0187000.*STATES(:,1)).*power(STATES(:,13), 3.00000).*CONSTANTS(:,5) -  exp( -0.0187000.*STATES(:,1)).*power(CONSTANTS(:,4), 3.00000).*STATES(:,9)))./(1.00000+ 0.000100000.*( STATES(:,9).*power(CONSTANTS(:,4), 3.00000)+ CONSTANTS(:,5).*power(STATES(:,13), 3.00000)));
    ALGEBRAIC(:,73) = (( (CONSTANTS(:,129)./(1.00000+ 0.124500.*exp((  - 0.100000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))+ 0.0365000.*CONSTANTS(:,110).*exp((  - STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*CONSTANTS(:,6))./(CONSTANTS(:,6)+CONSTANTS(:,70)))./(1.00000+power(CONSTANTS(:,71)./STATES(:,13), 1.50000));
    ALGEBRAIC(:,63) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,6)./STATES(:,14));
    ALGEBRAIC(:,66) =  (( CONSTANTS(:,124).*(STATES(:,1) - (ALGEBRAIC(:,63)+1.73000)))./(1.00000+exp( (( 1.61300.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*(STATES(:,1) - (ALGEBRAIC(:,63)+1.73000))))).*(1.00000+exp( - (CONSTANTS(:,6) - 0.998800)./0.124000));
    ALGEBRAIC(:,64) =  CONSTANTS(:,122).*STATES(:,24).*( CONSTANTS(:,50).*STATES(:,25)+ CONSTANTS(:,51).*STATES(:,26)).*(STATES(:,1) - ALGEBRAIC(:,63));
    ALGEBRAIC(:,65) =  CONSTANTS(:,123).*STATES(:,27).*STATES(:,28).*(STATES(:,1) - ALGEBRAIC(:,63));
    ALGEBRAIC(:,74) = ( CONSTANTS(:,130).*STATES(:,9))./(STATES(:,9)+0.000400000);
    ALGEBRAIC(:,59) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,4)./STATES(:,13));
    ALGEBRAIC(:,68) =  CONSTANTS(:,125).*STATES(:,29).*( 0.200000.*(STATES(:,1) - ALGEBRAIC(:,59))+ 0.800000.*(STATES(:,1) - ALGEBRAIC(:,63)));
    ALGEBRAIC(:,69) =  CONSTANTS(:,127).*(STATES(:,1) - ALGEBRAIC(:,59));
    ALGEBRAIC(:,71) =  CONSTANTS(:,128).*(STATES(:,1) - ALGEBRAIC(:,63));
    ALGEBRAIC(:,70) =  CONSTANTS(:,126).*(STATES(:,1) - CONSTANTS(:,67));
    ALGEBRAIC(:,72) = ALGEBRAIC(:,69)+ALGEBRAIC(:,70)+ALGEBRAIC(:,71);
    ALGEBRAIC(:,79) =  CONSTANTS(:,133).*4.00000.*(( STATES(:,2).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*(( STATES(:,7).*exp(( 2.00000.*STATES(:,2).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  0.341000.*STATES(:,16))./(exp(( 2.00000.*STATES(:,2).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000)).*STATES(:,32).*( (0.900000+STATES(:,33)./10.0000).*STATES(:,34)+ (0.100000+STATES(:,33)./10.0000).*STATES(:,35));
    ALGEBRAIC(:,67) =  CONSTANTS(:,125).*STATES(:,29).*CONSTANTS(:,109).*(STATES(:,1) - ALGEBRAIC(:,63));
    ALGEBRAIC(:,90) = (exp(STATES(:,15)./67.3000) - 1.00000)./7.00000;
    ALGEBRAIC(:,91) = (( (CONSTANTS(:,141)./(1.00000+ 0.124500.*exp((  - 0.100000.*STATES(:,2).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))+ 0.0365000.*ALGEBRAIC(:,90).*exp((  - STATES(:,2).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*STATES(:,17))./(STATES(:,17)+CONSTANTS(:,101)))./(1.00000+power(CONSTANTS(:,102)./STATES(:,13), 1.50000));
    ALGEBRAIC(:,80) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(STATES(:,17)./STATES(:,14));
    ALGEBRAIC(:,84) =  CONSTANTS(:,137).*STATES(:,41).*CONSTANTS(:,112).*(STATES(:,2) - ALGEBRAIC(:,80));
    ALGEBRAIC(:,88) =  CONSTANTS(:,140).*(STATES(:,2) - ALGEBRAIC(:,80));
    ALGEBRAIC(:,83) =  (( CONSTANTS(:,136).*(STATES(:,2) - (ALGEBRAIC(:,80)+1.73000)))./(1.00000+exp( (( 1.61300.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*(STATES(:,2) - (ALGEBRAIC(:,80)+1.73000))))).*(1.00000+exp( - (STATES(:,17) - 0.998800)./0.124000));
    ALGEBRAIC(:,81) =  CONSTANTS(:,134).*STATES(:,36).*( CONSTANTS(:,81).*STATES(:,37)+ CONSTANTS(:,82).*STATES(:,38)).*(STATES(:,2) - ALGEBRAIC(:,80));
    ALGEBRAIC(:,82) =  CONSTANTS(:,135).*STATES(:,39).*STATES(:,40).*(STATES(:,2) - ALGEBRAIC(:,80));
    ALGEBRAIC(:,58) = ( 1.00000.*CONSTANTS(:,146))./( CONSTANTS(:,44).*(STATES(:,17) - CONSTANTS(:,6)));
    ALGEBRAIC(:,77) =  CONSTANTS(:,132).*power(STATES(:,30), 3.00000).*STATES(:,31).*(STATES(:,2) -  arbitrary_log((STATES(:,15)+ 0.120000.*STATES(:,17))./(STATES(:,13)+ 0.120000.*STATES(:,14)), 10).*(( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)));
    ALGEBRAIC(:,76) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(STATES(:,15)./STATES(:,13));
    ALGEBRAIC(:,86) =  CONSTANTS(:,139).*(STATES(:,2) - ALGEBRAIC(:,76));
    ALGEBRAIC(:,93) = ( CONSTANTS(:,143).*( exp( 0.0187000.*STATES(:,2)).*power(STATES(:,13), 3.00000).*STATES(:,16) -  exp( -0.0187000.*STATES(:,2)).*power(STATES(:,15), 3.00000).*STATES(:,9)))./(1.00000+ 0.000100000.*( STATES(:,9).*power(STATES(:,15), 3.00000)+ STATES(:,16).*power(STATES(:,13), 3.00000)));
    ALGEBRAIC(:,56) = ( 1.00000.*CONSTANTS(:,146))./( CONSTANTS(:,42).*(STATES(:,15) - CONSTANTS(:,4)));
    ALGEBRAIC(:,92) = ( CONSTANTS(:,142).*STATES(:,9))./(STATES(:,9)+0.000400000);
    ALGEBRAIC(:,87) =  CONSTANTS(:,138).*(STATES(:,2) - CONSTANTS(:,98));
    ALGEBRAIC(:,57) = ( 1.00000.*CONSTANTS(:,146))./( CONSTANTS(:,43).*(STATES(:,16) - CONSTANTS(:,5)));
    ALGEBRAIC(:,85) =  CONSTANTS(:,137).*STATES(:,41).*( 0.200000.*(STATES(:,2) - ALGEBRAIC(:,76))+ 0.800000.*(STATES(:,2) - ALGEBRAIC(:,80)));
    ALGEBRAIC(:,89) = ALGEBRAIC(:,86)+ALGEBRAIC(:,87)+ALGEBRAIC(:,88);
    ALGEBRAIC(:,1) = (STATES(:,7) - STATES(:,9))./CONSTANTS(:,28);
    ALGEBRAIC(:,54) = ALGEBRAIC(:,52)+ALGEBRAIC(:,53);
    ALGEBRAIC(:,61) =  CONSTANTS(:,125).*STATES(:,29).*CONSTANTS(:,60).*(STATES(:,1) - ALGEBRAIC(:,59));
    ALGEBRAIC(:,78) =  CONSTANTS(:,137).*STATES(:,41).*CONSTANTS(:,91).*(STATES(:,2) - ALGEBRAIC(:,76));
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

% Compute a logarithm to any base" +
function x = arbitrary_log(a, base)
    x = log(a) ./ log(base);
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