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 =115;
end
% There are a total of 30 entries in each of the rate and state variable arrays.
% There are a total of 83 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 (millisecond)');
    LEGEND_STATES(:,1) = strpad('V in component membrane (millivolt)');
    LEGEND_ALGEBRAIC(:,1) = strpad('i_stim in component membrane (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,93) = strpad('i_tot in component membrane (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,58) = strpad('i_Na in component i_Na (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,59) = strpad('i_Na_L in component i_Na_L (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,61) = strpad('i_Ca_L in component i_Ca_L (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,65) = strpad('i_Ca_T in component i_Ca_T (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,68) = strpad('i_to_1 in component i_to_1 (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,80) = strpad('i_to_2 in component i_to_2 (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,70) = strpad('i_Kr in component i_Kr (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,72) = strpad('i_Ks in component i_Ks (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,76) = strpad('i_K1 in component i_K1 (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,83) = strpad('i_NaCa in component i_NaCa (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,85) = strpad('i_NaK in component i_NaK (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,89) = strpad('i_Na_b in component background_currents (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,92) = strpad('i_Ca_b in component background_currents (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,90) = strpad('i_K_b in component background_currents (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,91) = strpad('i_Cl_b in component background_currents (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,86) = strpad('i_Ca_p in component i_Ca_p (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,78) = strpad('i_K_p in component i_K_p (microA_per_microF)');
    LEGEND_CONSTANTS(:,1) = strpad('stim_start in component membrane (millisecond)');
    LEGEND_CONSTANTS(:,2) = strpad('stim_end in component membrane (millisecond)');
    LEGEND_CONSTANTS(:,3) = strpad('stim_amplitude in component membrane (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,20) = strpad('E_Na in component equilibrium_potentials (millivolt)');
    LEGEND_ALGEBRAIC(:,37) = strpad('E_K in component equilibrium_potentials (millivolt)');
    LEGEND_ALGEBRAIC(:,2) = strpad('E_Ca in component equilibrium_potentials (millivolt)');
    LEGEND_ALGEBRAIC(:,47) = strpad('E_Cl in component equilibrium_potentials (millivolt)');
    LEGEND_ALGEBRAIC(:,57) = strpad('E_Ks in component equilibrium_potentials (millivolt)');
    LEGEND_CONSTANTS(:,4) = strpad('r_NaK in component equilibrium_potentials (dimensionless)');
    LEGEND_STATES(:,2) = strpad('Na_i in component intracellular_ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,5) = strpad('Na_o in component model_parameters (millimolar)');
    LEGEND_STATES(:,3) = strpad('Ca_i in component Ca_i (millimolar)');
    LEGEND_CONSTANTS(:,6) = strpad('Ca_o in component model_parameters (millimolar)');
    LEGEND_STATES(:,4) = strpad('K_i in component intracellular_ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,7) = strpad('K_o in component model_parameters (millimolar)');
    LEGEND_STATES(:,5) = strpad('Cl_i in component intracellular_ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,8) = strpad('Cl_o in component model_parameters (millimolar)');
    LEGEND_CONSTANTS(:,9) = strpad('R in component model_parameters (joule_per_kilomole_kelvin)');
    LEGEND_CONSTANTS(:,10) = strpad('F in component model_parameters (coulomb_per_mole)');
    LEGEND_CONSTANTS(:,11) = strpad('T in component model_parameters (kelvin)');
    LEGEND_CONSTANTS(:,12) = strpad('g_Na in component i_Na (milliS_per_microF)');
    LEGEND_STATES(:,6) = strpad('m in component i_Na_m_gate (dimensionless)');
    LEGEND_STATES(:,7) = strpad('h in component i_Na_h_gate (dimensionless)');
    LEGEND_STATES(:,8) = strpad('j in component i_Na_j_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,48) = strpad('tau_m in component i_Na_m_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,38) = strpad('m_infinity in component i_Na_m_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,3) = strpad('alpha_m in component i_Na_m_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,21) = strpad('beta_m in component i_Na_m_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,49) = strpad('tau_h in component i_Na_h_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,39) = strpad('h_infinity in component i_Na_h_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,4) = strpad('alpha_h in component i_Na_h_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,22) = strpad('beta_h in component i_Na_h_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,50) = strpad('tau_j in component i_Na_j_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,40) = strpad('j_infinity in component i_Na_j_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,5) = strpad('alpha_j in component i_Na_j_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,23) = strpad('beta_j in component i_Na_j_gate (per_millisecond)');
    LEGEND_CONSTANTS(:,13) = strpad('g_Na_L in component i_Na_L (milliS_per_microF)');
    LEGEND_STATES(:,9) = strpad('m_L in component i_Na_L_m_L_gate (dimensionless)');
    LEGEND_STATES(:,10) = strpad('h_L in component i_Na_L_h_L_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,51) = strpad('tau_m_L in component i_Na_L_m_L_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,41) = strpad('m_L_infinity in component i_Na_L_m_L_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,6) = strpad('alpha_m_L in component i_Na_L_m_L_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,24) = strpad('beta_m_L in component i_Na_L_m_L_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,25) = strpad('tau_h_L in component i_Na_L_h_L_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,7) = strpad('h_L_infinity in component i_Na_L_h_L_gate (dimensionless)');
    LEGEND_CONSTANTS(:,14) = strpad('g_Ca_L in component i_Ca_L (dimensionless)');
    LEGEND_ALGEBRAIC(:,60) = strpad('i_Ca_L_max in component i_Ca_L (microA_per_microF)');
    LEGEND_CONSTANTS(:,15) = strpad('p_Ca in component i_Ca_L (cm_per_second)');
    LEGEND_CONSTANTS(:,16) = strpad('z_Ca in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,17) = strpad('gamma_Cai in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,18) = strpad('gamma_Cao in component model_parameters (dimensionless)');
    LEGEND_STATES(:,11) = strpad('Ca_r in component Ca_r (millimolar)');
    LEGEND_ALGEBRAIC(:,98) = strpad('Ca_MK_act in component Ca_MK_act (dimensionless)');
    LEGEND_CONSTANTS(:,19) = strpad('km_Ca_MK in component Ca_MK_act (millimolar)');
    LEGEND_STATES(:,12) = strpad('d in component i_Ca_L_d_gate (dimensionless)');
    LEGEND_STATES(:,13) = strpad('f in component i_Ca_L_f_gate (dimensionless)');
    LEGEND_STATES(:,14) = strpad('f2 in component i_Ca_L_f2_gate (dimensionless)');
    LEGEND_STATES(:,15) = strpad('f_Ca in component i_Ca_L_f_Ca_gate (dimensionless)');
    LEGEND_STATES(:,16) = strpad('f_Ca2 in component i_Ca_L_f_Ca2_gate (dimensionless)');
    LEGEND_CONSTANTS(:,20) = strpad('Cm in component model_parameters (microF_per_cm2)');
    LEGEND_ALGEBRAIC(:,8) = strpad('d_infinity in component i_Ca_L_d_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,26) = strpad('tau_d in component i_Ca_L_d_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,9) = strpad('f_infinity in component i_Ca_L_f_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,27) = strpad('tau_f in component i_Ca_L_f_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,10) = strpad('f2_infinity in component i_Ca_L_f2_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,28) = strpad('tau_f2 in component i_Ca_L_f2_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,62) = strpad('f_Ca_infinity in component i_Ca_L_f_Ca_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,99) = strpad('tau_f_Ca in component i_Ca_L_f_Ca_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,63) = strpad('f_Ca2_infinity in component i_Ca_L_f_Ca2_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,66) = strpad('tau_f_Ca2 in component i_Ca_L_f_Ca2_gate (millisecond)');
    LEGEND_CONSTANTS(:,21) = strpad('g_Ca_T in component i_Ca_T (milliS_per_microF)');
    LEGEND_STATES(:,17) = strpad('b in component i_Ca_T_b_gate (dimensionless)');
    LEGEND_STATES(:,18) = strpad('g in component i_Ca_T_g_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,52) = strpad('tau_b in component i_Ca_T_b_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,42) = strpad('b_infinity in component i_Ca_T_b_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,11) = strpad('alpha_b in component i_Ca_T_b_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,29) = strpad('beta_b in component i_Ca_T_b_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,53) = strpad('tau_g in component i_Ca_T_g_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,43) = strpad('g_infinity in component i_Ca_T_g_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,12) = strpad('alpha_g in component i_Ca_T_g_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,30) = strpad('beta_g in component i_Ca_T_g_gate (per_millisecond)');
    LEGEND_CONSTANTS(:,22) = strpad('g_to_1 in component i_to_1 (milliS_per_microF)');
    LEGEND_STATES(:,19) = strpad('a in component i_to_1_a_gate (dimensionless)');
    LEGEND_STATES(:,20) = strpad('i in component i_to_1_i_gate (dimensionless)');
    LEGEND_STATES(:,21) = strpad('i2 in component i_to_1_i2_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,13) = strpad('alpha_a in component i_to_1_a_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,31) = strpad('beta_a in component i_to_1_a_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,44) = strpad('tau_a in component i_to_1_a_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,54) = strpad('a_infinity in component i_to_1_a_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,14) = strpad('alpha_i in component i_to_1_i_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,32) = strpad('beta_i in component i_to_1_i_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,45) = strpad('tau_i in component i_to_1_i_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,55) = strpad('i_infinity in component i_to_1_i_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,15) = strpad('alpha_i2 in component i_to_1_i2_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,33) = strpad('beta_i2 in component i_to_1_i2_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,46) = strpad('tau_i2 in component i_to_1_i2_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,56) = strpad('i2_infinity in component i_to_1_i2_gate (dimensionless)');
    LEGEND_CONSTANTS(:,75) = strpad('g_Kr in component i_Kr (milliS_per_microF)');
    LEGEND_ALGEBRAIC(:,69) = strpad('rr_infinity in component i_Kr (dimensionless)');
    LEGEND_STATES(:,22) = strpad('xr in component i_Kr_xr_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,16) = strpad('tau_xr in component i_Kr_xr_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,34) = strpad('xr_infinity in component i_Kr_xr_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,71) = strpad('g_Ks in component i_Ks (milliS_per_microF)');
    LEGEND_STATES(:,23) = strpad('xs1 in component i_Ks_xs1_gate (dimensionless)');
    LEGEND_STATES(:,24) = strpad('xs2 in component i_Ks_xs2_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,17) = strpad('tau_xs1 in component i_Ks_xs1_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,35) = strpad('xs1_infinity in component i_Ks_xs1_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,18) = strpad('tau_xs2 in component i_Ks_xs2_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,36) = strpad('xs2_infinity in component i_Ks_xs2_gate (dimensionless)');
    LEGEND_CONSTANTS(:,76) = strpad('g_K1 in component i_K1 (milliS_per_microF)');
    LEGEND_ALGEBRAIC(:,75) = strpad('xK1 in component i_K1_xK1_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,74) = strpad('alpha_xK1 in component i_K1_xK1_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,73) = strpad('beta_xK1 in component i_K1_xK1_gate (dimensionless)');
    LEGEND_CONSTANTS(:,23) = strpad('g_K_p in component i_K_p (milliS_per_microF)');
    LEGEND_ALGEBRAIC(:,77) = strpad('kp in component i_K_p (dimensionless)');
    LEGEND_CONSTANTS(:,24) = strpad('p_Cl in component i_to_2 (cm_per_second)');
    LEGEND_CONSTANTS(:,25) = strpad('z_Cl in component i_to_2 (dimensionless)');
    LEGEND_ALGEBRAIC(:,79) = strpad('i_to_2_max in component i_to_2 (microA_per_microF)');
    LEGEND_STATES(:,25) = strpad('a in component i_to_2_a_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,19) = strpad('a_infinity in component i_to_2_a_gate (dimensionless)');
    LEGEND_CONSTANTS(:,77) = strpad('tau_a in component i_to_2_a_gate (millisecond)');
    LEGEND_CONSTANTS(:,26) = strpad('km_to_2 in component i_to_2_a_gate (millimolar)');
    LEGEND_CONSTANTS(:,27) = strpad('X_NaCa in component i_NaCa (dimensionless)');
    LEGEND_CONSTANTS(:,28) = strpad('i_NaCa_max in component i_NaCa (microA_per_microF)');
    LEGEND_CONSTANTS(:,29) = strpad('km_Na_i_1 in component i_NaCa (millimolar)');
    LEGEND_CONSTANTS(:,30) = strpad('km_Na_o in component i_NaCa (millimolar)');
    LEGEND_CONSTANTS(:,31) = strpad('km_Ca_i in component i_NaCa (millimolar)');
    LEGEND_CONSTANTS(:,32) = strpad('km_Ca_o in component i_NaCa (millimolar)');
    LEGEND_CONSTANTS(:,33) = strpad('km_Ca_act in component i_NaCa (millimolar)');
    LEGEND_CONSTANTS(:,34) = strpad('k_sat in component i_NaCa (dimensionless)');
    LEGEND_ALGEBRAIC(:,81) = strpad('dNaCa_1 in component i_NaCa (millimolar4)');
    LEGEND_ALGEBRAIC(:,82) = strpad('dNaCa_2 in component i_NaCa (millimolar4)');
    LEGEND_CONSTANTS(:,35) = strpad('g_NaK in component i_NaK (microA_per_microF)');
    LEGEND_CONSTANTS(:,36) = strpad('km_Na_i_2 in component i_NaK (millimolar)');
    LEGEND_CONSTANTS(:,37) = strpad('km_K_o in component i_NaK (millimolar)');
    LEGEND_ALGEBRAIC(:,84) = strpad('f_NaK in component i_NaK (dimensionless)');
    LEGEND_CONSTANTS(:,78) = strpad('sigma in component i_NaK (dimensionless)');
    LEGEND_CONSTANTS(:,38) = strpad('i_Ca_p_max in component i_Ca_p (microA_per_microF)');
    LEGEND_CONSTANTS(:,39) = strpad('km_Ca_p in component i_Ca_p (millimolar)');
    LEGEND_ALGEBRAIC(:,87) = strpad('CT_K_Cl in component CT_K_Cl (millimolar_per_millisecond)');
    LEGEND_CONSTANTS(:,40) = strpad('CT_K_Cl_max in component CT_K_Cl (millimolar_per_millisecond)');
    LEGEND_ALGEBRAIC(:,88) = strpad('CT_Na_Cl in component CT_Na_Cl (millimolar_per_millisecond)');
    LEGEND_CONSTANTS(:,41) = strpad('CT_Na_Cl_max in component CT_Na_Cl (millimolar_per_millisecond)');
    LEGEND_CONSTANTS(:,42) = strpad('g_Na_b in component background_currents (milliS_per_microF)');
    LEGEND_CONSTANTS(:,43) = strpad('g_K_b in component background_currents (milliS_per_microF)');
    LEGEND_CONSTANTS(:,44) = strpad('p_Ca_b in component background_currents (cm_per_second)');
    LEGEND_CONSTANTS(:,45) = strpad('g_Cl_b in component background_currents (milliS_per_microF)');
    LEGEND_CONSTANTS(:,80) = strpad('Vol_myo in component model_parameters (microlitre)');
    LEGEND_CONSTANTS(:,79) = strpad('a_cap in component model_parameters (cm2)');
    LEGEND_CONSTANTS(:,46) = strpad('km_TRPN in component Ca_i (millimolar)');
    LEGEND_CONSTANTS(:,47) = strpad('km_CMDN in component Ca_i (millimolar)');
    LEGEND_CONSTANTS(:,48) = strpad('TRPN_max in component Ca_i (millimolar)');
    LEGEND_CONSTANTS(:,49) = strpad('CMDN_max in component Ca_i (millimolar)');
    LEGEND_ALGEBRAIC(:,95) = strpad('TRPN in component Ca_i (dimensionless)');
    LEGEND_ALGEBRAIC(:,94) = strpad('CMDN in component Ca_i (dimensionless)');
    LEGEND_ALGEBRAIC(:,96) = strpad('b_myo in component Ca_i (dimensionless)');
    LEGEND_CONSTANTS(:,81) = strpad('Vol_nsr in component model_parameters (microlitre)');
    LEGEND_CONSTANTS(:,83) = strpad('Vol_ss in component model_parameters (microlitre)');
    LEGEND_ALGEBRAIC(:,114) = strpad('q_up in component q_up (millimolar_per_millisecond)');
    LEGEND_ALGEBRAIC(:,111) = strpad('q_leak in component q_leak (millimolar_per_millisecond)');
    LEGEND_ALGEBRAIC(:,100) = strpad('q_diff in component Ca_r (millimolar_per_millisecond)');
    LEGEND_STATES(:,26) = strpad('Ca_MK_trap in component Ca_MK_act (dimensionless)');
    LEGEND_ALGEBRAIC(:,97) = strpad('Ca_MK_bound in component Ca_MK_act (dimensionless)');
    LEGEND_CONSTANTS(:,50) = strpad('alpha_Ca_MK in component Ca_MK_act (per_millisecond)');
    LEGEND_CONSTANTS(:,51) = strpad('beta_Ca_MK in component Ca_MK_act (per_millisecond)');
    LEGEND_CONSTANTS(:,52) = strpad('Ca_MK_0 in component Ca_MK_act (dimensionless)');
    LEGEND_STATES(:,27) = strpad('Ca_NSR in component Ca_NSR (millimolar)');
    LEGEND_CONSTANTS(:,82) = strpad('Vol_jsr in component model_parameters (microlitre)');
    LEGEND_ALGEBRAIC(:,115) = strpad('q_tr in component q_tr (millimolar_per_millisecond)');
    LEGEND_STATES(:,28) = strpad('Ca_JSR in component Ca_JSR (millimolar)');
    LEGEND_CONSTANTS(:,53) = strpad('CSQN_max in component Ca_JSR (millimolar)');
    LEGEND_CONSTANTS(:,54) = strpad('km_CSQN in component Ca_JSR (millimolar)');
    LEGEND_ALGEBRAIC(:,110) = strpad('q_rel in component q_rel (millimolar_per_millisecond)');
    LEGEND_CONSTANTS(:,55) = strpad('km_b_SR in component Ca_r (millimolar)');
    LEGEND_CONSTANTS(:,56) = strpad('km_b_SL in component Ca_r (millimolar)');
    LEGEND_CONSTANTS(:,57) = strpad('b_SR_max in component Ca_r (millimolar)');
    LEGEND_CONSTANTS(:,58) = strpad('b_SL_max in component Ca_r (millimolar)');
    LEGEND_CONSTANTS(:,59) = strpad('tau_ss in component Ca_r (millisecond)');
    LEGEND_ALGEBRAIC(:,104) = strpad('b_SR in component Ca_r (dimensionless)');
    LEGEND_ALGEBRAIC(:,102) = strpad('b_SL in component Ca_r (dimensionless)');
    LEGEND_ALGEBRAIC(:,106) = strpad('Ca_r_tot in component Ca_r (dimensionless)');
    LEGEND_ALGEBRAIC(:,109) = strpad('g_rel in component q_rel (per_millisecond)');
    LEGEND_ALGEBRAIC(:,108) = strpad('vg in component q_rel (dimensionless)');
    LEGEND_STATES(:,29) = strpad('ri in component q_rel_ri_gate (dimensionless)');
    LEGEND_STATES(:,30) = strpad('ro in component q_rel_ro_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,107) = strpad('tau_ri in component q_rel_ri_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,105) = strpad('tau_Ca_MK in component q_rel_ri_gate (millisecond)');
    LEGEND_CONSTANTS(:,60) = strpad('tau_Ca_MK_max in component q_rel_ri_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,101) = strpad('Ca_fac in component q_rel_ri_gate (millimolar)');
    LEGEND_ALGEBRAIC(:,103) = strpad('ri_infinity in component q_rel_ri_gate (dimensionless)');
    LEGEND_CONSTANTS(:,61) = strpad('tau_ro in component q_rel_ro_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,67) = strpad('ro_infinity in component q_rel_ro_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,64) = strpad('ro_infinity_JSR in component q_rel_ro_gate (dimensionless)');
    LEGEND_CONSTANTS(:,62) = strpad('q_leak_max in component q_leak (millimolar_per_millisecond)');
    LEGEND_CONSTANTS(:,63) = strpad('NSR_max in component q_leak (millimolar)');
    LEGEND_CONSTANTS(:,64) = strpad('X_q_up in component q_up (dimensionless)');
    LEGEND_CONSTANTS(:,65) = strpad('q_up_max in component q_up (millimolar_per_millisecond)');
    LEGEND_ALGEBRAIC(:,112) = strpad('dq_up_Ca_MK in component q_up (dimensionless)');
    LEGEND_CONSTANTS(:,66) = strpad('dq_up_Ca_MK_max in component q_up (dimensionless)');
    LEGEND_ALGEBRAIC(:,113) = strpad('dkm_plb in component q_up (millimolar)');
    LEGEND_CONSTANTS(:,67) = strpad('dkm_plb_max in component q_up (millimolar)');
    LEGEND_CONSTANTS(:,68) = strpad('km_up in component q_up (millimolar)');
    LEGEND_CONSTANTS(:,69) = strpad('tau_tr in component q_tr (millisecond)');
    LEGEND_CONSTANTS(:,70) = strpad('Vol_cell in component model_parameters (microlitre)');
    LEGEND_CONSTANTS(:,74) = strpad('a_geo in component model_parameters (cm2)');
    LEGEND_CONSTANTS(:,71) = strpad('radius in component model_parameters (cm)');
    LEGEND_CONSTANTS(:,72) = strpad('length in component model_parameters (cm)');
    LEGEND_CONSTANTS(:,73) = strpad('rcg in component model_parameters (dimensionless)');
    LEGEND_RATES(:,1) = strpad('d/dt V in component membrane (millivolt)');
    LEGEND_RATES(:,6) = strpad('d/dt m in component i_Na_m_gate (dimensionless)');
    LEGEND_RATES(:,7) = strpad('d/dt h in component i_Na_h_gate (dimensionless)');
    LEGEND_RATES(:,8) = strpad('d/dt j in component i_Na_j_gate (dimensionless)');
    LEGEND_RATES(:,9) = strpad('d/dt m_L in component i_Na_L_m_L_gate (dimensionless)');
    LEGEND_RATES(:,10) = strpad('d/dt h_L in component i_Na_L_h_L_gate (dimensionless)');
    LEGEND_RATES(:,12) = strpad('d/dt d in component i_Ca_L_d_gate (dimensionless)');
    LEGEND_RATES(:,13) = strpad('d/dt f in component i_Ca_L_f_gate (dimensionless)');
    LEGEND_RATES(:,14) = strpad('d/dt f2 in component i_Ca_L_f2_gate (dimensionless)');
    LEGEND_RATES(:,15) = strpad('d/dt f_Ca in component i_Ca_L_f_Ca_gate (dimensionless)');
    LEGEND_RATES(:,16) = strpad('d/dt f_Ca2 in component i_Ca_L_f_Ca2_gate (dimensionless)');
    LEGEND_RATES(:,17) = strpad('d/dt b in component i_Ca_T_b_gate (dimensionless)');
    LEGEND_RATES(:,18) = strpad('d/dt g in component i_Ca_T_g_gate (dimensionless)');
    LEGEND_RATES(:,19) = strpad('d/dt a in component i_to_1_a_gate (dimensionless)');
    LEGEND_RATES(:,20) = strpad('d/dt i in component i_to_1_i_gate (dimensionless)');
    LEGEND_RATES(:,21) = strpad('d/dt i2 in component i_to_1_i2_gate (dimensionless)');
    LEGEND_RATES(:,22) = strpad('d/dt xr in component i_Kr_xr_gate (dimensionless)');
    LEGEND_RATES(:,23) = strpad('d/dt xs1 in component i_Ks_xs1_gate (dimensionless)');
    LEGEND_RATES(:,24) = strpad('d/dt xs2 in component i_Ks_xs2_gate (dimensionless)');
    LEGEND_RATES(:,25) = strpad('d/dt a in component i_to_2_a_gate (dimensionless)');
    LEGEND_RATES(:,2) = strpad('d/dt Na_i in component intracellular_ion_concentrations (millimolar)');
    LEGEND_RATES(:,4) = strpad('d/dt K_i in component intracellular_ion_concentrations (millimolar)');
    LEGEND_RATES(:,5) = strpad('d/dt Cl_i in component intracellular_ion_concentrations (millimolar)');
    LEGEND_RATES(:,3) = strpad('d/dt Ca_i in component Ca_i (millimolar)');
    LEGEND_RATES(:,26) = strpad('d/dt Ca_MK_trap in component Ca_MK_act (dimensionless)');
    LEGEND_RATES(:,27) = strpad('d/dt Ca_NSR in component Ca_NSR (millimolar)');
    LEGEND_RATES(:,28) = strpad('d/dt Ca_JSR in component Ca_JSR (millimolar)');
    LEGEND_RATES(:,11) = strpad('d/dt Ca_r in component Ca_r (millimolar)');
    LEGEND_RATES(:,29) = strpad('d/dt ri in component q_rel_ri_gate (dimensionless)');
    LEGEND_RATES(:,30) = strpad('d/dt ro in component q_rel_ro_gate (dimensionless)');
    LEGEND_STATES  = LEGEND_STATES';
    LEGEND_ALGEBRAIC = LEGEND_ALGEBRAIC';
    LEGEND_RATES = LEGEND_RATES';
    LEGEND_CONSTANTS = LEGEND_CONSTANTS';
end

function [STATES, CONSTANTS] = initConsts()
    VOI = 0; CONSTANTS = []; STATES = []; ALGEBRAIC = [];
    STATES(:,1) = -83.43812846286808;
    CONSTANTS(:,1) = 0;
    CONSTANTS(:,2) = 1;
    CONSTANTS(:,3) = -80;
    CONSTANTS(:,4) = 0.01833;
    STATES(:,2) = 9.927155552932733;
    CONSTANTS(:,5) = 140;
    STATES(:,3) = 0.00022355433459434943;
    CONSTANTS(:,6) = 1.8;
    STATES(:,4) = 141.9670801746057;
    CONSTANTS(:,7) = 5.4;
    STATES(:,5) = 18.904682470140408;
    CONSTANTS(:,8) = 100;
    CONSTANTS(:,9) = 8314;
    CONSTANTS(:,10) = 96485;
    CONSTANTS(:,11) = 310;
    CONSTANTS(:,12) = 8;
    STATES(:,6) = 0.002003390432234504;
    STATES(:,7) = 0.9786390933308567;
    STATES(:,8) = 0.09866447258167589;
    CONSTANTS(:,13) = 0.037375;
    STATES(:,9) = 0.002003390432234504;
    STATES(:,10) = 0.8946968372659203;
    CONSTANTS(:,14) = 0.3392328;
    CONSTANTS(:,15) = 0.000243;
    CONSTANTS(:,16) = 2;
    CONSTANTS(:,17) = 1;
    CONSTANTS(:,18) = 0.341;
    STATES(:,11) = 0.00022418117117903934;
    CONSTANTS(:,19) = 0.15;
    STATES(:,12) = 0.000002322223865147363;
    STATES(:,13) = 0.9985607329462358;
    STATES(:,14) = 0.8173435436674658;
    STATES(:,15) = 0.9610551285529658;
    STATES(:,16) = 0.868690796671854;
    CONSTANTS(:,20) = 1;
    CONSTANTS(:,21) = 0.13;
    STATES(:,17) = 0.0002563937630984438;
    STATES(:,18) = 0.9720432601848331;
    CONSTANTS(:,22) = 0.14135944;
    STATES(:,19) = 0.0004238729429342389;
    STATES(:,20) = 0.9990935802459496;
    STATES(:,21) = 0.9777368439681764;
    STATES(:,22) = 0.07084939408222911;
    STATES(:,23) = 0.0011737654433043125;
    STATES(:,24) = 0.001179442867470093;
    CONSTANTS(:,23) = 0.00276;
    CONSTANTS(:,24) = 0.0000004;
    CONSTANTS(:,25) = -1;
    STATES(:,25) = 0.0014909437525000811;
    CONSTANTS(:,26) = 0.1502;
    CONSTANTS(:,27) = 0.4;
    CONSTANTS(:,28) = 4.5;
    CONSTANTS(:,29) = 12.3;
    CONSTANTS(:,30) = 87.5;
    CONSTANTS(:,31) = 0.0036;
    CONSTANTS(:,32) = 1.3;
    CONSTANTS(:,33) = 0.000125;
    CONSTANTS(:,34) = 0.27;
    CONSTANTS(:,35) = 0.61875;
    CONSTANTS(:,36) = 10;
    CONSTANTS(:,37) = 1.5;
    CONSTANTS(:,38) = 0.0575;
    CONSTANTS(:,39) = 0.0005;
    CONSTANTS(:,40) = 7.0756e-6;
    CONSTANTS(:,41) = 9.8443e-6;
    CONSTANTS(:,42) = 0.0025;
    CONSTANTS(:,43) = 0.005;
    CONSTANTS(:,44) = 1.995084e-7;
    CONSTANTS(:,45) = 0.000225;
    CONSTANTS(:,46) = 0.0005;
    CONSTANTS(:,47) = 0.00238;
    CONSTANTS(:,48) = 0.07;
    CONSTANTS(:,49) = 0.05;
    STATES(:,26) = 0.000008789168284782809;
    CONSTANTS(:,50) = 0.05;
    CONSTANTS(:,51) = 0.00068;
    CONSTANTS(:,52) = 0.05;
    STATES(:,27) = 1.2132524695849454;
    STATES(:,28) = 1.1433050636518596;
    CONSTANTS(:,53) = 10;
    CONSTANTS(:,54) = 0.8;
    CONSTANTS(:,55) = 0.00087;
    CONSTANTS(:,56) = 0.0087;
    CONSTANTS(:,57) = 0.047;
    CONSTANTS(:,58) = 1.124;
    CONSTANTS(:,59) = 0.2;
    STATES(:,29) = 0.7802870066567904;
    STATES(:,30) = 1.2785734760674763e-9;
    CONSTANTS(:,60) = 10;
    CONSTANTS(:,61) = 3;
    CONSTANTS(:,62) = 0.004375;
    CONSTANTS(:,63) = 15;
    CONSTANTS(:,64) = 0.5;
    CONSTANTS(:,65) = 0.004375;
    CONSTANTS(:,66) = 0.75;
    CONSTANTS(:,67) = 0.00017;
    CONSTANTS(:,68) = 0.00092;
    CONSTANTS(:,69) = 120;
    CONSTANTS(:,70) = 0.3454;
    CONSTANTS(:,71) = 0.0011;
    CONSTANTS(:,72) = 0.01;
    CONSTANTS(:,73) = 2;
    CONSTANTS(:,74) =  2.00000.*3.14000.*power(CONSTANTS(:,71), 2.00000)+ 2.00000.*3.14000.*CONSTANTS(:,71).*CONSTANTS(:,72);
    CONSTANTS(:,75) =  0.0400085.*power((CONSTANTS(:,7)./5.40000), 1.0 ./ 2);
    CONSTANTS(:,76) =  0.250000.*power((CONSTANTS(:,7)./5.40000), 1.0 ./ 2);
    CONSTANTS(:,77) = 1.00000;
    CONSTANTS(:,78) =  (1.00000./7.00000).*(exp(CONSTANTS(:,5)./67.3000) - 1.00000);
    CONSTANTS(:,79) =  CONSTANTS(:,73).*CONSTANTS(:,74);
    CONSTANTS(:,80) =  CONSTANTS(:,70).*0.680000;
    CONSTANTS(:,81) =  CONSTANTS(:,70).*0.0552000;
    CONSTANTS(:,82) =  CONSTANTS(:,70).*0.00480000;
    CONSTANTS(:,83) =  CONSTANTS(:,70).*0.0200000;
    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(:,19) = 1.00000./(1.00000+CONSTANTS(:,26)./STATES(:,11));
    RATES(:,25) = (ALGEBRAIC(:,19) - STATES(:,25))./CONSTANTS(:,77);
    ALGEBRAIC(:,25) = 175.000+125.000./(1.00000+exp( - (STATES(:,1)+25.0000)./6.00000));
    ALGEBRAIC(:,7) = 1.00000./(1.00000+exp((STATES(:,1)+69.0000)./6.10000));
    RATES(:,10) = (ALGEBRAIC(:,7) - STATES(:,10))./ALGEBRAIC(:,25);
    ALGEBRAIC(:,8) = 1.00000./(1.00000+exp( - (STATES(:,1) - 4.00000)./6.74000));
    ALGEBRAIC(:,26) = 0.590000+( 0.800000.*exp( 0.0520000.*(STATES(:,1)+13.0000)))./(1.00000+exp( 0.132000.*(STATES(:,1)+13.0000)));
    RATES(:,12) = (ALGEBRAIC(:,8) - STATES(:,12))./ALGEBRAIC(:,26);
    ALGEBRAIC(:,9) = 1.00000./(1.00000+exp((STATES(:,1)+18.0000)./10.0000));
    ALGEBRAIC(:,27) = 4.00000+ 0.00500000.*power(STATES(:,1) - 2.50000, 2.00000);
    RATES(:,13) = (ALGEBRAIC(:,9) - STATES(:,13))./ALGEBRAIC(:,27);
    ALGEBRAIC(:,10) = 1.00000./(1.00000+exp((STATES(:,1)+18.0000)./10.0000));
    ALGEBRAIC(:,28) = 38.0000+ 0.0700000.*power(STATES(:,1) - 18.6000, 2.00000);
    RATES(:,14) = (ALGEBRAIC(:,10) - STATES(:,14))./ALGEBRAIC(:,28);
    ALGEBRAIC(:,16) = 900.000./(1.00000+exp(STATES(:,1)./5.00000))+100.000;
    ALGEBRAIC(:,34) = 1.00000./(1.00000+exp( - (STATES(:,1)+0.0850000)./12.2500));
    RATES(:,22) = (ALGEBRAIC(:,34) - STATES(:,22))./ALGEBRAIC(:,16);
    ALGEBRAIC(:,17) = 1.00000./(( 7.61000e-05.*(STATES(:,1)+44.6000))./(1.00000 - exp(  - 9.97000.*(STATES(:,1)+44.6000)))+( 0.000360000.*(STATES(:,1) - 0.550000))./(exp( 0.128000.*(STATES(:,1) - 0.550000)) - 1.00000));
    ALGEBRAIC(:,35) = 1.00000./(1.00000+exp( - (STATES(:,1) - 9.00000)./13.7000));
    RATES(:,23) = (ALGEBRAIC(:,35) - STATES(:,23))./ALGEBRAIC(:,17);
    ALGEBRAIC(:,18) = ( 2.00000.*1.00000)./(( 7.61000e-05.*(STATES(:,1)+44.6000))./(1.00000 - exp(  - 9.97000.*(STATES(:,1)+44.6000)))+( 0.000360000.*(STATES(:,1) - 0.550000))./(exp( 0.128000.*(STATES(:,1) - 0.550000)) - 1.00000));
    ALGEBRAIC(:,36) = 1.00000./(1.00000+exp( - (STATES(:,1) - 9.00000)./13.7000));
    RATES(:,24) = (ALGEBRAIC(:,36) - STATES(:,24))./ALGEBRAIC(:,18);
    ALGEBRAIC(:,3) = ( 0.320000.*(STATES(:,1)+47.1300))./(1.00000 - exp(  - 0.100000.*(STATES(:,1)+47.1300)));
    ALGEBRAIC(:,21) =  0.0800000.*exp( - STATES(:,1)./11.0000);
    ALGEBRAIC(:,48) = 1.00000./(ALGEBRAIC(:,3)+ALGEBRAIC(:,21));
    ALGEBRAIC(:,38) = ALGEBRAIC(:,3)./(ALGEBRAIC(:,3)+ALGEBRAIC(:,21));
    RATES(:,6) = (ALGEBRAIC(:,38) - STATES(:,6))./ALGEBRAIC(:,48);
    ALGEBRAIC(:,4) = piecewise({STATES(:,1)< - 40.0000,  0.135000.*exp((STATES(:,1)+80.0000)./ - 6.80000) }, 0.00000);
    ALGEBRAIC(:,22) = piecewise({STATES(:,1)< - 40.0000,  3.56000.*exp( 0.0790000.*STATES(:,1))+ 310000..*exp( 0.350000.*STATES(:,1)) }, 1.00000./( 0.130000.*(1.00000+exp((STATES(:,1)+10.6600)./ - 11.1000))));
    ALGEBRAIC(:,49) = 1.00000./(ALGEBRAIC(:,4)+ALGEBRAIC(:,22));
    ALGEBRAIC(:,39) = ALGEBRAIC(:,4)./(ALGEBRAIC(:,4)+ALGEBRAIC(:,22));
    RATES(:,7) = (ALGEBRAIC(:,39) - STATES(:,7))./ALGEBRAIC(:,49);
    ALGEBRAIC(:,5) = piecewise({STATES(:,1)< - 40.0000, ( (  - 127140..*exp( 0.244400.*STATES(:,1)) -  3.47400e-05.*exp(  - 0.0439100.*STATES(:,1))).*(STATES(:,1)+37.7800))./(1.00000+exp( 0.311000.*(STATES(:,1)+79.2300))) }, 0.00000);
    ALGEBRAIC(:,23) = piecewise({STATES(:,1)< - 40.0000, ( 0.121200.*exp(  - 0.0105200.*STATES(:,1)))./(1.00000+exp(  - 0.137800.*(STATES(:,1)+40.1400))) }, ( 0.300000.*exp(  - 2.53500e-07.*STATES(:,1)))./(1.00000+exp(  - 0.100000.*(STATES(:,1)+32.0000))));
    ALGEBRAIC(:,50) = 0.100000./(ALGEBRAIC(:,5)+ALGEBRAIC(:,23));
    ALGEBRAIC(:,40) = ( 0.100000.*ALGEBRAIC(:,5))./(ALGEBRAIC(:,5)+ALGEBRAIC(:,23));
    RATES(:,8) = (ALGEBRAIC(:,40) - STATES(:,8))./ALGEBRAIC(:,50);
    ALGEBRAIC(:,6) = ( 0.320000.*(STATES(:,1)+47.1300))./(1.00000 - exp(  - 0.100000.*(STATES(:,1)+47.1300)));
    ALGEBRAIC(:,24) =  0.0800000.*exp( - STATES(:,1)./11.0000);
    ALGEBRAIC(:,51) = 1.00000./(ALGEBRAIC(:,6)+ALGEBRAIC(:,24));
    ALGEBRAIC(:,41) = ALGEBRAIC(:,6)./(ALGEBRAIC(:,6)+ALGEBRAIC(:,24));
    RATES(:,9) = (ALGEBRAIC(:,41) - STATES(:,9))./ALGEBRAIC(:,51);
    ALGEBRAIC(:,11) =  1.06800.*exp((STATES(:,1)+16.3000)./30.0000);
    ALGEBRAIC(:,29) =  1.06800.*exp( - (STATES(:,1)+16.3000)./30.0000);
    ALGEBRAIC(:,52) = 1.00000./(ALGEBRAIC(:,11)+ALGEBRAIC(:,29));
    ALGEBRAIC(:,42) = 1.00000./(1.00000+exp( - (STATES(:,1)+33.0000)./6.10000));
    RATES(:,17) = (ALGEBRAIC(:,42) - STATES(:,17))./ALGEBRAIC(:,52);
    ALGEBRAIC(:,12) =  0.0150000.*exp( - (STATES(:,1)+71.7000)./83.3000);
    ALGEBRAIC(:,30) =  0.0150000.*exp((STATES(:,1)+71.7000)./15.4000);
    ALGEBRAIC(:,53) = 1.00000./(ALGEBRAIC(:,12)+ALGEBRAIC(:,30));
    ALGEBRAIC(:,43) = 1.00000./(1.00000+exp((STATES(:,1)+60.0000)./6.60000));
    RATES(:,18) = (ALGEBRAIC(:,43) - STATES(:,18))./ALGEBRAIC(:,53);
    ALGEBRAIC(:,13) = ( 25.0000.*exp((STATES(:,1) - 76.0000)./20.0000))./(1.00000+exp((STATES(:,1) - 76.0000)./20.0000));
    ALGEBRAIC(:,31) = ( 25.0000.*exp( - (STATES(:,1)+54.0000)./20.0000))./(1.00000+exp( - (STATES(:,1)+54.0000)./20.0000));
    ALGEBRAIC(:,44) = 1.00000./(ALGEBRAIC(:,13)+ALGEBRAIC(:,31));
    ALGEBRAIC(:,54) = ALGEBRAIC(:,13)./(ALGEBRAIC(:,13)+ALGEBRAIC(:,31));
    RATES(:,19) = (ALGEBRAIC(:,54) - STATES(:,19))./ALGEBRAIC(:,44);
    ALGEBRAIC(:,45) = 6.00000+5.00000./(1.00000+exp((STATES(:,1) - 16.5000)./10.0000));
    ALGEBRAIC(:,14) = 0.0300000./(1.00000+exp((STATES(:,1)+25.0000)./15.0000));
    ALGEBRAIC(:,32) = ( 0.100000.*exp((STATES(:,1) - 40.0000)./15.0000))./(1.00000+exp((STATES(:,1) - 40.0000)./15.0000));
    ALGEBRAIC(:,55) = ALGEBRAIC(:,14)./(ALGEBRAIC(:,14)+ALGEBRAIC(:,32));
    RATES(:,20) = (ALGEBRAIC(:,55) - STATES(:,20))./ALGEBRAIC(:,45);
    ALGEBRAIC(:,46) = 21.5000+30.0000./(1.00000+exp((STATES(:,1) - 25.0000)./10.0000));
    ALGEBRAIC(:,15) = 0.00442000./(1.00000+exp((STATES(:,1)+26.0000)./15.0000));
    ALGEBRAIC(:,33) = ( 0.0500000.*exp((STATES(:,1) - 10.0000)./15.0000))./(1.00000+exp((STATES(:,1) - 10.0000)./15.0000));
    ALGEBRAIC(:,56) = ALGEBRAIC(:,15)./(ALGEBRAIC(:,15)+ALGEBRAIC(:,33));
    RATES(:,21) = (ALGEBRAIC(:,56) - STATES(:,21))./ALGEBRAIC(:,46);
    ALGEBRAIC(:,60) = ( (( (( 1.00000.*CONSTANTS(:,15))./CONSTANTS(:,20)).*power(CONSTANTS(:,16), 2.00000).*(STATES(:,1) - 15.0000).*power(CONSTANTS(:,10), 2.00000))./( CONSTANTS(:,9).*CONSTANTS(:,11))).*( CONSTANTS(:,17).*STATES(:,11).*exp(( CONSTANTS(:,16).*CONSTANTS(:,10).*(STATES(:,1) - 15.0000))./( CONSTANTS(:,9).*CONSTANTS(:,11))) -  CONSTANTS(:,18).*CONSTANTS(:,6)))./(exp(( CONSTANTS(:,16).*CONSTANTS(:,10).*(STATES(:,1) - 15.0000))./( CONSTANTS(:,9).*CONSTANTS(:,11))) - 1.00000);
    ALGEBRAIC(:,61) =  CONSTANTS(:,14).*STATES(:,12).*STATES(:,13).*STATES(:,14).*STATES(:,15).*STATES(:,16).*ALGEBRAIC(:,60);
    ALGEBRAIC(:,63) = 1.00000./(1.00000 - ALGEBRAIC(:,61)./0.0100000);
    ALGEBRAIC(:,66) = 125.000+300.000./(1.00000+exp(( - ALGEBRAIC(:,61) - 0.175000)./0.0400000));
    RATES(:,16) = (ALGEBRAIC(:,63) - STATES(:,16))./ALGEBRAIC(:,66);
    ALGEBRAIC(:,64) = power(STATES(:,28), 1.90000)./(power(STATES(:,28), 1.90000)+power(( 49.2800.*STATES(:,11))./(STATES(:,11)+0.00280000), 1.90000));
    ALGEBRAIC(:,67) = ( ALGEBRAIC(:,64).*power(ALGEBRAIC(:,61), 2.00000))./(power(ALGEBRAIC(:,61), 2.00000)+1.00000);
    RATES(:,30) = (ALGEBRAIC(:,67) - STATES(:,30))./CONSTANTS(:,61);
    ALGEBRAIC(:,20) =  (( CONSTANTS(:,9).*CONSTANTS(:,11))./CONSTANTS(:,10)).*log(CONSTANTS(:,5)./STATES(:,2));
    ALGEBRAIC(:,58) =  CONSTANTS(:,12).*power(STATES(:,6), 3.00000).*( 0.800000.*STATES(:,7)+ 0.200000.*STATES(:,8)).*(STATES(:,1) - ALGEBRAIC(:,20));
    ALGEBRAIC(:,59) =  CONSTANTS(:,13).*power(STATES(:,9), 3.00000).*STATES(:,10).*(STATES(:,1) - ALGEBRAIC(:,20));
    ALGEBRAIC(:,81) =  CONSTANTS(:,32).*power(STATES(:,2), 3.00000)+ 1.50000.*power(CONSTANTS(:,30), 3.00000).*STATES(:,3)+ power(CONSTANTS(:,29), 3.00000).*CONSTANTS(:,6).*(1.00000+( 1.50000.*STATES(:,3))./CONSTANTS(:,31));
    ALGEBRAIC(:,82) =  CONSTANTS(:,31).*power(CONSTANTS(:,5), 3.00000).*(1.00000+STATES(:,2)./CONSTANTS(:,29))+ power(STATES(:,2), 3.00000).*CONSTANTS(:,6)+ 1.50000.*power(CONSTANTS(:,5), 3.00000).*STATES(:,3);
    ALGEBRAIC(:,83) = ( CONSTANTS(:,27).*CONSTANTS(:,28).*power(STATES(:,2), 3.00000).*CONSTANTS(:,6).*exp(( 0.350000.*CONSTANTS(:,10).*STATES(:,1))./( CONSTANTS(:,9).*CONSTANTS(:,11))) -  1.50000.*power(CONSTANTS(:,5), 3.00000).*STATES(:,3).*exp((  - 0.650000.*CONSTANTS(:,10).*STATES(:,1))./( CONSTANTS(:,9).*CONSTANTS(:,11))))./( (1.00000+power(CONSTANTS(:,33)./( 1.50000.*STATES(:,3)), 2.00000)).*(1.00000+ CONSTANTS(:,34).*exp((  - 0.650000.*STATES(:,1).*CONSTANTS(:,10))./( CONSTANTS(:,9).*CONSTANTS(:,11)))).*(ALGEBRAIC(:,81)+ALGEBRAIC(:,82)));
    ALGEBRAIC(:,84) = 1.00000./(1.00000+ 0.124500.*exp((  - 0.100000.*CONSTANTS(:,10).*STATES(:,1))./( CONSTANTS(:,9).*CONSTANTS(:,11)))+ 0.0365000.*CONSTANTS(:,78).*exp((  - CONSTANTS(:,10).*STATES(:,1))./( CONSTANTS(:,9).*CONSTANTS(:,11))));
    ALGEBRAIC(:,85) = ( (( CONSTANTS(:,35).*ALGEBRAIC(:,84).*1.00000)./(1.00000+power(CONSTANTS(:,36)./STATES(:,2), 2.00000))).*CONSTANTS(:,7))./(CONSTANTS(:,7)+CONSTANTS(:,37));
    ALGEBRAIC(:,89) =  CONSTANTS(:,42).*(STATES(:,1) - ALGEBRAIC(:,20));
    ALGEBRAIC(:,47) =  ((  - CONSTANTS(:,9).*CONSTANTS(:,11))./CONSTANTS(:,10)).*log(CONSTANTS(:,8)./STATES(:,5));
    ALGEBRAIC(:,88) = ( CONSTANTS(:,41).*power(ALGEBRAIC(:,20) - ALGEBRAIC(:,47), 4.00000))./(power(ALGEBRAIC(:,20) - ALGEBRAIC(:,47), 4.00000)+power(87.8251, 4.00000));
    RATES(:,2) = (  - CONSTANTS(:,20).*(ALGEBRAIC(:,58)+ALGEBRAIC(:,59)+ALGEBRAIC(:,89)+ 3.00000.*ALGEBRAIC(:,85)+ 3.00000.*ALGEBRAIC(:,83)).*CONSTANTS(:,79))./( CONSTANTS(:,80).*CONSTANTS(:,10))+ALGEBRAIC(:,88);
    ALGEBRAIC(:,37) =  (( CONSTANTS(:,9).*CONSTANTS(:,11))./CONSTANTS(:,10)).*log(CONSTANTS(:,7)./STATES(:,4));
    ALGEBRAIC(:,68) =  CONSTANTS(:,22).*STATES(:,19).*( 0.800000.*STATES(:,20)+ 0.200000.*STATES(:,21)).*(STATES(:,1) - ALGEBRAIC(:,37));
    ALGEBRAIC(:,69) = 1.00000./(1.00000+exp((STATES(:,1) - 5.40000)./20.4000));
    ALGEBRAIC(:,70) =  CONSTANTS(:,75).*STATES(:,22).*ALGEBRAIC(:,69).*(STATES(:,1) - ALGEBRAIC(:,37));
    ALGEBRAIC(:,57) =  (( CONSTANTS(:,9).*CONSTANTS(:,11))./CONSTANTS(:,10)).*log((CONSTANTS(:,7)+ CONSTANTS(:,4).*CONSTANTS(:,5))./(STATES(:,4)+ CONSTANTS(:,4).*STATES(:,2)));
    ALGEBRAIC(:,71) =  0.0525813.*(1.00000+0.600000./(1.00000+power(3.80000e-05./STATES(:,3), 1.40000)));
    ALGEBRAIC(:,72) =  ALGEBRAIC(:,71).*STATES(:,23).*STATES(:,24).*(STATES(:,1) - ALGEBRAIC(:,57));
    ALGEBRAIC(:,74) = 1.02000./(1.00000+exp( 0.238500.*(STATES(:,1) - (ALGEBRAIC(:,37)+59.2150))));
    ALGEBRAIC(:,73) = ( 0.491240.*exp( 0.0803200.*((STATES(:,1)+5.47600) - ALGEBRAIC(:,37)))+exp( 0.0617500.*(STATES(:,1) - (594.310+ALGEBRAIC(:,37)))))./(1.00000+exp(  - 0.514300.*((STATES(:,1)+4.75300) - ALGEBRAIC(:,37))));
    ALGEBRAIC(:,75) = ALGEBRAIC(:,74)./(ALGEBRAIC(:,74)+ALGEBRAIC(:,73));
    ALGEBRAIC(:,76) =  ( CONSTANTS(:,76).*ALGEBRAIC(:,75)+0.00400000).*(STATES(:,1) - ALGEBRAIC(:,37));
    ALGEBRAIC(:,90) =  CONSTANTS(:,43).*(STATES(:,1) - ALGEBRAIC(:,37));
    ALGEBRAIC(:,77) = 1.00000./(1.00000+exp((7.48800 - STATES(:,1))./5.98000));
    ALGEBRAIC(:,78) =  CONSTANTS(:,23).*ALGEBRAIC(:,77).*(STATES(:,1) - ALGEBRAIC(:,37));
    ALGEBRAIC(:,87) = ( CONSTANTS(:,40).*(ALGEBRAIC(:,37) - ALGEBRAIC(:,47)))./((ALGEBRAIC(:,37)+87.8251) - ALGEBRAIC(:,47));
    RATES(:,4) = (  - CONSTANTS(:,20).*((ALGEBRAIC(:,68)+ALGEBRAIC(:,76)+ALGEBRAIC(:,70)+ALGEBRAIC(:,72)+ALGEBRAIC(:,78)+ALGEBRAIC(:,90)) -  2.00000.*ALGEBRAIC(:,85)).*CONSTANTS(:,79))./( CONSTANTS(:,80).*CONSTANTS(:,10))+ALGEBRAIC(:,87);
    ALGEBRAIC(:,79) = ( (( (( 1.00000.*CONSTANTS(:,24))./CONSTANTS(:,20)).*power(CONSTANTS(:,25), 2.00000).*STATES(:,1).*power(CONSTANTS(:,10), 2.00000))./( CONSTANTS(:,9).*CONSTANTS(:,11))).*(STATES(:,5) -  CONSTANTS(:,8).*exp((  - CONSTANTS(:,25).*STATES(:,1).*CONSTANTS(:,10))./( CONSTANTS(:,9).*CONSTANTS(:,11)))))./(1.00000 - exp((  - CONSTANTS(:,25).*STATES(:,1).*CONSTANTS(:,10))./( CONSTANTS(:,9).*CONSTANTS(:,11))));
    ALGEBRAIC(:,80) =  20.0000.*ALGEBRAIC(:,79).*STATES(:,25);
    ALGEBRAIC(:,91) =  CONSTANTS(:,45).*(STATES(:,1) - ALGEBRAIC(:,47));
    RATES(:,5) = (  - CONSTANTS(:,20).*(ALGEBRAIC(:,80)+ALGEBRAIC(:,91)).*CONSTANTS(:,79))./( CONSTANTS(:,80).*CONSTANTS(:,10))+ALGEBRAIC(:,88)+ALGEBRAIC(:,87);
    ALGEBRAIC(:,1) = piecewise({VOI>=CONSTANTS(:,1)&VOI<=CONSTANTS(:,2), CONSTANTS(:,3) }, 0.00000);
    ALGEBRAIC(:,65) =  CONSTANTS(:,21).*STATES(:,17).*STATES(:,18).*(STATES(:,1) - 50.0000);
    ALGEBRAIC(:,92) = ( (( (( 1.00000.*CONSTANTS(:,44))./CONSTANTS(:,20)).*power(CONSTANTS(:,16), 2.00000).*STATES(:,1).*power(CONSTANTS(:,10), 2.00000))./( CONSTANTS(:,9).*CONSTANTS(:,11))).*( CONSTANTS(:,17).*STATES(:,3).*exp(( CONSTANTS(:,16).*STATES(:,1).*CONSTANTS(:,10))./( CONSTANTS(:,9).*CONSTANTS(:,11))) -  CONSTANTS(:,18).*CONSTANTS(:,6)))./(exp(( CONSTANTS(:,16).*STATES(:,1).*CONSTANTS(:,10))./( CONSTANTS(:,9).*CONSTANTS(:,11))) - 1.00000);
    ALGEBRAIC(:,86) = ( CONSTANTS(:,38).*STATES(:,3))./(CONSTANTS(:,39)+STATES(:,3));
    ALGEBRAIC(:,93) = ALGEBRAIC(:,58)+ALGEBRAIC(:,59)+ALGEBRAIC(:,61)+ALGEBRAIC(:,65)+ALGEBRAIC(:,68)+ALGEBRAIC(:,80)+ALGEBRAIC(:,70)+ALGEBRAIC(:,72)+ALGEBRAIC(:,76)+ALGEBRAIC(:,83)+ALGEBRAIC(:,85)+ALGEBRAIC(:,89)+ALGEBRAIC(:,90)+ALGEBRAIC(:,92)+ALGEBRAIC(:,91)+ALGEBRAIC(:,86)+ALGEBRAIC(:,78);
    RATES(:,1) =  - (ALGEBRAIC(:,93)+ALGEBRAIC(:,1));
    ALGEBRAIC(:,97) = ( CONSTANTS(:,52).*(1.00000 - STATES(:,26)))./(1.00000+CONSTANTS(:,19)./STATES(:,11));
    RATES(:,26) =  CONSTANTS(:,50).*ALGEBRAIC(:,97).*(ALGEBRAIC(:,97)+STATES(:,26)) -  CONSTANTS(:,51).*STATES(:,26);
    ALGEBRAIC(:,62) = 0.300000./(1.00000 - ALGEBRAIC(:,61)./0.0500000)+0.550000./(1.00000+STATES(:,11)./0.00300000)+0.150000;
    ALGEBRAIC(:,98) = ALGEBRAIC(:,97)+STATES(:,26);
    ALGEBRAIC(:,99) = 0.500000+( 10.0000.*1.00000.*ALGEBRAIC(:,98))./( 1.00000.*ALGEBRAIC(:,98)+CONSTANTS(:,19))+1.00000./(1.00000+STATES(:,11)./0.00300000);
    RATES(:,15) = (ALGEBRAIC(:,62) - STATES(:,15))./ALGEBRAIC(:,99);
    ALGEBRAIC(:,105) = ( CONSTANTS(:,60).*1.00000.*ALGEBRAIC(:,98))./(CONSTANTS(:,19)+ 1.00000.*ALGEBRAIC(:,98));
    ALGEBRAIC(:,101) = 1.00000./(1.00000+exp((ALGEBRAIC(:,61)+0.0500000)./0.0150000));
    ALGEBRAIC(:,107) = (350.000 - ALGEBRAIC(:,105))./(1.00000+exp(((STATES(:,11) - 0.00300000)+ 0.00300000.*ALGEBRAIC(:,101))./0.000200000))+3.00000+ALGEBRAIC(:,105);
    ALGEBRAIC(:,103) = 1.00000./(1.00000+exp(((STATES(:,11) - 0.000400000)+ 0.00200000.*ALGEBRAIC(:,101))./2.50000e-05));
    RATES(:,29) = (ALGEBRAIC(:,103) - STATES(:,29))./ALGEBRAIC(:,107);
    ALGEBRAIC(:,100) = (STATES(:,11) - STATES(:,3))./CONSTANTS(:,59);
    ALGEBRAIC(:,108) = 1.00000./(1.00000+exp(( CONSTANTS(:,14).*ALGEBRAIC(:,60)+13.0000)./5.00000));
    ALGEBRAIC(:,109) =  3000.00.*ALGEBRAIC(:,108);
    ALGEBRAIC(:,110) =  ALGEBRAIC(:,109).*STATES(:,30).*STATES(:,29).*(STATES(:,28) - STATES(:,11));
    ALGEBRAIC(:,104) = ( 2.00000.*CONSTANTS(:,57).*STATES(:,11))./power(STATES(:,11)+CONSTANTS(:,55), 2.00000);
    ALGEBRAIC(:,102) = ( 2.00000.*CONSTANTS(:,58).*STATES(:,11))./power(STATES(:,11)+CONSTANTS(:,56), 2.00000);
    ALGEBRAIC(:,106) = 1.00000./(1.00000+ALGEBRAIC(:,104)+ALGEBRAIC(:,102));
    RATES(:,11) =  ALGEBRAIC(:,106).*(((  - CONSTANTS(:,20).*ALGEBRAIC(:,61).*CONSTANTS(:,79))./( CONSTANTS(:,83).*CONSTANTS(:,16).*CONSTANTS(:,10))+( ALGEBRAIC(:,110).*CONSTANTS(:,82))./CONSTANTS(:,83)) - ALGEBRAIC(:,100));
    ALGEBRAIC(:,95) = ( 2.00000.*CONSTANTS(:,48).*STATES(:,3))./power(STATES(:,3)+CONSTANTS(:,46), 2.00000);
    ALGEBRAIC(:,94) = ( 2.00000.*CONSTANTS(:,49).*STATES(:,3))./power(STATES(:,3)+CONSTANTS(:,47), 2.00000);
    ALGEBRAIC(:,96) = 1.00000./(1.00000+ALGEBRAIC(:,95)+ALGEBRAIC(:,94));
    ALGEBRAIC(:,112) = ( CONSTANTS(:,66).*ALGEBRAIC(:,98).*1.00000)./(CONSTANTS(:,19)+ ALGEBRAIC(:,98).*1.00000);
    ALGEBRAIC(:,113) = ( CONSTANTS(:,67).*ALGEBRAIC(:,98).*1.00000)./(CONSTANTS(:,19)+ ALGEBRAIC(:,98).*1.00000);
    ALGEBRAIC(:,114) = ( CONSTANTS(:,64).*(ALGEBRAIC(:,112)+1.00000).*CONSTANTS(:,65).*STATES(:,3))./((STATES(:,3)+CONSTANTS(:,68)) - ALGEBRAIC(:,113));
    ALGEBRAIC(:,111) = ( CONSTANTS(:,62).*STATES(:,27))./CONSTANTS(:,63);
    RATES(:,3) =   - ALGEBRAIC(:,96).*((( CONSTANTS(:,20).*((ALGEBRAIC(:,92)+ALGEBRAIC(:,86)) -  2.00000.*ALGEBRAIC(:,83)).*CONSTANTS(:,79))./( 2.00000.*CONSTANTS(:,80).*CONSTANTS(:,10))+( (ALGEBRAIC(:,114) - ALGEBRAIC(:,111)).*CONSTANTS(:,81))./CONSTANTS(:,80)) - ( ALGEBRAIC(:,100).*CONSTANTS(:,83))./CONSTANTS(:,80));
    ALGEBRAIC(:,115) = (STATES(:,27) - STATES(:,28))./CONSTANTS(:,69);
    RATES(:,27) = ALGEBRAIC(:,114) - (ALGEBRAIC(:,111)+( ALGEBRAIC(:,115).*CONSTANTS(:,82))./CONSTANTS(:,81));
    RATES(:,28) = (ALGEBRAIC(:,115) - ALGEBRAIC(:,110))./(1.00000+( CONSTANTS(:,53).*CONSTANTS(:,54))./power(CONSTANTS(:,54)+STATES(:,28), 2.00000));
   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(:,19) = 1.00000./(1.00000+CONSTANTS(:,26)./STATES(:,11));
    ALGEBRAIC(:,25) = 175.000+125.000./(1.00000+exp( - (STATES(:,1)+25.0000)./6.00000));
    ALGEBRAIC(:,7) = 1.00000./(1.00000+exp((STATES(:,1)+69.0000)./6.10000));
    ALGEBRAIC(:,8) = 1.00000./(1.00000+exp( - (STATES(:,1) - 4.00000)./6.74000));
    ALGEBRAIC(:,26) = 0.590000+( 0.800000.*exp( 0.0520000.*(STATES(:,1)+13.0000)))./(1.00000+exp( 0.132000.*(STATES(:,1)+13.0000)));
    ALGEBRAIC(:,9) = 1.00000./(1.00000+exp((STATES(:,1)+18.0000)./10.0000));
    ALGEBRAIC(:,27) = 4.00000+ 0.00500000.*power(STATES(:,1) - 2.50000, 2.00000);
    ALGEBRAIC(:,10) = 1.00000./(1.00000+exp((STATES(:,1)+18.0000)./10.0000));
    ALGEBRAIC(:,28) = 38.0000+ 0.0700000.*power(STATES(:,1) - 18.6000, 2.00000);
    ALGEBRAIC(:,16) = 900.000./(1.00000+exp(STATES(:,1)./5.00000))+100.000;
    ALGEBRAIC(:,34) = 1.00000./(1.00000+exp( - (STATES(:,1)+0.0850000)./12.2500));
    ALGEBRAIC(:,17) = 1.00000./(( 7.61000e-05.*(STATES(:,1)+44.6000))./(1.00000 - exp(  - 9.97000.*(STATES(:,1)+44.6000)))+( 0.000360000.*(STATES(:,1) - 0.550000))./(exp( 0.128000.*(STATES(:,1) - 0.550000)) - 1.00000));
    ALGEBRAIC(:,35) = 1.00000./(1.00000+exp( - (STATES(:,1) - 9.00000)./13.7000));
    ALGEBRAIC(:,18) = ( 2.00000.*1.00000)./(( 7.61000e-05.*(STATES(:,1)+44.6000))./(1.00000 - exp(  - 9.97000.*(STATES(:,1)+44.6000)))+( 0.000360000.*(STATES(:,1) - 0.550000))./(exp( 0.128000.*(STATES(:,1) - 0.550000)) - 1.00000));
    ALGEBRAIC(:,36) = 1.00000./(1.00000+exp( - (STATES(:,1) - 9.00000)./13.7000));
    ALGEBRAIC(:,3) = ( 0.320000.*(STATES(:,1)+47.1300))./(1.00000 - exp(  - 0.100000.*(STATES(:,1)+47.1300)));
    ALGEBRAIC(:,21) =  0.0800000.*exp( - STATES(:,1)./11.0000);
    ALGEBRAIC(:,48) = 1.00000./(ALGEBRAIC(:,3)+ALGEBRAIC(:,21));
    ALGEBRAIC(:,38) = ALGEBRAIC(:,3)./(ALGEBRAIC(:,3)+ALGEBRAIC(:,21));
    ALGEBRAIC(:,4) = piecewise({STATES(:,1)< - 40.0000,  0.135000.*exp((STATES(:,1)+80.0000)./ - 6.80000) }, 0.00000);
    ALGEBRAIC(:,22) = piecewise({STATES(:,1)< - 40.0000,  3.56000.*exp( 0.0790000.*STATES(:,1))+ 310000..*exp( 0.350000.*STATES(:,1)) }, 1.00000./( 0.130000.*(1.00000+exp((STATES(:,1)+10.6600)./ - 11.1000))));
    ALGEBRAIC(:,49) = 1.00000./(ALGEBRAIC(:,4)+ALGEBRAIC(:,22));
    ALGEBRAIC(:,39) = ALGEBRAIC(:,4)./(ALGEBRAIC(:,4)+ALGEBRAIC(:,22));
    ALGEBRAIC(:,5) = piecewise({STATES(:,1)< - 40.0000, ( (  - 127140..*exp( 0.244400.*STATES(:,1)) -  3.47400e-05.*exp(  - 0.0439100.*STATES(:,1))).*(STATES(:,1)+37.7800))./(1.00000+exp( 0.311000.*(STATES(:,1)+79.2300))) }, 0.00000);
    ALGEBRAIC(:,23) = piecewise({STATES(:,1)< - 40.0000, ( 0.121200.*exp(  - 0.0105200.*STATES(:,1)))./(1.00000+exp(  - 0.137800.*(STATES(:,1)+40.1400))) }, ( 0.300000.*exp(  - 2.53500e-07.*STATES(:,1)))./(1.00000+exp(  - 0.100000.*(STATES(:,1)+32.0000))));
    ALGEBRAIC(:,50) = 0.100000./(ALGEBRAIC(:,5)+ALGEBRAIC(:,23));
    ALGEBRAIC(:,40) = ( 0.100000.*ALGEBRAIC(:,5))./(ALGEBRAIC(:,5)+ALGEBRAIC(:,23));
    ALGEBRAIC(:,6) = ( 0.320000.*(STATES(:,1)+47.1300))./(1.00000 - exp(  - 0.100000.*(STATES(:,1)+47.1300)));
    ALGEBRAIC(:,24) =  0.0800000.*exp( - STATES(:,1)./11.0000);
    ALGEBRAIC(:,51) = 1.00000./(ALGEBRAIC(:,6)+ALGEBRAIC(:,24));
    ALGEBRAIC(:,41) = ALGEBRAIC(:,6)./(ALGEBRAIC(:,6)+ALGEBRAIC(:,24));
    ALGEBRAIC(:,11) =  1.06800.*exp((STATES(:,1)+16.3000)./30.0000);
    ALGEBRAIC(:,29) =  1.06800.*exp( - (STATES(:,1)+16.3000)./30.0000);
    ALGEBRAIC(:,52) = 1.00000./(ALGEBRAIC(:,11)+ALGEBRAIC(:,29));
    ALGEBRAIC(:,42) = 1.00000./(1.00000+exp( - (STATES(:,1)+33.0000)./6.10000));
    ALGEBRAIC(:,12) =  0.0150000.*exp( - (STATES(:,1)+71.7000)./83.3000);
    ALGEBRAIC(:,30) =  0.0150000.*exp((STATES(:,1)+71.7000)./15.4000);
    ALGEBRAIC(:,53) = 1.00000./(ALGEBRAIC(:,12)+ALGEBRAIC(:,30));
    ALGEBRAIC(:,43) = 1.00000./(1.00000+exp((STATES(:,1)+60.0000)./6.60000));
    ALGEBRAIC(:,13) = ( 25.0000.*exp((STATES(:,1) - 76.0000)./20.0000))./(1.00000+exp((STATES(:,1) - 76.0000)./20.0000));
    ALGEBRAIC(:,31) = ( 25.0000.*exp( - (STATES(:,1)+54.0000)./20.0000))./(1.00000+exp( - (STATES(:,1)+54.0000)./20.0000));
    ALGEBRAIC(:,44) = 1.00000./(ALGEBRAIC(:,13)+ALGEBRAIC(:,31));
    ALGEBRAIC(:,54) = ALGEBRAIC(:,13)./(ALGEBRAIC(:,13)+ALGEBRAIC(:,31));
    ALGEBRAIC(:,45) = 6.00000+5.00000./(1.00000+exp((STATES(:,1) - 16.5000)./10.0000));
    ALGEBRAIC(:,14) = 0.0300000./(1.00000+exp((STATES(:,1)+25.0000)./15.0000));
    ALGEBRAIC(:,32) = ( 0.100000.*exp((STATES(:,1) - 40.0000)./15.0000))./(1.00000+exp((STATES(:,1) - 40.0000)./15.0000));
    ALGEBRAIC(:,55) = ALGEBRAIC(:,14)./(ALGEBRAIC(:,14)+ALGEBRAIC(:,32));
    ALGEBRAIC(:,46) = 21.5000+30.0000./(1.00000+exp((STATES(:,1) - 25.0000)./10.0000));
    ALGEBRAIC(:,15) = 0.00442000./(1.00000+exp((STATES(:,1)+26.0000)./15.0000));
    ALGEBRAIC(:,33) = ( 0.0500000.*exp((STATES(:,1) - 10.0000)./15.0000))./(1.00000+exp((STATES(:,1) - 10.0000)./15.0000));
    ALGEBRAIC(:,56) = ALGEBRAIC(:,15)./(ALGEBRAIC(:,15)+ALGEBRAIC(:,33));
    ALGEBRAIC(:,60) = ( (( (( 1.00000.*CONSTANTS(:,15))./CONSTANTS(:,20)).*power(CONSTANTS(:,16), 2.00000).*(STATES(:,1) - 15.0000).*power(CONSTANTS(:,10), 2.00000))./( CONSTANTS(:,9).*CONSTANTS(:,11))).*( CONSTANTS(:,17).*STATES(:,11).*exp(( CONSTANTS(:,16).*CONSTANTS(:,10).*(STATES(:,1) - 15.0000))./( CONSTANTS(:,9).*CONSTANTS(:,11))) -  CONSTANTS(:,18).*CONSTANTS(:,6)))./(exp(( CONSTANTS(:,16).*CONSTANTS(:,10).*(STATES(:,1) - 15.0000))./( CONSTANTS(:,9).*CONSTANTS(:,11))) - 1.00000);
    ALGEBRAIC(:,61) =  CONSTANTS(:,14).*STATES(:,12).*STATES(:,13).*STATES(:,14).*STATES(:,15).*STATES(:,16).*ALGEBRAIC(:,60);
    ALGEBRAIC(:,63) = 1.00000./(1.00000 - ALGEBRAIC(:,61)./0.0100000);
    ALGEBRAIC(:,66) = 125.000+300.000./(1.00000+exp(( - ALGEBRAIC(:,61) - 0.175000)./0.0400000));
    ALGEBRAIC(:,64) = power(STATES(:,28), 1.90000)./(power(STATES(:,28), 1.90000)+power(( 49.2800.*STATES(:,11))./(STATES(:,11)+0.00280000), 1.90000));
    ALGEBRAIC(:,67) = ( ALGEBRAIC(:,64).*power(ALGEBRAIC(:,61), 2.00000))./(power(ALGEBRAIC(:,61), 2.00000)+1.00000);
    ALGEBRAIC(:,20) =  (( CONSTANTS(:,9).*CONSTANTS(:,11))./CONSTANTS(:,10)).*log(CONSTANTS(:,5)./STATES(:,2));
    ALGEBRAIC(:,58) =  CONSTANTS(:,12).*power(STATES(:,6), 3.00000).*( 0.800000.*STATES(:,7)+ 0.200000.*STATES(:,8)).*(STATES(:,1) - ALGEBRAIC(:,20));
    ALGEBRAIC(:,59) =  CONSTANTS(:,13).*power(STATES(:,9), 3.00000).*STATES(:,10).*(STATES(:,1) - ALGEBRAIC(:,20));
    ALGEBRAIC(:,81) =  CONSTANTS(:,32).*power(STATES(:,2), 3.00000)+ 1.50000.*power(CONSTANTS(:,30), 3.00000).*STATES(:,3)+ power(CONSTANTS(:,29), 3.00000).*CONSTANTS(:,6).*(1.00000+( 1.50000.*STATES(:,3))./CONSTANTS(:,31));
    ALGEBRAIC(:,82) =  CONSTANTS(:,31).*power(CONSTANTS(:,5), 3.00000).*(1.00000+STATES(:,2)./CONSTANTS(:,29))+ power(STATES(:,2), 3.00000).*CONSTANTS(:,6)+ 1.50000.*power(CONSTANTS(:,5), 3.00000).*STATES(:,3);
    ALGEBRAIC(:,83) = ( CONSTANTS(:,27).*CONSTANTS(:,28).*power(STATES(:,2), 3.00000).*CONSTANTS(:,6).*exp(( 0.350000.*CONSTANTS(:,10).*STATES(:,1))./( CONSTANTS(:,9).*CONSTANTS(:,11))) -  1.50000.*power(CONSTANTS(:,5), 3.00000).*STATES(:,3).*exp((  - 0.650000.*CONSTANTS(:,10).*STATES(:,1))./( CONSTANTS(:,9).*CONSTANTS(:,11))))./( (1.00000+power(CONSTANTS(:,33)./( 1.50000.*STATES(:,3)), 2.00000)).*(1.00000+ CONSTANTS(:,34).*exp((  - 0.650000.*STATES(:,1).*CONSTANTS(:,10))./( CONSTANTS(:,9).*CONSTANTS(:,11)))).*(ALGEBRAIC(:,81)+ALGEBRAIC(:,82)));
    ALGEBRAIC(:,84) = 1.00000./(1.00000+ 0.124500.*exp((  - 0.100000.*CONSTANTS(:,10).*STATES(:,1))./( CONSTANTS(:,9).*CONSTANTS(:,11)))+ 0.0365000.*CONSTANTS(:,78).*exp((  - CONSTANTS(:,10).*STATES(:,1))./( CONSTANTS(:,9).*CONSTANTS(:,11))));
    ALGEBRAIC(:,85) = ( (( CONSTANTS(:,35).*ALGEBRAIC(:,84).*1.00000)./(1.00000+power(CONSTANTS(:,36)./STATES(:,2), 2.00000))).*CONSTANTS(:,7))./(CONSTANTS(:,7)+CONSTANTS(:,37));
    ALGEBRAIC(:,89) =  CONSTANTS(:,42).*(STATES(:,1) - ALGEBRAIC(:,20));
    ALGEBRAIC(:,47) =  ((  - CONSTANTS(:,9).*CONSTANTS(:,11))./CONSTANTS(:,10)).*log(CONSTANTS(:,8)./STATES(:,5));
    ALGEBRAIC(:,88) = ( CONSTANTS(:,41).*power(ALGEBRAIC(:,20) - ALGEBRAIC(:,47), 4.00000))./(power(ALGEBRAIC(:,20) - ALGEBRAIC(:,47), 4.00000)+power(87.8251, 4.00000));
    ALGEBRAIC(:,37) =  (( CONSTANTS(:,9).*CONSTANTS(:,11))./CONSTANTS(:,10)).*log(CONSTANTS(:,7)./STATES(:,4));
    ALGEBRAIC(:,68) =  CONSTANTS(:,22).*STATES(:,19).*( 0.800000.*STATES(:,20)+ 0.200000.*STATES(:,21)).*(STATES(:,1) - ALGEBRAIC(:,37));
    ALGEBRAIC(:,69) = 1.00000./(1.00000+exp((STATES(:,1) - 5.40000)./20.4000));
    ALGEBRAIC(:,70) =  CONSTANTS(:,75).*STATES(:,22).*ALGEBRAIC(:,69).*(STATES(:,1) - ALGEBRAIC(:,37));
    ALGEBRAIC(:,57) =  (( CONSTANTS(:,9).*CONSTANTS(:,11))./CONSTANTS(:,10)).*log((CONSTANTS(:,7)+ CONSTANTS(:,4).*CONSTANTS(:,5))./(STATES(:,4)+ CONSTANTS(:,4).*STATES(:,2)));
    ALGEBRAIC(:,71) =  0.0525813.*(1.00000+0.600000./(1.00000+power(3.80000e-05./STATES(:,3), 1.40000)));
    ALGEBRAIC(:,72) =  ALGEBRAIC(:,71).*STATES(:,23).*STATES(:,24).*(STATES(:,1) - ALGEBRAIC(:,57));
    ALGEBRAIC(:,74) = 1.02000./(1.00000+exp( 0.238500.*(STATES(:,1) - (ALGEBRAIC(:,37)+59.2150))));
    ALGEBRAIC(:,73) = ( 0.491240.*exp( 0.0803200.*((STATES(:,1)+5.47600) - ALGEBRAIC(:,37)))+exp( 0.0617500.*(STATES(:,1) - (594.310+ALGEBRAIC(:,37)))))./(1.00000+exp(  - 0.514300.*((STATES(:,1)+4.75300) - ALGEBRAIC(:,37))));
    ALGEBRAIC(:,75) = ALGEBRAIC(:,74)./(ALGEBRAIC(:,74)+ALGEBRAIC(:,73));
    ALGEBRAIC(:,76) =  ( CONSTANTS(:,76).*ALGEBRAIC(:,75)+0.00400000).*(STATES(:,1) - ALGEBRAIC(:,37));
    ALGEBRAIC(:,90) =  CONSTANTS(:,43).*(STATES(:,1) - ALGEBRAIC(:,37));
    ALGEBRAIC(:,77) = 1.00000./(1.00000+exp((7.48800 - STATES(:,1))./5.98000));
    ALGEBRAIC(:,78) =  CONSTANTS(:,23).*ALGEBRAIC(:,77).*(STATES(:,1) - ALGEBRAIC(:,37));
    ALGEBRAIC(:,87) = ( CONSTANTS(:,40).*(ALGEBRAIC(:,37) - ALGEBRAIC(:,47)))./((ALGEBRAIC(:,37)+87.8251) - ALGEBRAIC(:,47));
    ALGEBRAIC(:,79) = ( (( (( 1.00000.*CONSTANTS(:,24))./CONSTANTS(:,20)).*power(CONSTANTS(:,25), 2.00000).*STATES(:,1).*power(CONSTANTS(:,10), 2.00000))./( CONSTANTS(:,9).*CONSTANTS(:,11))).*(STATES(:,5) -  CONSTANTS(:,8).*exp((  - CONSTANTS(:,25).*STATES(:,1).*CONSTANTS(:,10))./( CONSTANTS(:,9).*CONSTANTS(:,11)))))./(1.00000 - exp((  - CONSTANTS(:,25).*STATES(:,1).*CONSTANTS(:,10))./( CONSTANTS(:,9).*CONSTANTS(:,11))));
    ALGEBRAIC(:,80) =  20.0000.*ALGEBRAIC(:,79).*STATES(:,25);
    ALGEBRAIC(:,91) =  CONSTANTS(:,45).*(STATES(:,1) - ALGEBRAIC(:,47));
    ALGEBRAIC(:,1) = piecewise({VOI>=CONSTANTS(:,1)&VOI<=CONSTANTS(:,2), CONSTANTS(:,3) }, 0.00000);
    ALGEBRAIC(:,65) =  CONSTANTS(:,21).*STATES(:,17).*STATES(:,18).*(STATES(:,1) - 50.0000);
    ALGEBRAIC(:,92) = ( (( (( 1.00000.*CONSTANTS(:,44))./CONSTANTS(:,20)).*power(CONSTANTS(:,16), 2.00000).*STATES(:,1).*power(CONSTANTS(:,10), 2.00000))./( CONSTANTS(:,9).*CONSTANTS(:,11))).*( CONSTANTS(:,17).*STATES(:,3).*exp(( CONSTANTS(:,16).*STATES(:,1).*CONSTANTS(:,10))./( CONSTANTS(:,9).*CONSTANTS(:,11))) -  CONSTANTS(:,18).*CONSTANTS(:,6)))./(exp(( CONSTANTS(:,16).*STATES(:,1).*CONSTANTS(:,10))./( CONSTANTS(:,9).*CONSTANTS(:,11))) - 1.00000);
    ALGEBRAIC(:,86) = ( CONSTANTS(:,38).*STATES(:,3))./(CONSTANTS(:,39)+STATES(:,3));
    ALGEBRAIC(:,93) = ALGEBRAIC(:,58)+ALGEBRAIC(:,59)+ALGEBRAIC(:,61)+ALGEBRAIC(:,65)+ALGEBRAIC(:,68)+ALGEBRAIC(:,80)+ALGEBRAIC(:,70)+ALGEBRAIC(:,72)+ALGEBRAIC(:,76)+ALGEBRAIC(:,83)+ALGEBRAIC(:,85)+ALGEBRAIC(:,89)+ALGEBRAIC(:,90)+ALGEBRAIC(:,92)+ALGEBRAIC(:,91)+ALGEBRAIC(:,86)+ALGEBRAIC(:,78);
    ALGEBRAIC(:,97) = ( CONSTANTS(:,52).*(1.00000 - STATES(:,26)))./(1.00000+CONSTANTS(:,19)./STATES(:,11));
    ALGEBRAIC(:,62) = 0.300000./(1.00000 - ALGEBRAIC(:,61)./0.0500000)+0.550000./(1.00000+STATES(:,11)./0.00300000)+0.150000;
    ALGEBRAIC(:,98) = ALGEBRAIC(:,97)+STATES(:,26);
    ALGEBRAIC(:,99) = 0.500000+( 10.0000.*1.00000.*ALGEBRAIC(:,98))./( 1.00000.*ALGEBRAIC(:,98)+CONSTANTS(:,19))+1.00000./(1.00000+STATES(:,11)./0.00300000);
    ALGEBRAIC(:,105) = ( CONSTANTS(:,60).*1.00000.*ALGEBRAIC(:,98))./(CONSTANTS(:,19)+ 1.00000.*ALGEBRAIC(:,98));
    ALGEBRAIC(:,101) = 1.00000./(1.00000+exp((ALGEBRAIC(:,61)+0.0500000)./0.0150000));
    ALGEBRAIC(:,107) = (350.000 - ALGEBRAIC(:,105))./(1.00000+exp(((STATES(:,11) - 0.00300000)+ 0.00300000.*ALGEBRAIC(:,101))./0.000200000))+3.00000+ALGEBRAIC(:,105);
    ALGEBRAIC(:,103) = 1.00000./(1.00000+exp(((STATES(:,11) - 0.000400000)+ 0.00200000.*ALGEBRAIC(:,101))./2.50000e-05));
    ALGEBRAIC(:,100) = (STATES(:,11) - STATES(:,3))./CONSTANTS(:,59);
    ALGEBRAIC(:,108) = 1.00000./(1.00000+exp(( CONSTANTS(:,14).*ALGEBRAIC(:,60)+13.0000)./5.00000));
    ALGEBRAIC(:,109) =  3000.00.*ALGEBRAIC(:,108);
    ALGEBRAIC(:,110) =  ALGEBRAIC(:,109).*STATES(:,30).*STATES(:,29).*(STATES(:,28) - STATES(:,11));
    ALGEBRAIC(:,104) = ( 2.00000.*CONSTANTS(:,57).*STATES(:,11))./power(STATES(:,11)+CONSTANTS(:,55), 2.00000);
    ALGEBRAIC(:,102) = ( 2.00000.*CONSTANTS(:,58).*STATES(:,11))./power(STATES(:,11)+CONSTANTS(:,56), 2.00000);
    ALGEBRAIC(:,106) = 1.00000./(1.00000+ALGEBRAIC(:,104)+ALGEBRAIC(:,102));
    ALGEBRAIC(:,95) = ( 2.00000.*CONSTANTS(:,48).*STATES(:,3))./power(STATES(:,3)+CONSTANTS(:,46), 2.00000);
    ALGEBRAIC(:,94) = ( 2.00000.*CONSTANTS(:,49).*STATES(:,3))./power(STATES(:,3)+CONSTANTS(:,47), 2.00000);
    ALGEBRAIC(:,96) = 1.00000./(1.00000+ALGEBRAIC(:,95)+ALGEBRAIC(:,94));
    ALGEBRAIC(:,112) = ( CONSTANTS(:,66).*ALGEBRAIC(:,98).*1.00000)./(CONSTANTS(:,19)+ ALGEBRAIC(:,98).*1.00000);
    ALGEBRAIC(:,113) = ( CONSTANTS(:,67).*ALGEBRAIC(:,98).*1.00000)./(CONSTANTS(:,19)+ ALGEBRAIC(:,98).*1.00000);
    ALGEBRAIC(:,114) = ( CONSTANTS(:,64).*(ALGEBRAIC(:,112)+1.00000).*CONSTANTS(:,65).*STATES(:,3))./((STATES(:,3)+CONSTANTS(:,68)) - ALGEBRAIC(:,113));
    ALGEBRAIC(:,111) = ( CONSTANTS(:,62).*STATES(:,27))./CONSTANTS(:,63);
    ALGEBRAIC(:,115) = (STATES(:,27) - STATES(:,28))./CONSTANTS(:,69);
    ALGEBRAIC(:,2) =  (( CONSTANTS(:,9).*CONSTANTS(:,11))./( 2.00000.*CONSTANTS(:,10))).*log(CONSTANTS(:,6)./STATES(:,3));
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