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 =82;
end
% There are a total of 29 entries in each of the rate and state variable arrays.
% There are a total of 63 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_STATES(:,1) = strpad('V in component membrane (millivolt)');
    LEGEND_CONSTANTS(:,1) = strpad('R in component membrane (joule_per_kilomole_kelvin)');
    LEGEND_CONSTANTS(:,2) = strpad('T in component membrane (kelvin)');
    LEGEND_CONSTANTS(:,3) = strpad('F in component membrane (coulomb_per_mole)');
    LEGEND_CONSTANTS(:,4) = strpad('C in component membrane (microF)');
    LEGEND_CONSTANTS(:,54) = strpad('RTONF in component membrane (millivolt)');
    LEGEND_ALGEBRAIC(:,67) = strpad('i_Na in component fast_sodium_current (nanoA)');
    LEGEND_ALGEBRAIC(:,72) = strpad('i_CaL in component L_type_calcium_current (nanoA)');
    LEGEND_ALGEBRAIC(:,68) = strpad('i_to in component transient_outward_potassium_current (nanoA)');
    LEGEND_ALGEBRAIC(:,43) = strpad('i_Kr in component rapid_delayed_rectifier_potassium_current (nanoA)');
    LEGEND_ALGEBRAIC(:,35) = strpad('i_f in component hyperpolarising_activated_current (nanoA)');
    LEGEND_ALGEBRAIC(:,69) = strpad('i_st in component sustained_outward_potassium_current (nanoA)');
    LEGEND_ALGEBRAIC(:,51) = strpad('i_K1 in component time_independent_potassium_current (nanoA)');
    LEGEND_ALGEBRAIC(:,66) = strpad('i_NaCa in component sodium_calcium_exchange_current (nanoA)');
    LEGEND_ALGEBRAIC(:,53) = strpad('i_p in component sodium_potassium_pump (nanoA)');
    LEGEND_ALGEBRAIC(:,52) = strpad('i_b in component background_current (nanoA)');
    LEGEND_ALGEBRAIC(:,71) = strpad('i_ACh in component acetylcholine_sensitive_current (nanoA)');
    LEGEND_ALGEBRAIC(:,18) = strpad('i_Stim in component membrane (nanoA)');
    LEGEND_CONSTANTS(:,5) = strpad('stim_start in component membrane (second)');
    LEGEND_CONSTANTS(:,6) = strpad('stim_end in component membrane (second)');
    LEGEND_CONSTANTS(:,7) = strpad('stim_period in component membrane (second)');
    LEGEND_CONSTANTS(:,8) = strpad('stim_duration in component membrane (second)');
    LEGEND_CONSTANTS(:,9) = strpad('stim_amplitude in component membrane (nanoA)');
    LEGEND_CONSTANTS(:,10) = strpad('g_f in component hyperpolarising_activated_current (microS)');
    LEGEND_CONSTANTS(:,11) = strpad('ACh in component acetylcholine_sensitive_current (millimolar)');
    LEGEND_STATES(:,2) = strpad('y in component hyperpolarising_activated_current_y_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,1) = strpad('y_inf in component hyperpolarising_activated_current_y_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,20) = strpad('tau_y in component hyperpolarising_activated_current_y_gate (second)');
    LEGEND_CONSTANTS(:,12) = strpad('g_Kr in component rapid_delayed_rectifier_potassium_current (microS)');
    LEGEND_CONSTANTS(:,56) = strpad('E_K in component rapid_delayed_rectifier_potassium_current (millivolt)');
    LEGEND_CONSTANTS(:,13) = strpad('Ki in component intracellular_potassium_concentration (millimolar)');
    LEGEND_CONSTANTS(:,14) = strpad('Kc in component extracellular_potassium_concentration (millimolar)');
    LEGEND_STATES(:,3) = strpad('paf in component rapid_delayed_rectifier_potassium_current_paf_gate (dimensionless)');
    LEGEND_STATES(:,4) = strpad('pas in component rapid_delayed_rectifier_potassium_current_pas_gate (dimensionless)');
    LEGEND_STATES(:,5) = strpad('pik in component rapid_delayed_rectifier_potassium_current_pik_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,2) = strpad('paf_infinity in component rapid_delayed_rectifier_potassium_current_paf_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,21) = strpad('tau_paf in component rapid_delayed_rectifier_potassium_current_paf_gate (second)');
    LEGEND_ALGEBRAIC(:,3) = strpad('pas_infinity in component rapid_delayed_rectifier_potassium_current_pas_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,22) = strpad('tau_pas in component rapid_delayed_rectifier_potassium_current_pas_gate (second)');
    LEGEND_ALGEBRAIC(:,4) = strpad('pik_infinity in component rapid_delayed_rectifier_potassium_current_pik_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,23) = strpad('alpha_pik in component rapid_delayed_rectifier_potassium_current_pik_gate (per_second)');
    LEGEND_ALGEBRAIC(:,36) = strpad('beta_pik in component rapid_delayed_rectifier_potassium_current_pik_gate (per_second)');
    LEGEND_ALGEBRAIC(:,44) = strpad('tau_pik in component rapid_delayed_rectifier_potassium_current_pik_gate (second)');
    LEGEND_CONSTANTS(:,15) = strpad('g_K1 in component time_independent_potassium_current (microS)');
    LEGEND_ALGEBRAIC(:,50) = strpad('g_K1_prime in component time_independent_potassium_current (microS)');
    LEGEND_CONSTANTS(:,16) = strpad('g_b in component background_current (microS)');
    LEGEND_CONSTANTS(:,17) = strpad('E_b in component background_current (millivolt)');
    LEGEND_CONSTANTS(:,18) = strpad('I_p in component sodium_potassium_pump (nanoA)');
    LEGEND_CONSTANTS(:,19) = strpad('Nai in component intracellular_sodium_concentration (millimolar)');
    LEGEND_CONSTANTS(:,20) = strpad('kNaCa in component sodium_calcium_exchange_current (nanoA)');
    LEGEND_ALGEBRAIC(:,62) = strpad('x1 in component sodium_calcium_exchange_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,63) = strpad('x2 in component sodium_calcium_exchange_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,64) = strpad('x3 in component sodium_calcium_exchange_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,65) = strpad('x4 in component sodium_calcium_exchange_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,59) = strpad('k41 in component sodium_calcium_exchange_current (dimensionless)');
    LEGEND_CONSTANTS(:,55) = strpad('k34 in component sodium_calcium_exchange_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,56) = strpad('k23 in component sodium_calcium_exchange_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,57) = strpad('k21 in component sodium_calcium_exchange_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,55) = strpad('k32 in component sodium_calcium_exchange_current (dimensionless)');
    LEGEND_CONSTANTS(:,59) = strpad('k43 in component sodium_calcium_exchange_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,61) = strpad('k12 in component sodium_calcium_exchange_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,60) = strpad('k14 in component sodium_calcium_exchange_current (dimensionless)');
    LEGEND_CONSTANTS(:,21) = strpad('Qci in component sodium_calcium_exchange_current (dimensionless)');
    LEGEND_CONSTANTS(:,22) = strpad('Qn in component sodium_calcium_exchange_current (dimensionless)');
    LEGEND_CONSTANTS(:,23) = strpad('Qco in component sodium_calcium_exchange_current (dimensionless)');
    LEGEND_CONSTANTS(:,24) = strpad('Kci in component sodium_calcium_exchange_current (millimolar)');
    LEGEND_CONSTANTS(:,25) = strpad('K1ni in component sodium_calcium_exchange_current (millimolar)');
    LEGEND_CONSTANTS(:,26) = strpad('K2ni in component sodium_calcium_exchange_current (millimolar)');
    LEGEND_CONSTANTS(:,27) = strpad('K3ni in component sodium_calcium_exchange_current (millimolar)');
    LEGEND_CONSTANTS(:,28) = strpad('Kcni in component sodium_calcium_exchange_current (millimolar)');
    LEGEND_CONSTANTS(:,29) = strpad('K3no in component sodium_calcium_exchange_current (millimolar)');
    LEGEND_CONSTANTS(:,30) = strpad('K1no in component sodium_calcium_exchange_current (millimolar)');
    LEGEND_CONSTANTS(:,31) = strpad('K2no in component sodium_calcium_exchange_current (millimolar)');
    LEGEND_CONSTANTS(:,32) = strpad('Kco in component sodium_calcium_exchange_current (millimolar)');
    LEGEND_ALGEBRAIC(:,54) = strpad('do in component sodium_calcium_exchange_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,58) = strpad('di in component sodium_calcium_exchange_current (dimensionless)');
    LEGEND_CONSTANTS(:,33) = strpad('Cao in component extracellular_calcium_concentration (millimolar)');
    LEGEND_CONSTANTS(:,34) = strpad('Nao in component extracellular_sodium_concentration (millimolar)');
    LEGEND_STATES(:,6) = strpad('Casub in component intracellular_calcium_concentration (millimolar)');
    LEGEND_CONSTANTS(:,35) = strpad('g_Na in component fast_sodium_current (microlitre_per_second)');
    LEGEND_CONSTANTS(:,57) = strpad('E_Na in component fast_sodium_current (millivolt)');
    LEGEND_STATES(:,7) = strpad('m in component fast_sodium_current_m_gate (dimensionless)');
    LEGEND_STATES(:,8) = strpad('h1 in component fast_sodium_current_h1_gate (dimensionless)');
    LEGEND_STATES(:,9) = strpad('h2 in component fast_sodium_current_h2_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,24) = strpad('alpha_m in component fast_sodium_current_m_gate (per_second)');
    LEGEND_ALGEBRAIC(:,37) = strpad('beta_m in component fast_sodium_current_m_gate (per_second)');
    LEGEND_CONSTANTS(:,36) = strpad('delta_m in component fast_sodium_current_m_gate (millivolt)');
    LEGEND_ALGEBRAIC(:,5) = strpad('E0_m in component fast_sodium_current_m_gate (millivolt)');
    LEGEND_ALGEBRAIC(:,6) = strpad('alpha_h1 in component fast_sodium_current_h1_gate (per_second)');
    LEGEND_ALGEBRAIC(:,25) = strpad('beta_h1 in component fast_sodium_current_h1_gate (per_second)');
    LEGEND_ALGEBRAIC(:,38) = strpad('h1_inf in component fast_sodium_current_h1_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,45) = strpad('tau_h1 in component fast_sodium_current_h1_gate (second)');
    LEGEND_ALGEBRAIC(:,7) = strpad('alpha_h2 in component fast_sodium_current_h2_gate (per_second)');
    LEGEND_ALGEBRAIC(:,26) = strpad('beta_h2 in component fast_sodium_current_h2_gate (per_second)');
    LEGEND_ALGEBRAIC(:,39) = strpad('h2_inf in component fast_sodium_current_h2_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,46) = strpad('tau_h2 in component fast_sodium_current_h2_gate (second)');
    LEGEND_CONSTANTS(:,37) = strpad('g_CaL in component L_type_calcium_current (microS)');
    LEGEND_CONSTANTS(:,38) = strpad('E_CaL in component L_type_calcium_current (millivolt)');
    LEGEND_STATES(:,10) = strpad('d in component L_type_calcium_current_d_gate (dimensionless)');
    LEGEND_STATES(:,11) = strpad('f in component L_type_calcium_current_f_gate (dimensionless)');
    LEGEND_STATES(:,12) = strpad('f2 in component L_type_calcium_current_f2_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,8) = strpad('alpha_d in component L_type_calcium_current_d_gate (per_second)');
    LEGEND_ALGEBRAIC(:,27) = strpad('beta_d in component L_type_calcium_current_d_gate (per_second)');
    LEGEND_ALGEBRAIC(:,40) = strpad('d_inf in component L_type_calcium_current_d_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,47) = strpad('tau_d in component L_type_calcium_current_d_gate (second)');
    LEGEND_CONSTANTS(:,39) = strpad('act_shift in component L_type_calcium_current_d_gate (millivolt)');
    LEGEND_CONSTANTS(:,40) = strpad('slope_factor_act in component L_type_calcium_current_d_gate (millivolt)');
    LEGEND_ALGEBRAIC(:,9) = strpad('f_inf in component L_type_calcium_current_f_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,28) = strpad('tau_f in component L_type_calcium_current_f_gate (second)');
    LEGEND_CONSTANTS(:,41) = strpad('inact_shift in component L_type_calcium_current_f_gate (millivolt)');
    LEGEND_ALGEBRAIC(:,10) = strpad('f2_inf in component L_type_calcium_current_f2_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,29) = strpad('tau_f2 in component L_type_calcium_current_f2_gate (second)');
    LEGEND_CONSTANTS(:,42) = strpad('inact_shift in component L_type_calcium_current_f2_gate (millivolt)');
    LEGEND_CONSTANTS(:,58) = strpad('E_K in component transient_outward_potassium_current (millivolt)');
    LEGEND_CONSTANTS(:,43) = strpad('g_to in component transient_outward_potassium_current (microS)');
    LEGEND_STATES(:,13) = strpad('r in component transient_outward_potassium_current_r_gate (dimensionless)');
    LEGEND_STATES(:,14) = strpad('q_fast in component transient_outward_potassium_current_qfast_gate (dimensionless)');
    LEGEND_STATES(:,15) = strpad('q_slow in component transient_outward_potassium_current_qslow_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,30) = strpad('tau_r in component transient_outward_potassium_current_r_gate (second)');
    LEGEND_ALGEBRAIC(:,11) = strpad('r_infinity in component transient_outward_potassium_current_r_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,31) = strpad('tau_qfast in component transient_outward_potassium_current_qfast_gate (second)');
    LEGEND_ALGEBRAIC(:,12) = strpad('qfast_infinity in component transient_outward_potassium_current_qfast_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,32) = strpad('tau_qslow in component transient_outward_potassium_current_qslow_gate (second)');
    LEGEND_ALGEBRAIC(:,13) = strpad('qslow_infinity in component transient_outward_potassium_current_qslow_gate (dimensionless)');
    LEGEND_CONSTANTS(:,44) = strpad('E_st in component sustained_outward_potassium_current (millivolt)');
    LEGEND_CONSTANTS(:,45) = strpad('g_st in component sustained_outward_potassium_current (microS)');
    LEGEND_STATES(:,16) = strpad('qa in component sustained_outward_potassium_current_qa_gate (dimensionless)');
    LEGEND_STATES(:,17) = strpad('qi in component sustained_outward_potassium_current_qi_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,48) = strpad('tau_qa in component sustained_outward_potassium_current_qa_gate (second)');
    LEGEND_ALGEBRAIC(:,14) = strpad('qa_infinity in component sustained_outward_potassium_current_qa_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,33) = strpad('alpha_qa in component sustained_outward_potassium_current_qa_gate (per_second)');
    LEGEND_ALGEBRAIC(:,41) = strpad('beta_qa in component sustained_outward_potassium_current_qa_gate (per_second)');
    LEGEND_ALGEBRAIC(:,49) = strpad('tau_qi in component sustained_outward_potassium_current_qi_gate (second)');
    LEGEND_ALGEBRAIC(:,15) = strpad('alpha_qi in component sustained_outward_potassium_current_qi_gate (per_second)');
    LEGEND_ALGEBRAIC(:,34) = strpad('beta_qi in component sustained_outward_potassium_current_qi_gate (per_second)');
    LEGEND_ALGEBRAIC(:,42) = strpad('qi_infinity in component sustained_outward_potassium_current_qi_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,70) = strpad('g_ACh in component acetylcholine_sensitive_current (microS)');
    LEGEND_CONSTANTS(:,46) = strpad('g_ACh_max in component acetylcholine_sensitive_current (microS)');
    LEGEND_CONSTANTS(:,47) = strpad('K_ACh in component acetylcholine_sensitive_current (millimolar)');
    LEGEND_STATES(:,18) = strpad('achf in component acetylcholine_sensitive_current_achf_gate (dimensionless)');
    LEGEND_STATES(:,19) = strpad('achs in component acetylcholine_sensitive_current_achs_gate (dimensionless)');
    LEGEND_CONSTANTS(:,48) = strpad('alpha_achf in component acetylcholine_sensitive_current_achf_gate (per_second)');
    LEGEND_ALGEBRAIC(:,16) = strpad('beta_achf in component acetylcholine_sensitive_current_achf_gate (per_second)');
    LEGEND_CONSTANTS(:,49) = strpad('alpha_achs in component acetylcholine_sensitive_current_achs_gate (per_second)');
    LEGEND_ALGEBRAIC(:,17) = strpad('beta_achs in component acetylcholine_sensitive_current_achs_gate (per_second)');
    LEGEND_STATES(:,20) = strpad('Cai in component intracellular_calcium_concentration (millimolar)');
    LEGEND_CONSTANTS(:,60) = strpad('V_up in component intracellular_calcium_concentration (micrometre3)');
    LEGEND_CONSTANTS(:,61) = strpad('V_rel in component intracellular_calcium_concentration (micrometre3)');
    LEGEND_CONSTANTS(:,62) = strpad('V_sub in component intracellular_calcium_concentration (micrometre3)');
    LEGEND_CONSTANTS(:,63) = strpad('Vi in component intracellular_calcium_concentration (micrometre3)');
    LEGEND_CONSTANTS(:,50) = strpad('V_cell in component intracellular_calcium_concentration (micrometre3)');
    LEGEND_ALGEBRAIC(:,74) = strpad('i_up in component intracellular_calcium_concentration (millimolar_per_second)');
    LEGEND_ALGEBRAIC(:,75) = strpad('i_tr in component intracellular_calcium_concentration (millimolar_per_second)');
    LEGEND_ALGEBRAIC(:,77) = strpad('i_rel in component intracellular_calcium_concentration (millimolar_per_second)');
    LEGEND_ALGEBRAIC(:,73) = strpad('i_diff in component intracellular_calcium_concentration (millimolar_per_second)');
    LEGEND_STATES(:,21) = strpad('Ca_up in component intracellular_calcium_concentration (millimolar)');
    LEGEND_STATES(:,22) = strpad('Ca_rel in component intracellular_calcium_concentration (millimolar)');
    LEGEND_CONSTANTS(:,51) = strpad('P_rel in component intracellular_calcium_concentration (per_second)');
    LEGEND_CONSTANTS(:,52) = strpad('K_up in component intracellular_calcium_concentration (millimolar)');
    LEGEND_CONSTANTS(:,53) = strpad('tau_tr in component intracellular_calcium_concentration (second)');
    LEGEND_STATES(:,23) = strpad('f_TC in component intracellular_calcium_concentration (dimensionless)');
    LEGEND_STATES(:,24) = strpad('f_TMC in component intracellular_calcium_concentration (dimensionless)');
    LEGEND_STATES(:,25) = strpad('f_TMM in component intracellular_calcium_concentration (dimensionless)');
    LEGEND_STATES(:,26) = strpad('f_CMi in component intracellular_calcium_concentration (dimensionless)');
    LEGEND_STATES(:,27) = strpad('f_CMs in component intracellular_calcium_concentration (dimensionless)');
    LEGEND_STATES(:,28) = strpad('f_CQ in component intracellular_calcium_concentration (dimensionless)');
    LEGEND_STATES(:,29) = strpad('f_CSL in component intracellular_calcium_concentration (dimensionless)');
    LEGEND_ALGEBRAIC(:,76) = strpad('diff_f_TC in component intracellular_calcium_concentration (per_second)');
    LEGEND_ALGEBRAIC(:,78) = strpad('diff_f_TMC in component intracellular_calcium_concentration (per_second)');
    LEGEND_ALGEBRAIC(:,19) = strpad('diff_f_TMM in component intracellular_calcium_concentration (per_second)');
    LEGEND_ALGEBRAIC(:,79) = strpad('diff_f_CMi in component intracellular_calcium_concentration (per_second)');
    LEGEND_ALGEBRAIC(:,80) = strpad('diff_f_CMs in component intracellular_calcium_concentration (per_second)');
    LEGEND_ALGEBRAIC(:,81) = strpad('diff_f_CQ in component intracellular_calcium_concentration (per_second)');
    LEGEND_ALGEBRAIC(:,82) = strpad('diff_f_CSL in component intracellular_calcium_concentration (per_second)');
    LEGEND_RATES(:,1) = strpad('d/dt V in component membrane (millivolt)');
    LEGEND_RATES(:,2) = strpad('d/dt y in component hyperpolarising_activated_current_y_gate (dimensionless)');
    LEGEND_RATES(:,3) = strpad('d/dt paf in component rapid_delayed_rectifier_potassium_current_paf_gate (dimensionless)');
    LEGEND_RATES(:,4) = strpad('d/dt pas in component rapid_delayed_rectifier_potassium_current_pas_gate (dimensionless)');
    LEGEND_RATES(:,5) = strpad('d/dt pik in component rapid_delayed_rectifier_potassium_current_pik_gate (dimensionless)');
    LEGEND_RATES(:,7) = strpad('d/dt m in component fast_sodium_current_m_gate (dimensionless)');
    LEGEND_RATES(:,8) = strpad('d/dt h1 in component fast_sodium_current_h1_gate (dimensionless)');
    LEGEND_RATES(:,9) = strpad('d/dt h2 in component fast_sodium_current_h2_gate (dimensionless)');
    LEGEND_RATES(:,10) = strpad('d/dt d in component L_type_calcium_current_d_gate (dimensionless)');
    LEGEND_RATES(:,11) = strpad('d/dt f in component L_type_calcium_current_f_gate (dimensionless)');
    LEGEND_RATES(:,12) = strpad('d/dt f2 in component L_type_calcium_current_f2_gate (dimensionless)');
    LEGEND_RATES(:,13) = strpad('d/dt r in component transient_outward_potassium_current_r_gate (dimensionless)');
    LEGEND_RATES(:,14) = strpad('d/dt q_fast in component transient_outward_potassium_current_qfast_gate (dimensionless)');
    LEGEND_RATES(:,15) = strpad('d/dt q_slow in component transient_outward_potassium_current_qslow_gate (dimensionless)');
    LEGEND_RATES(:,16) = strpad('d/dt qa in component sustained_outward_potassium_current_qa_gate (dimensionless)');
    LEGEND_RATES(:,17) = strpad('d/dt qi in component sustained_outward_potassium_current_qi_gate (dimensionless)');
    LEGEND_RATES(:,18) = strpad('d/dt achf in component acetylcholine_sensitive_current_achf_gate (dimensionless)');
    LEGEND_RATES(:,19) = strpad('d/dt achs in component acetylcholine_sensitive_current_achs_gate (dimensionless)');
    LEGEND_RATES(:,21) = strpad('d/dt Ca_up in component intracellular_calcium_concentration (millimolar)');
    LEGEND_RATES(:,22) = strpad('d/dt Ca_rel in component intracellular_calcium_concentration (millimolar)');
    LEGEND_RATES(:,20) = strpad('d/dt Cai in component intracellular_calcium_concentration (millimolar)');
    LEGEND_RATES(:,6) = strpad('d/dt Casub in component intracellular_calcium_concentration (millimolar)');
    LEGEND_RATES(:,23) = strpad('d/dt f_TC in component intracellular_calcium_concentration (dimensionless)');
    LEGEND_RATES(:,24) = strpad('d/dt f_TMC in component intracellular_calcium_concentration (dimensionless)');
    LEGEND_RATES(:,25) = strpad('d/dt f_TMM in component intracellular_calcium_concentration (dimensionless)');
    LEGEND_RATES(:,26) = strpad('d/dt f_CMi in component intracellular_calcium_concentration (dimensionless)');
    LEGEND_RATES(:,27) = strpad('d/dt f_CMs in component intracellular_calcium_concentration (dimensionless)');
    LEGEND_RATES(:,28) = strpad('d/dt f_CQ in component intracellular_calcium_concentration (dimensionless)');
    LEGEND_RATES(:,29) = strpad('d/dt f_CSL in component intracellular_calcium_concentration (dimensionless)');
    LEGEND_STATES  = LEGEND_STATES';
    LEGEND_ALGEBRAIC = LEGEND_ALGEBRAIC';
    LEGEND_RATES = LEGEND_RATES';
    LEGEND_CONSTANTS = LEGEND_CONSTANTS';
end

function [STATES, CONSTANTS] = initConsts()
    VOI = 0; CONSTANTS = []; STATES = []; ALGEBRAIC = [];
    STATES(:,1) = -69.760276376489;
    CONSTANTS(:,1) = 8314.472;
    CONSTANTS(:,2) = 310;
    CONSTANTS(:,3) = 96485.3415;
    CONSTANTS(:,4) = 2.9e-5;
    CONSTANTS(:,5) = 0.1;
    CONSTANTS(:,6) = 99999;
    CONSTANTS(:,7) = 1;
    CONSTANTS(:,8) = 0.001;
    CONSTANTS(:,9) = -2;
    CONSTANTS(:,10) = 0;
    CONSTANTS(:,11) = 0;
    STATES(:,2) = 0.19584111039096;
    CONSTANTS(:,12) = 0.002;
    CONSTANTS(:,13) = 140;
    CONSTANTS(:,14) = 5.4;
    STATES(:,3) = 0.00141762995766447;
    STATES(:,4) = 0.00539771950846456;
    STATES(:,5) = 0.98638204514681;
    CONSTANTS(:,15) = 0.015;
    CONSTANTS(:,16) = 0.002;
    CONSTANTS(:,17) = -40;
    CONSTANTS(:,18) = 0.1968;
    CONSTANTS(:,19) = 8;
    CONSTANTS(:,20) = 5.916;
    CONSTANTS(:,21) = 0.1369;
    CONSTANTS(:,22) = 0.4315;
    CONSTANTS(:,23) = 0;
    CONSTANTS(:,24) = 0.0207;
    CONSTANTS(:,25) = 395.3;
    CONSTANTS(:,26) = 2.289;
    CONSTANTS(:,27) = 26.44;
    CONSTANTS(:,28) = 26.44;
    CONSTANTS(:,29) = 4.663;
    CONSTANTS(:,30) = 1628;
    CONSTANTS(:,31) = 561.4;
    CONSTANTS(:,32) = 3.663;
    CONSTANTS(:,33) = 2;
    CONSTANTS(:,34) = 140;
    STATES(:,6) = 3.27335718697622e-5;
    CONSTANTS(:,35) = 5e-7;
    STATES(:,7) = 0.0132200747771872;
    STATES(:,8) = 0.706622937059237;
    STATES(:,9) = 0.701626826712569;
    CONSTANTS(:,36) = 1e-5;
    CONSTANTS(:,37) = 0.021;
    CONSTANTS(:,38) = 62.1;
    STATES(:,10) = 4.23500474189711e-5;
    STATES(:,11) = 0.998435073735753;
    STATES(:,12) = 0.998424216938754;
    CONSTANTS(:,39) = 0;
    CONSTANTS(:,40) = -6.61;
    CONSTANTS(:,41) = -5;
    CONSTANTS(:,42) = -5;
    CONSTANTS(:,43) = 0.014;
    STATES(:,13) = 0.00894826428663828;
    STATES(:,14) = 0.994837524153424;
    STATES(:,15) = 0.427382372349565;
    CONSTANTS(:,44) = -37.4;
    CONSTANTS(:,45) = 0;
    STATES(:,16) = 0.0910882041816457;
    STATES(:,17) = 0.890389014175329;
    CONSTANTS(:,46) = 0.0198;
    CONSTANTS(:,47) = 0.00035;
    STATES(:,18) = 0.74242774587522;
    STATES(:,19) = 0.746918323597392;
    CONSTANTS(:,48) = 73.1;
    CONSTANTS(:,49) = 3.7;
    STATES(:,20) = 3.73317163732586e-5;
    CONSTANTS(:,50) = 4.39823e-6;
    STATES(:,21) = 0.818671555213184;
    STATES(:,22) = 0.682159360306652;
    CONSTANTS(:,51) = 1805.6;
    CONSTANTS(:,52) = 0.0006;
    CONSTANTS(:,53) = 0.06;
    STATES(:,23) = 0.00739583869345967;
    STATES(:,24) = 0.133773505989393;
    STATES(:,25) = 0.765246381247448;
    STATES(:,26) = 0.0154714370092264;
    STATES(:,27) = 0.0135767851016544;
    STATES(:,28) = 0.449992033196647;
    STATES(:,29) = 1.21722016147587e-5;
    CONSTANTS(:,54) = ( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3);
    CONSTANTS(:,55) = CONSTANTS(:,34)./(CONSTANTS(:,29)+CONSTANTS(:,34));
    CONSTANTS(:,56) =  CONSTANTS(:,54).*log(CONSTANTS(:,14)./CONSTANTS(:,13));
    CONSTANTS(:,57) =  CONSTANTS(:,54).*log(CONSTANTS(:,34)./CONSTANTS(:,19));
    CONSTANTS(:,58) =  CONSTANTS(:,54).*log(CONSTANTS(:,14)./CONSTANTS(:,13));
    CONSTANTS(:,59) = CONSTANTS(:,19)./(CONSTANTS(:,27)+CONSTANTS(:,19));
    CONSTANTS(:,60) =  0.0116000.*CONSTANTS(:,50);
    CONSTANTS(:,61) =  0.00120000.*CONSTANTS(:,50);
    CONSTANTS(:,62) =  0.0100000.*CONSTANTS(:,50);
    CONSTANTS(:,63) =  0.460000.*CONSTANTS(:,50) - CONSTANTS(:,62);
    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(:,16) = 120.000./(1.00000+exp( - (STATES(:,1)+50.0000)./15.0000));
    RATES(:,18) =  CONSTANTS(:,48).*(1.00000 - STATES(:,18)) -  ALGEBRAIC(:,16).*STATES(:,18);
    ALGEBRAIC(:,17) = 5.82000./(1.00000+exp( - (STATES(:,1)+50.0000)./15.0000));
    RATES(:,19) =  CONSTANTS(:,49).*(1.00000 - STATES(:,19)) -  ALGEBRAIC(:,17).*STATES(:,19);
    ALGEBRAIC(:,19) =  2277.00.*2.50000.*((1.00000 - STATES(:,24)) - STATES(:,25)) -  751.000.*STATES(:,25);
    RATES(:,25) = ALGEBRAIC(:,19);
    ALGEBRAIC(:,1) = 1.00000./(1.00000+exp(((STATES(:,1)+83.1900) - (  - 7.20000.*power(CONSTANTS(:,11), 0.690000))./(power(1.26000e-05, 0.690000)+power(CONSTANTS(:,11), 0.690000)))./13.5600));
    ALGEBRAIC(:,20) = 0.250000+ 2.00000.*exp( - power(STATES(:,1)+70.0000, 2.00000)./500.000);
    RATES(:,2) = (ALGEBRAIC(:,1) - STATES(:,2))./ALGEBRAIC(:,20);
    ALGEBRAIC(:,2) = 1.00000./(1.00000+exp((STATES(:,1)+10.2200)./ - 8.50000));
    ALGEBRAIC(:,21) = 1.00000./( 17.0000.*exp( 0.0398000.*STATES(:,1))+ 0.211000.*exp(  - 0.0510000.*STATES(:,1)));
    RATES(:,3) = (ALGEBRAIC(:,2) - STATES(:,3))./ALGEBRAIC(:,21);
    ALGEBRAIC(:,3) = 1.00000./(1.00000+exp((STATES(:,1)+10.2200)./ - 8.50000));
    ALGEBRAIC(:,22) = 0.335810+ 0.906730.*exp( - power(STATES(:,1)+10.0000, 2.00000)./988.050);
    RATES(:,4) = (ALGEBRAIC(:,3) - STATES(:,4))./ALGEBRAIC(:,22);
    ALGEBRAIC(:,9) = 1.00000./(1.00000+exp((STATES(:,1) - ( - 24.0000+CONSTANTS(:,41)))./6.31000));
    ALGEBRAIC(:,28) = 0.0100000+ 0.153900.*exp( - power(STATES(:,1)+40.0000, 2.00000)./185.670);
    RATES(:,11) = (ALGEBRAIC(:,9) - STATES(:,11))./ALGEBRAIC(:,28);
    ALGEBRAIC(:,10) = 1.00000./(1.00000+exp((STATES(:,1) - ( - 24.0000+CONSTANTS(:,42)))./6.31000));
    ALGEBRAIC(:,29) = 0.0600000+ 0.480760.*2.25000.*exp( - power(STATES(:,1) -  - 40.0000, 2.00000)./138.040);
    RATES(:,12) = (ALGEBRAIC(:,10) - STATES(:,12))./ALGEBRAIC(:,29);
    ALGEBRAIC(:,30) = 0.000596000+0.00311800./( 1.03700.*exp( 0.0900000.*(STATES(:,1)+30.6100))+ 0.396000.*exp(  - 0.120000.*(STATES(:,1)+23.8400)));
    ALGEBRAIC(:,11) = 1.00000./(1.00000+exp((STATES(:,1) - 7.44000)./ - 16.4000));
    RATES(:,13) = (ALGEBRAIC(:,11) - STATES(:,13))./ALGEBRAIC(:,30);
    ALGEBRAIC(:,31) = 0.0126600+4.72716./(1.00000+exp((STATES(:,1)+154.500)./23.9600));
    ALGEBRAIC(:,12) = 1.00000./(1.00000+exp((STATES(:,1)+33.8000)./6.12000));
    RATES(:,14) = (ALGEBRAIC(:,12) - STATES(:,14))./ALGEBRAIC(:,31);
    ALGEBRAIC(:,32) = 0.100000+ 4.00000.*exp( - power(STATES(:,1)+65.0000, 2.00000)./500.000);
    ALGEBRAIC(:,13) = 1.00000./(1.00000+exp((STATES(:,1)+33.8000)./6.12000));
    RATES(:,15) = (ALGEBRAIC(:,13) - STATES(:,15))./ALGEBRAIC(:,32);
    ALGEBRAIC(:,5) = STATES(:,1)+44.4000;
    ALGEBRAIC(:,24) = piecewise({abs(ALGEBRAIC(:,5))<CONSTANTS(:,36), (  - 460.000.* - 12.6730)./exp(ALGEBRAIC(:,5)./ - 12.6730) }, (  - 460.000.*ALGEBRAIC(:,5))./(exp(ALGEBRAIC(:,5)./ - 12.6730) - 1.00000));
    ALGEBRAIC(:,37) =  18400.0.*exp(ALGEBRAIC(:,5)./ - 12.6730);
    RATES(:,7) =  ALGEBRAIC(:,24).*(1.00000 - STATES(:,7)) -  ALGEBRAIC(:,37).*STATES(:,7);
    ALGEBRAIC(:,4) =  (1.00000./(1.00000+exp((STATES(:,1)+4.90000)./15.1400))).*(1.00000 -  0.300000.*exp( - power(STATES(:,1), 2.00000)./500.000));
    ALGEBRAIC(:,23) =  92.0100.*exp(  - 0.0183000.*STATES(:,1));
    ALGEBRAIC(:,36) =  603.600.*exp( 0.00942000.*STATES(:,1));
    ALGEBRAIC(:,44) = 1.00000./(ALGEBRAIC(:,23)+ALGEBRAIC(:,36));
    RATES(:,5) = (ALGEBRAIC(:,4) - STATES(:,5))./ALGEBRAIC(:,44);
    ALGEBRAIC(:,6) =  44.9000.*exp((STATES(:,1)+66.9000)./ - 5.57000);
    ALGEBRAIC(:,25) = 1491.00./(1.00000+ 323.300.*exp((STATES(:,1)+94.6000)./ - 12.9000));
    ALGEBRAIC(:,38) = ALGEBRAIC(:,6)./(ALGEBRAIC(:,6)+ALGEBRAIC(:,25));
    ALGEBRAIC(:,45) = 0.0300000./(1.00000+exp((STATES(:,1)+40.0000)./6.00000))+0.000350000;
    RATES(:,8) = (ALGEBRAIC(:,38) - STATES(:,8))./ALGEBRAIC(:,45);
    ALGEBRAIC(:,7) =  44.9000.*exp((STATES(:,1)+66.9000)./ - 5.57000);
    ALGEBRAIC(:,26) = 1491.00./(1.00000+ 323.300.*exp((STATES(:,1)+94.6000)./ - 12.9000));
    ALGEBRAIC(:,39) = ALGEBRAIC(:,7)./(ALGEBRAIC(:,7)+ALGEBRAIC(:,26));
    ALGEBRAIC(:,46) = 0.120000./(1.00000+exp((STATES(:,1)+60.0000)./2.00000))+0.00295000;
    RATES(:,9) = (ALGEBRAIC(:,39) - STATES(:,9))./ALGEBRAIC(:,46);
    ALGEBRAIC(:,40) = 1.00000./(1.00000+exp((STATES(:,1) - ( - 3.20000+CONSTANTS(:,39)))./CONSTANTS(:,40)));
    ALGEBRAIC(:,8) = (  - 26.1200.*(STATES(:,1)+35.0000))./(exp((STATES(:,1)+35.0000)./ - 2.50000) - 1.00000)+(  - 78.1100.*STATES(:,1))./(exp(  - 0.208000.*STATES(:,1)) - 1.00000);
    ALGEBRAIC(:,27) = ( 10.5200.*(STATES(:,1) - 5.00000))./(exp( 0.400000.*(STATES(:,1) - 5.00000)) - 1.00000);
    ALGEBRAIC(:,47) = 1.00000./(ALGEBRAIC(:,8)+ALGEBRAIC(:,27));
    RATES(:,10) = (ALGEBRAIC(:,40) - STATES(:,10))./ALGEBRAIC(:,47);
    ALGEBRAIC(:,33) = 1.00000./( 0.150000.*exp( - STATES(:,1)./11.0000)+ 0.200000.*exp( - STATES(:,1)./700.000));
    ALGEBRAIC(:,41) = 1.00000./( 16.0000.*exp(STATES(:,1)./8.00000)+ 15.0000.*exp(STATES(:,1)./50.0000));
    ALGEBRAIC(:,48) = 0.00100000./(ALGEBRAIC(:,33)+ALGEBRAIC(:,41));
    ALGEBRAIC(:,14) = 1.00000./(1.00000+exp((STATES(:,1) -  - 49.1000)./ - 8.98000));
    RATES(:,16) = (ALGEBRAIC(:,14) - STATES(:,16))./ALGEBRAIC(:,48);
    ALGEBRAIC(:,15) = 0.150400./( 3100.00.*exp(STATES(:,1)./13.0000)+ 700.000.*exp(STATES(:,1)./70.0000));
    ALGEBRAIC(:,34) = 0.150400./( 95.0000.*exp( - STATES(:,1)./10.0000)+ 50.0000.*exp( - STATES(:,1)./700.000))+0.000229000./(1.00000+exp( - STATES(:,1)./5.00000));
    ALGEBRAIC(:,49) = 0.00100000./(ALGEBRAIC(:,15)+ALGEBRAIC(:,34));
    ALGEBRAIC(:,42) = ALGEBRAIC(:,15)./(ALGEBRAIC(:,15)+ALGEBRAIC(:,34));
    RATES(:,17) = (ALGEBRAIC(:,42) - STATES(:,17))./ALGEBRAIC(:,49);
    ALGEBRAIC(:,67) = ( (( CONSTANTS(:,35).*power(STATES(:,7), 3.00000).*( 0.635000.*STATES(:,8)+ 0.365000.*STATES(:,9)).*CONSTANTS(:,34).*STATES(:,1).*CONSTANTS(:,3))./CONSTANTS(:,54)).*(exp((STATES(:,1) - CONSTANTS(:,57))./CONSTANTS(:,54)) - 1.00000))./(exp(STATES(:,1)./CONSTANTS(:,54)) - 1.00000);
    ALGEBRAIC(:,70) = ( CONSTANTS(:,46).*STATES(:,18).*STATES(:,19).*power(CONSTANTS(:,11), 1.50000))./(power(CONSTANTS(:,47), 1.50000)+power(CONSTANTS(:,11), 1.50000));
    ALGEBRAIC(:,71) = ( (( ALGEBRAIC(:,70).*CONSTANTS(:,14))./(10.0000+CONSTANTS(:,14))).*(STATES(:,1) - CONSTANTS(:,56)))./(1.00000+exp(((STATES(:,1) - CONSTANTS(:,56)) - 140.000)./( 2.50000.*CONSTANTS(:,54))));
    ALGEBRAIC(:,72) =  CONSTANTS(:,37).*STATES(:,10).*( 0.675000.*STATES(:,11)+ 0.325000.*STATES(:,12)).*(STATES(:,1) - CONSTANTS(:,38)).*(1.00000 - (( ALGEBRAIC(:,71).*CONSTANTS(:,11))./(9.00000e-05+CONSTANTS(:,11)))./1.00000);
    ALGEBRAIC(:,68) =  CONSTANTS(:,43).*STATES(:,13).*( 0.450000.*STATES(:,14)+ 0.550000.*STATES(:,15)).*(STATES(:,1) - CONSTANTS(:,58));
    ALGEBRAIC(:,43) =  CONSTANTS(:,12).*( 0.900000.*STATES(:,3)+ 0.100000.*STATES(:,4)).*STATES(:,5).*(STATES(:,1) - CONSTANTS(:,56));
    ALGEBRAIC(:,35) =  STATES(:,2).*CONSTANTS(:,10).*(STATES(:,1) -  - 30.0000);
    ALGEBRAIC(:,69) =  CONSTANTS(:,45).*STATES(:,16).*STATES(:,17).*(STATES(:,1) - CONSTANTS(:,44));
    ALGEBRAIC(:,50) =  CONSTANTS(:,15).*(0.500000+0.500000./(1.00000+exp((STATES(:,1)+30.0000)./5.00000)));
    ALGEBRAIC(:,51) = ( ALGEBRAIC(:,50).*power(CONSTANTS(:,14)./(CONSTANTS(:,14)+0.590000), 3.00000).*(STATES(:,1)+81.9000))./(1.00000+exp(( 1.39300.*(STATES(:,1)+81.9000+3.60000))./CONSTANTS(:,54)));
    ALGEBRAIC(:,59) = exp((  - CONSTANTS(:,22).*STATES(:,1))./( 2.00000.*CONSTANTS(:,54)));
    ALGEBRAIC(:,54) = 1.00000+ (CONSTANTS(:,33)./CONSTANTS(:,32)).*(1.00000+exp(( CONSTANTS(:,23).*STATES(:,1))./CONSTANTS(:,54)))+CONSTANTS(:,34)./CONSTANTS(:,30)+power(CONSTANTS(:,34), 2.00000)./( CONSTANTS(:,30).*CONSTANTS(:,31))+power(CONSTANTS(:,34), 3.00000)./( CONSTANTS(:,30).*CONSTANTS(:,31).*CONSTANTS(:,29));
    ALGEBRAIC(:,56) = ( (power(CONSTANTS(:,34), 2.00000)./( CONSTANTS(:,30).*CONSTANTS(:,31))+power(CONSTANTS(:,34), 3.00000)./( CONSTANTS(:,30).*CONSTANTS(:,31).*CONSTANTS(:,29))).*exp((  - CONSTANTS(:,22).*STATES(:,1))./( 2.00000.*CONSTANTS(:,54))))./ALGEBRAIC(:,54);
    ALGEBRAIC(:,57) = ( (CONSTANTS(:,33)./CONSTANTS(:,32)).*exp((  - CONSTANTS(:,23).*STATES(:,1))./CONSTANTS(:,54)))./ALGEBRAIC(:,54);
    ALGEBRAIC(:,55) = exp(( CONSTANTS(:,22).*STATES(:,1))./( 2.00000.*CONSTANTS(:,54)));
    ALGEBRAIC(:,62) =  ALGEBRAIC(:,59).*CONSTANTS(:,55).*(ALGEBRAIC(:,56)+ALGEBRAIC(:,57))+ ALGEBRAIC(:,57).*ALGEBRAIC(:,55).*(CONSTANTS(:,59)+ALGEBRAIC(:,59));
    ALGEBRAIC(:,58) = 1.00000+ (STATES(:,6)./CONSTANTS(:,24)).*(1.00000+exp((  - CONSTANTS(:,21).*STATES(:,1))./CONSTANTS(:,54))+CONSTANTS(:,19)./CONSTANTS(:,28))+CONSTANTS(:,19)./CONSTANTS(:,25)+power(CONSTANTS(:,19), 2.00000)./( CONSTANTS(:,25).*CONSTANTS(:,26))+power(CONSTANTS(:,19), 3.00000)./( CONSTANTS(:,25).*CONSTANTS(:,26).*CONSTANTS(:,27));
    ALGEBRAIC(:,61) = ( (STATES(:,6)./CONSTANTS(:,24)).*exp((  - CONSTANTS(:,21).*STATES(:,1))./CONSTANTS(:,54)))./ALGEBRAIC(:,58);
    ALGEBRAIC(:,60) = ( (power(CONSTANTS(:,19), 2.00000)./( CONSTANTS(:,25).*CONSTANTS(:,26))+power(CONSTANTS(:,19), 3.00000)./( CONSTANTS(:,25).*CONSTANTS(:,26).*CONSTANTS(:,27))).*exp(( CONSTANTS(:,22).*STATES(:,1))./( 2.00000.*CONSTANTS(:,54))))./ALGEBRAIC(:,58);
    ALGEBRAIC(:,63) =  ALGEBRAIC(:,55).*CONSTANTS(:,59).*(ALGEBRAIC(:,60)+ALGEBRAIC(:,61))+ ALGEBRAIC(:,59).*ALGEBRAIC(:,61).*(CONSTANTS(:,55)+ALGEBRAIC(:,55));
    ALGEBRAIC(:,64) =  ALGEBRAIC(:,60).*CONSTANTS(:,59).*(ALGEBRAIC(:,56)+ALGEBRAIC(:,57))+ ALGEBRAIC(:,61).*ALGEBRAIC(:,56).*(CONSTANTS(:,59)+ALGEBRAIC(:,59));
    ALGEBRAIC(:,65) =  ALGEBRAIC(:,56).*CONSTANTS(:,55).*(ALGEBRAIC(:,60)+ALGEBRAIC(:,61))+ ALGEBRAIC(:,60).*ALGEBRAIC(:,57).*(CONSTANTS(:,55)+ALGEBRAIC(:,55));
    ALGEBRAIC(:,66) = ( CONSTANTS(:,20).*( ALGEBRAIC(:,63).*ALGEBRAIC(:,57) -  ALGEBRAIC(:,62).*ALGEBRAIC(:,61)))./(ALGEBRAIC(:,62)+ALGEBRAIC(:,63)+ALGEBRAIC(:,64)+ALGEBRAIC(:,65));
    ALGEBRAIC(:,53) = ( CONSTANTS(:,18).*power(CONSTANTS(:,19)./(5.64000+CONSTANTS(:,19)), 3.00000).*power(CONSTANTS(:,14)./(0.621000+CONSTANTS(:,14)), 2.00000).*1.60000)./(1.50000+exp( - (STATES(:,1)+60.0000)./40.0000));
    ALGEBRAIC(:,52) =  CONSTANTS(:,16).*(STATES(:,1) - CONSTANTS(:,17));
    ALGEBRAIC(:,18) = piecewise({VOI>=CONSTANTS(:,5)&VOI<=CONSTANTS(:,6)&(VOI - CONSTANTS(:,5)) -  floor((VOI - CONSTANTS(:,5))./CONSTANTS(:,7)).*CONSTANTS(:,7)<=CONSTANTS(:,8), CONSTANTS(:,9) }, 0.00000);
    RATES(:,1) =  - (ALGEBRAIC(:,67)+ALGEBRAIC(:,72)+ALGEBRAIC(:,68)+ALGEBRAIC(:,43)+ALGEBRAIC(:,35)+ALGEBRAIC(:,69)+ALGEBRAIC(:,51)+ALGEBRAIC(:,66)+ALGEBRAIC(:,53)+ALGEBRAIC(:,52)+ALGEBRAIC(:,71)+ALGEBRAIC(:,18))./CONSTANTS(:,4);
    ALGEBRAIC(:,74) = 5.00000./(1.00000+CONSTANTS(:,52)./STATES(:,20));
    ALGEBRAIC(:,75) = (STATES(:,21) - STATES(:,22))./CONSTANTS(:,53);
    RATES(:,21) = ALGEBRAIC(:,74) - ( ALGEBRAIC(:,75).*CONSTANTS(:,61))./CONSTANTS(:,60);
    ALGEBRAIC(:,76) =  88800.0.*STATES(:,20).*(1.00000 - STATES(:,23)) -  446.000.*STATES(:,23);
    RATES(:,23) = ALGEBRAIC(:,76);
    ALGEBRAIC(:,78) =  227700..*STATES(:,20).*((1.00000 - STATES(:,24)) - STATES(:,25)) -  7.51000.*STATES(:,24);
    RATES(:,24) = ALGEBRAIC(:,78);
    ALGEBRAIC(:,77) = ( CONSTANTS(:,51).*(STATES(:,22) - STATES(:,6)))./(1.00000+power(0.00120000./STATES(:,6), 2.00000));
    ALGEBRAIC(:,81) =  534.000.*STATES(:,22).*(1.00000 - STATES(:,28)) -  445.000.*STATES(:,28);
    RATES(:,22) = (ALGEBRAIC(:,75) - ALGEBRAIC(:,77)) -  10.0000.*ALGEBRAIC(:,81);
    ALGEBRAIC(:,73) = (STATES(:,6) - STATES(:,20))./4.00000e-05;
    ALGEBRAIC(:,79) =  227700..*STATES(:,20).*(1.00000 - STATES(:,26)) -  542.000.*STATES(:,26);
    RATES(:,20) = ( ALGEBRAIC(:,73).*CONSTANTS(:,62) -  ALGEBRAIC(:,74).*CONSTANTS(:,60))./CONSTANTS(:,63) - ( 0.0450000.*ALGEBRAIC(:,79)+ 0.0310000.*ALGEBRAIC(:,76)+ 0.0620000.*ALGEBRAIC(:,78));
    RATES(:,26) = ALGEBRAIC(:,79);
    ALGEBRAIC(:,80) =  227700..*STATES(:,6).*(1.00000 - STATES(:,27)) -  542.000.*STATES(:,27);
    RATES(:,27) = ALGEBRAIC(:,80);
    RATES(:,28) = ALGEBRAIC(:,81);
    ALGEBRAIC(:,82) =  0.00100000.*( 115.000.*STATES(:,6).*(1.00000 - STATES(:,29)) -  1000.00.*STATES(:,29));
    RATES(:,6) = ((( - (ALGEBRAIC(:,72) -  2.00000.*ALGEBRAIC(:,66))./( 2.00000.*CONSTANTS(:,3))+ ALGEBRAIC(:,77).*CONSTANTS(:,61))./CONSTANTS(:,62) - ALGEBRAIC(:,73)) -  0.0450000.*ALGEBRAIC(:,80)) -  (0.0310000./1.20000).*ALGEBRAIC(:,82);
    RATES(:,29) = ALGEBRAIC(:,82);
   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(:,16) = 120.000./(1.00000+exp( - (STATES(:,1)+50.0000)./15.0000));
    ALGEBRAIC(:,17) = 5.82000./(1.00000+exp( - (STATES(:,1)+50.0000)./15.0000));
    ALGEBRAIC(:,19) =  2277.00.*2.50000.*((1.00000 - STATES(:,24)) - STATES(:,25)) -  751.000.*STATES(:,25);
    ALGEBRAIC(:,1) = 1.00000./(1.00000+exp(((STATES(:,1)+83.1900) - (  - 7.20000.*power(CONSTANTS(:,11), 0.690000))./(power(1.26000e-05, 0.690000)+power(CONSTANTS(:,11), 0.690000)))./13.5600));
    ALGEBRAIC(:,20) = 0.250000+ 2.00000.*exp( - power(STATES(:,1)+70.0000, 2.00000)./500.000);
    ALGEBRAIC(:,2) = 1.00000./(1.00000+exp((STATES(:,1)+10.2200)./ - 8.50000));
    ALGEBRAIC(:,21) = 1.00000./( 17.0000.*exp( 0.0398000.*STATES(:,1))+ 0.211000.*exp(  - 0.0510000.*STATES(:,1)));
    ALGEBRAIC(:,3) = 1.00000./(1.00000+exp((STATES(:,1)+10.2200)./ - 8.50000));
    ALGEBRAIC(:,22) = 0.335810+ 0.906730.*exp( - power(STATES(:,1)+10.0000, 2.00000)./988.050);
    ALGEBRAIC(:,9) = 1.00000./(1.00000+exp((STATES(:,1) - ( - 24.0000+CONSTANTS(:,41)))./6.31000));
    ALGEBRAIC(:,28) = 0.0100000+ 0.153900.*exp( - power(STATES(:,1)+40.0000, 2.00000)./185.670);
    ALGEBRAIC(:,10) = 1.00000./(1.00000+exp((STATES(:,1) - ( - 24.0000+CONSTANTS(:,42)))./6.31000));
    ALGEBRAIC(:,29) = 0.0600000+ 0.480760.*2.25000.*exp( - power(STATES(:,1) -  - 40.0000, 2.00000)./138.040);
    ALGEBRAIC(:,30) = 0.000596000+0.00311800./( 1.03700.*exp( 0.0900000.*(STATES(:,1)+30.6100))+ 0.396000.*exp(  - 0.120000.*(STATES(:,1)+23.8400)));
    ALGEBRAIC(:,11) = 1.00000./(1.00000+exp((STATES(:,1) - 7.44000)./ - 16.4000));
    ALGEBRAIC(:,31) = 0.0126600+4.72716./(1.00000+exp((STATES(:,1)+154.500)./23.9600));
    ALGEBRAIC(:,12) = 1.00000./(1.00000+exp((STATES(:,1)+33.8000)./6.12000));
    ALGEBRAIC(:,32) = 0.100000+ 4.00000.*exp( - power(STATES(:,1)+65.0000, 2.00000)./500.000);
    ALGEBRAIC(:,13) = 1.00000./(1.00000+exp((STATES(:,1)+33.8000)./6.12000));
    ALGEBRAIC(:,5) = STATES(:,1)+44.4000;
    ALGEBRAIC(:,24) = piecewise({abs(ALGEBRAIC(:,5))<CONSTANTS(:,36), (  - 460.000.* - 12.6730)./exp(ALGEBRAIC(:,5)./ - 12.6730) }, (  - 460.000.*ALGEBRAIC(:,5))./(exp(ALGEBRAIC(:,5)./ - 12.6730) - 1.00000));
    ALGEBRAIC(:,37) =  18400.0.*exp(ALGEBRAIC(:,5)./ - 12.6730);
    ALGEBRAIC(:,4) =  (1.00000./(1.00000+exp((STATES(:,1)+4.90000)./15.1400))).*(1.00000 -  0.300000.*exp( - power(STATES(:,1), 2.00000)./500.000));
    ALGEBRAIC(:,23) =  92.0100.*exp(  - 0.0183000.*STATES(:,1));
    ALGEBRAIC(:,36) =  603.600.*exp( 0.00942000.*STATES(:,1));
    ALGEBRAIC(:,44) = 1.00000./(ALGEBRAIC(:,23)+ALGEBRAIC(:,36));
    ALGEBRAIC(:,6) =  44.9000.*exp((STATES(:,1)+66.9000)./ - 5.57000);
    ALGEBRAIC(:,25) = 1491.00./(1.00000+ 323.300.*exp((STATES(:,1)+94.6000)./ - 12.9000));
    ALGEBRAIC(:,38) = ALGEBRAIC(:,6)./(ALGEBRAIC(:,6)+ALGEBRAIC(:,25));
    ALGEBRAIC(:,45) = 0.0300000./(1.00000+exp((STATES(:,1)+40.0000)./6.00000))+0.000350000;
    ALGEBRAIC(:,7) =  44.9000.*exp((STATES(:,1)+66.9000)./ - 5.57000);
    ALGEBRAIC(:,26) = 1491.00./(1.00000+ 323.300.*exp((STATES(:,1)+94.6000)./ - 12.9000));
    ALGEBRAIC(:,39) = ALGEBRAIC(:,7)./(ALGEBRAIC(:,7)+ALGEBRAIC(:,26));
    ALGEBRAIC(:,46) = 0.120000./(1.00000+exp((STATES(:,1)+60.0000)./2.00000))+0.00295000;
    ALGEBRAIC(:,40) = 1.00000./(1.00000+exp((STATES(:,1) - ( - 3.20000+CONSTANTS(:,39)))./CONSTANTS(:,40)));
    ALGEBRAIC(:,8) = (  - 26.1200.*(STATES(:,1)+35.0000))./(exp((STATES(:,1)+35.0000)./ - 2.50000) - 1.00000)+(  - 78.1100.*STATES(:,1))./(exp(  - 0.208000.*STATES(:,1)) - 1.00000);
    ALGEBRAIC(:,27) = ( 10.5200.*(STATES(:,1) - 5.00000))./(exp( 0.400000.*(STATES(:,1) - 5.00000)) - 1.00000);
    ALGEBRAIC(:,47) = 1.00000./(ALGEBRAIC(:,8)+ALGEBRAIC(:,27));
    ALGEBRAIC(:,33) = 1.00000./( 0.150000.*exp( - STATES(:,1)./11.0000)+ 0.200000.*exp( - STATES(:,1)./700.000));
    ALGEBRAIC(:,41) = 1.00000./( 16.0000.*exp(STATES(:,1)./8.00000)+ 15.0000.*exp(STATES(:,1)./50.0000));
    ALGEBRAIC(:,48) = 0.00100000./(ALGEBRAIC(:,33)+ALGEBRAIC(:,41));
    ALGEBRAIC(:,14) = 1.00000./(1.00000+exp((STATES(:,1) -  - 49.1000)./ - 8.98000));
    ALGEBRAIC(:,15) = 0.150400./( 3100.00.*exp(STATES(:,1)./13.0000)+ 700.000.*exp(STATES(:,1)./70.0000));
    ALGEBRAIC(:,34) = 0.150400./( 95.0000.*exp( - STATES(:,1)./10.0000)+ 50.0000.*exp( - STATES(:,1)./700.000))+0.000229000./(1.00000+exp( - STATES(:,1)./5.00000));
    ALGEBRAIC(:,49) = 0.00100000./(ALGEBRAIC(:,15)+ALGEBRAIC(:,34));
    ALGEBRAIC(:,42) = ALGEBRAIC(:,15)./(ALGEBRAIC(:,15)+ALGEBRAIC(:,34));
    ALGEBRAIC(:,67) = ( (( CONSTANTS(:,35).*power(STATES(:,7), 3.00000).*( 0.635000.*STATES(:,8)+ 0.365000.*STATES(:,9)).*CONSTANTS(:,34).*STATES(:,1).*CONSTANTS(:,3))./CONSTANTS(:,54)).*(exp((STATES(:,1) - CONSTANTS(:,57))./CONSTANTS(:,54)) - 1.00000))./(exp(STATES(:,1)./CONSTANTS(:,54)) - 1.00000);
    ALGEBRAIC(:,70) = ( CONSTANTS(:,46).*STATES(:,18).*STATES(:,19).*power(CONSTANTS(:,11), 1.50000))./(power(CONSTANTS(:,47), 1.50000)+power(CONSTANTS(:,11), 1.50000));
    ALGEBRAIC(:,71) = ( (( ALGEBRAIC(:,70).*CONSTANTS(:,14))./(10.0000+CONSTANTS(:,14))).*(STATES(:,1) - CONSTANTS(:,56)))./(1.00000+exp(((STATES(:,1) - CONSTANTS(:,56)) - 140.000)./( 2.50000.*CONSTANTS(:,54))));
    ALGEBRAIC(:,72) =  CONSTANTS(:,37).*STATES(:,10).*( 0.675000.*STATES(:,11)+ 0.325000.*STATES(:,12)).*(STATES(:,1) - CONSTANTS(:,38)).*(1.00000 - (( ALGEBRAIC(:,71).*CONSTANTS(:,11))./(9.00000e-05+CONSTANTS(:,11)))./1.00000);
    ALGEBRAIC(:,68) =  CONSTANTS(:,43).*STATES(:,13).*( 0.450000.*STATES(:,14)+ 0.550000.*STATES(:,15)).*(STATES(:,1) - CONSTANTS(:,58));
    ALGEBRAIC(:,43) =  CONSTANTS(:,12).*( 0.900000.*STATES(:,3)+ 0.100000.*STATES(:,4)).*STATES(:,5).*(STATES(:,1) - CONSTANTS(:,56));
    ALGEBRAIC(:,35) =  STATES(:,2).*CONSTANTS(:,10).*(STATES(:,1) -  - 30.0000);
    ALGEBRAIC(:,69) =  CONSTANTS(:,45).*STATES(:,16).*STATES(:,17).*(STATES(:,1) - CONSTANTS(:,44));
    ALGEBRAIC(:,50) =  CONSTANTS(:,15).*(0.500000+0.500000./(1.00000+exp((STATES(:,1)+30.0000)./5.00000)));
    ALGEBRAIC(:,51) = ( ALGEBRAIC(:,50).*power(CONSTANTS(:,14)./(CONSTANTS(:,14)+0.590000), 3.00000).*(STATES(:,1)+81.9000))./(1.00000+exp(( 1.39300.*(STATES(:,1)+81.9000+3.60000))./CONSTANTS(:,54)));
    ALGEBRAIC(:,59) = exp((  - CONSTANTS(:,22).*STATES(:,1))./( 2.00000.*CONSTANTS(:,54)));
    ALGEBRAIC(:,54) = 1.00000+ (CONSTANTS(:,33)./CONSTANTS(:,32)).*(1.00000+exp(( CONSTANTS(:,23).*STATES(:,1))./CONSTANTS(:,54)))+CONSTANTS(:,34)./CONSTANTS(:,30)+power(CONSTANTS(:,34), 2.00000)./( CONSTANTS(:,30).*CONSTANTS(:,31))+power(CONSTANTS(:,34), 3.00000)./( CONSTANTS(:,30).*CONSTANTS(:,31).*CONSTANTS(:,29));
    ALGEBRAIC(:,56) = ( (power(CONSTANTS(:,34), 2.00000)./( CONSTANTS(:,30).*CONSTANTS(:,31))+power(CONSTANTS(:,34), 3.00000)./( CONSTANTS(:,30).*CONSTANTS(:,31).*CONSTANTS(:,29))).*exp((  - CONSTANTS(:,22).*STATES(:,1))./( 2.00000.*CONSTANTS(:,54))))./ALGEBRAIC(:,54);
    ALGEBRAIC(:,57) = ( (CONSTANTS(:,33)./CONSTANTS(:,32)).*exp((  - CONSTANTS(:,23).*STATES(:,1))./CONSTANTS(:,54)))./ALGEBRAIC(:,54);
    ALGEBRAIC(:,55) = exp(( CONSTANTS(:,22).*STATES(:,1))./( 2.00000.*CONSTANTS(:,54)));
    ALGEBRAIC(:,62) =  ALGEBRAIC(:,59).*CONSTANTS(:,55).*(ALGEBRAIC(:,56)+ALGEBRAIC(:,57))+ ALGEBRAIC(:,57).*ALGEBRAIC(:,55).*(CONSTANTS(:,59)+ALGEBRAIC(:,59));
    ALGEBRAIC(:,58) = 1.00000+ (STATES(:,6)./CONSTANTS(:,24)).*(1.00000+exp((  - CONSTANTS(:,21).*STATES(:,1))./CONSTANTS(:,54))+CONSTANTS(:,19)./CONSTANTS(:,28))+CONSTANTS(:,19)./CONSTANTS(:,25)+power(CONSTANTS(:,19), 2.00000)./( CONSTANTS(:,25).*CONSTANTS(:,26))+power(CONSTANTS(:,19), 3.00000)./( CONSTANTS(:,25).*CONSTANTS(:,26).*CONSTANTS(:,27));
    ALGEBRAIC(:,61) = ( (STATES(:,6)./CONSTANTS(:,24)).*exp((  - CONSTANTS(:,21).*STATES(:,1))./CONSTANTS(:,54)))./ALGEBRAIC(:,58);
    ALGEBRAIC(:,60) = ( (power(CONSTANTS(:,19), 2.00000)./( CONSTANTS(:,25).*CONSTANTS(:,26))+power(CONSTANTS(:,19), 3.00000)./( CONSTANTS(:,25).*CONSTANTS(:,26).*CONSTANTS(:,27))).*exp(( CONSTANTS(:,22).*STATES(:,1))./( 2.00000.*CONSTANTS(:,54))))./ALGEBRAIC(:,58);
    ALGEBRAIC(:,63) =  ALGEBRAIC(:,55).*CONSTANTS(:,59).*(ALGEBRAIC(:,60)+ALGEBRAIC(:,61))+ ALGEBRAIC(:,59).*ALGEBRAIC(:,61).*(CONSTANTS(:,55)+ALGEBRAIC(:,55));
    ALGEBRAIC(:,64) =  ALGEBRAIC(:,60).*CONSTANTS(:,59).*(ALGEBRAIC(:,56)+ALGEBRAIC(:,57))+ ALGEBRAIC(:,61).*ALGEBRAIC(:,56).*(CONSTANTS(:,59)+ALGEBRAIC(:,59));
    ALGEBRAIC(:,65) =  ALGEBRAIC(:,56).*CONSTANTS(:,55).*(ALGEBRAIC(:,60)+ALGEBRAIC(:,61))+ ALGEBRAIC(:,60).*ALGEBRAIC(:,57).*(CONSTANTS(:,55)+ALGEBRAIC(:,55));
    ALGEBRAIC(:,66) = ( CONSTANTS(:,20).*( ALGEBRAIC(:,63).*ALGEBRAIC(:,57) -  ALGEBRAIC(:,62).*ALGEBRAIC(:,61)))./(ALGEBRAIC(:,62)+ALGEBRAIC(:,63)+ALGEBRAIC(:,64)+ALGEBRAIC(:,65));
    ALGEBRAIC(:,53) = ( CONSTANTS(:,18).*power(CONSTANTS(:,19)./(5.64000+CONSTANTS(:,19)), 3.00000).*power(CONSTANTS(:,14)./(0.621000+CONSTANTS(:,14)), 2.00000).*1.60000)./(1.50000+exp( - (STATES(:,1)+60.0000)./40.0000));
    ALGEBRAIC(:,52) =  CONSTANTS(:,16).*(STATES(:,1) - CONSTANTS(:,17));
    ALGEBRAIC(:,18) = piecewise({VOI>=CONSTANTS(:,5)&VOI<=CONSTANTS(:,6)&(VOI - CONSTANTS(:,5)) -  floor((VOI - CONSTANTS(:,5))./CONSTANTS(:,7)).*CONSTANTS(:,7)<=CONSTANTS(:,8), CONSTANTS(:,9) }, 0.00000);
    ALGEBRAIC(:,74) = 5.00000./(1.00000+CONSTANTS(:,52)./STATES(:,20));
    ALGEBRAIC(:,75) = (STATES(:,21) - STATES(:,22))./CONSTANTS(:,53);
    ALGEBRAIC(:,76) =  88800.0.*STATES(:,20).*(1.00000 - STATES(:,23)) -  446.000.*STATES(:,23);
    ALGEBRAIC(:,78) =  227700..*STATES(:,20).*((1.00000 - STATES(:,24)) - STATES(:,25)) -  7.51000.*STATES(:,24);
    ALGEBRAIC(:,77) = ( CONSTANTS(:,51).*(STATES(:,22) - STATES(:,6)))./(1.00000+power(0.00120000./STATES(:,6), 2.00000));
    ALGEBRAIC(:,81) =  534.000.*STATES(:,22).*(1.00000 - STATES(:,28)) -  445.000.*STATES(:,28);
    ALGEBRAIC(:,73) = (STATES(:,6) - STATES(:,20))./4.00000e-05;
    ALGEBRAIC(:,79) =  227700..*STATES(:,20).*(1.00000 - STATES(:,26)) -  542.000.*STATES(:,26);
    ALGEBRAIC(:,80) =  227700..*STATES(:,6).*(1.00000 - STATES(:,27)) -  542.000.*STATES(:,27);
    ALGEBRAIC(:,82) =  0.00100000.*( 115.000.*STATES(:,6).*(1.00000 - STATES(:,29)) -  1000.00.*STATES(:,29));
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