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 =71;
end
% There are a total of 22 entries in each of the rate and state variable arrays.
% There are a total of 90 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('dCell in component membrane (dimensionless)');
    LEGEND_CONSTANTS(:,67) = strpad('FCell in component membrane (dimensionless)');
    LEGEND_STATES(:,1) = strpad('V in component membrane (millivolt)');
    LEGEND_CONSTANTS(:,2) = strpad('R in component membrane (millijoule_per_mole_kelvin)');
    LEGEND_CONSTANTS(:,3) = strpad('T in component membrane (kelvin)');
    LEGEND_CONSTANTS(:,4) = strpad('F in component membrane (coulomb_per_mole)');
    LEGEND_CONSTANTS(:,72) = strpad('Cm in component membrane (microF)');
    LEGEND_CONSTANTS(:,5) = strpad('CmCentre in component membrane (microF)');
    LEGEND_CONSTANTS(:,6) = strpad('CmPeriphery in component membrane (microF)');
    LEGEND_ALGEBRAIC(:,34) = strpad('i_Na in component sodium_current (nanoA)');
    LEGEND_ALGEBRAIC(:,43) = strpad('i_Ca_L in component L_type_Ca_channel (nanoA)');
    LEGEND_ALGEBRAIC(:,50) = strpad('i_Ca_T in component T_type_Ca_channel (nanoA)');
    LEGEND_ALGEBRAIC(:,51) = strpad('i_to in component four_AP_sensitive_currents (nanoA)');
    LEGEND_ALGEBRAIC(:,52) = strpad('i_sus in component four_AP_sensitive_currents (nanoA)');
    LEGEND_ALGEBRAIC(:,54) = strpad('i_K_r in component rapid_delayed_rectifying_potassium_current (nanoA)');
    LEGEND_ALGEBRAIC(:,55) = strpad('i_K_s in component slow_delayed_rectifying_potassium_current (nanoA)');
    LEGEND_ALGEBRAIC(:,56) = strpad('i_f_Na in component hyperpolarisation_activated_current (nanoA)');
    LEGEND_ALGEBRAIC(:,57) = strpad('i_f_K in component hyperpolarisation_activated_current (nanoA)');
    LEGEND_ALGEBRAIC(:,58) = strpad('i_b_Na in component sodium_background_current (nanoA)');
    LEGEND_ALGEBRAIC(:,60) = strpad('i_b_Ca in component calcium_background_current (nanoA)');
    LEGEND_ALGEBRAIC(:,59) = strpad('i_b_K in component potassium_background_current (nanoA)');
    LEGEND_ALGEBRAIC(:,61) = strpad('i_NaCa in component sodium_calcium_exchanger (nanoA)');
    LEGEND_ALGEBRAIC(:,62) = strpad('i_p in component sodium_potassium_pump (nanoA)');
    LEGEND_ALGEBRAIC(:,64) = strpad('i_Ca_P in component intracellular_calcium_handling (nanoA)');
    LEGEND_ALGEBRAIC(:,2) = strpad('i_st in component sustained_inward_current (nanoA)');
    LEGEND_CONSTANTS(:,73) = strpad('g_Na in component sodium_current (microlitre_per_second)');
    LEGEND_CONSTANTS(:,7) = strpad('g_Na_Centre in component sodium_current (microlitre_per_second)');
    LEGEND_CONSTANTS(:,8) = strpad('g_Na_Periphery in component sodium_current (microlitre_per_second)');
    LEGEND_CONSTANTS(:,68) = strpad('E_Na in component reversal_and_equilibrium_potentials (millivolt)');
    LEGEND_CONSTANTS(:,9) = strpad('Na_o in component ionic_concentrations (millimolar)');
    LEGEND_STATES(:,2) = strpad('m in component sodium_current_m_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,18) = strpad('h in component sodium_current_h_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,3) = strpad('m_infinity in component sodium_current_m_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,19) = 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(:,4) = strpad('h1_infinity in component sodium_current_h_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,20) = strpad('h2_infinity in component sodium_current_h_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,21) = strpad('tau_h1 in component sodium_current_h_gate (second)');
    LEGEND_ALGEBRAIC(:,35) = strpad('tau_h2 in component sodium_current_h_gate (second)');
    LEGEND_CONSTANTS(:,10) = strpad('g_Ca_L_Centre in component L_type_Ca_channel (microS)');
    LEGEND_CONSTANTS(:,11) = strpad('g_Ca_L_Periphery in component L_type_Ca_channel (microS)');
    LEGEND_CONSTANTS(:,74) = strpad('g_Ca_L in component L_type_Ca_channel (microS)');
    LEGEND_CONSTANTS(:,12) = 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(:,5) = strpad('alpha_d_L in component L_type_Ca_channel_d_gate (per_second)');
    LEGEND_ALGEBRAIC(:,22) = strpad('beta_d_L in component L_type_Ca_channel_d_gate (per_second)');
    LEGEND_ALGEBRAIC(:,44) = strpad('d_L_infinity in component L_type_Ca_channel_d_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,36) = strpad('tau_d_L in component L_type_Ca_channel_d_gate (second)');
    LEGEND_ALGEBRAIC(:,6) = strpad('alpha_f_L in component L_type_Ca_channel_f_gate (per_second)');
    LEGEND_ALGEBRAIC(:,23) = strpad('beta_f_L in component L_type_Ca_channel_f_gate (per_second)');
    LEGEND_ALGEBRAIC(:,45) = strpad('f_L_infinity in component L_type_Ca_channel_f_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,37) = strpad('tau_f_L in component L_type_Ca_channel_f_gate (second)');
    LEGEND_CONSTANTS(:,13) = strpad('g_Ca_T_Centre in component T_type_Ca_channel (microS)');
    LEGEND_CONSTANTS(:,14) = strpad('g_Ca_T_Periphery in component T_type_Ca_channel (microS)');
    LEGEND_CONSTANTS(:,75) = strpad('g_Ca_T in component T_type_Ca_channel (microS)');
    LEGEND_CONSTANTS(:,15) = 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(:,7) = strpad('alpha_d_T in component T_type_Ca_channel_d_gate (per_second)');
    LEGEND_ALGEBRAIC(:,24) = strpad('beta_d_T in component T_type_Ca_channel_d_gate (per_second)');
    LEGEND_ALGEBRAIC(:,46) = strpad('d_T_infinity in component T_type_Ca_channel_d_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,38) = strpad('tau_d_T in component T_type_Ca_channel_d_gate (second)');
    LEGEND_ALGEBRAIC(:,8) = strpad('alpha_f_T in component T_type_Ca_channel_f_gate (per_second)');
    LEGEND_ALGEBRAIC(:,25) = strpad('beta_f_T in component T_type_Ca_channel_f_gate (per_second)');
    LEGEND_ALGEBRAIC(:,47) = strpad('f_T_infinity in component T_type_Ca_channel_f_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,39) = strpad('tau_f_T in component T_type_Ca_channel_f_gate (second)');
    LEGEND_CONSTANTS(:,16) = strpad('g_to_Centre in component four_AP_sensitive_currents (microS)');
    LEGEND_CONSTANTS(:,17) = strpad('g_to_Periphery in component four_AP_sensitive_currents (microS)');
    LEGEND_CONSTANTS(:,76) = strpad('g_to in component four_AP_sensitive_currents (microS)');
    LEGEND_CONSTANTS(:,18) = strpad('g_sus_Centre in component four_AP_sensitive_currents (microS)');
    LEGEND_CONSTANTS(:,19) = strpad('g_sus_Periphery in component four_AP_sensitive_currents (microS)');
    LEGEND_CONSTANTS(:,77) = strpad('g_sus in component four_AP_sensitive_currents (microS)');
    LEGEND_CONSTANTS(:,69) = 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(:,9) = strpad('q_infinity in component four_AP_sensitive_currents_q_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,26) = strpad('tau_q in component four_AP_sensitive_currents_q_gate (second)');
    LEGEND_ALGEBRAIC(:,10) = strpad('r_infinity in component four_AP_sensitive_currents_r_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,27) = strpad('tau_r in component four_AP_sensitive_currents_r_gate (second)');
    LEGEND_CONSTANTS(:,20) = strpad('g_K_r_Centre in component rapid_delayed_rectifying_potassium_current (microS)');
    LEGEND_CONSTANTS(:,21) = strpad('g_K_r_Periphery in component rapid_delayed_rectifying_potassium_current (microS)');
    LEGEND_CONSTANTS(:,78) = strpad('g_K_r in component rapid_delayed_rectifying_potassium_current (microS)');
    LEGEND_ALGEBRAIC(:,53) = 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(:,11) = strpad('P_af_infinity in component rapid_delayed_rectifying_potassium_current_P_af_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,28) = strpad('tau_P_af in component rapid_delayed_rectifying_potassium_current_P_af_gate (second)');
    LEGEND_ALGEBRAIC(:,29) = strpad('P_as_infinity in component rapid_delayed_rectifying_potassium_current_P_as_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,40) = strpad('tau_P_as in component rapid_delayed_rectifying_potassium_current_P_as_gate (second)');
    LEGEND_ALGEBRAIC(:,12) = strpad('P_i_infinity in component rapid_delayed_rectifying_potassium_current_P_i_gate (dimensionless)');
    LEGEND_CONSTANTS(:,22) = strpad('tau_P_i in component rapid_delayed_rectifying_potassium_current_P_i_gate (second)');
    LEGEND_CONSTANTS(:,23) = strpad('g_K_s_Centre in component slow_delayed_rectifying_potassium_current (microS)');
    LEGEND_CONSTANTS(:,24) = strpad('g_K_s_Periphery in component slow_delayed_rectifying_potassium_current (microS)');
    LEGEND_CONSTANTS(:,79) = strpad('g_K_s in component slow_delayed_rectifying_potassium_current (microS)');
    LEGEND_CONSTANTS(:,70) = 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(:,13) = strpad('alpha_xs in component slow_delayed_rectifying_potassium_current_xs_gate (per_second)');
    LEGEND_ALGEBRAIC(:,30) = strpad('beta_xs in component slow_delayed_rectifying_potassium_current_xs_gate (per_second)');
    LEGEND_CONSTANTS(:,25) = strpad('g_f_Na_Centre in component hyperpolarisation_activated_current (microS)');
    LEGEND_CONSTANTS(:,26) = strpad('g_f_Na_Periphery in component hyperpolarisation_activated_current (microS)');
    LEGEND_CONSTANTS(:,80) = strpad('g_f_Na in component hyperpolarisation_activated_current (microS)');
    LEGEND_CONSTANTS(:,27) = strpad('g_f_K_Centre in component hyperpolarisation_activated_current (microS)');
    LEGEND_CONSTANTS(:,28) = strpad('g_f_K_Periphery in component hyperpolarisation_activated_current (microS)');
    LEGEND_CONSTANTS(:,81) = 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(:,14) = strpad('alpha_y in component hyperpolarisation_activated_current_y_gate (per_second)');
    LEGEND_ALGEBRAIC(:,31) = strpad('beta_y in component hyperpolarisation_activated_current_y_gate (per_second)');
    LEGEND_CONSTANTS(:,29) = strpad('g_b_Na_Centre in component sodium_background_current (microS)');
    LEGEND_CONSTANTS(:,30) = strpad('g_b_Na_Periphery in component sodium_background_current (microS)');
    LEGEND_CONSTANTS(:,82) = strpad('g_b_Na in component sodium_background_current (microS)');
    LEGEND_CONSTANTS(:,31) = strpad('g_b_K_Centre in component potassium_background_current (microS)');
    LEGEND_CONSTANTS(:,32) = strpad('g_b_K_Periphery in component potassium_background_current (microS)');
    LEGEND_CONSTANTS(:,83) = strpad('g_b_K in component potassium_background_current (microS)');
    LEGEND_CONSTANTS(:,33) = strpad('g_b_Ca_Centre in component calcium_background_current (microS)');
    LEGEND_CONSTANTS(:,34) = strpad('g_b_Ca_Periphery in component calcium_background_current (microS)');
    LEGEND_CONSTANTS(:,84) = strpad('g_b_Ca in component calcium_background_current (microS)');
    LEGEND_CONSTANTS(:,71) = strpad('E_Ca in component reversal_and_equilibrium_potentials (millivolt)');
    LEGEND_CONSTANTS(:,35) = strpad('k_NaCa_Centre in component sodium_calcium_exchanger (nanoA)');
    LEGEND_CONSTANTS(:,36) = strpad('k_NaCa_Periphery in component sodium_calcium_exchanger (nanoA)');
    LEGEND_CONSTANTS(:,85) = strpad('k_NaCa in component sodium_calcium_exchanger (nanoA)');
    LEGEND_CONSTANTS(:,37) = strpad('d_NaCa in component sodium_calcium_exchanger (dimensionless)');
    LEGEND_CONSTANTS(:,38) = strpad('gamma_NaCa in component sodium_calcium_exchanger (dimensionless)');
    LEGEND_CONSTANTS(:,39) = strpad('Na_i in component ionic_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,40) = strpad('Ca_i in component ionic_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,41) = strpad('Ca_o in component ionic_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,42) = strpad('K_m_Na in component sodium_potassium_pump (millimolar)');
    LEGEND_CONSTANTS(:,43) = strpad('K_m_K in component sodium_potassium_pump (millimolar)');
    LEGEND_CONSTANTS(:,44) = strpad('i_p_max_Centre in component sodium_potassium_pump (nanoA)');
    LEGEND_CONSTANTS(:,45) = strpad('i_p_max_Periphery in component sodium_potassium_pump (nanoA)');
    LEGEND_CONSTANTS(:,86) = strpad('i_p_max in component sodium_potassium_pump (nanoA)');
    LEGEND_CONSTANTS(:,46) = strpad('K_o in component ionic_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,47) = strpad('K_i in component ionic_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,48) = strpad('g_st in component sustained_inward_current (microS)');
    LEGEND_STATES(:,16) = strpad('d_s in component sustained_inward_current_d_gate (dimensionless)');
    LEGEND_STATES(:,17) = strpad('f_s in component sustained_inward_current_f_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,15) = strpad('alpha_d_s in component sustained_inward_current_d_gate (per_second)');
    LEGEND_ALGEBRAIC(:,32) = strpad('beta_d_s in component sustained_inward_current_d_gate (per_second)');
    LEGEND_ALGEBRAIC(:,48) = strpad('d_s_infinity in component sustained_inward_current_d_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,41) = strpad('tau_d_s in component sustained_inward_current_d_gate (second)');
    LEGEND_ALGEBRAIC(:,16) = strpad('alpha_f_s in component sustained_inward_current_f_gate (per_second)');
    LEGEND_ALGEBRAIC(:,33) = strpad('beta_f_s in component sustained_inward_current_f_gate (per_second)');
    LEGEND_ALGEBRAIC(:,49) = strpad('f_s_infinity in component sustained_inward_current_f_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,42) = strpad('tau_f_s in component sustained_inward_current_f_gate (second)');
    LEGEND_ALGEBRAIC(:,63) = strpad('U_d in component intracellular_calcium_handling (dimensionless)');
    LEGEND_ALGEBRAIC(:,67) = strpad('U_s in component intracellular_calcium_handling (dimensionless)');
    LEGEND_CONSTANTS(:,49) = strpad('i_Ca_P_max in component intracellular_calcium_handling (nanoA)');
    LEGEND_ALGEBRAIC(:,65) = strpad('J_Ca_ds in component intracellular_calcium_handling (millimole_per_second)');
    LEGEND_ALGEBRAIC(:,66) = strpad('J_Ca_r in component intracellular_calcium_handling (millimole_per_second)');
    LEGEND_ALGEBRAIC(:,17) = strpad('J_Ca_P in component intracellular_calcium_handling (millimole_per_second)');
    LEGEND_CONSTANTS(:,50) = strpad('J_Ca_P_max in component intracellular_calcium_handling (millimole_per_second)');
    LEGEND_ALGEBRAIC(:,68) = strpad('J_Ca_u in component intracellular_calcium_handling (millimole_per_second)');
    LEGEND_CONSTANTS(:,51) = strpad('J_Ca_u_max in component intracellular_calcium_handling (millimole_per_second)');
    LEGEND_ALGEBRAIC(:,69) = strpad('J_Ca_ur in component intracellular_calcium_handling (millimole_per_second)');
    LEGEND_ALGEBRAIC(:,70) = strpad('J_Ca_1 in component intracellular_calcium_handling (millimole_per_second)');
    LEGEND_STATES(:,18) = strpad('Ca_d in component intracellular_calcium_handling (millimolar)');
    LEGEND_STATES(:,19) = strpad('Ca_s in component intracellular_calcium_handling (millimolar)');
    LEGEND_STATES(:,20) = strpad('Ca_u in component intracellular_calcium_handling (millimolar)');
    LEGEND_STATES(:,21) = strpad('Ca_r in component intracellular_calcium_handling (millimolar)');
    LEGEND_CONSTANTS(:,52) = strpad('B_d in component intracellular_calcium_handling (millimolar)');
    LEGEND_CONSTANTS(:,53) = strpad('B_s in component intracellular_calcium_handling (millimolar)');
    LEGEND_CONSTANTS(:,87) = strpad('Vol_u in component intracellular_calcium_handling (litre)');
    LEGEND_CONSTANTS(:,88) = strpad('Vol_r in component intracellular_calcium_handling (litre)');
    LEGEND_CONSTANTS(:,89) = strpad('Vol_d in component intracellular_calcium_handling (litre)');
    LEGEND_CONSTANTS(:,90) = strpad('Vol_s in component intracellular_calcium_handling (litre)');
    LEGEND_CONSTANTS(:,54) = strpad('Vol_c in component intracellular_calcium_handling (litre)');
    LEGEND_CONSTANTS(:,55) = strpad('K_m_b in component intracellular_calcium_handling (millimolar)');
    LEGEND_CONSTANTS(:,56) = strpad('K_m_r in component intracellular_calcium_handling (millimolar)');
    LEGEND_CONSTANTS(:,57) = strpad('K_m_u in component intracellular_calcium_handling (millimolar)');
    LEGEND_CONSTANTS(:,58) = strpad('f_d in component intracellular_calcium_handling (dimensionless)');
    LEGEND_CONSTANTS(:,59) = strpad('f_r in component intracellular_calcium_handling (dimensionless)');
    LEGEND_CONSTANTS(:,60) = strpad('f_u in component intracellular_calcium_handling (dimensionless)');
    LEGEND_CONSTANTS(:,61) = strpad('alpha_ds in component intracellular_calcium_handling (per_second)');
    LEGEND_CONSTANTS(:,62) = strpad('alpha_fR in component intracellular_calcium_handling (per_second_millimolar)');
    LEGEND_CONSTANTS(:,63) = strpad('alpha_1 in component intracellular_calcium_handling (per_second)');
    LEGEND_CONSTANTS(:,64) = strpad('alpha_r in component intracellular_calcium_handling (per_second)');
    LEGEND_CONSTANTS(:,65) = strpad('alpha_ur in component intracellular_calcium_handling (per_second)');
    LEGEND_CONSTANTS(:,66) = strpad('beta_fR in component intracellular_calcium_handling (per_second)');
    LEGEND_STATES(:,22) = strpad('f_R in component intracellular_calcium_handling (dimensionless)');
    LEGEND_ALGEBRAIC(:,71) = strpad('i_Ca in component intracellular_calcium_handling (nanoA)');
    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_RATES(:,16) = strpad('d/dt d_s in component sustained_inward_current_d_gate (dimensionless)');
    LEGEND_RATES(:,17) = strpad('d/dt f_s in component sustained_inward_current_f_gate (dimensionless)');
    LEGEND_RATES(:,22) = strpad('d/dt f_R in component intracellular_calcium_handling (dimensionless)');
    LEGEND_RATES(:,18) = strpad('d/dt Ca_d in component intracellular_calcium_handling (millimolar)');
    LEGEND_RATES(:,19) = strpad('d/dt Ca_s in component intracellular_calcium_handling (millimolar)');
    LEGEND_RATES(:,20) = strpad('d/dt Ca_u in component intracellular_calcium_handling (millimolar)');
    LEGEND_RATES(:,21) = strpad('d/dt Ca_r in component intracellular_calcium_handling (millimolar)');
    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) = 0;
    STATES(:,1) = -39.013558536;
    CONSTANTS(:,2) = 8314;
    CONSTANTS(:,3) = 310;
    CONSTANTS(:,4) = 96845;
    CONSTANTS(:,5) = 2e-5;
    CONSTANTS(:,6) = 6.5e-5;
    CONSTANTS(:,7) = 0;
    CONSTANTS(:,8) = 1.2e-6;
    CONSTANTS(:,9) = 140;
    STATES(:,2) = 0.092361701692;
    STATES(:,3) = 0.015905380261;
    STATES(:,4) = 0.01445216109;
    CONSTANTS(:,10) = 0.0058;
    CONSTANTS(:,11) = 0.0659;
    CONSTANTS(:,12) = 46.4;
    STATES(:,5) = 0.04804900895;
    STATES(:,6) = 0.48779845203;
    CONSTANTS(:,13) = 0.0043;
    CONSTANTS(:,14) = 0.0139;
    CONSTANTS(:,15) = 45;
    STATES(:,7) = 0.42074047435;
    STATES(:,8) = 0.038968420558;
    CONSTANTS(:,16) = 0.00491;
    CONSTANTS(:,17) = 0.03649;
    CONSTANTS(:,18) = 6.65e-5;
    CONSTANTS(:,19) = 0.0114;
    STATES(:,9) = 0.29760539675;
    STATES(:,10) = 0.064402950262;
    CONSTANTS(:,20) = 0.000797;
    CONSTANTS(:,21) = 0.016;
    STATES(:,11) = 0.13034201158;
    STATES(:,12) = 0.46960956028;
    STATES(:,13) = 0.87993375273;
    CONSTANTS(:,22) = 0.002;
    CONSTANTS(:,23) = 0.000518;
    CONSTANTS(:,24) = 0.0104;
    STATES(:,14) = 0.082293827208;
    CONSTANTS(:,25) = 0.000548;
    CONSTANTS(:,26) = 0.0069;
    CONSTANTS(:,27) = 0.000548;
    CONSTANTS(:,28) = 0.0069;
    STATES(:,15) = 0.03889291759;
    CONSTANTS(:,29) = 5.8e-5;
    CONSTANTS(:,30) = 0.000189;
    CONSTANTS(:,31) = 2.52e-5;
    CONSTANTS(:,32) = 8.19e-5;
    CONSTANTS(:,33) = 1.32e-5;
    CONSTANTS(:,34) = 4.3e-5;
    CONSTANTS(:,35) = 2.7e-6;
    CONSTANTS(:,36) = 8.8e-6;
    CONSTANTS(:,37) = 0.0001;
    CONSTANTS(:,38) = 0.5;
    CONSTANTS(:,39) = 8;
    CONSTANTS(:,40) = 0.0001;
    CONSTANTS(:,41) = 2;
    CONSTANTS(:,42) = 5.64;
    CONSTANTS(:,43) = 0.621;
    CONSTANTS(:,44) = 0.0478;
    CONSTANTS(:,45) = 0.16;
    CONSTANTS(:,46) = 5.4;
    CONSTANTS(:,47) = 140;
    CONSTANTS(:,48) = 0.00214;
    STATES(:,16) = 0.230;
    STATES(:,17) = 0.283;
    CONSTANTS(:,49) = 0.24;
    CONSTANTS(:,50) = 0.00000000096;
    CONSTANTS(:,51) = 0.00000000096;
    STATES(:,18) = 0.001544;
    STATES(:,19) = 0.05487;
    STATES(:,20) = 6.983;
    STATES(:,21) = 4.909;
    CONSTANTS(:,52) = 0.4;
    CONSTANTS(:,53) = 0.2;
    CONSTANTS(:,54) = 8.0e-12;
    CONSTANTS(:,55) = 0.002;
    CONSTANTS(:,56) = 0.001;
    CONSTANTS(:,57) = 0.005;
    CONSTANTS(:,58) = 0.1;
    CONSTANTS(:,59) = 0.3;
    CONSTANTS(:,60) = 0.06;
    CONSTANTS(:,61) = 3300.0;
    CONSTANTS(:,62) = 6670.0;
    CONSTANTS(:,63) = 0.172;
    CONSTANTS(:,64) = 333.5;
    CONSTANTS(:,65) = 533.6;
    CONSTANTS(:,66) = 2.0;
    STATES(:,22) = 0.188;
    CONSTANTS(:,67) = ( 1.07000.*( 3.00000.*CONSTANTS(:,1) - 0.100000))./( 3.00000.*(1.00000+ 0.774500.*exp( - ( 3.00000.*CONSTANTS(:,1) - 2.05000)./0.295000)));
    CONSTANTS(:,68) =  (( CONSTANTS(:,2).*CONSTANTS(:,3))./CONSTANTS(:,4)).*log(CONSTANTS(:,9)./CONSTANTS(:,39));
    CONSTANTS(:,69) =  (( CONSTANTS(:,2).*CONSTANTS(:,3))./CONSTANTS(:,4)).*log(CONSTANTS(:,46)./CONSTANTS(:,47));
    CONSTANTS(:,70) =  (( CONSTANTS(:,2).*CONSTANTS(:,3))./CONSTANTS(:,4)).*log((CONSTANTS(:,46)+ 0.120000.*CONSTANTS(:,9))./(CONSTANTS(:,47)+ 0.120000.*CONSTANTS(:,39)));
    CONSTANTS(:,71) =  (( CONSTANTS(:,2).*CONSTANTS(:,3))./( 2.00000.*CONSTANTS(:,4))).*log(CONSTANTS(:,41)./CONSTANTS(:,40));
    CONSTANTS(:,72) = CONSTANTS(:,5)+ CONSTANTS(:,67).*(CONSTANTS(:,6) - CONSTANTS(:,5));
    CONSTANTS(:,73) = CONSTANTS(:,7)+ CONSTANTS(:,67).*(CONSTANTS(:,8) - CONSTANTS(:,7));
    CONSTANTS(:,74) = CONSTANTS(:,10)+ CONSTANTS(:,67).*(CONSTANTS(:,11) - CONSTANTS(:,10));
    CONSTANTS(:,75) = CONSTANTS(:,13)+ CONSTANTS(:,67).*(CONSTANTS(:,14) - CONSTANTS(:,13));
    CONSTANTS(:,76) = CONSTANTS(:,16)+ CONSTANTS(:,67).*(CONSTANTS(:,17) - CONSTANTS(:,16));
    CONSTANTS(:,77) = CONSTANTS(:,18)+ CONSTANTS(:,67).*(CONSTANTS(:,19) - CONSTANTS(:,18));
    CONSTANTS(:,78) = CONSTANTS(:,20)+ CONSTANTS(:,67).*(CONSTANTS(:,21) - CONSTANTS(:,20));
    CONSTANTS(:,79) = CONSTANTS(:,23)+ CONSTANTS(:,67).*(CONSTANTS(:,24) - CONSTANTS(:,23));
    CONSTANTS(:,80) = CONSTANTS(:,25)+ CONSTANTS(:,67).*(CONSTANTS(:,26) - CONSTANTS(:,25));
    CONSTANTS(:,81) = CONSTANTS(:,27)+ CONSTANTS(:,67).*(CONSTANTS(:,28) - CONSTANTS(:,27));
    CONSTANTS(:,82) = CONSTANTS(:,29)+ CONSTANTS(:,67).*(CONSTANTS(:,30) - CONSTANTS(:,29));
    CONSTANTS(:,83) = CONSTANTS(:,31)+ CONSTANTS(:,67).*(CONSTANTS(:,32) - CONSTANTS(:,31));
    CONSTANTS(:,84) = CONSTANTS(:,33)+ CONSTANTS(:,67).*(CONSTANTS(:,34) - CONSTANTS(:,33));
    CONSTANTS(:,85) = CONSTANTS(:,35)+ CONSTANTS(:,67).*(CONSTANTS(:,36) - CONSTANTS(:,35));
    CONSTANTS(:,86) = CONSTANTS(:,44)+ CONSTANTS(:,67).*(CONSTANTS(:,45) - CONSTANTS(:,44));
    CONSTANTS(:,87) =  CONSTANTS(:,60).*CONSTANTS(:,54);
    CONSTANTS(:,88) =  CONSTANTS(:,59).*CONSTANTS(:,54);
    CONSTANTS(:,89) =  CONSTANTS(:,58).*CONSTANTS(:,54);
    CONSTANTS(:,90) = CONSTANTS(:,54) - (CONSTANTS(:,87)+CONSTANTS(:,89));
    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(:,22) =   - CONSTANTS(:,62).*STATES(:,18).*STATES(:,22)+ CONSTANTS(:,66).*(1.00000 - STATES(:,22));
    ALGEBRAIC(:,12) = 1.00000./(1.00000+exp((STATES(:,1)+18.6000)./10.1000));
    RATES(:,13) = (ALGEBRAIC(:,12) - STATES(:,13))./CONSTANTS(:,22);
    ALGEBRAIC(:,3) = power(1.00000./(1.00000+exp( - STATES(:,1)./5.46000)), 1.00000./3.00000);
    ALGEBRAIC(:,19) = 0.000624700./( 0.832000.*exp(  - 0.335000.*(STATES(:,1)+56.7000))+ 0.627000.*exp( 0.0820000.*(STATES(:,1)+65.0100)))+4.00000e-05;
    RATES(:,2) = (ALGEBRAIC(:,3) - STATES(:,2))./ALGEBRAIC(:,19);
    ALGEBRAIC(:,4) = 1.00000./(1.00000+exp((STATES(:,1)+66.1000)./6.40000));
    ALGEBRAIC(:,21) = ( 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(:,4) - STATES(:,3))./ALGEBRAIC(:,21);
    ALGEBRAIC(:,9) = 1.00000./(1.00000+exp((STATES(:,1)+59.3700)./13.1000));
    ALGEBRAIC(:,26) = 0.0101000+0.0651700./( 0.570000.*exp(  - 0.0800000.*(STATES(:,1)+49.0000)))+ 2.40000e-05.*exp( 0.100000.*(STATES(:,1)+50.9300));
    RATES(:,9) = (ALGEBRAIC(:,9) - STATES(:,9))./ALGEBRAIC(:,26);
    ALGEBRAIC(:,10) = 1.00000./(1.00000+exp( - (STATES(:,1) - 10.9300)./19.7000));
    ALGEBRAIC(:,27) =  0.00100000.*(2.98000+15.5900./( 1.03700.*exp( 0.0900000.*(STATES(:,1)+30.6100))+ 0.369000.*exp(  - 0.120000.*(STATES(:,1)+23.8400))));
    RATES(:,10) = (ALGEBRAIC(:,10) - STATES(:,10))./ALGEBRAIC(:,27);
    ALGEBRAIC(:,11) = 1.00000./(1.00000+exp( - (STATES(:,1)+14.2000)./10.6000));
    ALGEBRAIC(:,28) = 1.00000./( 37.2000.*exp((STATES(:,1) - 9.00000)./15.9000)+ 0.960000.*exp( - (STATES(:,1) - 9.00000)./22.5000));
    RATES(:,11) = (ALGEBRAIC(:,11) - STATES(:,11))./ALGEBRAIC(:,28);
    ALGEBRAIC(:,13) = 14.0000./(1.00000+exp( - (STATES(:,1) - 40.0000)./9.00000));
    ALGEBRAIC(:,30) =  1.00000.*exp( - STATES(:,1)./45.0000);
    RATES(:,14) =  ALGEBRAIC(:,13).*(1.00000 - STATES(:,14)) -  ALGEBRAIC(:,30).*STATES(:,14);
    ALGEBRAIC(:,14) =  1.00000.*exp( - (STATES(:,1)+78.9100)./26.6200);
    ALGEBRAIC(:,31) =  1.00000.*exp((STATES(:,1)+75.1300)./21.2500);
    RATES(:,15) =  ALGEBRAIC(:,14).*(1.00000 - STATES(:,15)) -  ALGEBRAIC(:,31).*STATES(:,15);
    ALGEBRAIC(:,20) = ALGEBRAIC(:,4);
    ALGEBRAIC(:,35) = ( 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(:,20) - STATES(:,4))./ALGEBRAIC(:,35);
    ALGEBRAIC(:,29) = ALGEBRAIC(:,11);
    ALGEBRAIC(:,40) = 1.00000./( 4.20000.*exp((STATES(:,1) - 9.00000)./17.0000)+ 0.150000.*exp( - (STATES(:,1) - 9.00000)./21.6000));
    RATES(:,12) = (ALGEBRAIC(:,29) - STATES(:,12))./ALGEBRAIC(:,40);
    ALGEBRAIC(:,44) = 1.00000./(1.00000+exp( - (STATES(:,1)+23.1000)./6.00000));
    ALGEBRAIC(:,5) = (  - 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);
    ALGEBRAIC(:,22) = ( 11.4200.*(STATES(:,1) - 5.00000))./(exp( 0.400000.*(STATES(:,1) - 5.00000)) - 1.00000);
    ALGEBRAIC(:,36) = 2.00000./(ALGEBRAIC(:,5)+ALGEBRAIC(:,22));
    RATES(:,5) = (ALGEBRAIC(:,44) - STATES(:,5))./ALGEBRAIC(:,36);
    ALGEBRAIC(:,45) = 1.00000./(1.00000+exp((STATES(:,1)+45.0000)./5.00000));
    ALGEBRAIC(:,6) = ( 3.12000.*(STATES(:,1)+28.0000))./(exp((STATES(:,1)+28.0000)./4.00000) - 1.00000);
    ALGEBRAIC(:,23) = 25.0000./(1.00000+exp( - (STATES(:,1)+28.0000)./4.00000));
    ALGEBRAIC(:,37) = 1.00000./(ALGEBRAIC(:,6)+ALGEBRAIC(:,23));
    RATES(:,6) = (ALGEBRAIC(:,45) - STATES(:,6))./ALGEBRAIC(:,37);
    ALGEBRAIC(:,46) = 1.00000./(1.00000+exp( - (STATES(:,1)+37.0000)./6.80000));
    ALGEBRAIC(:,7) =  1068.00.*exp((STATES(:,1)+26.3000)./30.0000);
    ALGEBRAIC(:,24) =  1068.00.*exp( - (STATES(:,1)+26.3000)./30.0000);
    ALGEBRAIC(:,38) = 1.00000./(ALGEBRAIC(:,7)+ALGEBRAIC(:,24));
    RATES(:,7) = (ALGEBRAIC(:,46) - STATES(:,7))./ALGEBRAIC(:,38);
    ALGEBRAIC(:,47) = 1.00000./(1.00000+exp((STATES(:,1)+71.0000)./9.00000));
    ALGEBRAIC(:,8) =  15.3000.*exp( - (STATES(:,1)+71.7000)./83.3000);
    ALGEBRAIC(:,25) =  15.0000.*exp((STATES(:,1)+71.7000)./15.3800);
    ALGEBRAIC(:,39) = 1.00000./(ALGEBRAIC(:,8)+ALGEBRAIC(:,25));
    RATES(:,8) = (ALGEBRAIC(:,47) - STATES(:,8))./ALGEBRAIC(:,39);
    ALGEBRAIC(:,15) = 1000.00./( 0.150000.*exp( - STATES(:,1)./11.0000)+ 0.200000.*exp( - STATES(:,1)./700.000));
    ALGEBRAIC(:,32) = 1000.00./( 16.0000.*exp(STATES(:,1)./8.00000)+ 0.200000.*exp(STATES(:,1)./50.0000));
    ALGEBRAIC(:,48) = ALGEBRAIC(:,15)./(ALGEBRAIC(:,15)+ALGEBRAIC(:,32));
    ALGEBRAIC(:,41) = 1.00000./(ALGEBRAIC(:,15)+ALGEBRAIC(:,32));
    RATES(:,16) = (ALGEBRAIC(:,48) - STATES(:,16))./ALGEBRAIC(:,41);
    ALGEBRAIC(:,16) = 1000.00./( 3100.00.*exp( - STATES(:,1)./13.0000)+ 700.000.*exp( - STATES(:,1)./70.0000));
    ALGEBRAIC(:,33) = 1000.00./( 16.0000.*exp(STATES(:,1)./8.00000)+ 0.200000.*exp(STATES(:,1)./50.0000));
    ALGEBRAIC(:,49) = ALGEBRAIC(:,16)./(ALGEBRAIC(:,16)+ALGEBRAIC(:,33));
    ALGEBRAIC(:,42) = 1.00000./(ALGEBRAIC(:,16)+ALGEBRAIC(:,33));
    RATES(:,17) = (ALGEBRAIC(:,49) - STATES(:,17))./ALGEBRAIC(:,42);
    ALGEBRAIC(:,1) = ( 0.0952000.*exp(  - 0.0630000.*(STATES(:,1)+34.4000)))./(1.00000+ 1.66000.*exp(  - 0.225000.*(STATES(:,1)+63.7000)))+0.0869000;
    ALGEBRAIC(:,18) =  (1.00000 - ALGEBRAIC(:,1)).*STATES(:,3)+ ALGEBRAIC(:,1).*STATES(:,4);
    ALGEBRAIC(:,34) =  (( (( CONSTANTS(:,73).*power(STATES(:,2), 3.00000).*ALGEBRAIC(:,18).*CONSTANTS(:,9).*power(CONSTANTS(:,4), 2.00000))./( CONSTANTS(:,2).*CONSTANTS(:,3))).*(exp(( (STATES(:,1) - CONSTANTS(:,68)).*CONSTANTS(:,4))./( CONSTANTS(:,2).*CONSTANTS(:,3))) - 1.00000))./(exp(( STATES(:,1).*CONSTANTS(:,4))./( CONSTANTS(:,2).*CONSTANTS(:,3))) - 1.00000)).*STATES(:,1);
    ALGEBRAIC(:,43) =  CONSTANTS(:,74).*( STATES(:,6).*STATES(:,5)+0.00600000./(1.00000+exp( - (STATES(:,1)+14.1000)./6.00000))).*(STATES(:,1) - CONSTANTS(:,12));
    ALGEBRAIC(:,50) =  CONSTANTS(:,75).*STATES(:,7).*STATES(:,8).*(STATES(:,1) - CONSTANTS(:,15));
    ALGEBRAIC(:,51) =  CONSTANTS(:,76).*STATES(:,9).*STATES(:,10).*(STATES(:,1) - CONSTANTS(:,69));
    ALGEBRAIC(:,52) =  CONSTANTS(:,77).*STATES(:,10).*(STATES(:,1) - CONSTANTS(:,69));
    ALGEBRAIC(:,53) =  0.600000.*STATES(:,11)+ 0.400000.*STATES(:,12);
    ALGEBRAIC(:,54) =  CONSTANTS(:,78).*ALGEBRAIC(:,53).*STATES(:,13).*(STATES(:,1) - CONSTANTS(:,69));
    ALGEBRAIC(:,55) =  CONSTANTS(:,79).*power(STATES(:,14), 2.00000).*(STATES(:,1) - CONSTANTS(:,70));
    ALGEBRAIC(:,56) =  CONSTANTS(:,80).*STATES(:,15).*(STATES(:,1) - CONSTANTS(:,68));
    ALGEBRAIC(:,57) =  CONSTANTS(:,81).*STATES(:,15).*(STATES(:,1) - CONSTANTS(:,69));
    ALGEBRAIC(:,58) =  CONSTANTS(:,82).*(STATES(:,1) - CONSTANTS(:,68));
    ALGEBRAIC(:,60) =  CONSTANTS(:,84).*(STATES(:,1) - CONSTANTS(:,71));
    ALGEBRAIC(:,59) =  CONSTANTS(:,83).*(STATES(:,1) - CONSTANTS(:,69));
    ALGEBRAIC(:,61) = ( CONSTANTS(:,85).*( power(CONSTANTS(:,39), 3.00000).*CONSTANTS(:,41).*exp( 0.0374300.*STATES(:,1).*CONSTANTS(:,38)) -  power(CONSTANTS(:,9), 3.00000).*CONSTANTS(:,40).*exp( 0.0374000.*STATES(:,1).*(CONSTANTS(:,38) - 1.00000))))./(1.00000+ CONSTANTS(:,37).*( CONSTANTS(:,40).*power(CONSTANTS(:,9), 3.00000)+ CONSTANTS(:,41).*power(CONSTANTS(:,39), 3.00000)));
    ALGEBRAIC(:,62) = ( CONSTANTS(:,86).*power(CONSTANTS(:,39)./(CONSTANTS(:,42)+CONSTANTS(:,39)), 3.00000).*power(CONSTANTS(:,46)./(CONSTANTS(:,43)+CONSTANTS(:,46)), 2.00000).*1.60000)./(1.50000+exp( - (STATES(:,1)+60.0000)./40.0000));
    ALGEBRAIC(:,64) =  CONSTANTS(:,49).*(STATES(:,19)./(STATES(:,19)+0.000400000));
    RATES(:,1) =  ( - 1.00000./CONSTANTS(:,72)).*(ALGEBRAIC(:,34)+ALGEBRAIC(:,43)+ALGEBRAIC(:,50)+ALGEBRAIC(:,51)+ALGEBRAIC(:,52)+ALGEBRAIC(:,54)+ALGEBRAIC(:,55)+ALGEBRAIC(:,56)+ALGEBRAIC(:,57)+ALGEBRAIC(:,58)+ALGEBRAIC(:,60)+ALGEBRAIC(:,59)+ALGEBRAIC(:,61)+ALGEBRAIC(:,62)+ALGEBRAIC(:,64));
    ALGEBRAIC(:,66) =  CONSTANTS(:,64).*STATES(:,22).*(power(STATES(:,18), 2.00000)./(power(CONSTANTS(:,56), 2.00000)+power(STATES(:,18), 2.00000))).*CONSTANTS(:,88).*STATES(:,21);
    ALGEBRAIC(:,69) =  CONSTANTS(:,65).*CONSTANTS(:,87).*(STATES(:,20) - STATES(:,21));
    RATES(:,21) = (ALGEBRAIC(:,69) - ALGEBRAIC(:,66))./CONSTANTS(:,88);
    ALGEBRAIC(:,68) =  CONSTANTS(:,51).*(power(STATES(:,19), 2.00000)./(power(CONSTANTS(:,57), 2.00000)+power(STATES(:,19), 2.00000)));
    ALGEBRAIC(:,70) =  CONSTANTS(:,63).*CONSTANTS(:,87).*STATES(:,20);
    RATES(:,20) = (ALGEBRAIC(:,68) - (ALGEBRAIC(:,70)+ALGEBRAIC(:,69)))./CONSTANTS(:,87);
    ALGEBRAIC(:,63) = 1.00000 - CONSTANTS(:,52)./(CONSTANTS(:,55)+STATES(:,18)+CONSTANTS(:,52));
    ALGEBRAIC(:,65) =  CONSTANTS(:,61).*CONSTANTS(:,89).*(STATES(:,18) - STATES(:,19));
    ALGEBRAIC(:,71) = ALGEBRAIC(:,43)+ALGEBRAIC(:,50);
    RATES(:,18) =  (ALGEBRAIC(:,63)./CONSTANTS(:,89)).*(ALGEBRAIC(:,65) - ( 0.950000.*ALGEBRAIC(:,71))./( 2.00000.*CONSTANTS(:,4)));
    ALGEBRAIC(:,67) = 1.00000 - CONSTANTS(:,53)./(CONSTANTS(:,55)+STATES(:,19)+CONSTANTS(:,53));
    RATES(:,19) =  (ALGEBRAIC(:,67)./CONSTANTS(:,90)).*((ALGEBRAIC(:,65) - ((( 0.0500000.*ALGEBRAIC(:,71) -  2.00000.*ALGEBRAIC(:,61))+ALGEBRAIC(:,60))./( 2.00000.*CONSTANTS(:,4))+ALGEBRAIC(:,68)))+ALGEBRAIC(:,66)+ALGEBRAIC(:,70));
   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(:,12) = 1.00000./(1.00000+exp((STATES(:,1)+18.6000)./10.1000));
    ALGEBRAIC(:,3) = power(1.00000./(1.00000+exp( - STATES(:,1)./5.46000)), 1.00000./3.00000);
    ALGEBRAIC(:,19) = 0.000624700./( 0.832000.*exp(  - 0.335000.*(STATES(:,1)+56.7000))+ 0.627000.*exp( 0.0820000.*(STATES(:,1)+65.0100)))+4.00000e-05;
    ALGEBRAIC(:,4) = 1.00000./(1.00000+exp((STATES(:,1)+66.1000)./6.40000));
    ALGEBRAIC(:,21) = ( 3.71700e-06.*exp(  - 0.281500.*(STATES(:,1)+17.1100)))./(1.00000+ 0.00373200.*exp(  - 0.342600.*(STATES(:,1)+37.7600)))+0.000597700;
    ALGEBRAIC(:,9) = 1.00000./(1.00000+exp((STATES(:,1)+59.3700)./13.1000));
    ALGEBRAIC(:,26) = 0.0101000+0.0651700./( 0.570000.*exp(  - 0.0800000.*(STATES(:,1)+49.0000)))+ 2.40000e-05.*exp( 0.100000.*(STATES(:,1)+50.9300));
    ALGEBRAIC(:,10) = 1.00000./(1.00000+exp( - (STATES(:,1) - 10.9300)./19.7000));
    ALGEBRAIC(:,27) =  0.00100000.*(2.98000+15.5900./( 1.03700.*exp( 0.0900000.*(STATES(:,1)+30.6100))+ 0.369000.*exp(  - 0.120000.*(STATES(:,1)+23.8400))));
    ALGEBRAIC(:,11) = 1.00000./(1.00000+exp( - (STATES(:,1)+14.2000)./10.6000));
    ALGEBRAIC(:,28) = 1.00000./( 37.2000.*exp((STATES(:,1) - 9.00000)./15.9000)+ 0.960000.*exp( - (STATES(:,1) - 9.00000)./22.5000));
    ALGEBRAIC(:,13) = 14.0000./(1.00000+exp( - (STATES(:,1) - 40.0000)./9.00000));
    ALGEBRAIC(:,30) =  1.00000.*exp( - STATES(:,1)./45.0000);
    ALGEBRAIC(:,14) =  1.00000.*exp( - (STATES(:,1)+78.9100)./26.6200);
    ALGEBRAIC(:,31) =  1.00000.*exp((STATES(:,1)+75.1300)./21.2500);
    ALGEBRAIC(:,20) = ALGEBRAIC(:,4);
    ALGEBRAIC(:,35) = ( 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(:,29) = ALGEBRAIC(:,11);
    ALGEBRAIC(:,40) = 1.00000./( 4.20000.*exp((STATES(:,1) - 9.00000)./17.0000)+ 0.150000.*exp( - (STATES(:,1) - 9.00000)./21.6000));
    ALGEBRAIC(:,44) = 1.00000./(1.00000+exp( - (STATES(:,1)+23.1000)./6.00000));
    ALGEBRAIC(:,5) = (  - 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);
    ALGEBRAIC(:,22) = ( 11.4200.*(STATES(:,1) - 5.00000))./(exp( 0.400000.*(STATES(:,1) - 5.00000)) - 1.00000);
    ALGEBRAIC(:,36) = 2.00000./(ALGEBRAIC(:,5)+ALGEBRAIC(:,22));
    ALGEBRAIC(:,45) = 1.00000./(1.00000+exp((STATES(:,1)+45.0000)./5.00000));
    ALGEBRAIC(:,6) = ( 3.12000.*(STATES(:,1)+28.0000))./(exp((STATES(:,1)+28.0000)./4.00000) - 1.00000);
    ALGEBRAIC(:,23) = 25.0000./(1.00000+exp( - (STATES(:,1)+28.0000)./4.00000));
    ALGEBRAIC(:,37) = 1.00000./(ALGEBRAIC(:,6)+ALGEBRAIC(:,23));
    ALGEBRAIC(:,46) = 1.00000./(1.00000+exp( - (STATES(:,1)+37.0000)./6.80000));
    ALGEBRAIC(:,7) =  1068.00.*exp((STATES(:,1)+26.3000)./30.0000);
    ALGEBRAIC(:,24) =  1068.00.*exp( - (STATES(:,1)+26.3000)./30.0000);
    ALGEBRAIC(:,38) = 1.00000./(ALGEBRAIC(:,7)+ALGEBRAIC(:,24));
    ALGEBRAIC(:,47) = 1.00000./(1.00000+exp((STATES(:,1)+71.0000)./9.00000));
    ALGEBRAIC(:,8) =  15.3000.*exp( - (STATES(:,1)+71.7000)./83.3000);
    ALGEBRAIC(:,25) =  15.0000.*exp((STATES(:,1)+71.7000)./15.3800);
    ALGEBRAIC(:,39) = 1.00000./(ALGEBRAIC(:,8)+ALGEBRAIC(:,25));
    ALGEBRAIC(:,15) = 1000.00./( 0.150000.*exp( - STATES(:,1)./11.0000)+ 0.200000.*exp( - STATES(:,1)./700.000));
    ALGEBRAIC(:,32) = 1000.00./( 16.0000.*exp(STATES(:,1)./8.00000)+ 0.200000.*exp(STATES(:,1)./50.0000));
    ALGEBRAIC(:,48) = ALGEBRAIC(:,15)./(ALGEBRAIC(:,15)+ALGEBRAIC(:,32));
    ALGEBRAIC(:,41) = 1.00000./(ALGEBRAIC(:,15)+ALGEBRAIC(:,32));
    ALGEBRAIC(:,16) = 1000.00./( 3100.00.*exp( - STATES(:,1)./13.0000)+ 700.000.*exp( - STATES(:,1)./70.0000));
    ALGEBRAIC(:,33) = 1000.00./( 16.0000.*exp(STATES(:,1)./8.00000)+ 0.200000.*exp(STATES(:,1)./50.0000));
    ALGEBRAIC(:,49) = ALGEBRAIC(:,16)./(ALGEBRAIC(:,16)+ALGEBRAIC(:,33));
    ALGEBRAIC(:,42) = 1.00000./(ALGEBRAIC(:,16)+ALGEBRAIC(:,33));
    ALGEBRAIC(:,1) = ( 0.0952000.*exp(  - 0.0630000.*(STATES(:,1)+34.4000)))./(1.00000+ 1.66000.*exp(  - 0.225000.*(STATES(:,1)+63.7000)))+0.0869000;
    ALGEBRAIC(:,18) =  (1.00000 - ALGEBRAIC(:,1)).*STATES(:,3)+ ALGEBRAIC(:,1).*STATES(:,4);
    ALGEBRAIC(:,34) =  (( (( CONSTANTS(:,73).*power(STATES(:,2), 3.00000).*ALGEBRAIC(:,18).*CONSTANTS(:,9).*power(CONSTANTS(:,4), 2.00000))./( CONSTANTS(:,2).*CONSTANTS(:,3))).*(exp(( (STATES(:,1) - CONSTANTS(:,68)).*CONSTANTS(:,4))./( CONSTANTS(:,2).*CONSTANTS(:,3))) - 1.00000))./(exp(( STATES(:,1).*CONSTANTS(:,4))./( CONSTANTS(:,2).*CONSTANTS(:,3))) - 1.00000)).*STATES(:,1);
    ALGEBRAIC(:,43) =  CONSTANTS(:,74).*( STATES(:,6).*STATES(:,5)+0.00600000./(1.00000+exp( - (STATES(:,1)+14.1000)./6.00000))).*(STATES(:,1) - CONSTANTS(:,12));
    ALGEBRAIC(:,50) =  CONSTANTS(:,75).*STATES(:,7).*STATES(:,8).*(STATES(:,1) - CONSTANTS(:,15));
    ALGEBRAIC(:,51) =  CONSTANTS(:,76).*STATES(:,9).*STATES(:,10).*(STATES(:,1) - CONSTANTS(:,69));
    ALGEBRAIC(:,52) =  CONSTANTS(:,77).*STATES(:,10).*(STATES(:,1) - CONSTANTS(:,69));
    ALGEBRAIC(:,53) =  0.600000.*STATES(:,11)+ 0.400000.*STATES(:,12);
    ALGEBRAIC(:,54) =  CONSTANTS(:,78).*ALGEBRAIC(:,53).*STATES(:,13).*(STATES(:,1) - CONSTANTS(:,69));
    ALGEBRAIC(:,55) =  CONSTANTS(:,79).*power(STATES(:,14), 2.00000).*(STATES(:,1) - CONSTANTS(:,70));
    ALGEBRAIC(:,56) =  CONSTANTS(:,80).*STATES(:,15).*(STATES(:,1) - CONSTANTS(:,68));
    ALGEBRAIC(:,57) =  CONSTANTS(:,81).*STATES(:,15).*(STATES(:,1) - CONSTANTS(:,69));
    ALGEBRAIC(:,58) =  CONSTANTS(:,82).*(STATES(:,1) - CONSTANTS(:,68));
    ALGEBRAIC(:,60) =  CONSTANTS(:,84).*(STATES(:,1) - CONSTANTS(:,71));
    ALGEBRAIC(:,59) =  CONSTANTS(:,83).*(STATES(:,1) - CONSTANTS(:,69));
    ALGEBRAIC(:,61) = ( CONSTANTS(:,85).*( power(CONSTANTS(:,39), 3.00000).*CONSTANTS(:,41).*exp( 0.0374300.*STATES(:,1).*CONSTANTS(:,38)) -  power(CONSTANTS(:,9), 3.00000).*CONSTANTS(:,40).*exp( 0.0374000.*STATES(:,1).*(CONSTANTS(:,38) - 1.00000))))./(1.00000+ CONSTANTS(:,37).*( CONSTANTS(:,40).*power(CONSTANTS(:,9), 3.00000)+ CONSTANTS(:,41).*power(CONSTANTS(:,39), 3.00000)));
    ALGEBRAIC(:,62) = ( CONSTANTS(:,86).*power(CONSTANTS(:,39)./(CONSTANTS(:,42)+CONSTANTS(:,39)), 3.00000).*power(CONSTANTS(:,46)./(CONSTANTS(:,43)+CONSTANTS(:,46)), 2.00000).*1.60000)./(1.50000+exp( - (STATES(:,1)+60.0000)./40.0000));
    ALGEBRAIC(:,64) =  CONSTANTS(:,49).*(STATES(:,19)./(STATES(:,19)+0.000400000));
    ALGEBRAIC(:,66) =  CONSTANTS(:,64).*STATES(:,22).*(power(STATES(:,18), 2.00000)./(power(CONSTANTS(:,56), 2.00000)+power(STATES(:,18), 2.00000))).*CONSTANTS(:,88).*STATES(:,21);
    ALGEBRAIC(:,69) =  CONSTANTS(:,65).*CONSTANTS(:,87).*(STATES(:,20) - STATES(:,21));
    ALGEBRAIC(:,68) =  CONSTANTS(:,51).*(power(STATES(:,19), 2.00000)./(power(CONSTANTS(:,57), 2.00000)+power(STATES(:,19), 2.00000)));
    ALGEBRAIC(:,70) =  CONSTANTS(:,63).*CONSTANTS(:,87).*STATES(:,20);
    ALGEBRAIC(:,63) = 1.00000 - CONSTANTS(:,52)./(CONSTANTS(:,55)+STATES(:,18)+CONSTANTS(:,52));
    ALGEBRAIC(:,65) =  CONSTANTS(:,61).*CONSTANTS(:,89).*(STATES(:,18) - STATES(:,19));
    ALGEBRAIC(:,71) = ALGEBRAIC(:,43)+ALGEBRAIC(:,50);
    ALGEBRAIC(:,67) = 1.00000 - CONSTANTS(:,53)./(CONSTANTS(:,55)+STATES(:,19)+CONSTANTS(:,53));
    ALGEBRAIC(:,2) =  CONSTANTS(:,48).*STATES(:,16).*STATES(:,17).*(STATES(:,1) - 18.0000);
    ALGEBRAIC(:,17) =  CONSTANTS(:,50).*(STATES(:,19)./(STATES(:,19)+0.000400000));
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