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 =52;
end
% There are a total of 15 entries in each of the rate and state variable arrays.
% There are a total of 133 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('Version in component membrane (dimensionless)');
    LEGEND_CONSTANTS(:,2) = strpad('dCell in component membrane (dimensionless)');
    LEGEND_CONSTANTS(:,3) = strpad('FCellConstant in component membrane (dimensionless)');
    LEGEND_CONSTANTS(:,111) = strpad('FCell in component membrane (dimensionless)');
    LEGEND_STATES(:,1) = strpad('V in component membrane (millivolt)');
    LEGEND_CONSTANTS(:,4) = strpad('R in component membrane (millijoule_per_mole_kelvin)');
    LEGEND_CONSTANTS(:,5) = strpad('T in component membrane (kelvin)');
    LEGEND_CONSTANTS(:,6) = strpad('F in component membrane (coulomb_per_mole)');
    LEGEND_CONSTANTS(:,117) = strpad('Cm in component membrane (microF)');
    LEGEND_CONSTANTS(:,7) = strpad('CmCentre in component membrane (microF)');
    LEGEND_CONSTANTS(:,8) = strpad('CmPeriphery in component membrane (microF)');
    LEGEND_ALGEBRAIC(:,28) = strpad('i_Na in component sodium_current (nanoA)');
    LEGEND_ALGEBRAIC(:,35) = strpad('i_Ca_L in component L_type_Ca_channel (nanoA)');
    LEGEND_ALGEBRAIC(:,40) = strpad('i_Ca_T in component T_type_Ca_channel (nanoA)');
    LEGEND_ALGEBRAIC(:,41) = strpad('i_to in component four_AP_sensitive_currents (nanoA)');
    LEGEND_ALGEBRAIC(:,42) = strpad('i_sus in component four_AP_sensitive_currents (nanoA)');
    LEGEND_ALGEBRAIC(:,44) = strpad('i_K_r in component rapid_delayed_rectifying_potassium_current (nanoA)');
    LEGEND_ALGEBRAIC(:,45) = strpad('i_K_s in component slow_delayed_rectifying_potassium_current (nanoA)');
    LEGEND_ALGEBRAIC(:,46) = strpad('i_f_Na in component hyperpolarisation_activated_current (nanoA)');
    LEGEND_ALGEBRAIC(:,47) = strpad('i_f_K in component hyperpolarisation_activated_current (nanoA)');
    LEGEND_ALGEBRAIC(:,48) = strpad('i_b_Na in component sodium_background_current (nanoA)');
    LEGEND_ALGEBRAIC(:,50) = strpad('i_b_Ca in component calcium_background_current (nanoA)');
    LEGEND_ALGEBRAIC(:,49) = strpad('i_b_K in component potassium_background_current (nanoA)');
    LEGEND_ALGEBRAIC(:,51) = strpad('i_NaCa in component sodium_calcium_exchanger (nanoA)');
    LEGEND_ALGEBRAIC(:,52) = strpad('i_p in component sodium_potassium_pump (nanoA)');
    LEGEND_CONSTANTS(:,133) = strpad('i_Ca_p in component persistent_calcium_current (nanoA)');
    LEGEND_CONSTANTS(:,118) = strpad('g_Na in component sodium_current (microlitre_per_second)');
    LEGEND_CONSTANTS(:,9) = strpad('g_Na_Centre_Published in component sodium_current (microlitre_per_second)');
    LEGEND_CONSTANTS(:,10) = strpad('g_Na_Centre_0DCapable in component sodium_current (microlitre_per_second)');
    LEGEND_CONSTANTS(:,11) = strpad('g_Na_Centre_1DCapable in component sodium_current (microlitre_per_second)');
    LEGEND_CONSTANTS(:,12) = strpad('g_Na_Periphery_Published in component sodium_current (microlitre_per_second)');
    LEGEND_CONSTANTS(:,13) = strpad('g_Na_Periphery_0DCapable in component sodium_current (microlitre_per_second)');
    LEGEND_CONSTANTS(:,14) = strpad('g_Na_Periphery_1DCapable in component sodium_current (microlitre_per_second)');
    LEGEND_CONSTANTS(:,112) = strpad('E_Na in component reversal_and_equilibrium_potentials (millivolt)');
    LEGEND_CONSTANTS(:,15) = strpad('Na_o in component ionic_concentrations (millimolar)');
    LEGEND_STATES(:,2) = strpad('m in component sodium_current_m_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,14) = strpad('h in component sodium_current_h_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,2) = strpad('m_infinity in component sodium_current_m_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,15) = strpad('tau_m in component sodium_current_m_gate (second)');
    LEGEND_ALGEBRAIC(:,1) = strpad('F_Na in component sodium_current_h_gate (dimensionless)');
    LEGEND_STATES(:,3) = strpad('h1 in component sodium_current_h_gate (dimensionless)');
    LEGEND_STATES(:,4) = strpad('h2 in component sodium_current_h_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,3) = strpad('h1_infinity in component sodium_current_h_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,16) = strpad('h2_infinity in component sodium_current_h_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,17) = strpad('tau_h1 in component sodium_current_h_gate (second)');
    LEGEND_ALGEBRAIC(:,29) = strpad('tau_h2 in component sodium_current_h_gate (second)');
    LEGEND_CONSTANTS(:,16) = strpad('g_Ca_L_Centre_Published in component L_type_Ca_channel (microS)');
    LEGEND_CONSTANTS(:,17) = strpad('g_Ca_L_Centre_0DCapable in component L_type_Ca_channel (microS)');
    LEGEND_CONSTANTS(:,18) = strpad('g_Ca_L_Centre_1DCapable in component L_type_Ca_channel (microS)');
    LEGEND_CONSTANTS(:,19) = strpad('g_Ca_L_Periphery_Published in component L_type_Ca_channel (microS)');
    LEGEND_CONSTANTS(:,20) = strpad('g_Ca_L_Periphery_0DCapable in component L_type_Ca_channel (microS)');
    LEGEND_CONSTANTS(:,21) = strpad('g_Ca_L_Periphery_1DCapable in component L_type_Ca_channel (microS)');
    LEGEND_CONSTANTS(:,119) = strpad('g_Ca_L in component L_type_Ca_channel (microS)');
    LEGEND_CONSTANTS(:,22) = strpad('E_Ca_L in component L_type_Ca_channel (millivolt)');
    LEGEND_STATES(:,5) = strpad('d_L in component L_type_Ca_channel_d_gate (dimensionless)');
    LEGEND_STATES(:,6) = strpad('f_L in component L_type_Ca_channel_f_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,4) = strpad('alpha_d_L in component L_type_Ca_channel_d_gate (per_second)');
    LEGEND_ALGEBRAIC(:,18) = strpad('beta_d_L in component L_type_Ca_channel_d_gate (per_second)');
    LEGEND_ALGEBRAIC(:,36) = strpad('d_L_infinity in component L_type_Ca_channel_d_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,30) = strpad('tau_d_L in component L_type_Ca_channel_d_gate (second)');
    LEGEND_ALGEBRAIC(:,5) = strpad('alpha_f_L in component L_type_Ca_channel_f_gate (per_second)');
    LEGEND_ALGEBRAIC(:,19) = strpad('beta_f_L in component L_type_Ca_channel_f_gate (per_second)');
    LEGEND_ALGEBRAIC(:,37) = strpad('f_L_infinity in component L_type_Ca_channel_f_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,31) = strpad('tau_f_L in component L_type_Ca_channel_f_gate (second)');
    LEGEND_CONSTANTS(:,23) = strpad('g_Ca_T_Centre_Published in component T_type_Ca_channel (microS)');
    LEGEND_CONSTANTS(:,24) = strpad('g_Ca_T_Centre_0DCapable in component T_type_Ca_channel (microS)');
    LEGEND_CONSTANTS(:,25) = strpad('g_Ca_T_Centre_1DCapable in component T_type_Ca_channel (microS)');
    LEGEND_CONSTANTS(:,26) = strpad('g_Ca_T_Periphery_Published in component T_type_Ca_channel (microS)');
    LEGEND_CONSTANTS(:,27) = strpad('g_Ca_T_Periphery_0DCapable in component T_type_Ca_channel (microS)');
    LEGEND_CONSTANTS(:,28) = strpad('g_Ca_T_Periphery_1DCapable in component T_type_Ca_channel (microS)');
    LEGEND_CONSTANTS(:,120) = strpad('g_Ca_T in component T_type_Ca_channel (microS)');
    LEGEND_CONSTANTS(:,29) = strpad('E_Ca_T in component T_type_Ca_channel (millivolt)');
    LEGEND_STATES(:,7) = strpad('d_T in component T_type_Ca_channel_d_gate (dimensionless)');
    LEGEND_STATES(:,8) = strpad('f_T in component T_type_Ca_channel_f_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,6) = strpad('alpha_d_T in component T_type_Ca_channel_d_gate (per_second)');
    LEGEND_ALGEBRAIC(:,20) = strpad('beta_d_T in component T_type_Ca_channel_d_gate (per_second)');
    LEGEND_ALGEBRAIC(:,38) = strpad('d_T_infinity in component T_type_Ca_channel_d_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,32) = strpad('tau_d_T in component T_type_Ca_channel_d_gate (second)');
    LEGEND_ALGEBRAIC(:,7) = strpad('alpha_f_T in component T_type_Ca_channel_f_gate (per_second)');
    LEGEND_ALGEBRAIC(:,21) = strpad('beta_f_T in component T_type_Ca_channel_f_gate (per_second)');
    LEGEND_ALGEBRAIC(:,39) = strpad('f_T_infinity in component T_type_Ca_channel_f_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,33) = strpad('tau_f_T in component T_type_Ca_channel_f_gate (second)');
    LEGEND_CONSTANTS(:,30) = strpad('g_to_Centre_Published in component four_AP_sensitive_currents (microS)');
    LEGEND_CONSTANTS(:,31) = strpad('g_to_Centre_0DCapable in component four_AP_sensitive_currents (microS)');
    LEGEND_CONSTANTS(:,32) = strpad('g_to_Centre_1DCapable in component four_AP_sensitive_currents (microS)');
    LEGEND_CONSTANTS(:,33) = strpad('g_to_Periphery_Published in component four_AP_sensitive_currents (microS)');
    LEGEND_CONSTANTS(:,34) = strpad('g_to_Periphery_0DCapable in component four_AP_sensitive_currents (microS)');
    LEGEND_CONSTANTS(:,35) = strpad('g_to_Periphery_1DCapable in component four_AP_sensitive_currents (microS)');
    LEGEND_CONSTANTS(:,121) = strpad('g_to in component four_AP_sensitive_currents (microS)');
    LEGEND_CONSTANTS(:,36) = strpad('g_sus_Centre_Published in component four_AP_sensitive_currents (microS)');
    LEGEND_CONSTANTS(:,37) = strpad('g_sus_Centre_0DCapable in component four_AP_sensitive_currents (microS)');
    LEGEND_CONSTANTS(:,38) = strpad('g_sus_Centre_1DCapable in component four_AP_sensitive_currents (microS)');
    LEGEND_CONSTANTS(:,39) = strpad('g_sus_Periphery_Published in component four_AP_sensitive_currents (microS)');
    LEGEND_CONSTANTS(:,40) = strpad('g_sus_Periphery_0DCapable in component four_AP_sensitive_currents (microS)');
    LEGEND_CONSTANTS(:,41) = strpad('g_sus_Periphery_1DCapable in component four_AP_sensitive_currents (microS)');
    LEGEND_CONSTANTS(:,122) = strpad('g_sus in component four_AP_sensitive_currents (microS)');
    LEGEND_CONSTANTS(:,113) = strpad('E_K in component reversal_and_equilibrium_potentials (millivolt)');
    LEGEND_STATES(:,9) = strpad('q in component four_AP_sensitive_currents_q_gate (dimensionless)');
    LEGEND_STATES(:,10) = strpad('r in component four_AP_sensitive_currents_r_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,8) = strpad('q_infinity in component four_AP_sensitive_currents_q_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,22) = strpad('tau_q in component four_AP_sensitive_currents_q_gate (second)');
    LEGEND_ALGEBRAIC(:,9) = strpad('r_infinity in component four_AP_sensitive_currents_r_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,23) = strpad('tau_r in component four_AP_sensitive_currents_r_gate (second)');
    LEGEND_CONSTANTS(:,42) = strpad('g_K_r_Centre_Published in component rapid_delayed_rectifying_potassium_current (microS)');
    LEGEND_CONSTANTS(:,43) = strpad('g_K_r_Centre_0DCapable in component rapid_delayed_rectifying_potassium_current (microS)');
    LEGEND_CONSTANTS(:,44) = strpad('g_K_r_Centre_1DCapable in component rapid_delayed_rectifying_potassium_current (microS)');
    LEGEND_CONSTANTS(:,45) = strpad('g_K_r_Periphery_Published in component rapid_delayed_rectifying_potassium_current (microS)');
    LEGEND_CONSTANTS(:,46) = strpad('g_K_r_Periphery_0DCapable in component rapid_delayed_rectifying_potassium_current (microS)');
    LEGEND_CONSTANTS(:,47) = strpad('g_K_r_Periphery_1DCapable in component rapid_delayed_rectifying_potassium_current (microS)');
    LEGEND_CONSTANTS(:,123) = strpad('g_K_r in component rapid_delayed_rectifying_potassium_current (microS)');
    LEGEND_ALGEBRAIC(:,43) = strpad('P_a in component rapid_delayed_rectifying_potassium_current (dimensionless)');
    LEGEND_STATES(:,11) = strpad('P_af in component rapid_delayed_rectifying_potassium_current_P_af_gate (dimensionless)');
    LEGEND_STATES(:,12) = strpad('P_as in component rapid_delayed_rectifying_potassium_current_P_as_gate (dimensionless)');
    LEGEND_STATES(:,13) = strpad('P_i in component rapid_delayed_rectifying_potassium_current_P_i_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,10) = strpad('P_af_infinity in component rapid_delayed_rectifying_potassium_current_P_af_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,24) = strpad('tau_P_af in component rapid_delayed_rectifying_potassium_current_P_af_gate (second)');
    LEGEND_ALGEBRAIC(:,25) = strpad('P_as_infinity in component rapid_delayed_rectifying_potassium_current_P_as_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,34) = strpad('tau_P_as in component rapid_delayed_rectifying_potassium_current_P_as_gate (second)');
    LEGEND_ALGEBRAIC(:,11) = strpad('P_i_infinity in component rapid_delayed_rectifying_potassium_current_P_i_gate (dimensionless)');
    LEGEND_CONSTANTS(:,114) = strpad('tau_P_i in component rapid_delayed_rectifying_potassium_current_P_i_gate (second)');
    LEGEND_CONSTANTS(:,48) = strpad('g_K_s_Centre_Published in component slow_delayed_rectifying_potassium_current (microS)');
    LEGEND_CONSTANTS(:,49) = strpad('g_K_s_Centre_0DCapable in component slow_delayed_rectifying_potassium_current (microS)');
    LEGEND_CONSTANTS(:,50) = strpad('g_K_s_Centre_1DCapable in component slow_delayed_rectifying_potassium_current (microS)');
    LEGEND_CONSTANTS(:,51) = strpad('g_K_s_Periphery_Published in component slow_delayed_rectifying_potassium_current (microS)');
    LEGEND_CONSTANTS(:,52) = strpad('g_K_s_Periphery_0DCapable in component slow_delayed_rectifying_potassium_current (microS)');
    LEGEND_CONSTANTS(:,53) = strpad('g_K_s_Periphery_1DCapable in component slow_delayed_rectifying_potassium_current (microS)');
    LEGEND_CONSTANTS(:,124) = strpad('g_K_s in component slow_delayed_rectifying_potassium_current (microS)');
    LEGEND_CONSTANTS(:,115) = strpad('E_K_s in component reversal_and_equilibrium_potentials (millivolt)');
    LEGEND_STATES(:,14) = strpad('xs in component slow_delayed_rectifying_potassium_current_xs_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,12) = strpad('alpha_xs in component slow_delayed_rectifying_potassium_current_xs_gate (per_second)');
    LEGEND_ALGEBRAIC(:,26) = strpad('beta_xs in component slow_delayed_rectifying_potassium_current_xs_gate (per_second)');
    LEGEND_CONSTANTS(:,54) = strpad('g_f_Na_Centre_Published in component hyperpolarisation_activated_current (microS)');
    LEGEND_CONSTANTS(:,55) = strpad('g_f_Na_Centre_0DCapable in component hyperpolarisation_activated_current (microS)');
    LEGEND_CONSTANTS(:,56) = strpad('g_f_Na_Centre_1DCapable in component hyperpolarisation_activated_current (microS)');
    LEGEND_CONSTANTS(:,57) = strpad('g_f_Na_Periphery_Published in component hyperpolarisation_activated_current (microS)');
    LEGEND_CONSTANTS(:,58) = strpad('g_f_Na_Periphery_0DCapable in component hyperpolarisation_activated_current (microS)');
    LEGEND_CONSTANTS(:,59) = strpad('g_f_Na_Periphery_1DCapable in component hyperpolarisation_activated_current (microS)');
    LEGEND_CONSTANTS(:,125) = strpad('g_f_Na in component hyperpolarisation_activated_current (microS)');
    LEGEND_CONSTANTS(:,60) = strpad('g_f_K_Centre_Published in component hyperpolarisation_activated_current (microS)');
    LEGEND_CONSTANTS(:,61) = strpad('g_f_K_Centre_0DCapable in component hyperpolarisation_activated_current (microS)');
    LEGEND_CONSTANTS(:,62) = strpad('g_f_K_Centre_1DCapable in component hyperpolarisation_activated_current (microS)');
    LEGEND_CONSTANTS(:,63) = strpad('g_f_K_Periphery_Published in component hyperpolarisation_activated_current (microS)');
    LEGEND_CONSTANTS(:,64) = strpad('g_f_K_Periphery_0DCapable in component hyperpolarisation_activated_current (microS)');
    LEGEND_CONSTANTS(:,65) = strpad('g_f_K_Periphery_1DCapable in component hyperpolarisation_activated_current (microS)');
    LEGEND_CONSTANTS(:,126) = strpad('g_f_K in component hyperpolarisation_activated_current (microS)');
    LEGEND_STATES(:,15) = strpad('y in component hyperpolarisation_activated_current_y_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,13) = strpad('alpha_y in component hyperpolarisation_activated_current_y_gate (per_second)');
    LEGEND_ALGEBRAIC(:,27) = strpad('beta_y in component hyperpolarisation_activated_current_y_gate (per_second)');
    LEGEND_CONSTANTS(:,66) = strpad('g_b_Na_Centre_Published in component sodium_background_current (microS)');
    LEGEND_CONSTANTS(:,67) = strpad('g_b_Na_Centre_0DCapable in component sodium_background_current (microS)');
    LEGEND_CONSTANTS(:,68) = strpad('g_b_Na_Centre_1DCapable in component sodium_background_current (microS)');
    LEGEND_CONSTANTS(:,69) = strpad('g_b_Na_Periphery_Published in component sodium_background_current (microS)');
    LEGEND_CONSTANTS(:,70) = strpad('g_b_Na_Periphery_0DCapable in component sodium_background_current (microS)');
    LEGEND_CONSTANTS(:,71) = strpad('g_b_Na_Periphery_1DCapable in component sodium_background_current (microS)');
    LEGEND_CONSTANTS(:,127) = strpad('g_b_Na in component sodium_background_current (microS)');
    LEGEND_CONSTANTS(:,72) = strpad('g_b_K_Centre_Published in component potassium_background_current (microS)');
    LEGEND_CONSTANTS(:,73) = strpad('g_b_K_Centre_0DCapable in component potassium_background_current (microS)');
    LEGEND_CONSTANTS(:,74) = strpad('g_b_K_Centre_1DCapable in component potassium_background_current (microS)');
    LEGEND_CONSTANTS(:,75) = strpad('g_b_K_Periphery_Published in component potassium_background_current (microS)');
    LEGEND_CONSTANTS(:,76) = strpad('g_b_K_Periphery_0DCapable in component potassium_background_current (microS)');
    LEGEND_CONSTANTS(:,77) = strpad('g_b_K_Periphery_1DCapable in component potassium_background_current (microS)');
    LEGEND_CONSTANTS(:,128) = strpad('g_b_K in component potassium_background_current (microS)');
    LEGEND_CONSTANTS(:,78) = strpad('g_b_Ca_Centre_Published in component calcium_background_current (microS)');
    LEGEND_CONSTANTS(:,79) = strpad('g_b_Ca_Centre_0DCapable in component calcium_background_current (microS)');
    LEGEND_CONSTANTS(:,80) = strpad('g_b_Ca_Centre_1DCapable in component calcium_background_current (microS)');
    LEGEND_CONSTANTS(:,81) = strpad('g_b_Ca_Periphery_Published in component calcium_background_current (microS)');
    LEGEND_CONSTANTS(:,82) = strpad('g_b_Ca_Periphery_0DCapable in component calcium_background_current (microS)');
    LEGEND_CONSTANTS(:,83) = strpad('g_b_Ca_Periphery_1DCapable in component calcium_background_current (microS)');
    LEGEND_CONSTANTS(:,129) = strpad('g_b_Ca in component calcium_background_current (microS)');
    LEGEND_CONSTANTS(:,116) = strpad('E_Ca in component reversal_and_equilibrium_potentials (millivolt)');
    LEGEND_CONSTANTS(:,84) = strpad('k_NaCa_Centre_Published in component sodium_calcium_exchanger (nanoA)');
    LEGEND_CONSTANTS(:,85) = strpad('k_NaCa_Centre_0DCapable in component sodium_calcium_exchanger (nanoA)');
    LEGEND_CONSTANTS(:,86) = strpad('k_NaCa_Centre_1DCapable in component sodium_calcium_exchanger (nanoA)');
    LEGEND_CONSTANTS(:,87) = strpad('k_NaCa_Periphery_Published in component sodium_calcium_exchanger (nanoA)');
    LEGEND_CONSTANTS(:,88) = strpad('k_NaCa_Periphery_0DCapable in component sodium_calcium_exchanger (nanoA)');
    LEGEND_CONSTANTS(:,89) = strpad('k_NaCa_Periphery_1DCapable in component sodium_calcium_exchanger (nanoA)');
    LEGEND_CONSTANTS(:,130) = strpad('k_NaCa in component sodium_calcium_exchanger (nanoA)');
    LEGEND_CONSTANTS(:,90) = strpad('d_NaCa in component sodium_calcium_exchanger (dimensionless)');
    LEGEND_CONSTANTS(:,91) = strpad('gamma_NaCa in component sodium_calcium_exchanger (dimensionless)');
    LEGEND_CONSTANTS(:,92) = strpad('Na_i in component ionic_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,93) = strpad('Ca_i in component ionic_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,94) = strpad('Ca_o in component ionic_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,95) = strpad('K_m_Na in component sodium_potassium_pump (millimolar)');
    LEGEND_CONSTANTS(:,96) = strpad('K_m_K in component sodium_potassium_pump (millimolar)');
    LEGEND_CONSTANTS(:,97) = strpad('i_p_max_Centre_Published in component sodium_potassium_pump (nanoA)');
    LEGEND_CONSTANTS(:,98) = strpad('i_p_max_Centre_0DCapable in component sodium_potassium_pump (nanoA)');
    LEGEND_CONSTANTS(:,99) = strpad('i_p_max_Centre_1DCapable in component sodium_potassium_pump (nanoA)');
    LEGEND_CONSTANTS(:,100) = strpad('i_p_max_Periphery_Published in component sodium_potassium_pump (nanoA)');
    LEGEND_CONSTANTS(:,101) = strpad('i_p_max_Periphery_0DCapable in component sodium_potassium_pump (nanoA)');
    LEGEND_CONSTANTS(:,102) = strpad('i_p_max_Periphery_1DCapable in component sodium_potassium_pump (nanoA)');
    LEGEND_CONSTANTS(:,131) = strpad('i_p_max in component sodium_potassium_pump (nanoA)');
    LEGEND_CONSTANTS(:,103) = strpad('K_o in component ionic_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,104) = strpad('i_Ca_p_max_Centre_Published in component persistent_calcium_current (nanoA)');
    LEGEND_CONSTANTS(:,105) = strpad('i_Ca_p_max_Centre_0DCapable in component persistent_calcium_current (nanoA)');
    LEGEND_CONSTANTS(:,106) = strpad('i_Ca_p_max_Centre_1DCapable in component persistent_calcium_current (nanoA)');
    LEGEND_CONSTANTS(:,107) = strpad('i_Ca_p_max_Periphery_Published in component persistent_calcium_current (nanoA)');
    LEGEND_CONSTANTS(:,108) = strpad('i_Ca_p_max_Periphery_0DCapable in component persistent_calcium_current (nanoA)');
    LEGEND_CONSTANTS(:,109) = strpad('i_Ca_p_max_Periphery_1DCapable in component persistent_calcium_current (nanoA)');
    LEGEND_CONSTANTS(:,132) = strpad('i_Ca_p_max in component persistent_calcium_current (nanoA)');
    LEGEND_CONSTANTS(:,110) = strpad('K_i in component ionic_concentrations (millimolar)');
    LEGEND_RATES(:,1) = strpad('d/dt V in component membrane (millivolt)');
    LEGEND_RATES(:,2) = strpad('d/dt m in component sodium_current_m_gate (dimensionless)');
    LEGEND_RATES(:,3) = strpad('d/dt h1 in component sodium_current_h_gate (dimensionless)');
    LEGEND_RATES(:,4) = strpad('d/dt h2 in component sodium_current_h_gate (dimensionless)');
    LEGEND_RATES(:,5) = strpad('d/dt d_L in component L_type_Ca_channel_d_gate (dimensionless)');
    LEGEND_RATES(:,6) = strpad('d/dt f_L in component L_type_Ca_channel_f_gate (dimensionless)');
    LEGEND_RATES(:,7) = strpad('d/dt d_T in component T_type_Ca_channel_d_gate (dimensionless)');
    LEGEND_RATES(:,8) = strpad('d/dt f_T in component T_type_Ca_channel_f_gate (dimensionless)');
    LEGEND_RATES(:,9) = strpad('d/dt q in component four_AP_sensitive_currents_q_gate (dimensionless)');
    LEGEND_RATES(:,10) = strpad('d/dt r in component four_AP_sensitive_currents_r_gate (dimensionless)');
    LEGEND_RATES(:,11) = strpad('d/dt P_af in component rapid_delayed_rectifying_potassium_current_P_af_gate (dimensionless)');
    LEGEND_RATES(:,12) = strpad('d/dt P_as in component rapid_delayed_rectifying_potassium_current_P_as_gate (dimensionless)');
    LEGEND_RATES(:,13) = strpad('d/dt P_i in component rapid_delayed_rectifying_potassium_current_P_i_gate (dimensionless)');
    LEGEND_RATES(:,14) = strpad('d/dt xs in component slow_delayed_rectifying_potassium_current_xs_gate (dimensionless)');
    LEGEND_RATES(:,15) = 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) = 1;
    CONSTANTS(:,2) = 0;
    CONSTANTS(:,3) = 1.0309347;
    STATES(:,1) = -39.013558536;
    CONSTANTS(:,4) = 8314;
    CONSTANTS(:,5) = 310;
    CONSTANTS(:,6) = 96845;
    CONSTANTS(:,7) = 2e-5;
    CONSTANTS(:,8) = 6.5e-5;
    CONSTANTS(:,9) = 0;
    CONSTANTS(:,10) = 0;
    CONSTANTS(:,11) = 0;
    CONSTANTS(:,12) = 1.2e-6;
    CONSTANTS(:,13) = 1.204e-6;
    CONSTANTS(:,14) = 3.7e-7;
    CONSTANTS(:,15) = 140;
    STATES(:,2) = 0.092361701692;
    STATES(:,3) = 0.015905380261;
    STATES(:,4) = 0.01445216109;
    CONSTANTS(:,16) = 0.0058;
    CONSTANTS(:,17) = 0.0057938;
    CONSTANTS(:,18) = 0.0082;
    CONSTANTS(:,19) = 0.0659;
    CONSTANTS(:,20) = 0.06588648;
    CONSTANTS(:,21) = 0.0659;
    CONSTANTS(:,22) = 46.4;
    STATES(:,5) = 0.04804900895;
    STATES(:,6) = 0.48779845203;
    CONSTANTS(:,23) = 0.0043;
    CONSTANTS(:,24) = 0.00427806;
    CONSTANTS(:,25) = 0.0021;
    CONSTANTS(:,26) = 0.0139;
    CONSTANTS(:,27) = 0.0138823;
    CONSTANTS(:,28) = 0.00694;
    CONSTANTS(:,29) = 45;
    STATES(:,7) = 0.42074047435;
    STATES(:,8) = 0.038968420558;
    CONSTANTS(:,30) = 0.00491;
    CONSTANTS(:,31) = 0.004905;
    CONSTANTS(:,32) = 0.004905;
    CONSTANTS(:,33) = 0.03649;
    CONSTANTS(:,34) = 0.036495;
    CONSTANTS(:,35) = 0.0365;
    CONSTANTS(:,36) = 6.65e-5;
    CONSTANTS(:,37) = 6.645504e-5;
    CONSTANTS(:,38) = 0.000266;
    CONSTANTS(:,39) = 0.0114;
    CONSTANTS(:,40) = 0.01138376;
    CONSTANTS(:,41) = 0.0114;
    STATES(:,9) = 0.29760539675;
    STATES(:,10) = 0.064402950262;
    CONSTANTS(:,42) = 0.000797;
    CONSTANTS(:,43) = 0.00079704;
    CONSTANTS(:,44) = 0.000738;
    CONSTANTS(:,45) = 0.016;
    CONSTANTS(:,46) = 0.016;
    CONSTANTS(:,47) = 0.0208;
    STATES(:,11) = 0.13034201158;
    STATES(:,12) = 0.46960956028;
    STATES(:,13) = 0.87993375273;
    CONSTANTS(:,48) = 0.000518;
    CONSTANTS(:,49) = 0.0003445;
    CONSTANTS(:,50) = 0.000345;
    CONSTANTS(:,51) = 0.0104;
    CONSTANTS(:,52) = 0.0104;
    CONSTANTS(:,53) = 0.0104;
    STATES(:,14) = 0.082293827208;
    CONSTANTS(:,54) = 0.000548;
    CONSTANTS(:,55) = 0.0005465;
    CONSTANTS(:,56) = 0.000437;
    CONSTANTS(:,57) = 0.0069;
    CONSTANTS(:,58) = 0.006875;
    CONSTANTS(:,59) = 0.0055;
    CONSTANTS(:,60) = 0.000548;
    CONSTANTS(:,61) = 0.0005465;
    CONSTANTS(:,62) = 0.000437;
    CONSTANTS(:,63) = 0.0069;
    CONSTANTS(:,64) = 0.006875;
    CONSTANTS(:,65) = 0.0055;
    STATES(:,15) = 0.03889291759;
    CONSTANTS(:,66) = 5.8e-5;
    CONSTANTS(:,67) = 5.81818e-5;
    CONSTANTS(:,68) = 5.8e-5;
    CONSTANTS(:,69) = 0.000189;
    CONSTANTS(:,70) = 0.0001888;
    CONSTANTS(:,71) = 0.000189;
    CONSTANTS(:,72) = 2.52e-5;
    CONSTANTS(:,73) = 2.523636e-5;
    CONSTANTS(:,74) = 2.52e-5;
    CONSTANTS(:,75) = 8.19e-5;
    CONSTANTS(:,76) = 8.1892e-5;
    CONSTANTS(:,77) = 8.19e-5;
    CONSTANTS(:,78) = 1.32e-5;
    CONSTANTS(:,79) = 1.3236e-5;
    CONSTANTS(:,80) = 1.323e-5;
    CONSTANTS(:,81) = 4.3e-5;
    CONSTANTS(:,82) = 4.2952e-5;
    CONSTANTS(:,83) = 4.29e-5;
    CONSTANTS(:,84) = 2.7e-6;
    CONSTANTS(:,85) = 2.7229e-6;
    CONSTANTS(:,86) = 2.8e-6;
    CONSTANTS(:,87) = 8.8e-6;
    CONSTANTS(:,88) = 8.83584e-6;
    CONSTANTS(:,89) = 8.8e-6;
    CONSTANTS(:,90) = 0.0001;
    CONSTANTS(:,91) = 0.5;
    CONSTANTS(:,92) = 8;
    CONSTANTS(:,93) = 0.0001;
    CONSTANTS(:,94) = 2;
    CONSTANTS(:,95) = 5.64;
    CONSTANTS(:,96) = 0.621;
    CONSTANTS(:,97) = 0.0478;
    CONSTANTS(:,98) = 0.04782545;
    CONSTANTS(:,99) = 0.0478;
    CONSTANTS(:,100) = 0.16;
    CONSTANTS(:,101) = 0.1551936;
    CONSTANTS(:,102) = 0.16;
    CONSTANTS(:,103) = 5.4;
    CONSTANTS(:,104) = 0;
    CONSTANTS(:,105) = 0;
    CONSTANTS(:,106) = 0.0042;
    CONSTANTS(:,107) = 0;
    CONSTANTS(:,108) = 0;
    CONSTANTS(:,109) = 0.03339;
    CONSTANTS(:,110) = 140;
    CONSTANTS(:,111) = piecewise({CONSTANTS(:,1)==0.00000, ( 1.07000.*( 3.00000.*CONSTANTS(:,2) - 0.100000))./( 3.00000.*(1.00000+ 0.774500.*exp( - ( 3.00000.*CONSTANTS(:,2) - 2.05000)./0.295000))) , CONSTANTS(:,1)==1.00000, ( CONSTANTS(:,3).*CONSTANTS(:,2))./(1.00000+ 0.774500.*exp( - ( 3.00000.*CONSTANTS(:,2) - 2.05000)./0.295000)) }, ( 1.07000.*29.0000.*CONSTANTS(:,2))./( 30.0000.*(1.00000+ 0.774500.*exp( - ( 29.0000.*CONSTANTS(:,2) - 24.5000)./1.95000))));
    CONSTANTS(:,112) =  (( CONSTANTS(:,4).*CONSTANTS(:,5))./CONSTANTS(:,6)).*log(CONSTANTS(:,15)./CONSTANTS(:,92));
    CONSTANTS(:,113) =  (( CONSTANTS(:,4).*CONSTANTS(:,5))./CONSTANTS(:,6)).*log(CONSTANTS(:,103)./CONSTANTS(:,110));
    CONSTANTS(:,114) = piecewise({CONSTANTS(:,1)==0.00000, 0.00200000 , CONSTANTS(:,1)==1.00000, 0.00200000 }, 0.00600000);
    CONSTANTS(:,115) = piecewise({CONSTANTS(:,1)==0.00000,  (( CONSTANTS(:,4).*CONSTANTS(:,5))./CONSTANTS(:,6)).*log((CONSTANTS(:,103)+ 0.120000.*CONSTANTS(:,15))./(CONSTANTS(:,110)+ 0.120000.*CONSTANTS(:,92))) },  (( CONSTANTS(:,4).*CONSTANTS(:,5))./CONSTANTS(:,6)).*log((CONSTANTS(:,103)+ 0.0300000.*CONSTANTS(:,15))./(CONSTANTS(:,110)+ 0.0300000.*CONSTANTS(:,92))));
    CONSTANTS(:,116) =  (( CONSTANTS(:,4).*CONSTANTS(:,5))./( 2.00000.*CONSTANTS(:,6))).*log(CONSTANTS(:,94)./CONSTANTS(:,93));
    CONSTANTS(:,117) = CONSTANTS(:,7)+ CONSTANTS(:,111).*(CONSTANTS(:,8) - CONSTANTS(:,7));
    CONSTANTS(:,118) = piecewise({CONSTANTS(:,1)==0.00000, CONSTANTS(:,9)+ CONSTANTS(:,111).*(CONSTANTS(:,12) - CONSTANTS(:,9)) , CONSTANTS(:,1)==1.00000, CONSTANTS(:,10)+ CONSTANTS(:,111).*(CONSTANTS(:,13) - CONSTANTS(:,10)) }, CONSTANTS(:,11)+ CONSTANTS(:,111).*(CONSTANTS(:,14) - CONSTANTS(:,11)));
    CONSTANTS(:,119) = piecewise({CONSTANTS(:,1)==0.00000, CONSTANTS(:,16)+ CONSTANTS(:,111).*(CONSTANTS(:,19) - CONSTANTS(:,16)) , CONSTANTS(:,1)==1.00000, CONSTANTS(:,17)+ CONSTANTS(:,111).*(CONSTANTS(:,20) - CONSTANTS(:,17)) }, CONSTANTS(:,18)+ CONSTANTS(:,111).*(CONSTANTS(:,21) - CONSTANTS(:,18)));
    CONSTANTS(:,120) = piecewise({CONSTANTS(:,1)==0.00000, CONSTANTS(:,23)+ CONSTANTS(:,111).*(CONSTANTS(:,26) - CONSTANTS(:,23)) , CONSTANTS(:,1)==1.00000, CONSTANTS(:,24)+ CONSTANTS(:,111).*(CONSTANTS(:,27) - CONSTANTS(:,24)) }, CONSTANTS(:,25)+ CONSTANTS(:,111).*(CONSTANTS(:,28) - CONSTANTS(:,25)));
    CONSTANTS(:,121) = piecewise({CONSTANTS(:,1)==0.00000, CONSTANTS(:,30)+ CONSTANTS(:,111).*(CONSTANTS(:,33) - CONSTANTS(:,30)) , CONSTANTS(:,1)==1.00000, CONSTANTS(:,31)+ CONSTANTS(:,111).*(CONSTANTS(:,34) - CONSTANTS(:,31)) }, CONSTANTS(:,32)+ CONSTANTS(:,111).*(CONSTANTS(:,35) - CONSTANTS(:,32)));
    CONSTANTS(:,122) = piecewise({CONSTANTS(:,1)==0.00000, CONSTANTS(:,36)+ CONSTANTS(:,111).*(CONSTANTS(:,39) - CONSTANTS(:,36)) , CONSTANTS(:,1)==1.00000, CONSTANTS(:,37)+ CONSTANTS(:,111).*(CONSTANTS(:,40) - CONSTANTS(:,37)) }, CONSTANTS(:,38)+ CONSTANTS(:,111).*(CONSTANTS(:,41) - CONSTANTS(:,38)));
    CONSTANTS(:,123) = piecewise({CONSTANTS(:,1)==0.00000, CONSTANTS(:,42)+ CONSTANTS(:,111).*(CONSTANTS(:,45) - CONSTANTS(:,42)) , CONSTANTS(:,1)==1.00000, CONSTANTS(:,43)+ CONSTANTS(:,111).*(CONSTANTS(:,46) - CONSTANTS(:,43)) }, CONSTANTS(:,44)+ CONSTANTS(:,111).*(CONSTANTS(:,47) - CONSTANTS(:,44)));
    CONSTANTS(:,124) = piecewise({CONSTANTS(:,1)==0.00000, CONSTANTS(:,48)+ CONSTANTS(:,111).*(CONSTANTS(:,51) - CONSTANTS(:,48)) , CONSTANTS(:,1)==1.00000, CONSTANTS(:,49)+ CONSTANTS(:,111).*(CONSTANTS(:,52) - CONSTANTS(:,49)) }, CONSTANTS(:,50)+ CONSTANTS(:,111).*(CONSTANTS(:,53) - CONSTANTS(:,50)));
    CONSTANTS(:,125) = piecewise({CONSTANTS(:,1)==0.00000, CONSTANTS(:,54)+ CONSTANTS(:,111).*(CONSTANTS(:,57) - CONSTANTS(:,54)) , CONSTANTS(:,1)==1.00000, CONSTANTS(:,55)+ CONSTANTS(:,111).*(CONSTANTS(:,58) - CONSTANTS(:,55)) }, CONSTANTS(:,56)+ CONSTANTS(:,111).*(CONSTANTS(:,59) - CONSTANTS(:,56)));
    CONSTANTS(:,126) = piecewise({CONSTANTS(:,1)==0.00000, CONSTANTS(:,60)+ CONSTANTS(:,111).*(CONSTANTS(:,63) - CONSTANTS(:,60)) , CONSTANTS(:,1)==1.00000, CONSTANTS(:,61)+ CONSTANTS(:,111).*(CONSTANTS(:,64) - CONSTANTS(:,61)) }, CONSTANTS(:,62)+ CONSTANTS(:,111).*(CONSTANTS(:,65) - CONSTANTS(:,62)));
    CONSTANTS(:,127) = piecewise({CONSTANTS(:,1)==0.00000, CONSTANTS(:,66)+ CONSTANTS(:,111).*(CONSTANTS(:,69) - CONSTANTS(:,66)) , CONSTANTS(:,1)==1.00000, CONSTANTS(:,67)+ CONSTANTS(:,111).*(CONSTANTS(:,70) - CONSTANTS(:,67)) }, CONSTANTS(:,68)+ CONSTANTS(:,111).*(CONSTANTS(:,71) - CONSTANTS(:,68)));
    CONSTANTS(:,128) = piecewise({CONSTANTS(:,1)==0.00000, CONSTANTS(:,72)+ CONSTANTS(:,111).*(CONSTANTS(:,75) - CONSTANTS(:,72)) , CONSTANTS(:,1)==1.00000, CONSTANTS(:,73)+ CONSTANTS(:,111).*(CONSTANTS(:,76) - CONSTANTS(:,73)) }, CONSTANTS(:,74)+ CONSTANTS(:,111).*(CONSTANTS(:,77) - CONSTANTS(:,74)));
    CONSTANTS(:,129) = piecewise({CONSTANTS(:,1)==0.00000, CONSTANTS(:,78)+ CONSTANTS(:,111).*(CONSTANTS(:,81) - CONSTANTS(:,78)) , CONSTANTS(:,1)==1.00000, CONSTANTS(:,79)+ CONSTANTS(:,111).*(CONSTANTS(:,82) - CONSTANTS(:,79)) }, CONSTANTS(:,80)+ CONSTANTS(:,111).*(CONSTANTS(:,83) - CONSTANTS(:,80)));
    CONSTANTS(:,130) = piecewise({CONSTANTS(:,1)==0.00000, CONSTANTS(:,84)+ CONSTANTS(:,111).*(CONSTANTS(:,87) - CONSTANTS(:,84)) , CONSTANTS(:,1)==1.00000, CONSTANTS(:,85)+ CONSTANTS(:,111).*(CONSTANTS(:,88) - CONSTANTS(:,85)) }, CONSTANTS(:,86)+ CONSTANTS(:,111).*(CONSTANTS(:,89) - CONSTANTS(:,86)));
    CONSTANTS(:,131) = piecewise({CONSTANTS(:,1)==0.00000, CONSTANTS(:,97)+ CONSTANTS(:,111).*(CONSTANTS(:,100) - CONSTANTS(:,97)) , CONSTANTS(:,1)==1.00000, CONSTANTS(:,98)+ CONSTANTS(:,111).*(CONSTANTS(:,101) - CONSTANTS(:,98)) }, CONSTANTS(:,99)+ CONSTANTS(:,111).*(CONSTANTS(:,102) - CONSTANTS(:,99)));
    CONSTANTS(:,132) = piecewise({CONSTANTS(:,1)==0.00000, CONSTANTS(:,104)+ CONSTANTS(:,111).*(CONSTANTS(:,107) - CONSTANTS(:,104)) , CONSTANTS(:,1)==1.00000, CONSTANTS(:,105)+ CONSTANTS(:,111).*(CONSTANTS(:,108) - CONSTANTS(:,105)) }, CONSTANTS(:,106)+ CONSTANTS(:,111).*(CONSTANTS(:,109) - CONSTANTS(:,106)));
    CONSTANTS(:,133) = ( CONSTANTS(:,132).*CONSTANTS(:,93))./(CONSTANTS(:,93)+0.000400000);
    if (isempty(STATES)), warning('Initial values for states not set');, end
end

function [RATES, ALGEBRAIC] = computeRates(VOI, STATES, CONSTANTS)
    global algebraicVariableCount;
    statesSize = size(STATES);
    statesColumnCount = statesSize(2);
    if ( statesColumnCount == 1)
        STATES = STATES';
        ALGEBRAIC = zeros(1, algebraicVariableCount);
        utilOnes = 1;
    else
        statesRowCount = statesSize(1);
        ALGEBRAIC = zeros(statesRowCount, algebraicVariableCount);
        RATES = zeros(statesRowCount, statesColumnCount);
        utilOnes = ones(statesRowCount, 1);
    end
    ALGEBRAIC(:,11) = 1.00000./(1.00000+exp((STATES(:,1)+18.6000)./10.1000));
    RATES(:,13) = (ALGEBRAIC(:,11) - STATES(:,13))./CONSTANTS(:,114);
    ALGEBRAIC(:,2) = piecewise({CONSTANTS(:,1)==0.00000, power(1.00000./(1.00000+exp( - STATES(:,1)./5.46000)), 1.00000./3.00000) }, power(1.00000./(1.00000+exp( - (STATES(:,1)+30.3200)./5.46000)), 1.00000./3.00000));
    ALGEBRAIC(:,15) = piecewise({CONSTANTS(:,1)==0.00000, 0.000624700./( 0.832000.*exp(  - 0.335000.*(STATES(:,1)+56.7000))+ 0.627000.*exp( 0.0820000.*(STATES(:,1)+65.0100)))+4.00000e-05 }, 0.000624700./( 0.832217.*exp(  - 0.335660.*(STATES(:,1)+56.7062))+ 0.627400.*exp( 0.0823000.*(STATES(:,1)+65.0131)))+4.56900e-05);
    RATES(:,2) = (ALGEBRAIC(:,2) - STATES(:,2))./ALGEBRAIC(:,15);
    ALGEBRAIC(:,3) = 1.00000./(1.00000+exp((STATES(:,1)+66.1000)./6.40000));
    ALGEBRAIC(:,17) = ( 3.71700e-06.*exp(  - 0.281500.*(STATES(:,1)+17.1100)))./(1.00000+ 0.00373200.*exp(  - 0.342600.*(STATES(:,1)+37.7600)))+0.000597700;
    RATES(:,3) = (ALGEBRAIC(:,3) - STATES(:,3))./ALGEBRAIC(:,17);
    ALGEBRAIC(:,8) = 1.00000./(1.00000+exp((STATES(:,1)+59.3700)./13.1000));
    ALGEBRAIC(:,22) = piecewise({CONSTANTS(:,1)==0.00000, 0.0101000+0.0651700./( 0.570000.*exp(  - 0.0800000.*(STATES(:,1)+49.0000)))+ 2.40000e-05.*exp( 0.100000.*(STATES(:,1)+50.9300)) , CONSTANTS(:,1)==1.00000,  (0.00100000./3.00000).*(30.3100+195.500./( 0.568600.*exp(  - 0.0816100.*(STATES(:,1)+39.0000+ 10.0000.*CONSTANTS(:,111)))+ 0.717400.*exp( (0.271900 -  0.171900.*CONSTANTS(:,111)).*1.00000.*(STATES(:,1)+40.9300+ 10.0000.*CONSTANTS(:,111))))) }, 0.0101000+0.0651700./( 0.568600.*exp(  - 0.0816100.*(STATES(:,1)+39.0000))+ 0.717400.*exp( 0.271900.*(STATES(:,1)+40.9300))));
    RATES(:,9) = (ALGEBRAIC(:,8) - STATES(:,9))./ALGEBRAIC(:,22);
    ALGEBRAIC(:,9) = 1.00000./(1.00000+exp( - (STATES(:,1) - 10.9300)./19.7000));
    ALGEBRAIC(:,23) = piecewise({CONSTANTS(:,1)==0.00000,  0.00100000.*(2.98000+15.5900./( 1.03700.*exp( 0.0900000.*(STATES(:,1)+30.6100))+ 0.369000.*exp(  - 0.120000.*(STATES(:,1)+23.8400)))) , CONSTANTS(:,1)==1.00000,  0.00250000.*(1.19100+7.83800./( 1.03700.*exp( 0.0901200.*(STATES(:,1)+30.6100))+ 0.369000.*exp(  - 0.119000.*(STATES(:,1)+23.8400)))) },  0.00100000.*(2.98000+19.5900./( 1.03700.*exp( 0.0901200.*(STATES(:,1)+30.6100))+ 0.369000.*exp(  - 0.119000.*(STATES(:,1)+23.8400)))));
    RATES(:,10) = (ALGEBRAIC(:,9) - STATES(:,10))./ALGEBRAIC(:,23);
    ALGEBRAIC(:,10) = piecewise({CONSTANTS(:,1) ~= 2.00000, 1.00000./(1.00000+exp( - (STATES(:,1)+14.2000)./10.6000)) }, 1.00000./(1.00000+exp( - (STATES(:,1)+13.2000)./10.6000)));
    ALGEBRAIC(:,24) = piecewise({CONSTANTS(:,1) ~= 2.00000, 1.00000./( 37.2000.*exp((STATES(:,1) - 9.00000)./15.9000)+ 0.960000.*exp( - (STATES(:,1) - 9.00000)./22.5000)) }, 1.00000./( 37.2000.*exp((STATES(:,1) - 10.0000)./15.9000)+ 0.960000.*exp( - (STATES(:,1) - 10.0000)./22.5000)));
    RATES(:,11) = (ALGEBRAIC(:,10) - STATES(:,11))./ALGEBRAIC(:,24);
    ALGEBRAIC(:,12) = 14.0000./(1.00000+exp( - (STATES(:,1) - 40.0000)./9.00000));
    ALGEBRAIC(:,26) =  1.00000.*exp( - STATES(:,1)./45.0000);
    RATES(:,14) =  ALGEBRAIC(:,12).*(1.00000 - STATES(:,14)) -  ALGEBRAIC(:,26).*STATES(:,14);
    ALGEBRAIC(:,13) = piecewise({CONSTANTS(:,1)==0.00000,  1.00000.*exp( - (STATES(:,1)+78.9100)./26.6200) },  1.00000.*exp( - (STATES(:,1)+78.9100)./26.6300));
    ALGEBRAIC(:,27) =  1.00000.*exp((STATES(:,1)+75.1300)./21.2500);
    RATES(:,15) =  ALGEBRAIC(:,13).*(1.00000 - STATES(:,15)) -  ALGEBRAIC(:,27).*STATES(:,15);
    ALGEBRAIC(:,16) = ALGEBRAIC(:,3);
    ALGEBRAIC(:,29) = ( 3.18600e-08.*exp(  - 0.621900.*(STATES(:,1)+18.8000)))./(1.00000+ 7.18900e-05.*exp(  - 0.668300.*(STATES(:,1)+34.0700)))+0.00355600;
    RATES(:,4) = (ALGEBRAIC(:,16) - STATES(:,4))./ALGEBRAIC(:,29);
    ALGEBRAIC(:,25) = ALGEBRAIC(:,10);
    ALGEBRAIC(:,34) = piecewise({CONSTANTS(:,1) ~= 2.00000, 1.00000./( 4.20000.*exp((STATES(:,1) - 9.00000)./17.0000)+ 0.150000.*exp( - (STATES(:,1) - 9.00000)./21.6000)) }, 1.00000./( 4.20000.*exp((STATES(:,1) - 10.0000)./17.0000)+ 0.150000.*exp( - (STATES(:,1) - 10.0000)./21.6000)));
    RATES(:,12) = (ALGEBRAIC(:,25) - STATES(:,12))./ALGEBRAIC(:,34);
    ALGEBRAIC(:,36) = piecewise({CONSTANTS(:,1)==0.00000, 1.00000./(1.00000+exp( - (STATES(:,1)+23.1000)./6.00000)) , CONSTANTS(:,1)==1.00000, 1.00000./(1.00000+exp( - (STATES(:,1)+22.3000+ 0.800000.*CONSTANTS(:,111))./6.00000)) }, 1.00000./(1.00000+exp( - (STATES(:,1)+22.2000)./6.00000)));
    ALGEBRAIC(:,4) = piecewise({CONSTANTS(:,1)==0.00000, (  - 28.3800.*(STATES(:,1)+35.0000))./(exp( - (STATES(:,1)+35.0000)./2.50000) - 1.00000) - ( 84.9000.*STATES(:,1))./(exp(  - 0.208000.*STATES(:,1)) - 1.00000) , CONSTANTS(:,1)==1.00000, (  - 28.3900.*(STATES(:,1)+35.0000))./(exp( - (STATES(:,1)+35.0000)./2.50000) - 1.00000) - ( 84.9000.*STATES(:,1))./(exp(  - 0.208000.*STATES(:,1)) - 1.00000) }, (  - 28.4000.*(STATES(:,1)+35.0000))./(exp( - (STATES(:,1)+35.0000)./2.50000) - 1.00000) - ( 84.9000.*STATES(:,1))./(exp(  - 0.208000.*STATES(:,1)) - 1.00000));
    ALGEBRAIC(:,18) = piecewise({CONSTANTS(:,1)==1.00000, ( 11.4300.*(STATES(:,1) - 5.00000))./(exp( 0.400000.*(STATES(:,1) - 5.00000)) - 1.00000) }, ( 11.4200.*(STATES(:,1) - 5.00000))./(exp( 0.400000.*(STATES(:,1) - 5.00000)) - 1.00000));
    ALGEBRAIC(:,30) = 2.00000./(ALGEBRAIC(:,4)+ALGEBRAIC(:,18));
    RATES(:,5) = (ALGEBRAIC(:,36) - STATES(:,5))./ALGEBRAIC(:,30);
    ALGEBRAIC(:,37) = 1.00000./(1.00000+exp((STATES(:,1)+45.0000)./5.00000));
    ALGEBRAIC(:,5) = piecewise({CONSTANTS(:,1)==1.00000, ( 3.75000.*(STATES(:,1)+28.0000))./(exp((STATES(:,1)+28.0000)./4.00000) - 1.00000) }, ( 3.12000.*(STATES(:,1)+28.0000))./(exp((STATES(:,1)+28.0000)./4.00000) - 1.00000));
    ALGEBRAIC(:,19) = piecewise({CONSTANTS(:,1)==1.00000, 30.0000./(1.00000+exp( - (STATES(:,1)+28.0000)./4.00000)) }, 25.0000./(1.00000+exp( - (STATES(:,1)+28.0000)./4.00000)));
    ALGEBRAIC(:,31) = piecewise({CONSTANTS(:,1)==1.00000, (1.20000 -  0.200000.*CONSTANTS(:,111))./(ALGEBRAIC(:,5)+ALGEBRAIC(:,19)) }, 1.00000./(ALGEBRAIC(:,5)+ALGEBRAIC(:,19)));
    RATES(:,6) = (ALGEBRAIC(:,37) - STATES(:,6))./ALGEBRAIC(:,31);
    ALGEBRAIC(:,38) = 1.00000./(1.00000+exp( - (STATES(:,1)+37.0000)./6.80000));
    ALGEBRAIC(:,6) =  1068.00.*exp((STATES(:,1)+26.3000)./30.0000);
    ALGEBRAIC(:,20) =  1068.00.*exp( - (STATES(:,1)+26.3000)./30.0000);
    ALGEBRAIC(:,32) = 1.00000./(ALGEBRAIC(:,6)+ALGEBRAIC(:,20));
    RATES(:,7) = (ALGEBRAIC(:,38) - STATES(:,7))./ALGEBRAIC(:,32);
    ALGEBRAIC(:,39) = 1.00000./(1.00000+exp((STATES(:,1)+71.0000)./9.00000));
    ALGEBRAIC(:,7) = piecewise({CONSTANTS(:,1)==1.00000,  15.3000.*exp( - (STATES(:,1)+71.0000+ 0.700000.*CONSTANTS(:,111))./83.3000) },  15.3000.*exp( - (STATES(:,1)+71.7000)./83.3000));
    ALGEBRAIC(:,21) = piecewise({CONSTANTS(:,1)==1.00000,  15.0000.*exp((STATES(:,1)+71.0000)./15.3800) },  15.0000.*exp((STATES(:,1)+71.7000)./15.3800));
    ALGEBRAIC(:,33) = 1.00000./(ALGEBRAIC(:,7)+ALGEBRAIC(:,21));
    RATES(:,8) = (ALGEBRAIC(:,39) - STATES(:,8))./ALGEBRAIC(:,33);
    ALGEBRAIC(:,1) = piecewise({CONSTANTS(:,1)==0.00000, ( 0.0952000.*exp(  - 0.0630000.*(STATES(:,1)+34.4000)))./(1.00000+ 1.66000.*exp(  - 0.225000.*(STATES(:,1)+63.7000)))+0.0869000 }, ( 0.0951800.*exp(  - 0.0630600.*(STATES(:,1)+34.4000)))./(1.00000+ 1.66200.*exp(  - 0.225100.*(STATES(:,1)+63.7000)))+0.0869300);
    ALGEBRAIC(:,14) =  (1.00000 - ALGEBRAIC(:,1)).*STATES(:,3)+ ALGEBRAIC(:,1).*STATES(:,4);
    ALGEBRAIC(:,28) =  (( (( CONSTANTS(:,118).*power(STATES(:,2), 3.00000).*ALGEBRAIC(:,14).*CONSTANTS(:,15).*power(CONSTANTS(:,6), 2.00000))./( CONSTANTS(:,4).*CONSTANTS(:,5))).*(exp(( (STATES(:,1) - CONSTANTS(:,112)).*CONSTANTS(:,6))./( CONSTANTS(:,4).*CONSTANTS(:,5))) - 1.00000))./(exp(( STATES(:,1).*CONSTANTS(:,6))./( CONSTANTS(:,4).*CONSTANTS(:,5))) - 1.00000)).*STATES(:,1);
    ALGEBRAIC(:,35) =  CONSTANTS(:,119).*( STATES(:,6).*STATES(:,5)+0.00600000./(1.00000+exp( - (STATES(:,1)+14.1000)./6.00000))).*(STATES(:,1) - CONSTANTS(:,22));
    ALGEBRAIC(:,40) =  CONSTANTS(:,120).*STATES(:,7).*STATES(:,8).*(STATES(:,1) - CONSTANTS(:,29));
    ALGEBRAIC(:,41) =  CONSTANTS(:,121).*STATES(:,9).*STATES(:,10).*(STATES(:,1) - CONSTANTS(:,113));
    ALGEBRAIC(:,42) =  CONSTANTS(:,122).*STATES(:,10).*(STATES(:,1) - CONSTANTS(:,113));
    ALGEBRAIC(:,43) =  0.600000.*STATES(:,11)+ 0.400000.*STATES(:,12);
    ALGEBRAIC(:,44) =  CONSTANTS(:,123).*ALGEBRAIC(:,43).*STATES(:,13).*(STATES(:,1) - CONSTANTS(:,113));
    ALGEBRAIC(:,45) =  CONSTANTS(:,124).*power(STATES(:,14), 2.00000).*(STATES(:,1) - CONSTANTS(:,115));
    ALGEBRAIC(:,46) = piecewise({CONSTANTS(:,1) ~= 2.00000,  CONSTANTS(:,125).*STATES(:,15).*(STATES(:,1) - CONSTANTS(:,112)) },  CONSTANTS(:,125).*STATES(:,15).*(STATES(:,1) - 77.6000));
    ALGEBRAIC(:,47) = piecewise({CONSTANTS(:,1) ~= 2.00000,  CONSTANTS(:,126).*STATES(:,15).*(STATES(:,1) - CONSTANTS(:,113)) },  CONSTANTS(:,126).*STATES(:,15).*(STATES(:,1)+102.000));
    ALGEBRAIC(:,48) =  CONSTANTS(:,127).*(STATES(:,1) - CONSTANTS(:,112));
    ALGEBRAIC(:,50) =  CONSTANTS(:,129).*(STATES(:,1) - CONSTANTS(:,116));
    ALGEBRAIC(:,49) =  CONSTANTS(:,128).*(STATES(:,1) - CONSTANTS(:,113));
    ALGEBRAIC(:,51) = piecewise({CONSTANTS(:,1)==0.00000, ( CONSTANTS(:,130).*( power(CONSTANTS(:,92), 3.00000).*CONSTANTS(:,94).*exp( 0.0374300.*STATES(:,1).*CONSTANTS(:,91)) -  power(CONSTANTS(:,15), 3.00000).*CONSTANTS(:,93).*exp( 0.0374000.*STATES(:,1).*(CONSTANTS(:,91) - 1.00000))))./(1.00000+ CONSTANTS(:,90).*( CONSTANTS(:,93).*power(CONSTANTS(:,15), 3.00000)+ CONSTANTS(:,94).*power(CONSTANTS(:,92), 3.00000))) }, ( CONSTANTS(:,130).*( power(CONSTANTS(:,92), 3.00000).*CONSTANTS(:,94).*exp( 0.0374300.*STATES(:,1).*CONSTANTS(:,91)) -  power(CONSTANTS(:,15), 3.00000).*CONSTANTS(:,93).*exp( 0.0374300.*STATES(:,1).*(CONSTANTS(:,91) - 1.00000))))./(1.00000+ CONSTANTS(:,90).*( CONSTANTS(:,93).*power(CONSTANTS(:,15), 3.00000)+ CONSTANTS(:,94).*power(CONSTANTS(:,92), 3.00000))));
    ALGEBRAIC(:,52) = ( CONSTANTS(:,131).*power(CONSTANTS(:,92)./(CONSTANTS(:,95)+CONSTANTS(:,92)), 3.00000).*power(CONSTANTS(:,103)./(CONSTANTS(:,96)+CONSTANTS(:,103)), 2.00000).*1.60000)./(1.50000+exp( - (STATES(:,1)+60.0000)./40.0000));
    RATES(:,1) =  ( - 1.00000./CONSTANTS(:,117)).*(ALGEBRAIC(:,28)+ALGEBRAIC(:,35)+ALGEBRAIC(:,40)+ALGEBRAIC(:,41)+ALGEBRAIC(:,42)+ALGEBRAIC(:,44)+ALGEBRAIC(:,45)+ALGEBRAIC(:,46)+ALGEBRAIC(:,47)+ALGEBRAIC(:,48)+ALGEBRAIC(:,50)+ALGEBRAIC(:,49)+ALGEBRAIC(:,51)+ALGEBRAIC(:,52)+CONSTANTS(:,133));
   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(:,11) = 1.00000./(1.00000+exp((STATES(:,1)+18.6000)./10.1000));
    ALGEBRAIC(:,2) = piecewise({CONSTANTS(:,1)==0.00000, power(1.00000./(1.00000+exp( - STATES(:,1)./5.46000)), 1.00000./3.00000) }, power(1.00000./(1.00000+exp( - (STATES(:,1)+30.3200)./5.46000)), 1.00000./3.00000));
    ALGEBRAIC(:,15) = piecewise({CONSTANTS(:,1)==0.00000, 0.000624700./( 0.832000.*exp(  - 0.335000.*(STATES(:,1)+56.7000))+ 0.627000.*exp( 0.0820000.*(STATES(:,1)+65.0100)))+4.00000e-05 }, 0.000624700./( 0.832217.*exp(  - 0.335660.*(STATES(:,1)+56.7062))+ 0.627400.*exp( 0.0823000.*(STATES(:,1)+65.0131)))+4.56900e-05);
    ALGEBRAIC(:,3) = 1.00000./(1.00000+exp((STATES(:,1)+66.1000)./6.40000));
    ALGEBRAIC(:,17) = ( 3.71700e-06.*exp(  - 0.281500.*(STATES(:,1)+17.1100)))./(1.00000+ 0.00373200.*exp(  - 0.342600.*(STATES(:,1)+37.7600)))+0.000597700;
    ALGEBRAIC(:,8) = 1.00000./(1.00000+exp((STATES(:,1)+59.3700)./13.1000));
    ALGEBRAIC(:,22) = piecewise({CONSTANTS(:,1)==0.00000, 0.0101000+0.0651700./( 0.570000.*exp(  - 0.0800000.*(STATES(:,1)+49.0000)))+ 2.40000e-05.*exp( 0.100000.*(STATES(:,1)+50.9300)) , CONSTANTS(:,1)==1.00000,  (0.00100000./3.00000).*(30.3100+195.500./( 0.568600.*exp(  - 0.0816100.*(STATES(:,1)+39.0000+ 10.0000.*CONSTANTS(:,111)))+ 0.717400.*exp( (0.271900 -  0.171900.*CONSTANTS(:,111)).*1.00000.*(STATES(:,1)+40.9300+ 10.0000.*CONSTANTS(:,111))))) }, 0.0101000+0.0651700./( 0.568600.*exp(  - 0.0816100.*(STATES(:,1)+39.0000))+ 0.717400.*exp( 0.271900.*(STATES(:,1)+40.9300))));
    ALGEBRAIC(:,9) = 1.00000./(1.00000+exp( - (STATES(:,1) - 10.9300)./19.7000));
    ALGEBRAIC(:,23) = piecewise({CONSTANTS(:,1)==0.00000,  0.00100000.*(2.98000+15.5900./( 1.03700.*exp( 0.0900000.*(STATES(:,1)+30.6100))+ 0.369000.*exp(  - 0.120000.*(STATES(:,1)+23.8400)))) , CONSTANTS(:,1)==1.00000,  0.00250000.*(1.19100+7.83800./( 1.03700.*exp( 0.0901200.*(STATES(:,1)+30.6100))+ 0.369000.*exp(  - 0.119000.*(STATES(:,1)+23.8400)))) },  0.00100000.*(2.98000+19.5900./( 1.03700.*exp( 0.0901200.*(STATES(:,1)+30.6100))+ 0.369000.*exp(  - 0.119000.*(STATES(:,1)+23.8400)))));
    ALGEBRAIC(:,10) = piecewise({CONSTANTS(:,1) ~= 2.00000, 1.00000./(1.00000+exp( - (STATES(:,1)+14.2000)./10.6000)) }, 1.00000./(1.00000+exp( - (STATES(:,1)+13.2000)./10.6000)));
    ALGEBRAIC(:,24) = piecewise({CONSTANTS(:,1) ~= 2.00000, 1.00000./( 37.2000.*exp((STATES(:,1) - 9.00000)./15.9000)+ 0.960000.*exp( - (STATES(:,1) - 9.00000)./22.5000)) }, 1.00000./( 37.2000.*exp((STATES(:,1) - 10.0000)./15.9000)+ 0.960000.*exp( - (STATES(:,1) - 10.0000)./22.5000)));
    ALGEBRAIC(:,12) = 14.0000./(1.00000+exp( - (STATES(:,1) - 40.0000)./9.00000));
    ALGEBRAIC(:,26) =  1.00000.*exp( - STATES(:,1)./45.0000);
    ALGEBRAIC(:,13) = piecewise({CONSTANTS(:,1)==0.00000,  1.00000.*exp( - (STATES(:,1)+78.9100)./26.6200) },  1.00000.*exp( - (STATES(:,1)+78.9100)./26.6300));
    ALGEBRAIC(:,27) =  1.00000.*exp((STATES(:,1)+75.1300)./21.2500);
    ALGEBRAIC(:,16) = ALGEBRAIC(:,3);
    ALGEBRAIC(:,29) = ( 3.18600e-08.*exp(  - 0.621900.*(STATES(:,1)+18.8000)))./(1.00000+ 7.18900e-05.*exp(  - 0.668300.*(STATES(:,1)+34.0700)))+0.00355600;
    ALGEBRAIC(:,25) = ALGEBRAIC(:,10);
    ALGEBRAIC(:,34) = piecewise({CONSTANTS(:,1) ~= 2.00000, 1.00000./( 4.20000.*exp((STATES(:,1) - 9.00000)./17.0000)+ 0.150000.*exp( - (STATES(:,1) - 9.00000)./21.6000)) }, 1.00000./( 4.20000.*exp((STATES(:,1) - 10.0000)./17.0000)+ 0.150000.*exp( - (STATES(:,1) - 10.0000)./21.6000)));
    ALGEBRAIC(:,36) = piecewise({CONSTANTS(:,1)==0.00000, 1.00000./(1.00000+exp( - (STATES(:,1)+23.1000)./6.00000)) , CONSTANTS(:,1)==1.00000, 1.00000./(1.00000+exp( - (STATES(:,1)+22.3000+ 0.800000.*CONSTANTS(:,111))./6.00000)) }, 1.00000./(1.00000+exp( - (STATES(:,1)+22.2000)./6.00000)));
    ALGEBRAIC(:,4) = piecewise({CONSTANTS(:,1)==0.00000, (  - 28.3800.*(STATES(:,1)+35.0000))./(exp( - (STATES(:,1)+35.0000)./2.50000) - 1.00000) - ( 84.9000.*STATES(:,1))./(exp(  - 0.208000.*STATES(:,1)) - 1.00000) , CONSTANTS(:,1)==1.00000, (  - 28.3900.*(STATES(:,1)+35.0000))./(exp( - (STATES(:,1)+35.0000)./2.50000) - 1.00000) - ( 84.9000.*STATES(:,1))./(exp(  - 0.208000.*STATES(:,1)) - 1.00000) }, (  - 28.4000.*(STATES(:,1)+35.0000))./(exp( - (STATES(:,1)+35.0000)./2.50000) - 1.00000) - ( 84.9000.*STATES(:,1))./(exp(  - 0.208000.*STATES(:,1)) - 1.00000));
    ALGEBRAIC(:,18) = piecewise({CONSTANTS(:,1)==1.00000, ( 11.4300.*(STATES(:,1) - 5.00000))./(exp( 0.400000.*(STATES(:,1) - 5.00000)) - 1.00000) }, ( 11.4200.*(STATES(:,1) - 5.00000))./(exp( 0.400000.*(STATES(:,1) - 5.00000)) - 1.00000));
    ALGEBRAIC(:,30) = 2.00000./(ALGEBRAIC(:,4)+ALGEBRAIC(:,18));
    ALGEBRAIC(:,37) = 1.00000./(1.00000+exp((STATES(:,1)+45.0000)./5.00000));
    ALGEBRAIC(:,5) = piecewise({CONSTANTS(:,1)==1.00000, ( 3.75000.*(STATES(:,1)+28.0000))./(exp((STATES(:,1)+28.0000)./4.00000) - 1.00000) }, ( 3.12000.*(STATES(:,1)+28.0000))./(exp((STATES(:,1)+28.0000)./4.00000) - 1.00000));
    ALGEBRAIC(:,19) = piecewise({CONSTANTS(:,1)==1.00000, 30.0000./(1.00000+exp( - (STATES(:,1)+28.0000)./4.00000)) }, 25.0000./(1.00000+exp( - (STATES(:,1)+28.0000)./4.00000)));
    ALGEBRAIC(:,31) = piecewise({CONSTANTS(:,1)==1.00000, (1.20000 -  0.200000.*CONSTANTS(:,111))./(ALGEBRAIC(:,5)+ALGEBRAIC(:,19)) }, 1.00000./(ALGEBRAIC(:,5)+ALGEBRAIC(:,19)));
    ALGEBRAIC(:,38) = 1.00000./(1.00000+exp( - (STATES(:,1)+37.0000)./6.80000));
    ALGEBRAIC(:,6) =  1068.00.*exp((STATES(:,1)+26.3000)./30.0000);
    ALGEBRAIC(:,20) =  1068.00.*exp( - (STATES(:,1)+26.3000)./30.0000);
    ALGEBRAIC(:,32) = 1.00000./(ALGEBRAIC(:,6)+ALGEBRAIC(:,20));
    ALGEBRAIC(:,39) = 1.00000./(1.00000+exp((STATES(:,1)+71.0000)./9.00000));
    ALGEBRAIC(:,7) = piecewise({CONSTANTS(:,1)==1.00000,  15.3000.*exp( - (STATES(:,1)+71.0000+ 0.700000.*CONSTANTS(:,111))./83.3000) },  15.3000.*exp( - (STATES(:,1)+71.7000)./83.3000));
    ALGEBRAIC(:,21) = piecewise({CONSTANTS(:,1)==1.00000,  15.0000.*exp((STATES(:,1)+71.0000)./15.3800) },  15.0000.*exp((STATES(:,1)+71.7000)./15.3800));
    ALGEBRAIC(:,33) = 1.00000./(ALGEBRAIC(:,7)+ALGEBRAIC(:,21));
    ALGEBRAIC(:,1) = piecewise({CONSTANTS(:,1)==0.00000, ( 0.0952000.*exp(  - 0.0630000.*(STATES(:,1)+34.4000)))./(1.00000+ 1.66000.*exp(  - 0.225000.*(STATES(:,1)+63.7000)))+0.0869000 }, ( 0.0951800.*exp(  - 0.0630600.*(STATES(:,1)+34.4000)))./(1.00000+ 1.66200.*exp(  - 0.225100.*(STATES(:,1)+63.7000)))+0.0869300);
    ALGEBRAIC(:,14) =  (1.00000 - ALGEBRAIC(:,1)).*STATES(:,3)+ ALGEBRAIC(:,1).*STATES(:,4);
    ALGEBRAIC(:,28) =  (( (( CONSTANTS(:,118).*power(STATES(:,2), 3.00000).*ALGEBRAIC(:,14).*CONSTANTS(:,15).*power(CONSTANTS(:,6), 2.00000))./( CONSTANTS(:,4).*CONSTANTS(:,5))).*(exp(( (STATES(:,1) - CONSTANTS(:,112)).*CONSTANTS(:,6))./( CONSTANTS(:,4).*CONSTANTS(:,5))) - 1.00000))./(exp(( STATES(:,1).*CONSTANTS(:,6))./( CONSTANTS(:,4).*CONSTANTS(:,5))) - 1.00000)).*STATES(:,1);
    ALGEBRAIC(:,35) =  CONSTANTS(:,119).*( STATES(:,6).*STATES(:,5)+0.00600000./(1.00000+exp( - (STATES(:,1)+14.1000)./6.00000))).*(STATES(:,1) - CONSTANTS(:,22));
    ALGEBRAIC(:,40) =  CONSTANTS(:,120).*STATES(:,7).*STATES(:,8).*(STATES(:,1) - CONSTANTS(:,29));
    ALGEBRAIC(:,41) =  CONSTANTS(:,121).*STATES(:,9).*STATES(:,10).*(STATES(:,1) - CONSTANTS(:,113));
    ALGEBRAIC(:,42) =  CONSTANTS(:,122).*STATES(:,10).*(STATES(:,1) - CONSTANTS(:,113));
    ALGEBRAIC(:,43) =  0.600000.*STATES(:,11)+ 0.400000.*STATES(:,12);
    ALGEBRAIC(:,44) =  CONSTANTS(:,123).*ALGEBRAIC(:,43).*STATES(:,13).*(STATES(:,1) - CONSTANTS(:,113));
    ALGEBRAIC(:,45) =  CONSTANTS(:,124).*power(STATES(:,14), 2.00000).*(STATES(:,1) - CONSTANTS(:,115));
    ALGEBRAIC(:,46) = piecewise({CONSTANTS(:,1) ~= 2.00000,  CONSTANTS(:,125).*STATES(:,15).*(STATES(:,1) - CONSTANTS(:,112)) },  CONSTANTS(:,125).*STATES(:,15).*(STATES(:,1) - 77.6000));
    ALGEBRAIC(:,47) = piecewise({CONSTANTS(:,1) ~= 2.00000,  CONSTANTS(:,126).*STATES(:,15).*(STATES(:,1) - CONSTANTS(:,113)) },  CONSTANTS(:,126).*STATES(:,15).*(STATES(:,1)+102.000));
    ALGEBRAIC(:,48) =  CONSTANTS(:,127).*(STATES(:,1) - CONSTANTS(:,112));
    ALGEBRAIC(:,50) =  CONSTANTS(:,129).*(STATES(:,1) - CONSTANTS(:,116));
    ALGEBRAIC(:,49) =  CONSTANTS(:,128).*(STATES(:,1) - CONSTANTS(:,113));
    ALGEBRAIC(:,51) = piecewise({CONSTANTS(:,1)==0.00000, ( CONSTANTS(:,130).*( power(CONSTANTS(:,92), 3.00000).*CONSTANTS(:,94).*exp( 0.0374300.*STATES(:,1).*CONSTANTS(:,91)) -  power(CONSTANTS(:,15), 3.00000).*CONSTANTS(:,93).*exp( 0.0374000.*STATES(:,1).*(CONSTANTS(:,91) - 1.00000))))./(1.00000+ CONSTANTS(:,90).*( CONSTANTS(:,93).*power(CONSTANTS(:,15), 3.00000)+ CONSTANTS(:,94).*power(CONSTANTS(:,92), 3.00000))) }, ( CONSTANTS(:,130).*( power(CONSTANTS(:,92), 3.00000).*CONSTANTS(:,94).*exp( 0.0374300.*STATES(:,1).*CONSTANTS(:,91)) -  power(CONSTANTS(:,15), 3.00000).*CONSTANTS(:,93).*exp( 0.0374300.*STATES(:,1).*(CONSTANTS(:,91) - 1.00000))))./(1.00000+ CONSTANTS(:,90).*( CONSTANTS(:,93).*power(CONSTANTS(:,15), 3.00000)+ CONSTANTS(:,94).*power(CONSTANTS(:,92), 3.00000))));
    ALGEBRAIC(:,52) = ( CONSTANTS(:,131).*power(CONSTANTS(:,92)./(CONSTANTS(:,95)+CONSTANTS(:,92)), 3.00000).*power(CONSTANTS(:,103)./(CONSTANTS(:,96)+CONSTANTS(:,103)), 2.00000).*1.60000)./(1.50000+exp( - (STATES(:,1)+60.0000)./40.0000));
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