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 =85;
end
% There are a total of 18 entries in each of the rate and state variable arrays.
% There are a total of 71 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 (ms)');
    LEGEND_STATES(:,1) = strpad('V in component membrane (mV)');
    LEGEND_CONSTANTS(:,1) = strpad('R in component membrane (millijoule_per_mole_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('Cm in component membrane (uF)');
    LEGEND_ALGEBRAIC(:,23) = strpad('i_Na in component sodium_current (uA)');
    LEGEND_ALGEBRAIC(:,25) = strpad('i_t in component Ca_independent_transient_outward_K_current (uA)');
    LEGEND_ALGEBRAIC(:,26) = strpad('i_ss in component steady_state_outward_K_current (uA)');
    LEGEND_ALGEBRAIC(:,27) = strpad('i_K1 in component inward_rectifier (uA)');
    LEGEND_ALGEBRAIC(:,30) = strpad('i_f in component hyperpolarisation_activated_current (uA)');
    LEGEND_ALGEBRAIC(:,31) = strpad('i_B_Na in component background_currents (uA)');
    LEGEND_ALGEBRAIC(:,32) = strpad('i_B_K in component background_currents (uA)');
    LEGEND_ALGEBRAIC(:,35) = strpad('i_NaK in component sodium_potassium_pump (uA)');
    LEGEND_ALGEBRAIC(:,76) = strpad('i_Ncx2 in component Na_Ca_Exchanger (uA)');
    LEGEND_ALGEBRAIC(:,79) = strpad('i_pCa2 in component SarcolemMal_Ca_pump (uA)');
    LEGEND_ALGEBRAIC(:,73) = strpad('i_LCC2 in component LCC_current (uA)');
    LEGEND_ALGEBRAIC(:,82) = strpad('i_CaB2 in component Background_Ca_current (uA)');
    LEGEND_ALGEBRAIC(:,21) = strpad('i_Stim in component membrane (uA)');
    LEGEND_CONSTANTS(:,5) = strpad('stim_period in component membrane (ms)');
    LEGEND_CONSTANTS(:,6) = strpad('stim_duration in component membrane (ms)');
    LEGEND_CONSTANTS(:,7) = strpad('stim_amplitude in component membrane (uA)');
    LEGEND_ALGEBRAIC(:,1) = strpad('FVRT in component membrane (dimensionless)');
    LEGEND_ALGEBRAIC(:,20) = strpad('FVRT_Ca in component membrane (dimensionless)');
    LEGEND_CONSTANTS(:,8) = strpad('Vmyo in component cell_geometry (um3)');
    LEGEND_CONSTANTS(:,9) = strpad('Vmyo_uL in component cell_geometry (uL)');
    LEGEND_CONSTANTS(:,10) = strpad('VSR_uL in component cell_geometry (uL)');
    LEGEND_ALGEBRAIC(:,22) = strpad('E_Na in component sodium_current (mV)');
    LEGEND_CONSTANTS(:,11) = strpad('g_Na in component sodium_current (mSi)');
    LEGEND_STATES(:,2) = strpad('Na_i in component intracellular_ion_concentrations (mM)');
    LEGEND_CONSTANTS(:,12) = strpad('Na_o in component extracellular_ion_concentrations (mM)');
    LEGEND_STATES(:,3) = strpad('m in component sodium_current_m_gate (dimensionless)');
    LEGEND_STATES(:,4) = strpad('h in component sodium_current_h_gate (dimensionless)');
    LEGEND_STATES(:,5) = strpad('j in component sodium_current_j_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,2) = strpad('m_infinity in component sodium_current_m_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,12) = strpad('tau_m in component sodium_current_m_gate (ms)');
    LEGEND_ALGEBRAIC(:,3) = strpad('h_infinity in component sodium_current_h_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,13) = strpad('tau_h in component sodium_current_h_gate (ms)');
    LEGEND_ALGEBRAIC(:,4) = strpad('j_infinity in component sodium_current_j_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,14) = strpad('tau_j in component sodium_current_j_gate (ms)');
    LEGEND_ALGEBRAIC(:,24) = strpad('E_K in component Ca_independent_transient_outward_K_current (mV)');
    LEGEND_CONSTANTS(:,13) = strpad('g_t in component Ca_independent_transient_outward_K_current (mSi)');
    LEGEND_CONSTANTS(:,14) = strpad('a in component Ca_independent_transient_outward_K_current (dimensionless)');
    LEGEND_CONSTANTS(:,15) = strpad('b in component Ca_independent_transient_outward_K_current (dimensionless)');
    LEGEND_CONSTANTS(:,16) = strpad('K_o in component extracellular_ion_concentrations (mM)');
    LEGEND_STATES(:,6) = strpad('K_i in component intracellular_ion_concentrations (mM)');
    LEGEND_STATES(:,7) = strpad('r in component Ca_independent_transient_outward_K_current_r_gate (dimensionless)');
    LEGEND_STATES(:,8) = strpad('s in component Ca_independent_transient_outward_K_current_s_gate (dimensionless)');
    LEGEND_STATES(:,9) = strpad('s_slow in component Ca_independent_transient_outward_K_current_s_slow_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,15) = strpad('tau_r in component Ca_independent_transient_outward_K_current_r_gate (ms)');
    LEGEND_ALGEBRAIC(:,5) = strpad('r_infinity in component Ca_independent_transient_outward_K_current_r_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,16) = strpad('tau_s in component Ca_independent_transient_outward_K_current_s_gate (ms)');
    LEGEND_ALGEBRAIC(:,6) = strpad('s_infinity in component Ca_independent_transient_outward_K_current_s_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,17) = strpad('tau_s_slow in component Ca_independent_transient_outward_K_current_s_slow_gate (ms)');
    LEGEND_ALGEBRAIC(:,7) = strpad('s_slow_infinity in component Ca_independent_transient_outward_K_current_s_slow_gate (dimensionless)');
    LEGEND_CONSTANTS(:,17) = strpad('g_ss in component steady_state_outward_K_current (mSi)');
    LEGEND_STATES(:,10) = strpad('r_ss in component steady_state_outward_K_current_r_ss_gate (dimensionless)');
    LEGEND_STATES(:,11) = strpad('s_ss in component steady_state_outward_K_current_s_ss_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,18) = strpad('tau_r_ss in component steady_state_outward_K_current_r_ss_gate (ms)');
    LEGEND_ALGEBRAIC(:,8) = strpad('r_ss_infinity in component steady_state_outward_K_current_r_ss_gate (dimensionless)');
    LEGEND_CONSTANTS(:,68) = strpad('tau_s_ss in component steady_state_outward_K_current_s_ss_gate (ms)');
    LEGEND_ALGEBRAIC(:,9) = strpad('s_ss_infinity in component steady_state_outward_K_current_s_ss_gate (dimensionless)');
    LEGEND_CONSTANTS(:,18) = strpad('g_K1 in component inward_rectifier (mSi)');
    LEGEND_ALGEBRAIC(:,28) = strpad('i_f_Na in component hyperpolarisation_activated_current (uA)');
    LEGEND_ALGEBRAIC(:,29) = strpad('i_f_K in component hyperpolarisation_activated_current (uA)');
    LEGEND_CONSTANTS(:,19) = strpad('g_f in component hyperpolarisation_activated_current (mSi)');
    LEGEND_CONSTANTS(:,20) = strpad('f_Na in component hyperpolarisation_activated_current (dimensionless)');
    LEGEND_CONSTANTS(:,69) = strpad('f_K in component hyperpolarisation_activated_current (dimensionless)');
    LEGEND_STATES(:,12) = strpad('y in component hyperpolarisation_activated_current_y_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,19) = strpad('tau_y in component hyperpolarisation_activated_current_y_gate (ms)');
    LEGEND_ALGEBRAIC(:,10) = strpad('y_infinity in component hyperpolarisation_activated_current_y_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,33) = strpad('i_B in component background_currents (uA)');
    LEGEND_CONSTANTS(:,21) = strpad('g_B_Na in component background_currents (mSi)');
    LEGEND_CONSTANTS(:,22) = strpad('g_B_K in component background_currents (mSi)');
    LEGEND_CONSTANTS(:,23) = strpad('i_NaK_max in component sodium_potassium_pump (uA)');
    LEGEND_ALGEBRAIC(:,34) = strpad('nu_1 in component sodium_potassium_pump (dimensionless)');
    LEGEND_CONSTANTS(:,24) = strpad('gamma1 in component sodium_potassium_pump (dimensionless)');
    LEGEND_CONSTANTS(:,25) = strpad('KdNaio in component sodium_potassium_pump (mM)');
    LEGEND_CONSTANTS(:,26) = strpad('KdNais in component sodium_potassium_pump (mM)');
    LEGEND_CONSTANTS(:,27) = strpad('KdNaes in component sodium_potassium_pump (mM)');
    LEGEND_CONSTANTS(:,28) = strpad('Delta in component sodium_potassium_pump (dimensionless)');
    LEGEND_CONSTANTS(:,29) = strpad('alpha in component sodium_potassium_pump (mM)');
    LEGEND_CONSTANTS(:,30) = strpad('Ca_o in component extracellular_ion_concentrations (mM)');
    LEGEND_CONSTANTS(:,31) = strpad('g_D in component CaRU (um3_per_ms)');
    LEGEND_CONSTANTS(:,32) = strpad('J_R in component CaRU (um3_per_ms)');
    LEGEND_CONSTANTS(:,33) = strpad('J_L in component CaRU (um3_per_ms)');
    LEGEND_CONSTANTS(:,34) = strpad('N in component CaRU (dimensionless)');
    LEGEND_STATES(:,13) = strpad('Ca_i in component intracellular_ion_concentrations (mM)');
    LEGEND_STATES(:,14) = strpad('Ca_SR in component intracellular_ion_concentrations (mM)');
    LEGEND_ALGEBRAIC(:,65) = strpad('i_RyR2 in component RyR_current (mM_per_ms)');
    LEGEND_ALGEBRAIC(:,45) = strpad('C_oc in component DS_Calcium_Concentrations (mM)');
    LEGEND_ALGEBRAIC(:,43) = strpad('C_co in component DS_Calcium_Concentrations (mM)');
    LEGEND_CONSTANTS(:,35) = strpad('V_L in component CaRU_Transitions (mV)');
    LEGEND_CONSTANTS(:,36) = strpad('del_VL in component CaRU_Transitions (mV)');
    LEGEND_CONSTANTS(:,37) = strpad('phi_L in component CaRU_Transitions (dimensionless)');
    LEGEND_CONSTANTS(:,38) = strpad('t_L in component CaRU_Transitions (ms)');
    LEGEND_CONSTANTS(:,39) = strpad('tau_L in component CaRU_Transitions (ms)');
    LEGEND_CONSTANTS(:,40) = strpad('t_R in component CaRU_Transitions (ms)');
    LEGEND_CONSTANTS(:,41) = strpad('tau_R in component CaRU_Transitions (ms)');
    LEGEND_CONSTANTS(:,42) = strpad('phi_R in component CaRU_Transitions (dimensionless)');
    LEGEND_CONSTANTS(:,43) = strpad('theta_R in component CaRU_Transitions (dimensionless)');
    LEGEND_CONSTANTS(:,44) = strpad('K_RyR in component CaRU_Transitions (mM)');
    LEGEND_CONSTANTS(:,45) = strpad('K_L in component CaRU_Transitions (mM)');
    LEGEND_CONSTANTS(:,46) = strpad('a1 in component CaRU_Transitions (dimensionless)');
    LEGEND_CONSTANTS(:,47) = strpad('b1 in component CaRU_Transitions (dimensionless)');
    LEGEND_CONSTANTS(:,48) = strpad('c in component CaRU_Transitions (dimensionless)');
    LEGEND_CONSTANTS(:,49) = strpad('d in component CaRU_Transitions (dimensionless)');
    LEGEND_ALGEBRAIC(:,36) = strpad('expVL in component CaRU_Transitions (dimensionless)');
    LEGEND_ALGEBRAIC(:,37) = strpad('alpha_p in component CaRU_Transitions (per_ms)');
    LEGEND_CONSTANTS(:,70) = strpad('alpha_m in component CaRU_Transitions (per_ms)');
    LEGEND_ALGEBRAIC(:,46) = strpad('beta_poc in component CaRU_Transitions (per_ms)');
    LEGEND_ALGEBRAIC(:,38) = strpad('beta_pcc in component CaRU_Transitions (per_ms)');
    LEGEND_CONSTANTS(:,71) = strpad('beta_m in component CaRU_Transitions (per_ms)');
    LEGEND_ALGEBRAIC(:,44) = strpad('epsilon_pco in component CaRU_Transitions (per_ms)');
    LEGEND_ALGEBRAIC(:,39) = strpad('epsilon_pcc in component CaRU_Transitions (per_ms)');
    LEGEND_ALGEBRAIC(:,40) = strpad('epsilon_m in component CaRU_Transitions (per_ms)');
    LEGEND_ALGEBRAIC(:,47) = strpad('mu_poc in component CaRU_Transitions (per_ms)');
    LEGEND_ALGEBRAIC(:,41) = strpad('mu_pcc in component CaRU_Transitions (per_ms)');
    LEGEND_ALGEBRAIC(:,48) = strpad('mu_moc in component CaRU_Transitions (per_ms)');
    LEGEND_ALGEBRAIC(:,42) = strpad('mu_mcc in component CaRU_Transitions (per_ms)');
    LEGEND_ALGEBRAIC(:,11) = strpad('C_cc in component DS_Calcium_Concentrations (mM)');
    LEGEND_ALGEBRAIC(:,52) = strpad('J_Loo in component LCC_and_RyR_fluxes (um3_mM_per_ms)');
    LEGEND_ALGEBRAIC(:,51) = strpad('J_Loc in component LCC_and_RyR_fluxes (um3_mM_per_ms)');
    LEGEND_ALGEBRAIC(:,49) = strpad('J_Rco in component LCC_and_RyR_fluxes (um3_mM_per_ms)');
    LEGEND_ALGEBRAIC(:,50) = strpad('J_Roo in component LCC_and_RyR_fluxes (um3_mM_per_ms)');
    LEGEND_ALGEBRAIC(:,53) = strpad('denom in component CaRU_states (per_ms3)');
    LEGEND_ALGEBRAIC(:,54) = strpad('P1 in component CaRU_states (dimensionless)');
    LEGEND_ALGEBRAIC(:,55) = strpad('P2 in component CaRU_states (dimensionless)');
    LEGEND_ALGEBRAIC(:,56) = strpad('P3 in component CaRU_states (dimensionless)');
    LEGEND_ALGEBRAIC(:,57) = strpad('P4 in component CaRU_states (dimensionless)');
    LEGEND_ALGEBRAIC(:,58) = strpad('r_1 in component CaRU_reduced_states (per_ms)');
    LEGEND_ALGEBRAIC(:,60) = strpad('r_2 in component CaRU_reduced_states (per_ms)');
    LEGEND_ALGEBRAIC(:,62) = strpad('r_3 in component CaRU_reduced_states (per_ms)');
    LEGEND_ALGEBRAIC(:,64) = strpad('r_4 in component CaRU_reduced_states (per_ms)');
    LEGEND_ALGEBRAIC(:,66) = strpad('r_5 in component CaRU_reduced_states (per_ms)');
    LEGEND_ALGEBRAIC(:,68) = strpad('r_6 in component CaRU_reduced_states (per_ms)');
    LEGEND_ALGEBRAIC(:,70) = strpad('r_7 in component CaRU_reduced_states (per_ms)');
    LEGEND_ALGEBRAIC(:,72) = strpad('r_8 in component CaRU_reduced_states (per_ms)');
    LEGEND_STATES(:,15) = strpad('z_1 in component CaRU_reduced_states (dimensionless)');
    LEGEND_STATES(:,16) = strpad('z_2 in component CaRU_reduced_states (dimensionless)');
    LEGEND_STATES(:,17) = strpad('z_3 in component CaRU_reduced_states (dimensionless)');
    LEGEND_ALGEBRAIC(:,74) = strpad('z_4 in component CaRU_reduced_states (dimensionless)');
    LEGEND_ALGEBRAIC(:,59) = strpad('J_R1 in component RyR_current (um3_mM_per_ms)');
    LEGEND_ALGEBRAIC(:,61) = strpad('J_R3 in component RyR_current (um3_mM_per_ms)');
    LEGEND_ALGEBRAIC(:,63) = strpad('i_RyR1 in component RyR_current (mM_per_ms)');
    LEGEND_ALGEBRAIC(:,67) = strpad('J_L1 in component LCC_current (um3_mM_per_ms)');
    LEGEND_ALGEBRAIC(:,69) = strpad('J_L2 in component LCC_current (um3_mM_per_ms)');
    LEGEND_ALGEBRAIC(:,71) = strpad('i_LCC1 in component LCC_current (mM_per_ms)');
    LEGEND_CONSTANTS(:,50) = strpad('K_mNa in component Na_Ca_Exchanger (mM)');
    LEGEND_CONSTANTS(:,51) = strpad('K_mCa in component Na_Ca_Exchanger (mM)');
    LEGEND_CONSTANTS(:,52) = strpad('eta in component Na_Ca_Exchanger (dimensionless)');
    LEGEND_CONSTANTS(:,53) = strpad('k_sat in component Na_Ca_Exchanger (dimensionless)');
    LEGEND_CONSTANTS(:,54) = strpad('g_NCX in component Na_Ca_Exchanger (mM_per_ms)');
    LEGEND_ALGEBRAIC(:,75) = strpad('i_Ncx1 in component Na_Ca_Exchanger (mM_per_ms)');
    LEGEND_CONSTANTS(:,55) = strpad('g_SERCA in component SERCA (mM_per_ms)');
    LEGEND_CONSTANTS(:,56) = strpad('K_SERCA in component SERCA (mM)');
    LEGEND_ALGEBRAIC(:,77) = strpad('i_SERCA in component SERCA (mM_per_ms)');
    LEGEND_CONSTANTS(:,57) = strpad('g_pCa in component SarcolemMal_Ca_pump (mM_per_ms)');
    LEGEND_CONSTANTS(:,58) = strpad('K_mpCa in component SarcolemMal_Ca_pump (mM)');
    LEGEND_ALGEBRAIC(:,78) = strpad('i_pCa1 in component SarcolemMal_Ca_pump (mM_per_ms)');
    LEGEND_ALGEBRAIC(:,80) = strpad('E_Ca in component Background_Ca_current (mV)');
    LEGEND_CONSTANTS(:,59) = strpad('g_CaB in component Background_Ca_current (mM_per_mV_ms)');
    LEGEND_ALGEBRAIC(:,81) = strpad('i_CaB1 in component Background_Ca_current (mM_per_ms)');
    LEGEND_CONSTANTS(:,60) = strpad('g_SRl in component SR_Ca_leak_current (per_ms)');
    LEGEND_ALGEBRAIC(:,83) = strpad('i_SR in component SR_Ca_leak_current (mM_per_ms)');
    LEGEND_CONSTANTS(:,61) = strpad('k_m_TRPN in component troponin_Ca_buffer (per_ms)');
    LEGEND_CONSTANTS(:,62) = strpad('k_p_TRPN in component troponin_Ca_buffer (per_mM_ms)');
    LEGEND_CONSTANTS(:,63) = strpad('B_TRPN in component troponin_Ca_buffer (mM)');
    LEGEND_STATES(:,18) = strpad('TRPN in component intracellular_ion_concentrations (mM)');
    LEGEND_ALGEBRAIC(:,84) = strpad('i_TRPN in component troponin_Ca_buffer (mM_per_ms)');
    LEGEND_CONSTANTS(:,64) = strpad('k_CMDN in component calmodulin_Ca_buffer (mM)');
    LEGEND_CONSTANTS(:,65) = strpad('B_CMDN in component calmodulin_Ca_buffer (mM)');
    LEGEND_ALGEBRAIC(:,85) = strpad('beta_CMDN in component calmodulin_Ca_buffer (dimensionless)');
    LEGEND_CONSTANTS(:,66) = strpad('EGTA_tot in component calmodulin_Ca_buffer (mM)');
    LEGEND_CONSTANTS(:,67) = strpad('KmEGTA in component calmodulin_Ca_buffer (mM)');
    LEGEND_RATES(:,1) = strpad('d/dt V in component membrane (mV)');
    LEGEND_RATES(:,3) = strpad('d/dt m in component sodium_current_m_gate (dimensionless)');
    LEGEND_RATES(:,4) = strpad('d/dt h in component sodium_current_h_gate (dimensionless)');
    LEGEND_RATES(:,5) = strpad('d/dt j in component sodium_current_j_gate (dimensionless)');
    LEGEND_RATES(:,7) = strpad('d/dt r in component Ca_independent_transient_outward_K_current_r_gate (dimensionless)');
    LEGEND_RATES(:,8) = strpad('d/dt s in component Ca_independent_transient_outward_K_current_s_gate (dimensionless)');
    LEGEND_RATES(:,9) = strpad('d/dt s_slow in component Ca_independent_transient_outward_K_current_s_slow_gate (dimensionless)');
    LEGEND_RATES(:,10) = strpad('d/dt r_ss in component steady_state_outward_K_current_r_ss_gate (dimensionless)');
    LEGEND_RATES(:,11) = strpad('d/dt s_ss in component steady_state_outward_K_current_s_ss_gate (dimensionless)');
    LEGEND_RATES(:,12) = strpad('d/dt y in component hyperpolarisation_activated_current_y_gate (dimensionless)');
    LEGEND_RATES(:,15) = strpad('d/dt z_1 in component CaRU_reduced_states (dimensionless)');
    LEGEND_RATES(:,16) = strpad('d/dt z_2 in component CaRU_reduced_states (dimensionless)');
    LEGEND_RATES(:,17) = strpad('d/dt z_3 in component CaRU_reduced_states (dimensionless)');
    LEGEND_RATES(:,2) = strpad('d/dt Na_i in component intracellular_ion_concentrations (mM)');
    LEGEND_RATES(:,6) = strpad('d/dt K_i in component intracellular_ion_concentrations (mM)');
    LEGEND_RATES(:,18) = strpad('d/dt TRPN in component intracellular_ion_concentrations (mM)');
    LEGEND_RATES(:,13) = strpad('d/dt Ca_i in component intracellular_ion_concentrations (mM)');
    LEGEND_RATES(:,14) = strpad('d/dt Ca_SR in component intracellular_ion_concentrations (mM)');
    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) = -86.2742001770196;
    CONSTANTS(:,1) = 8314;
    CONSTANTS(:,2) = 310;
    CONSTANTS(:,3) = 96487;
    CONSTANTS(:,4) = 0.0001;
    CONSTANTS(:,5) = 170;
    CONSTANTS(:,6) = 3;
    CONSTANTS(:,7) = -0.0012;
    CONSTANTS(:,8) = 25850;
    CONSTANTS(:,9) = 2.585e-5;
    CONSTANTS(:,10) = 2.098e-6;
    CONSTANTS(:,11) = 0.0007;
    STATES(:,2) = 10.83563050735;
    CONSTANTS(:,12) = 140;
    STATES(:,3) = 0.00174392847776228;
    STATES(:,4) = 0.831855538514125;
    STATES(:,5) = 0.585528587217805;
    CONSTANTS(:,13) = 1.4e-5;
    CONSTANTS(:,14) = 0.883;
    CONSTANTS(:,15) = 0.117;
    CONSTANTS(:,16) = 5.4;
    STATES(:,6) = 140.1638657529;
    STATES(:,7) = 0.00132309740749641;
    STATES(:,8) = 0.913059928712858;
    STATES(:,9) = 0.215036691884835;
    CONSTANTS(:,17) = 1e-6;
    STATES(:,10) = 0.00178817500396492;
    STATES(:,11) = 0.209855226174927;
    CONSTANTS(:,18) = 1.5e-5;
    CONSTANTS(:,19) = 1.45e-6;
    CONSTANTS(:,20) = 0.2;
    STATES(:,12) = 0.0025539544569868;
    CONSTANTS(:,21) = 8.015e-8;
    CONSTANTS(:,22) = 1.38e-7;
    CONSTANTS(:,23) = 0.00138;
    CONSTANTS(:,24) = 3.6;
    CONSTANTS(:,25) = 19;
    CONSTANTS(:,26) = 22;
    CONSTANTS(:,27) = 880;
    CONSTANTS(:,28) = 0.3;
    CONSTANTS(:,29) = 1.8;
    CONSTANTS(:,30) = 1.8;
    CONSTANTS(:,31) = 0.1;
    CONSTANTS(:,32) = 0.02;
    CONSTANTS(:,33) = 0.0012;
    CONSTANTS(:,34) = 50000;
    STATES(:,13) = 0.000145080891755077;
    STATES(:,14) = 1.78499523287115;
    CONSTANTS(:,35) = -13;
    CONSTANTS(:,36) = 7;
    CONSTANTS(:,37) = 11.5;
    CONSTANTS(:,38) = 1;
    CONSTANTS(:,39) = 1550;
    CONSTANTS(:,40) = 1.17;
    CONSTANTS(:,41) = 2.4;
    CONSTANTS(:,42) = 0.05;
    CONSTANTS(:,43) = 0.012;
    CONSTANTS(:,44) = 0.065;
    CONSTANTS(:,45) = 0.00016;
    CONSTANTS(:,46) = 0.0625;
    CONSTANTS(:,47) = 14;
    CONSTANTS(:,48) = 0.01;
    CONSTANTS(:,49) = 100;
    STATES(:,15) = 0.650490049579104;
    STATES(:,16) = 0.00570189155987283;
    STATES(:,17) = 0.340821224038804;
    CONSTANTS(:,50) = 87.5;
    CONSTANTS(:,51) = 1.38;
    CONSTANTS(:,52) = 0.35;
    CONSTANTS(:,53) = 0.1;
    CONSTANTS(:,54) = 0.0456;
    CONSTANTS(:,55) = 0.00049;
    CONSTANTS(:,56) = 0.00025;
    CONSTANTS(:,57) = 5e-6;
    CONSTANTS(:,58) = 0.00035;
    CONSTANTS(:,59) = 6e-9;
    CONSTANTS(:,60) = 1e-6;
    CONSTANTS(:,61) = 0.04;
    CONSTANTS(:,62) = 40;
    CONSTANTS(:,63) = 0.07;
    STATES(:,18) = 0.0590608556435992;
    CONSTANTS(:,64) = 0.002382;
    CONSTANTS(:,65) = 0.05;
    CONSTANTS(:,66) = 0;
    CONSTANTS(:,67) = 0.00015;
    CONSTANTS(:,68) = 2100.00;
    CONSTANTS(:,69) = 1.00000 - CONSTANTS(:,20);
    CONSTANTS(:,70) = CONSTANTS(:,37)./CONSTANTS(:,38);
    CONSTANTS(:,71) = CONSTANTS(:,42)./CONSTANTS(:,40);
    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(:,9) = 1.00000./(1.00000+exp((STATES(:,1)+87.5000)./10.3000));
    RATES(:,11) = (ALGEBRAIC(:,9) - STATES(:,11))./CONSTANTS(:,68);
    ALGEBRAIC(:,2) = 1.00000./(1.00000+exp((STATES(:,1)+45.0000)./ - 6.50000));
    ALGEBRAIC(:,12) = 1.36000./(( 0.320000.*(STATES(:,1)+47.1300))./(1.00000 - exp(  - 0.100000.*(STATES(:,1)+47.1300)))+ 0.0800000.*exp( - STATES(:,1)./11.0000));
    RATES(:,3) = (ALGEBRAIC(:,2) - STATES(:,3))./ALGEBRAIC(:,12);
    ALGEBRAIC(:,3) = 1.00000./(1.00000+exp((STATES(:,1)+76.1000)./6.07000));
    ALGEBRAIC(:,13) = piecewise({STATES(:,1)>= - 40.0000,  0.453700.*(1.00000+exp( - (STATES(:,1)+10.6600)./11.1000)) }, 3.49000./( 0.135000.*exp( - (STATES(:,1)+80.0000)./6.80000)+ 3.56000.*exp( 0.0790000.*STATES(:,1))+ 310000..*exp( 0.350000.*STATES(:,1))));
    RATES(:,4) = (ALGEBRAIC(:,3) - STATES(:,4))./ALGEBRAIC(:,13);
    ALGEBRAIC(:,4) = 1.00000./(1.00000+exp((STATES(:,1)+76.1000)./6.07000));
    ALGEBRAIC(:,14) = piecewise({STATES(:,1)>= - 40.0000, ( 11.6300.*(1.00000+exp(  - 0.100000.*(STATES(:,1)+32.0000))))./exp(  - 2.53500e-07.*STATES(:,1)) }, 3.49000./( ((STATES(:,1)+37.7800)./(1.00000+exp( 0.311000.*(STATES(:,1)+79.2300)))).*(  - 127140..*exp( 0.244400.*STATES(:,1)) -  3.47400e-05.*exp(  - 0.0439100.*STATES(:,1)))+( 0.121200.*exp(  - 0.0105200.*STATES(:,1)))./(1.00000+exp(  - 0.137800.*(STATES(:,1)+40.1400)))));
    RATES(:,5) = (ALGEBRAIC(:,4) - STATES(:,5))./ALGEBRAIC(:,14);
    ALGEBRAIC(:,15) = 100.000./( 45.1600.*exp( 0.0357700.*(STATES(:,1)+50.0000))+ 98.9000.*exp(  - 0.100000.*(STATES(:,1)+38.0000)));
    ALGEBRAIC(:,5) = 1.00000./(1.00000+exp((STATES(:,1)+10.6000)./ - 11.4200));
    RATES(:,7) = (ALGEBRAIC(:,5) - STATES(:,7))./ALGEBRAIC(:,15);
    ALGEBRAIC(:,16) =  20.0000.*exp( - power((STATES(:,1)+70.0000)./25.0000, 2.00000))+35.0000;
    ALGEBRAIC(:,6) = 1.00000./(1.00000+exp((STATES(:,1)+45.3000)./6.88410));
    RATES(:,8) = (ALGEBRAIC(:,6) - STATES(:,8))./ALGEBRAIC(:,16);
    ALGEBRAIC(:,17) =  1300.00.*exp( - power((STATES(:,1)+70.0000)./30.0000, 2.00000))+35.0000;
    ALGEBRAIC(:,7) = 1.00000./(1.00000+exp((STATES(:,1)+45.3000)./6.88410));
    RATES(:,9) = (ALGEBRAIC(:,7) - STATES(:,9))./ALGEBRAIC(:,17);
    ALGEBRAIC(:,18) = 10000.0./( 45.1600.*exp( 0.0357700.*(STATES(:,1)+50.0000))+ 98.9000.*exp(  - 0.100000.*(STATES(:,1)+38.0000)));
    ALGEBRAIC(:,8) = 1.00000./(1.00000+exp((STATES(:,1)+11.5000)./ - 11.8200));
    RATES(:,10) = (ALGEBRAIC(:,8) - STATES(:,10))./ALGEBRAIC(:,18);
    ALGEBRAIC(:,19) = 1000.00./( 0.118850.*exp((STATES(:,1)+80.0000)./28.3700)+ 0.562300.*exp((STATES(:,1)+80.0000)./ - 14.1900));
    ALGEBRAIC(:,10) = 1.00000./(1.00000+exp((STATES(:,1)+138.600)./10.4800));
    RATES(:,12) = (ALGEBRAIC(:,10) - STATES(:,12))./ALGEBRAIC(:,19);
    ALGEBRAIC(:,24) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,16)./STATES(:,6));
    ALGEBRAIC(:,25) =  CONSTANTS(:,13).*STATES(:,7).*( CONSTANTS(:,14).*STATES(:,8)+ CONSTANTS(:,15).*STATES(:,9)).*(STATES(:,1) - ALGEBRAIC(:,24));
    ALGEBRAIC(:,26) =  CONSTANTS(:,17).*STATES(:,10).*STATES(:,11).*(STATES(:,1) - ALGEBRAIC(:,24));
    ALGEBRAIC(:,27) = ( (0.0480000./(exp((STATES(:,1)+37.0000)./25.0000)+exp((STATES(:,1)+37.0000)./ - 25.0000))+0.0100000).*0.00100000)./(1.00000+exp((STATES(:,1) - (ALGEBRAIC(:,24)+76.7700))./ - 17.0000))+( CONSTANTS(:,18).*(STATES(:,1) - (ALGEBRAIC(:,24)+1.73000)))./( (1.00000+exp(( 1.61300.*CONSTANTS(:,3).*(STATES(:,1) - (ALGEBRAIC(:,24)+1.73000)))./( CONSTANTS(:,1).*CONSTANTS(:,2)))).*(1.00000+exp((CONSTANTS(:,16) - 0.998800)./ - 0.124000)));
    ALGEBRAIC(:,32) =  CONSTANTS(:,22).*(STATES(:,1) - ALGEBRAIC(:,24));
    ALGEBRAIC(:,34) =  CONSTANTS(:,24).*power(1.00000+CONSTANTS(:,25)./STATES(:,2), 2.00000).*(1.00000+ (CONSTANTS(:,26)./STATES(:,2)).*exp(((  - CONSTANTS(:,28).*CONSTANTS(:,3).*STATES(:,1))./CONSTANTS(:,1))./CONSTANTS(:,2)))+ power(1.00000+CONSTANTS(:,29)./CONSTANTS(:,16), 2.00000).*(1.00000+ (CONSTANTS(:,12)./CONSTANTS(:,27)).*exp(((  - (1.00000 - CONSTANTS(:,28)).*CONSTANTS(:,3).*STATES(:,1))./CONSTANTS(:,1))./CONSTANTS(:,2)));
    ALGEBRAIC(:,35) = ( CONSTANTS(:,23).*(CONSTANTS(:,24)+1.00000))./ALGEBRAIC(:,34);
    ALGEBRAIC(:,21) = piecewise({VOI -  floor(VOI./CONSTANTS(:,5)).*CONSTANTS(:,5)>=0.00000&VOI -  floor(VOI./CONSTANTS(:,5)).*CONSTANTS(:,5)<=CONSTANTS(:,6), CONSTANTS(:,7) }, 0.00000);
    ALGEBRAIC(:,29) =  CONSTANTS(:,19).*STATES(:,12).*CONSTANTS(:,69).*(STATES(:,1) - ALGEBRAIC(:,24));
    RATES(:,6) = (  - (ALGEBRAIC(:,21)+ALGEBRAIC(:,26)+ALGEBRAIC(:,32)+ALGEBRAIC(:,25)+ALGEBRAIC(:,27)+ALGEBRAIC(:,29)+  - 2.00000.*ALGEBRAIC(:,35)).*1.00000)./( CONSTANTS(:,9).*CONSTANTS(:,3));
    ALGEBRAIC(:,1) = ( CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2));
    ALGEBRAIC(:,20) =  2.00000.*ALGEBRAIC(:,1);
    ALGEBRAIC(:,45) = piecewise({abs(ALGEBRAIC(:,20))>1.00000e-09, (STATES(:,13)+( (CONSTANTS(:,33)./CONSTANTS(:,31)).*CONSTANTS(:,30).*ALGEBRAIC(:,20).*exp( - ALGEBRAIC(:,20)))./(1.00000 - exp( - ALGEBRAIC(:,20))))./(1.00000+( (CONSTANTS(:,33)./CONSTANTS(:,31)).*ALGEBRAIC(:,20))./(1.00000 - exp( - ALGEBRAIC(:,20)))) }, (STATES(:,13)+ (CONSTANTS(:,33)./CONSTANTS(:,31)).*CONSTANTS(:,30))./(1.00000+CONSTANTS(:,33)./CONSTANTS(:,31)));
    ALGEBRAIC(:,47) = (power(ALGEBRAIC(:,45), 2.00000)+ CONSTANTS(:,48).*power(CONSTANTS(:,44), 2.00000))./( CONSTANTS(:,41).*(power(ALGEBRAIC(:,45), 2.00000)+power(CONSTANTS(:,44), 2.00000)));
    ALGEBRAIC(:,41) = (power(STATES(:,13), 2.00000)+ CONSTANTS(:,48).*power(CONSTANTS(:,44), 2.00000))./( CONSTANTS(:,41).*(power(STATES(:,13), 2.00000)+power(CONSTANTS(:,44), 2.00000)));
    ALGEBRAIC(:,36) = exp((STATES(:,1) - CONSTANTS(:,35))./CONSTANTS(:,36));
    ALGEBRAIC(:,37) = ALGEBRAIC(:,36)./( CONSTANTS(:,38).*(ALGEBRAIC(:,36)+1.00000));
    ALGEBRAIC(:,38) = power(STATES(:,13), 2.00000)./( CONSTANTS(:,40).*(power(STATES(:,13), 2.00000)+power(CONSTANTS(:,44), 2.00000)));
    ALGEBRAIC(:,46) = power(ALGEBRAIC(:,45), 2.00000)./( CONSTANTS(:,40).*(power(ALGEBRAIC(:,45), 2.00000)+power(CONSTANTS(:,44), 2.00000)));
    ALGEBRAIC(:,53) =  (ALGEBRAIC(:,37)+CONSTANTS(:,70)).*( (CONSTANTS(:,70)+CONSTANTS(:,71)+ALGEBRAIC(:,46)).*(CONSTANTS(:,71)+ALGEBRAIC(:,38))+ ALGEBRAIC(:,37).*(CONSTANTS(:,71)+ALGEBRAIC(:,46)));
    ALGEBRAIC(:,54) = ( ALGEBRAIC(:,37).*CONSTANTS(:,71).*(ALGEBRAIC(:,37)+CONSTANTS(:,70)+CONSTANTS(:,71)+ALGEBRAIC(:,38)))./ALGEBRAIC(:,53);
    ALGEBRAIC(:,57) = ( CONSTANTS(:,70).*CONSTANTS(:,71).*(CONSTANTS(:,70)+ALGEBRAIC(:,37)+CONSTANTS(:,71)+ALGEBRAIC(:,46)))./ALGEBRAIC(:,53);
    ALGEBRAIC(:,58) =  ALGEBRAIC(:,54).*ALGEBRAIC(:,47)+ ALGEBRAIC(:,57).*ALGEBRAIC(:,41);
    ALGEBRAIC(:,48) = ( CONSTANTS(:,43).*CONSTANTS(:,49).*(power(ALGEBRAIC(:,45), 2.00000)+ CONSTANTS(:,48).*power(CONSTANTS(:,44), 2.00000)))./( CONSTANTS(:,41).*( CONSTANTS(:,49).*power(ALGEBRAIC(:,45), 2.00000)+ CONSTANTS(:,48).*power(CONSTANTS(:,44), 2.00000)));
    ALGEBRAIC(:,42) = ( CONSTANTS(:,43).*CONSTANTS(:,49).*(power(STATES(:,13), 2.00000)+ CONSTANTS(:,48).*power(CONSTANTS(:,44), 2.00000)))./( CONSTANTS(:,41).*( CONSTANTS(:,49).*power(STATES(:,13), 2.00000)+ CONSTANTS(:,48).*power(CONSTANTS(:,44), 2.00000)));
    ALGEBRAIC(:,60) = ( ALGEBRAIC(:,37).*ALGEBRAIC(:,48)+ CONSTANTS(:,70).*ALGEBRAIC(:,42))./(ALGEBRAIC(:,37)+CONSTANTS(:,70));
    ALGEBRAIC(:,43) = (STATES(:,13)+ (CONSTANTS(:,32)./CONSTANTS(:,31)).*STATES(:,14))./(1.00000+CONSTANTS(:,32)./CONSTANTS(:,31));
    ALGEBRAIC(:,44) = ( ALGEBRAIC(:,43).*(ALGEBRAIC(:,36)+CONSTANTS(:,46)))./( CONSTANTS(:,39).*CONSTANTS(:,45).*(ALGEBRAIC(:,36)+1.00000));
    ALGEBRAIC(:,39) = ( STATES(:,13).*(ALGEBRAIC(:,36)+CONSTANTS(:,46)))./( CONSTANTS(:,39).*CONSTANTS(:,45).*(ALGEBRAIC(:,36)+1.00000));
    ALGEBRAIC(:,55) = ( CONSTANTS(:,70).*( ALGEBRAIC(:,38).*(CONSTANTS(:,70)+CONSTANTS(:,71)+ALGEBRAIC(:,46))+ ALGEBRAIC(:,46).*ALGEBRAIC(:,37)))./ALGEBRAIC(:,53);
    ALGEBRAIC(:,66) =  ALGEBRAIC(:,55).*ALGEBRAIC(:,44)+ ALGEBRAIC(:,57).*ALGEBRAIC(:,39);
    ALGEBRAIC(:,40) = ( CONSTANTS(:,47).*(ALGEBRAIC(:,36)+CONSTANTS(:,46)))./( CONSTANTS(:,39).*( CONSTANTS(:,47).*ALGEBRAIC(:,36)+CONSTANTS(:,46)));
    ALGEBRAIC(:,68) = ALGEBRAIC(:,40);
    RATES(:,15) =   - (ALGEBRAIC(:,58)+ALGEBRAIC(:,66)).*STATES(:,15)+ ALGEBRAIC(:,60).*STATES(:,16)+ ALGEBRAIC(:,68).*STATES(:,17);
    ALGEBRAIC(:,70) = ( CONSTANTS(:,70).*ALGEBRAIC(:,39))./(ALGEBRAIC(:,37)+CONSTANTS(:,70));
    ALGEBRAIC(:,72) = ALGEBRAIC(:,40);
    ALGEBRAIC(:,74) = ((1.00000 - STATES(:,15)) - STATES(:,16)) - STATES(:,17);
    RATES(:,16) = ( ALGEBRAIC(:,58).*STATES(:,15) -  (ALGEBRAIC(:,60)+ALGEBRAIC(:,70)).*STATES(:,16))+ ALGEBRAIC(:,72).*ALGEBRAIC(:,74);
    ALGEBRAIC(:,62) = ( CONSTANTS(:,71).*ALGEBRAIC(:,41))./(CONSTANTS(:,71)+ALGEBRAIC(:,38));
    ALGEBRAIC(:,64) = ALGEBRAIC(:,42);
    RATES(:,17) = ( ALGEBRAIC(:,66).*STATES(:,15) -  (ALGEBRAIC(:,68)+ALGEBRAIC(:,62)).*STATES(:,17))+ ALGEBRAIC(:,64).*ALGEBRAIC(:,74);
    ALGEBRAIC(:,22) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,12)./STATES(:,2));
    ALGEBRAIC(:,23) =  CONSTANTS(:,11).*power(STATES(:,3), 3.00000).*STATES(:,4).*STATES(:,5).*(STATES(:,1) - ALGEBRAIC(:,22));
    ALGEBRAIC(:,31) =  CONSTANTS(:,21).*(STATES(:,1) - ALGEBRAIC(:,22));
    ALGEBRAIC(:,75) = ( CONSTANTS(:,54).*( exp( CONSTANTS(:,52).*ALGEBRAIC(:,1)).*power(STATES(:,2), 3.00000).*CONSTANTS(:,30) -  exp( (CONSTANTS(:,52) - 1.00000).*ALGEBRAIC(:,1)).*power(CONSTANTS(:,12), 3.00000).*STATES(:,13)))./( (power(CONSTANTS(:,12), 3.00000)+power(CONSTANTS(:,50), 3.00000)).*(CONSTANTS(:,30)+CONSTANTS(:,51)).*(1.00000+ CONSTANTS(:,53).*exp( (CONSTANTS(:,52) - 1.00000).*ALGEBRAIC(:,1))));
    ALGEBRAIC(:,76) =  ALGEBRAIC(:,75).*CONSTANTS(:,3).*CONSTANTS(:,9);
    ALGEBRAIC(:,28) =  CONSTANTS(:,19).*STATES(:,12).*CONSTANTS(:,20).*(STATES(:,1) - ALGEBRAIC(:,22));
    RATES(:,2) = (  - (ALGEBRAIC(:,23)+ALGEBRAIC(:,31)+ ALGEBRAIC(:,76).*3.00000+ ALGEBRAIC(:,35).*3.00000+ALGEBRAIC(:,28)).*1.00000)./( CONSTANTS(:,9).*CONSTANTS(:,3));
    ALGEBRAIC(:,30) = ALGEBRAIC(:,28)+ALGEBRAIC(:,29);
    ALGEBRAIC(:,78) = ( CONSTANTS(:,57).*STATES(:,13))./(CONSTANTS(:,58)+STATES(:,13));
    ALGEBRAIC(:,79) =  ALGEBRAIC(:,78).*2.00000.*CONSTANTS(:,3).*CONSTANTS(:,9);
    ALGEBRAIC(:,52) = piecewise({abs(ALGEBRAIC(:,20))>1.00000e-05, ( (( CONSTANTS(:,33).*ALGEBRAIC(:,20))./(1.00000 - exp( - ALGEBRAIC(:,20)))).*(( CONSTANTS(:,30).*exp( - ALGEBRAIC(:,20)) - STATES(:,13))+ (CONSTANTS(:,32)./CONSTANTS(:,31)).*( CONSTANTS(:,30).*exp( - ALGEBRAIC(:,20)) - STATES(:,14))))./(1.00000+CONSTANTS(:,32)./CONSTANTS(:,31)+( (CONSTANTS(:,33)./CONSTANTS(:,31)).*ALGEBRAIC(:,20))./(1.00000 - exp(ALGEBRAIC(:,20)))) }, ( (( CONSTANTS(:,33).*1.00000e-05)./(1.00000 - exp( - 1.00000e-05))).*(( CONSTANTS(:,30).*exp( - 1.00000e-05) - STATES(:,13))+ (CONSTANTS(:,32)./CONSTANTS(:,31)).*( CONSTANTS(:,30).*exp( - 1.00000e-05) - STATES(:,14))))./(1.00000+CONSTANTS(:,32)./CONSTANTS(:,31)+( (CONSTANTS(:,33)./CONSTANTS(:,31)).*1.00000e-05)./(1.00000 - exp( - 1.00000e-05))));
    ALGEBRAIC(:,51) = piecewise({abs(ALGEBRAIC(:,20))>1.00000e-05, ( (( CONSTANTS(:,33).*ALGEBRAIC(:,20))./(1.00000 - exp( - ALGEBRAIC(:,20)))).*( CONSTANTS(:,30).*exp( - ALGEBRAIC(:,20)) - STATES(:,13)))./(1.00000+( (CONSTANTS(:,33)./CONSTANTS(:,31)).*ALGEBRAIC(:,20))./(1.00000 - exp( - ALGEBRAIC(:,20)))) }, ( (( CONSTANTS(:,33).*1.00000e-05)./(1.00000 - exp( - 1.00000e-05))).*( CONSTANTS(:,30).*exp( - 1.00000e-05) - STATES(:,13)))./(1.00000+( (CONSTANTS(:,33)./CONSTANTS(:,31)).*1.00000e-05)./(1.00000 - exp( - 1.00000e-05))));
    ALGEBRAIC(:,56) = ( ALGEBRAIC(:,37).*( ALGEBRAIC(:,46).*(ALGEBRAIC(:,37)+CONSTANTS(:,71)+ALGEBRAIC(:,38))+ ALGEBRAIC(:,38).*CONSTANTS(:,70)))./ALGEBRAIC(:,53);
    ALGEBRAIC(:,67) =  ALGEBRAIC(:,52).*ALGEBRAIC(:,56)+ ALGEBRAIC(:,51).*ALGEBRAIC(:,54);
    ALGEBRAIC(:,69) = ( ALGEBRAIC(:,51).*ALGEBRAIC(:,37))./(ALGEBRAIC(:,37)+CONSTANTS(:,70));
    ALGEBRAIC(:,71) = ( ( STATES(:,15).*ALGEBRAIC(:,67)+ STATES(:,16).*ALGEBRAIC(:,69)).*CONSTANTS(:,34))./CONSTANTS(:,8);
    ALGEBRAIC(:,73) =   - ALGEBRAIC(:,71).*2.00000.*CONSTANTS(:,3).*CONSTANTS(:,9);
    ALGEBRAIC(:,80) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./( 2.00000.*CONSTANTS(:,3))).*log(CONSTANTS(:,30)./STATES(:,13));
    ALGEBRAIC(:,81) =  CONSTANTS(:,59).*(ALGEBRAIC(:,80) - STATES(:,1));
    ALGEBRAIC(:,82) =   - ALGEBRAIC(:,81).*2.00000.*CONSTANTS(:,3).*CONSTANTS(:,9);
    RATES(:,1) =  - (ALGEBRAIC(:,23)+ALGEBRAIC(:,25)+ALGEBRAIC(:,26)+ALGEBRAIC(:,30)+ALGEBRAIC(:,27)+ALGEBRAIC(:,31)+ALGEBRAIC(:,32)+ALGEBRAIC(:,35)+ALGEBRAIC(:,82)+ALGEBRAIC(:,76)+ALGEBRAIC(:,79)+ALGEBRAIC(:,73)+ALGEBRAIC(:,21))./CONSTANTS(:,4);
    ALGEBRAIC(:,49) = ( CONSTANTS(:,32).*(STATES(:,14) - STATES(:,13)))./(1.00000+CONSTANTS(:,32)./CONSTANTS(:,31));
    ALGEBRAIC(:,50) = piecewise({abs(ALGEBRAIC(:,20))>1.00000e-05, ( CONSTANTS(:,32).*((STATES(:,14) - STATES(:,13))+ (( (CONSTANTS(:,33)./CONSTANTS(:,31)).*ALGEBRAIC(:,20))./(1.00000 - exp( - ALGEBRAIC(:,20)))).*(STATES(:,14) -  CONSTANTS(:,30).*exp( - ALGEBRAIC(:,20)))))./(1.00000+CONSTANTS(:,32)./CONSTANTS(:,31)+( (CONSTANTS(:,33)./CONSTANTS(:,31)).*ALGEBRAIC(:,20))./(1.00000 - exp( - ALGEBRAIC(:,20)))) }, ( CONSTANTS(:,32).*((STATES(:,14) - STATES(:,13))+ (( (CONSTANTS(:,33)./CONSTANTS(:,31)).*1.00000e-05)./(1.00000 - exp( - 1.00000e-05))).*(STATES(:,14) -  CONSTANTS(:,30).*exp( - 1.00000e-05))))./(1.00000+CONSTANTS(:,32)./CONSTANTS(:,31)+( (CONSTANTS(:,33)./CONSTANTS(:,31)).*1.00000e-05)./(1.00000 - exp( - 1.00000e-05))));
    ALGEBRAIC(:,59) =  ALGEBRAIC(:,56).*ALGEBRAIC(:,50)+ ALGEBRAIC(:,49).*ALGEBRAIC(:,55);
    ALGEBRAIC(:,61) = ( ALGEBRAIC(:,49).*ALGEBRAIC(:,38))./(CONSTANTS(:,71)+ALGEBRAIC(:,38));
    ALGEBRAIC(:,63) = ( ( STATES(:,15).*ALGEBRAIC(:,59)+ STATES(:,17).*ALGEBRAIC(:,61)).*CONSTANTS(:,34))./CONSTANTS(:,8);
    ALGEBRAIC(:,65) = ALGEBRAIC(:,63);
    ALGEBRAIC(:,77) = ( CONSTANTS(:,55).*power(STATES(:,13), 2.00000))./(power(CONSTANTS(:,56), 2.00000)+power(STATES(:,13), 2.00000));
    ALGEBRAIC(:,83) =  CONSTANTS(:,60).*(STATES(:,14) - STATES(:,13));
    RATES(:,14) =  (CONSTANTS(:,9)./CONSTANTS(:,10)).*(( - ALGEBRAIC(:,65)+ALGEBRAIC(:,77)) - ALGEBRAIC(:,83));
    ALGEBRAIC(:,84) =  CONSTANTS(:,61).*(CONSTANTS(:,63) - STATES(:,18)) -  CONSTANTS(:,62).*STATES(:,18).*STATES(:,13);
    RATES(:,18) = ALGEBRAIC(:,84);
    ALGEBRAIC(:,85) = power(1.00000+( CONSTANTS(:,64).*CONSTANTS(:,65))./power(CONSTANTS(:,64)+STATES(:,13), 2.00000)+( CONSTANTS(:,66).*CONSTANTS(:,67))./power(CONSTANTS(:,67)+STATES(:,13), 2.00000),  - 1.00000);
    RATES(:,13) =  ALGEBRAIC(:,85).*(((ALGEBRAIC(:,65) - ALGEBRAIC(:,77))+ALGEBRAIC(:,83)+ALGEBRAIC(:,84)) - (  - 2.00000.*ALGEBRAIC(:,76)+ALGEBRAIC(:,73)+ALGEBRAIC(:,79)+ALGEBRAIC(:,82))./( 2.00000.*CONSTANTS(:,9).*CONSTANTS(:,3)));
   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(:,9) = 1.00000./(1.00000+exp((STATES(:,1)+87.5000)./10.3000));
    ALGEBRAIC(:,2) = 1.00000./(1.00000+exp((STATES(:,1)+45.0000)./ - 6.50000));
    ALGEBRAIC(:,12) = 1.36000./(( 0.320000.*(STATES(:,1)+47.1300))./(1.00000 - exp(  - 0.100000.*(STATES(:,1)+47.1300)))+ 0.0800000.*exp( - STATES(:,1)./11.0000));
    ALGEBRAIC(:,3) = 1.00000./(1.00000+exp((STATES(:,1)+76.1000)./6.07000));
    ALGEBRAIC(:,13) = piecewise({STATES(:,1)>= - 40.0000,  0.453700.*(1.00000+exp( - (STATES(:,1)+10.6600)./11.1000)) }, 3.49000./( 0.135000.*exp( - (STATES(:,1)+80.0000)./6.80000)+ 3.56000.*exp( 0.0790000.*STATES(:,1))+ 310000..*exp( 0.350000.*STATES(:,1))));
    ALGEBRAIC(:,4) = 1.00000./(1.00000+exp((STATES(:,1)+76.1000)./6.07000));
    ALGEBRAIC(:,14) = piecewise({STATES(:,1)>= - 40.0000, ( 11.6300.*(1.00000+exp(  - 0.100000.*(STATES(:,1)+32.0000))))./exp(  - 2.53500e-07.*STATES(:,1)) }, 3.49000./( ((STATES(:,1)+37.7800)./(1.00000+exp( 0.311000.*(STATES(:,1)+79.2300)))).*(  - 127140..*exp( 0.244400.*STATES(:,1)) -  3.47400e-05.*exp(  - 0.0439100.*STATES(:,1)))+( 0.121200.*exp(  - 0.0105200.*STATES(:,1)))./(1.00000+exp(  - 0.137800.*(STATES(:,1)+40.1400)))));
    ALGEBRAIC(:,15) = 100.000./( 45.1600.*exp( 0.0357700.*(STATES(:,1)+50.0000))+ 98.9000.*exp(  - 0.100000.*(STATES(:,1)+38.0000)));
    ALGEBRAIC(:,5) = 1.00000./(1.00000+exp((STATES(:,1)+10.6000)./ - 11.4200));
    ALGEBRAIC(:,16) =  20.0000.*exp( - power((STATES(:,1)+70.0000)./25.0000, 2.00000))+35.0000;
    ALGEBRAIC(:,6) = 1.00000./(1.00000+exp((STATES(:,1)+45.3000)./6.88410));
    ALGEBRAIC(:,17) =  1300.00.*exp( - power((STATES(:,1)+70.0000)./30.0000, 2.00000))+35.0000;
    ALGEBRAIC(:,7) = 1.00000./(1.00000+exp((STATES(:,1)+45.3000)./6.88410));
    ALGEBRAIC(:,18) = 10000.0./( 45.1600.*exp( 0.0357700.*(STATES(:,1)+50.0000))+ 98.9000.*exp(  - 0.100000.*(STATES(:,1)+38.0000)));
    ALGEBRAIC(:,8) = 1.00000./(1.00000+exp((STATES(:,1)+11.5000)./ - 11.8200));
    ALGEBRAIC(:,19) = 1000.00./( 0.118850.*exp((STATES(:,1)+80.0000)./28.3700)+ 0.562300.*exp((STATES(:,1)+80.0000)./ - 14.1900));
    ALGEBRAIC(:,10) = 1.00000./(1.00000+exp((STATES(:,1)+138.600)./10.4800));
    ALGEBRAIC(:,24) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,16)./STATES(:,6));
    ALGEBRAIC(:,25) =  CONSTANTS(:,13).*STATES(:,7).*( CONSTANTS(:,14).*STATES(:,8)+ CONSTANTS(:,15).*STATES(:,9)).*(STATES(:,1) - ALGEBRAIC(:,24));
    ALGEBRAIC(:,26) =  CONSTANTS(:,17).*STATES(:,10).*STATES(:,11).*(STATES(:,1) - ALGEBRAIC(:,24));
    ALGEBRAIC(:,27) = ( (0.0480000./(exp((STATES(:,1)+37.0000)./25.0000)+exp((STATES(:,1)+37.0000)./ - 25.0000))+0.0100000).*0.00100000)./(1.00000+exp((STATES(:,1) - (ALGEBRAIC(:,24)+76.7700))./ - 17.0000))+( CONSTANTS(:,18).*(STATES(:,1) - (ALGEBRAIC(:,24)+1.73000)))./( (1.00000+exp(( 1.61300.*CONSTANTS(:,3).*(STATES(:,1) - (ALGEBRAIC(:,24)+1.73000)))./( CONSTANTS(:,1).*CONSTANTS(:,2)))).*(1.00000+exp((CONSTANTS(:,16) - 0.998800)./ - 0.124000)));
    ALGEBRAIC(:,32) =  CONSTANTS(:,22).*(STATES(:,1) - ALGEBRAIC(:,24));
    ALGEBRAIC(:,34) =  CONSTANTS(:,24).*power(1.00000+CONSTANTS(:,25)./STATES(:,2), 2.00000).*(1.00000+ (CONSTANTS(:,26)./STATES(:,2)).*exp(((  - CONSTANTS(:,28).*CONSTANTS(:,3).*STATES(:,1))./CONSTANTS(:,1))./CONSTANTS(:,2)))+ power(1.00000+CONSTANTS(:,29)./CONSTANTS(:,16), 2.00000).*(1.00000+ (CONSTANTS(:,12)./CONSTANTS(:,27)).*exp(((  - (1.00000 - CONSTANTS(:,28)).*CONSTANTS(:,3).*STATES(:,1))./CONSTANTS(:,1))./CONSTANTS(:,2)));
    ALGEBRAIC(:,35) = ( CONSTANTS(:,23).*(CONSTANTS(:,24)+1.00000))./ALGEBRAIC(:,34);
    ALGEBRAIC(:,21) = piecewise({VOI -  floor(VOI./CONSTANTS(:,5)).*CONSTANTS(:,5)>=0.00000&VOI -  floor(VOI./CONSTANTS(:,5)).*CONSTANTS(:,5)<=CONSTANTS(:,6), CONSTANTS(:,7) }, 0.00000);
    ALGEBRAIC(:,29) =  CONSTANTS(:,19).*STATES(:,12).*CONSTANTS(:,69).*(STATES(:,1) - ALGEBRAIC(:,24));
    ALGEBRAIC(:,1) = ( CONSTANTS(:,3).*STATES(:,1))./( CONSTANTS(:,1).*CONSTANTS(:,2));
    ALGEBRAIC(:,20) =  2.00000.*ALGEBRAIC(:,1);
    ALGEBRAIC(:,45) = piecewise({abs(ALGEBRAIC(:,20))>1.00000e-09, (STATES(:,13)+( (CONSTANTS(:,33)./CONSTANTS(:,31)).*CONSTANTS(:,30).*ALGEBRAIC(:,20).*exp( - ALGEBRAIC(:,20)))./(1.00000 - exp( - ALGEBRAIC(:,20))))./(1.00000+( (CONSTANTS(:,33)./CONSTANTS(:,31)).*ALGEBRAIC(:,20))./(1.00000 - exp( - ALGEBRAIC(:,20)))) }, (STATES(:,13)+ (CONSTANTS(:,33)./CONSTANTS(:,31)).*CONSTANTS(:,30))./(1.00000+CONSTANTS(:,33)./CONSTANTS(:,31)));
    ALGEBRAIC(:,47) = (power(ALGEBRAIC(:,45), 2.00000)+ CONSTANTS(:,48).*power(CONSTANTS(:,44), 2.00000))./( CONSTANTS(:,41).*(power(ALGEBRAIC(:,45), 2.00000)+power(CONSTANTS(:,44), 2.00000)));
    ALGEBRAIC(:,41) = (power(STATES(:,13), 2.00000)+ CONSTANTS(:,48).*power(CONSTANTS(:,44), 2.00000))./( CONSTANTS(:,41).*(power(STATES(:,13), 2.00000)+power(CONSTANTS(:,44), 2.00000)));
    ALGEBRAIC(:,36) = exp((STATES(:,1) - CONSTANTS(:,35))./CONSTANTS(:,36));
    ALGEBRAIC(:,37) = ALGEBRAIC(:,36)./( CONSTANTS(:,38).*(ALGEBRAIC(:,36)+1.00000));
    ALGEBRAIC(:,38) = power(STATES(:,13), 2.00000)./( CONSTANTS(:,40).*(power(STATES(:,13), 2.00000)+power(CONSTANTS(:,44), 2.00000)));
    ALGEBRAIC(:,46) = power(ALGEBRAIC(:,45), 2.00000)./( CONSTANTS(:,40).*(power(ALGEBRAIC(:,45), 2.00000)+power(CONSTANTS(:,44), 2.00000)));
    ALGEBRAIC(:,53) =  (ALGEBRAIC(:,37)+CONSTANTS(:,70)).*( (CONSTANTS(:,70)+CONSTANTS(:,71)+ALGEBRAIC(:,46)).*(CONSTANTS(:,71)+ALGEBRAIC(:,38))+ ALGEBRAIC(:,37).*(CONSTANTS(:,71)+ALGEBRAIC(:,46)));
    ALGEBRAIC(:,54) = ( ALGEBRAIC(:,37).*CONSTANTS(:,71).*(ALGEBRAIC(:,37)+CONSTANTS(:,70)+CONSTANTS(:,71)+ALGEBRAIC(:,38)))./ALGEBRAIC(:,53);
    ALGEBRAIC(:,57) = ( CONSTANTS(:,70).*CONSTANTS(:,71).*(CONSTANTS(:,70)+ALGEBRAIC(:,37)+CONSTANTS(:,71)+ALGEBRAIC(:,46)))./ALGEBRAIC(:,53);
    ALGEBRAIC(:,58) =  ALGEBRAIC(:,54).*ALGEBRAIC(:,47)+ ALGEBRAIC(:,57).*ALGEBRAIC(:,41);
    ALGEBRAIC(:,48) = ( CONSTANTS(:,43).*CONSTANTS(:,49).*(power(ALGEBRAIC(:,45), 2.00000)+ CONSTANTS(:,48).*power(CONSTANTS(:,44), 2.00000)))./( CONSTANTS(:,41).*( CONSTANTS(:,49).*power(ALGEBRAIC(:,45), 2.00000)+ CONSTANTS(:,48).*power(CONSTANTS(:,44), 2.00000)));
    ALGEBRAIC(:,42) = ( CONSTANTS(:,43).*CONSTANTS(:,49).*(power(STATES(:,13), 2.00000)+ CONSTANTS(:,48).*power(CONSTANTS(:,44), 2.00000)))./( CONSTANTS(:,41).*( CONSTANTS(:,49).*power(STATES(:,13), 2.00000)+ CONSTANTS(:,48).*power(CONSTANTS(:,44), 2.00000)));
    ALGEBRAIC(:,60) = ( ALGEBRAIC(:,37).*ALGEBRAIC(:,48)+ CONSTANTS(:,70).*ALGEBRAIC(:,42))./(ALGEBRAIC(:,37)+CONSTANTS(:,70));
    ALGEBRAIC(:,43) = (STATES(:,13)+ (CONSTANTS(:,32)./CONSTANTS(:,31)).*STATES(:,14))./(1.00000+CONSTANTS(:,32)./CONSTANTS(:,31));
    ALGEBRAIC(:,44) = ( ALGEBRAIC(:,43).*(ALGEBRAIC(:,36)+CONSTANTS(:,46)))./( CONSTANTS(:,39).*CONSTANTS(:,45).*(ALGEBRAIC(:,36)+1.00000));
    ALGEBRAIC(:,39) = ( STATES(:,13).*(ALGEBRAIC(:,36)+CONSTANTS(:,46)))./( CONSTANTS(:,39).*CONSTANTS(:,45).*(ALGEBRAIC(:,36)+1.00000));
    ALGEBRAIC(:,55) = ( CONSTANTS(:,70).*( ALGEBRAIC(:,38).*(CONSTANTS(:,70)+CONSTANTS(:,71)+ALGEBRAIC(:,46))+ ALGEBRAIC(:,46).*ALGEBRAIC(:,37)))./ALGEBRAIC(:,53);
    ALGEBRAIC(:,66) =  ALGEBRAIC(:,55).*ALGEBRAIC(:,44)+ ALGEBRAIC(:,57).*ALGEBRAIC(:,39);
    ALGEBRAIC(:,40) = ( CONSTANTS(:,47).*(ALGEBRAIC(:,36)+CONSTANTS(:,46)))./( CONSTANTS(:,39).*( CONSTANTS(:,47).*ALGEBRAIC(:,36)+CONSTANTS(:,46)));
    ALGEBRAIC(:,68) = ALGEBRAIC(:,40);
    ALGEBRAIC(:,70) = ( CONSTANTS(:,70).*ALGEBRAIC(:,39))./(ALGEBRAIC(:,37)+CONSTANTS(:,70));
    ALGEBRAIC(:,72) = ALGEBRAIC(:,40);
    ALGEBRAIC(:,74) = ((1.00000 - STATES(:,15)) - STATES(:,16)) - STATES(:,17);
    ALGEBRAIC(:,62) = ( CONSTANTS(:,71).*ALGEBRAIC(:,41))./(CONSTANTS(:,71)+ALGEBRAIC(:,38));
    ALGEBRAIC(:,64) = ALGEBRAIC(:,42);
    ALGEBRAIC(:,22) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,12)./STATES(:,2));
    ALGEBRAIC(:,23) =  CONSTANTS(:,11).*power(STATES(:,3), 3.00000).*STATES(:,4).*STATES(:,5).*(STATES(:,1) - ALGEBRAIC(:,22));
    ALGEBRAIC(:,31) =  CONSTANTS(:,21).*(STATES(:,1) - ALGEBRAIC(:,22));
    ALGEBRAIC(:,75) = ( CONSTANTS(:,54).*( exp( CONSTANTS(:,52).*ALGEBRAIC(:,1)).*power(STATES(:,2), 3.00000).*CONSTANTS(:,30) -  exp( (CONSTANTS(:,52) - 1.00000).*ALGEBRAIC(:,1)).*power(CONSTANTS(:,12), 3.00000).*STATES(:,13)))./( (power(CONSTANTS(:,12), 3.00000)+power(CONSTANTS(:,50), 3.00000)).*(CONSTANTS(:,30)+CONSTANTS(:,51)).*(1.00000+ CONSTANTS(:,53).*exp( (CONSTANTS(:,52) - 1.00000).*ALGEBRAIC(:,1))));
    ALGEBRAIC(:,76) =  ALGEBRAIC(:,75).*CONSTANTS(:,3).*CONSTANTS(:,9);
    ALGEBRAIC(:,28) =  CONSTANTS(:,19).*STATES(:,12).*CONSTANTS(:,20).*(STATES(:,1) - ALGEBRAIC(:,22));
    ALGEBRAIC(:,30) = ALGEBRAIC(:,28)+ALGEBRAIC(:,29);
    ALGEBRAIC(:,78) = ( CONSTANTS(:,57).*STATES(:,13))./(CONSTANTS(:,58)+STATES(:,13));
    ALGEBRAIC(:,79) =  ALGEBRAIC(:,78).*2.00000.*CONSTANTS(:,3).*CONSTANTS(:,9);
    ALGEBRAIC(:,52) = piecewise({abs(ALGEBRAIC(:,20))>1.00000e-05, ( (( CONSTANTS(:,33).*ALGEBRAIC(:,20))./(1.00000 - exp( - ALGEBRAIC(:,20)))).*(( CONSTANTS(:,30).*exp( - ALGEBRAIC(:,20)) - STATES(:,13))+ (CONSTANTS(:,32)./CONSTANTS(:,31)).*( CONSTANTS(:,30).*exp( - ALGEBRAIC(:,20)) - STATES(:,14))))./(1.00000+CONSTANTS(:,32)./CONSTANTS(:,31)+( (CONSTANTS(:,33)./CONSTANTS(:,31)).*ALGEBRAIC(:,20))./(1.00000 - exp(ALGEBRAIC(:,20)))) }, ( (( CONSTANTS(:,33).*1.00000e-05)./(1.00000 - exp( - 1.00000e-05))).*(( CONSTANTS(:,30).*exp( - 1.00000e-05) - STATES(:,13))+ (CONSTANTS(:,32)./CONSTANTS(:,31)).*( CONSTANTS(:,30).*exp( - 1.00000e-05) - STATES(:,14))))./(1.00000+CONSTANTS(:,32)./CONSTANTS(:,31)+( (CONSTANTS(:,33)./CONSTANTS(:,31)).*1.00000e-05)./(1.00000 - exp( - 1.00000e-05))));
    ALGEBRAIC(:,51) = piecewise({abs(ALGEBRAIC(:,20))>1.00000e-05, ( (( CONSTANTS(:,33).*ALGEBRAIC(:,20))./(1.00000 - exp( - ALGEBRAIC(:,20)))).*( CONSTANTS(:,30).*exp( - ALGEBRAIC(:,20)) - STATES(:,13)))./(1.00000+( (CONSTANTS(:,33)./CONSTANTS(:,31)).*ALGEBRAIC(:,20))./(1.00000 - exp( - ALGEBRAIC(:,20)))) }, ( (( CONSTANTS(:,33).*1.00000e-05)./(1.00000 - exp( - 1.00000e-05))).*( CONSTANTS(:,30).*exp( - 1.00000e-05) - STATES(:,13)))./(1.00000+( (CONSTANTS(:,33)./CONSTANTS(:,31)).*1.00000e-05)./(1.00000 - exp( - 1.00000e-05))));
    ALGEBRAIC(:,56) = ( ALGEBRAIC(:,37).*( ALGEBRAIC(:,46).*(ALGEBRAIC(:,37)+CONSTANTS(:,71)+ALGEBRAIC(:,38))+ ALGEBRAIC(:,38).*CONSTANTS(:,70)))./ALGEBRAIC(:,53);
    ALGEBRAIC(:,67) =  ALGEBRAIC(:,52).*ALGEBRAIC(:,56)+ ALGEBRAIC(:,51).*ALGEBRAIC(:,54);
    ALGEBRAIC(:,69) = ( ALGEBRAIC(:,51).*ALGEBRAIC(:,37))./(ALGEBRAIC(:,37)+CONSTANTS(:,70));
    ALGEBRAIC(:,71) = ( ( STATES(:,15).*ALGEBRAIC(:,67)+ STATES(:,16).*ALGEBRAIC(:,69)).*CONSTANTS(:,34))./CONSTANTS(:,8);
    ALGEBRAIC(:,73) =   - ALGEBRAIC(:,71).*2.00000.*CONSTANTS(:,3).*CONSTANTS(:,9);
    ALGEBRAIC(:,80) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./( 2.00000.*CONSTANTS(:,3))).*log(CONSTANTS(:,30)./STATES(:,13));
    ALGEBRAIC(:,81) =  CONSTANTS(:,59).*(ALGEBRAIC(:,80) - STATES(:,1));
    ALGEBRAIC(:,82) =   - ALGEBRAIC(:,81).*2.00000.*CONSTANTS(:,3).*CONSTANTS(:,9);
    ALGEBRAIC(:,49) = ( CONSTANTS(:,32).*(STATES(:,14) - STATES(:,13)))./(1.00000+CONSTANTS(:,32)./CONSTANTS(:,31));
    ALGEBRAIC(:,50) = piecewise({abs(ALGEBRAIC(:,20))>1.00000e-05, ( CONSTANTS(:,32).*((STATES(:,14) - STATES(:,13))+ (( (CONSTANTS(:,33)./CONSTANTS(:,31)).*ALGEBRAIC(:,20))./(1.00000 - exp( - ALGEBRAIC(:,20)))).*(STATES(:,14) -  CONSTANTS(:,30).*exp( - ALGEBRAIC(:,20)))))./(1.00000+CONSTANTS(:,32)./CONSTANTS(:,31)+( (CONSTANTS(:,33)./CONSTANTS(:,31)).*ALGEBRAIC(:,20))./(1.00000 - exp( - ALGEBRAIC(:,20)))) }, ( CONSTANTS(:,32).*((STATES(:,14) - STATES(:,13))+ (( (CONSTANTS(:,33)./CONSTANTS(:,31)).*1.00000e-05)./(1.00000 - exp( - 1.00000e-05))).*(STATES(:,14) -  CONSTANTS(:,30).*exp( - 1.00000e-05))))./(1.00000+CONSTANTS(:,32)./CONSTANTS(:,31)+( (CONSTANTS(:,33)./CONSTANTS(:,31)).*1.00000e-05)./(1.00000 - exp( - 1.00000e-05))));
    ALGEBRAIC(:,59) =  ALGEBRAIC(:,56).*ALGEBRAIC(:,50)+ ALGEBRAIC(:,49).*ALGEBRAIC(:,55);
    ALGEBRAIC(:,61) = ( ALGEBRAIC(:,49).*ALGEBRAIC(:,38))./(CONSTANTS(:,71)+ALGEBRAIC(:,38));
    ALGEBRAIC(:,63) = ( ( STATES(:,15).*ALGEBRAIC(:,59)+ STATES(:,17).*ALGEBRAIC(:,61)).*CONSTANTS(:,34))./CONSTANTS(:,8);
    ALGEBRAIC(:,65) = ALGEBRAIC(:,63);
    ALGEBRAIC(:,77) = ( CONSTANTS(:,55).*power(STATES(:,13), 2.00000))./(power(CONSTANTS(:,56), 2.00000)+power(STATES(:,13), 2.00000));
    ALGEBRAIC(:,83) =  CONSTANTS(:,60).*(STATES(:,14) - STATES(:,13));
    ALGEBRAIC(:,84) =  CONSTANTS(:,61).*(CONSTANTS(:,63) - STATES(:,18)) -  CONSTANTS(:,62).*STATES(:,18).*STATES(:,13);
    ALGEBRAIC(:,85) = power(1.00000+( CONSTANTS(:,64).*CONSTANTS(:,65))./power(CONSTANTS(:,64)+STATES(:,13), 2.00000)+( CONSTANTS(:,66).*CONSTANTS(:,67))./power(CONSTANTS(:,67)+STATES(:,13), 2.00000),  - 1.00000);
    ALGEBRAIC(:,11) = STATES(:,13);
    ALGEBRAIC(:,33) = ALGEBRAIC(:,31)+ALGEBRAIC(:,32);
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