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 =73;
end
% There are a total of 29 entries in each of the rate and state variable arrays.
% There are a total of 55 entries in the constant variable array.
%

function [VOI, STATES, ALGEBRAIC, CONSTANTS] = solveModel()
    % Create ALGEBRAIC of correct size
    global algebraicVariableCount;  algebraicVariableCount = getAlgebraicVariableCount();
    % Initialise constants and state variables
    [INIT_STATES, CONSTANTS] = initConsts;

    % Set timespan to solve over 
    tspan = [0, 10];

    % Set numerical accuracy options for ODE solver
    options = odeset('RelTol', 1e-06, 'AbsTol', 1e-06, 'MaxStep', 1);

    % Solve model with ODE solver
    [VOI, STATES] = ode15s(@(VOI, STATES)computeRates(VOI, STATES, CONSTANTS), tspan, INIT_STATES, options);

    % Compute algebraic variables
    [RATES, ALGEBRAIC] = computeRates(VOI, STATES, CONSTANTS);
    ALGEBRAIC = computeAlgebraic(ALGEBRAIC, CONSTANTS, STATES, VOI);

    % Plot state variables against variable of integration
    [LEGEND_STATES, LEGEND_ALGEBRAIC, LEGEND_VOI, LEGEND_CONSTANTS] = createLegends();
    figure();
    plot(VOI, STATES);
    xlabel(LEGEND_VOI);
    l = legend(LEGEND_STATES);
    set(l,'Interpreter','none');
end

function [LEGEND_STATES, LEGEND_ALGEBRAIC, LEGEND_VOI, LEGEND_CONSTANTS] = createLegends()
    LEGEND_STATES = ''; LEGEND_ALGEBRAIC = ''; LEGEND_VOI = ''; LEGEND_CONSTANTS = '';
    LEGEND_VOI = strpad('time in component environment (second)');
    LEGEND_STATES(:,1) = strpad('V in component membrane (millivolt)');
    LEGEND_CONSTANTS(:,1) = strpad('R in component membrane (joule_per_kilomole_kelvin)');
    LEGEND_CONSTANTS(:,2) = strpad('T in component membrane (kelvin)');
    LEGEND_CONSTANTS(:,3) = strpad('F in component membrane (coulomb_per_mole)');
    LEGEND_CONSTANTS(:,4) = strpad('Cm in component membrane (microF)');
    LEGEND_ALGEBRAIC(:,64) = strpad('i_Na in component sodium_current (nanoA)');
    LEGEND_ALGEBRAIC(:,41) = strpad('i_Ca_T in component T_type_Ca_channel (nanoA)');
    LEGEND_ALGEBRAIC(:,40) = strpad('i_Ca_L in component L_type_Ca_channel (nanoA)');
    LEGEND_ALGEBRAIC(:,67) = strpad('i_K in component delayed_rectifying_potassium_current (nanoA)');
    LEGEND_ALGEBRAIC(:,46) = strpad('i_f in component hyperpolarisation_activated_current (nanoA)');
    LEGEND_ALGEBRAIC(:,73) = strpad('i_B in component linear_background_current (nanoA)');
    LEGEND_ALGEBRAIC(:,48) = strpad('i_NaK in component sodium_potassium_pump (nanoA)');
    LEGEND_ALGEBRAIC(:,50) = strpad('i_NaCa in component sodium_calcium_pump (nanoA)');
    LEGEND_ALGEBRAIC(:,49) = strpad('i_Ca_P in component calcium_pump_current (nanoA)');
    LEGEND_ALGEBRAIC(:,70) = strpad('i_K_ACh in component muscarinic_potassium_current (nanoA)');
    LEGEND_CONSTANTS(:,5) = strpad('P_Na in component sodium_current (mul_per_second)');
    LEGEND_ALGEBRAIC(:,63) = strpad('E_Na in component reversal_potentials (millivolt)');
    LEGEND_STATES(:,2) = strpad('Na_c in component cleft_space_equations (millimolar)');
    LEGEND_CONSTANTS(:,46) = strpad('F_ACh_Na in component sodium_current (dimensionless)');
    LEGEND_CONSTANTS(:,6) = strpad('ACh in component cAMP_balance (millimolar)');
    LEGEND_STATES(:,3) = strpad('m in component sodium_current_m_gate (dimensionless)');
    LEGEND_STATES(:,4) = strpad('h1 in component sodium_current_h_gate (dimensionless)');
    LEGEND_STATES(:,5) = strpad('h2 in component sodium_current_h_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,23) = strpad('m_infinity in component sodium_current_m_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,30) = strpad('tau_m in component sodium_current_m_gate (second)');
    LEGEND_ALGEBRAIC(:,1) = strpad('alpha_m in component sodium_current_m_gate (per_second)');
    LEGEND_ALGEBRAIC(:,13) = strpad('beta_m in component sodium_current_m_gate (per_second)');
    LEGEND_ALGEBRAIC(:,24) = strpad('h1_infinity in component sodium_current_h_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,36) = strpad('h2_infinity in component sodium_current_h_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,31) = strpad('tau_h1 in component sodium_current_h_gate (second)');
    LEGEND_ALGEBRAIC(:,38) = strpad('tau_h2 in component sodium_current_h_gate (second)');
    LEGEND_ALGEBRAIC(:,2) = strpad('alpha_h1 in component sodium_current_h_gate (per_second)');
    LEGEND_ALGEBRAIC(:,14) = strpad('beta_h1 in component sodium_current_h_gate (per_second)');
    LEGEND_ALGEBRAIC(:,21) = strpad('g_Ca_L in component L_type_Ca_channel (microS)');
    LEGEND_CONSTANTS(:,7) = strpad('g_Ca_L_cont in component L_type_Ca_channel (microS)');
    LEGEND_ALGEBRAIC(:,10) = strpad('F_cAMP_CaL in component L_type_Ca_channel (dimensionless)');
    LEGEND_STATES(:,6) = strpad('cAMP in component cAMP_balance (millimolar)');
    LEGEND_CONSTANTS(:,8) = strpad('E_Ca_L in component L_type_Ca_channel (millivolt)');
    LEGEND_STATES(:,7) = strpad('d_L in component L_type_Ca_channel_d_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,39) = strpad('d_L_infinity in component L_type_Ca_channel_d_gate (dimensionless)');
    LEGEND_STATES(:,8) = strpad('f_L in component L_type_Ca_channel_f_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,29) = strpad('alpha_d_L in component L_type_Ca_channel_d_gate (per_second)');
    LEGEND_ALGEBRAIC(:,35) = strpad('beta_d_L in component L_type_Ca_channel_d_gate (per_second)');
    LEGEND_ALGEBRAIC(:,37) = strpad('tau_d_L in component L_type_Ca_channel_d_gate (second)');
    LEGEND_ALGEBRAIC(:,3) = strpad('alpha_f_L in component L_type_Ca_channel_f_gate (per_second)');
    LEGEND_ALGEBRAIC(:,15) = strpad('beta_f_L in component L_type_Ca_channel_f_gate (per_second)');
    LEGEND_ALGEBRAIC(:,32) = strpad('f_L_infinity in component L_type_Ca_channel_f_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,25) = strpad('tau_f_L in component L_type_Ca_channel_f_gate (second)');
    LEGEND_CONSTANTS(:,9) = strpad('g_Ca_T in component T_type_Ca_channel (microS)');
    LEGEND_CONSTANTS(:,10) = strpad('E_Ca_T in component T_type_Ca_channel (millivolt)');
    LEGEND_STATES(:,9) = strpad('d_T in component T_type_Ca_channel_d_gate (dimensionless)');
    LEGEND_STATES(:,10) = strpad('f_T in component T_type_Ca_channel_f_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,4) = strpad('alpha_d_T in component T_type_Ca_channel_d_gate (per_second)');
    LEGEND_ALGEBRAIC(:,16) = strpad('beta_d_T in component T_type_Ca_channel_d_gate (per_second)');
    LEGEND_ALGEBRAIC(:,33) = strpad('d_T_infinity in component T_type_Ca_channel_d_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,26) = strpad('tau_d_T in component T_type_Ca_channel_d_gate (second)');
    LEGEND_ALGEBRAIC(:,5) = strpad('alpha_f_T in component T_type_Ca_channel_f_gate (per_second)');
    LEGEND_ALGEBRAIC(:,17) = strpad('beta_f_T in component T_type_Ca_channel_f_gate (per_second)');
    LEGEND_ALGEBRAIC(:,34) = strpad('f_T_infinity in component T_type_Ca_channel_f_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,27) = strpad('tau_f_T in component T_type_Ca_channel_f_gate (second)');
    LEGEND_ALGEBRAIC(:,43) = strpad('g_K in component delayed_rectifying_potassium_current (microS)');
    LEGEND_ALGEBRAIC(:,42) = strpad('F_cAMP_K in component delayed_rectifying_potassium_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,66) = strpad('E_K in component reversal_potentials (millivolt)');
    LEGEND_CONSTANTS(:,11) = strpad('K_b in component cleft_space_equations (millimolar)');
    LEGEND_STATES(:,11) = strpad('P_a in component delayed_rectifying_potassium_current_P_a_gate (dimensionless)');
    LEGEND_STATES(:,12) = strpad('P_i in component delayed_rectifying_potassium_current_P_i_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,18) = strpad('tau_P_a in component delayed_rectifying_potassium_current_P_a_gate (second)');
    LEGEND_ALGEBRAIC(:,6) = strpad('P_a_infinity in component delayed_rectifying_potassium_current_P_a_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,7) = strpad('alpha_P_i in component delayed_rectifying_potassium_current_P_i_gate (per_second)');
    LEGEND_ALGEBRAIC(:,19) = strpad('beta_P_i in component delayed_rectifying_potassium_current_P_i_gate (per_second)');
    LEGEND_ALGEBRAIC(:,65) = strpad('i_B_Na in component linear_background_current (nanoA)');
    LEGEND_ALGEBRAIC(:,72) = strpad('i_B_Ca in component linear_background_current (nanoA)');
    LEGEND_ALGEBRAIC(:,68) = strpad('i_B_K in component linear_background_current (nanoA)');
    LEGEND_CONSTANTS(:,12) = strpad('g_B_Na in component linear_background_current (microS)');
    LEGEND_CONSTANTS(:,13) = strpad('g_B_Ca in component linear_background_current (microS)');
    LEGEND_CONSTANTS(:,14) = strpad('g_B_K in component linear_background_current (microS)');
    LEGEND_ALGEBRAIC(:,71) = strpad('E_Ca in component reversal_potentials (millivolt)');
    LEGEND_CONSTANTS(:,47) = strpad('F_ACh_bNa in component linear_background_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,44) = strpad('i_f_Na in component hyperpolarisation_activated_current (nanoA)');
    LEGEND_ALGEBRAIC(:,45) = strpad('i_f_K in component hyperpolarisation_activated_current (nanoA)');
    LEGEND_CONSTANTS(:,15) = strpad('g_f_Na in component hyperpolarisation_activated_current (microS)');
    LEGEND_CONSTANTS(:,16) = strpad('g_f_K in component hyperpolarisation_activated_current (microS)');
    LEGEND_STATES(:,13) = strpad('y in component hyperpolarisation_activated_current_y_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,20) = strpad('y_infinity in component hyperpolarisation_activated_current_y_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,8) = strpad('V_half in component hyperpolarisation_activated_current_y_gate (millivolt)');
    LEGEND_ALGEBRAIC(:,28) = strpad('tau_y in component hyperpolarisation_activated_current_y_gate (second)');
    LEGEND_CONSTANTS(:,17) = strpad('K_m_Na in component sodium_potassium_pump (millimolar)');
    LEGEND_CONSTANTS(:,18) = strpad('K_m_K in component sodium_potassium_pump (millimolar)');
    LEGEND_CONSTANTS(:,19) = strpad('i_NaK_max in component sodium_potassium_pump (nanoA)');
    LEGEND_ALGEBRAIC(:,47) = strpad('F_cAMP_NaK in component sodium_potassium_pump (dimensionless)');
    LEGEND_STATES(:,14) = strpad('Na_i in component intracellular_concentrations_and_buffer_equations (millimolar)');
    LEGEND_STATES(:,15) = strpad('K_c in component cleft_space_equations (millimolar)');
    LEGEND_STATES(:,16) = strpad('Ca_i in component intracellular_concentrations_and_buffer_equations (millimolar)');
    LEGEND_CONSTANTS(:,20) = strpad('i_Ca_P_max in component calcium_pump_current (nanoA)');
    LEGEND_CONSTANTS(:,21) = strpad('K_NaCa in component sodium_calcium_pump (nanoA)');
    LEGEND_CONSTANTS(:,22) = strpad('d_NaCa in component sodium_calcium_pump (dimensionless)');
    LEGEND_CONSTANTS(:,23) = strpad('gamma in component sodium_calcium_pump (dimensionless)');
    LEGEND_STATES(:,17) = strpad('Ca_c in component cleft_space_equations (millimolar)');
    LEGEND_ALGEBRAIC(:,69) = strpad('I_K_ACh in component muscarinic_potassium_current (nanoA)');
    LEGEND_CONSTANTS(:,53) = strpad('g_K_ACh in component muscarinic_potassium_current (microS)');
    LEGEND_CONSTANTS(:,24) = strpad('g_K_ACh_base in component muscarinic_potassium_current (microS)');
    LEGEND_CONSTANTS(:,48) = strpad('P_M2_KACh in component muscarinic_potassium_current (dimensionless)');
    LEGEND_STATES(:,18) = strpad('a in component muscarinic_potassium_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,9) = strpad('alpha_a in component muscarinic_potassium_current (per_second)');
    LEGEND_CONSTANTS(:,49) = strpad('beta_a in component muscarinic_potassium_current (per_second)');
    LEGEND_CONSTANTS(:,25) = strpad('f_Vagal in component cAMP_balance (per_second)');
    LEGEND_STATES(:,19) = strpad('K_i in component intracellular_concentrations_and_buffer_equations (millimolar)');
    LEGEND_STATES(:,20) = strpad('Ca_Calmod in component intracellular_concentrations_and_buffer_equations (dimensionless)');
    LEGEND_STATES(:,21) = strpad('Ca_Trop in component intracellular_concentrations_and_buffer_equations (dimensionless)');
    LEGEND_STATES(:,22) = strpad('Ca_Mg_Trop in component intracellular_concentrations_and_buffer_equations (dimensionless)');
    LEGEND_STATES(:,23) = strpad('Mg_Mg_Trop in component intracellular_concentrations_and_buffer_equations (dimensionless)');
    LEGEND_ALGEBRAIC(:,51) = strpad('phi_C in component intracellular_concentrations_and_buffer_equations (per_second)');
    LEGEND_ALGEBRAIC(:,52) = strpad('phi_TC in component intracellular_concentrations_and_buffer_equations (per_second)');
    LEGEND_ALGEBRAIC(:,53) = strpad('phi_TMgC in component intracellular_concentrations_and_buffer_equations (per_second)');
    LEGEND_ALGEBRAIC(:,11) = strpad('phi_TMgM in component intracellular_concentrations_and_buffer_equations (per_second)');
    LEGEND_ALGEBRAIC(:,57) = strpad('phi_B in component intracellular_concentrations_and_buffer_equations (millimolar_per_second)');
    LEGEND_CONSTANTS(:,26) = strpad('Mg_i in component intracellular_concentrations_and_buffer_equations (millimolar)');
    LEGEND_ALGEBRAIC(:,54) = strpad('F_C in component intracellular_concentrations_and_buffer_equations (millimolar_per_second)');
    LEGEND_ALGEBRAIC(:,55) = strpad('F_TC in component intracellular_concentrations_and_buffer_equations (millimolar_per_second)');
    LEGEND_ALGEBRAIC(:,56) = strpad('F_TMgC in component intracellular_concentrations_and_buffer_equations (millimolar_per_second)');
    LEGEND_CONSTANTS(:,27) = strpad('Vol in component cleft_space_equations (mm_cubed)');
    LEGEND_CONSTANTS(:,50) = strpad('V_i in component intracellular_concentrations_and_buffer_equations (mm_cubed)');
    LEGEND_ALGEBRAIC(:,62) = strpad('i_up in component SR_Ca_uptake_and_release (nanoA)');
    LEGEND_ALGEBRAIC(:,60) = strpad('i_rel in component SR_Ca_uptake_and_release (nanoA)');
    LEGEND_CONSTANTS(:,28) = strpad('Na_b in component cleft_space_equations (millimolar)');
    LEGEND_CONSTANTS(:,29) = strpad('Ca_b in component cleft_space_equations (millimolar)');
    LEGEND_CONSTANTS(:,51) = strpad('V_c in component cleft_space_equations (mm_cubed)');
    LEGEND_CONSTANTS(:,30) = strpad('tau_p in component cleft_space_equations (second)');
    LEGEND_STATES(:,24) = strpad('Ca_up in component SR_Ca_uptake_and_release (millimolar)');
    LEGEND_CONSTANTS(:,31) = strpad('alpha_up in component SR_Ca_uptake_and_release (nanoA)');
    LEGEND_CONSTANTS(:,32) = strpad('beta_up in component SR_Ca_uptake_and_release (nanoA)');
    LEGEND_STATES(:,25) = strpad('Ca_rel in component SR_Ca_uptake_and_release (millimolar)');
    LEGEND_CONSTANTS(:,33) = strpad('alpha_rel in component SR_Ca_uptake_and_release (nanoA_per_millimolar)');
    LEGEND_ALGEBRAIC(:,61) = strpad('i_tr in component SR_Ca_uptake_and_release (nanoA)');
    LEGEND_CONSTANTS(:,52) = strpad('K1 in component SR_Ca_uptake_and_release (dimensionless)');
    LEGEND_ALGEBRAIC(:,58) = strpad('K2 in component SR_Ca_uptake_and_release (millimolar)');
    LEGEND_CONSTANTS(:,34) = strpad('k_cyca in component SR_Ca_uptake_and_release (millimolar)');
    LEGEND_CONSTANTS(:,35) = strpad('k_xcs in component SR_Ca_uptake_and_release (dimensionless)');
    LEGEND_CONSTANTS(:,36) = strpad('k_SRCa in component SR_Ca_uptake_and_release (millimolar)');
    LEGEND_CONSTANTS(:,37) = strpad('k_rel in component SR_Ca_uptake_and_release (millimolar)');
    LEGEND_ALGEBRAIC(:,12) = strpad('r_act in component SR_Ca_uptake_and_release (per_second)');
    LEGEND_ALGEBRAIC(:,22) = strpad('r_inact in component SR_Ca_uptake_and_release (per_second)');
    LEGEND_STATES(:,26) = strpad('Ca_Calse in component SR_Ca_uptake_and_release (dimensionless)');
    LEGEND_ALGEBRAIC(:,59) = strpad('phi_Calse in component SR_Ca_uptake_and_release (per_second)');
    LEGEND_STATES(:,27) = strpad('F1 in component SR_Ca_uptake_and_release (dimensionless)');
    LEGEND_STATES(:,28) = strpad('F2 in component SR_Ca_uptake_and_release (dimensionless)');
    LEGEND_STATES(:,29) = strpad('F3 in component SR_Ca_uptake_and_release (dimensionless)');
    LEGEND_CONSTANTS(:,54) = strpad('V_up in component SR_Ca_uptake_and_release (mm_cubed)');
    LEGEND_CONSTANTS(:,55) = strpad('V_rel in component SR_Ca_uptake_and_release (mm_cubed)');
    LEGEND_CONSTANTS(:,38) = strpad('cGMP in component cAMP_balance (millimolar)');
    LEGEND_CONSTANTS(:,39) = strpad('Iso in component cAMP_balance (millimolar)');
    LEGEND_CONSTANTS(:,40) = strpad('Km_Iso in component cAMP_balance (millimolar)');
    LEGEND_CONSTANTS(:,41) = strpad('Km_ACh in component cAMP_balance (millimolar)');
    LEGEND_CONSTANTS(:,42) = strpad('K_PDE in component cAMP_balance (dimensionless)');
    LEGEND_CONSTANTS(:,43) = strpad('K_ADC in component cAMP_balance (millimolar_per_second)');
    LEGEND_CONSTANTS(:,44) = strpad('V_PDE in component cAMP_balance (per_second)');
    LEGEND_CONSTANTS(:,45) = strpad('P_M2_ADC in component cAMP_balance (dimensionless)');
    LEGEND_RATES(:,1) = strpad('d/dt V in component membrane (millivolt)');
    LEGEND_RATES(:,3) = strpad('d/dt m in component sodium_current_m_gate (dimensionless)');
    LEGEND_RATES(:,4) = strpad('d/dt h1 in component sodium_current_h_gate (dimensionless)');
    LEGEND_RATES(:,5) = strpad('d/dt h2 in component sodium_current_h_gate (dimensionless)');
    LEGEND_RATES(:,7) = strpad('d/dt d_L in component L_type_Ca_channel_d_gate (dimensionless)');
    LEGEND_RATES(:,8) = strpad('d/dt f_L in component L_type_Ca_channel_f_gate (dimensionless)');
    LEGEND_RATES(:,9) = strpad('d/dt d_T in component T_type_Ca_channel_d_gate (dimensionless)');
    LEGEND_RATES(:,10) = strpad('d/dt f_T in component T_type_Ca_channel_f_gate (dimensionless)');
    LEGEND_RATES(:,11) = strpad('d/dt P_a in component delayed_rectifying_potassium_current_P_a_gate (dimensionless)');
    LEGEND_RATES(:,12) = strpad('d/dt P_i in component delayed_rectifying_potassium_current_P_i_gate (dimensionless)');
    LEGEND_RATES(:,13) = strpad('d/dt y in component hyperpolarisation_activated_current_y_gate (dimensionless)');
    LEGEND_RATES(:,18) = strpad('d/dt a in component muscarinic_potassium_current (dimensionless)');
    LEGEND_RATES(:,20) = strpad('d/dt Ca_Calmod in component intracellular_concentrations_and_buffer_equations (dimensionless)');
    LEGEND_RATES(:,21) = strpad('d/dt Ca_Trop in component intracellular_concentrations_and_buffer_equations (dimensionless)');
    LEGEND_RATES(:,22) = strpad('d/dt Ca_Mg_Trop in component intracellular_concentrations_and_buffer_equations (dimensionless)');
    LEGEND_RATES(:,23) = strpad('d/dt Mg_Mg_Trop in component intracellular_concentrations_and_buffer_equations (dimensionless)');
    LEGEND_RATES(:,14) = strpad('d/dt Na_i in component intracellular_concentrations_and_buffer_equations (millimolar)');
    LEGEND_RATES(:,19) = strpad('d/dt K_i in component intracellular_concentrations_and_buffer_equations (millimolar)');
    LEGEND_RATES(:,16) = strpad('d/dt Ca_i in component intracellular_concentrations_and_buffer_equations (millimolar)');
    LEGEND_RATES(:,2) = strpad('d/dt Na_c in component cleft_space_equations (millimolar)');
    LEGEND_RATES(:,15) = strpad('d/dt K_c in component cleft_space_equations (millimolar)');
    LEGEND_RATES(:,17) = strpad('d/dt Ca_c in component cleft_space_equations (millimolar)');
    LEGEND_RATES(:,26) = strpad('d/dt Ca_Calse in component SR_Ca_uptake_and_release (dimensionless)');
    LEGEND_RATES(:,27) = strpad('d/dt F1 in component SR_Ca_uptake_and_release (dimensionless)');
    LEGEND_RATES(:,28) = strpad('d/dt F2 in component SR_Ca_uptake_and_release (dimensionless)');
    LEGEND_RATES(:,29) = strpad('d/dt F3 in component SR_Ca_uptake_and_release (dimensionless)');
    LEGEND_RATES(:,24) = strpad('d/dt Ca_up in component SR_Ca_uptake_and_release (millimolar)');
    LEGEND_RATES(:,25) = strpad('d/dt Ca_rel in component SR_Ca_uptake_and_release (millimolar)');
    LEGEND_RATES(:,6) = strpad('d/dt cAMP in component cAMP_balance (millimolar)');
    LEGEND_STATES  = LEGEND_STATES';
    LEGEND_ALGEBRAIC = LEGEND_ALGEBRAIC';
    LEGEND_RATES = LEGEND_RATES';
    LEGEND_CONSTANTS = LEGEND_CONSTANTS';
end

function [STATES, CONSTANTS] = initConsts()
    VOI = 0; CONSTANTS = []; STATES = []; ALGEBRAIC = [];
    STATES(:,1) = -49.54105;
    CONSTANTS(:,1) = 8314.472;
    CONSTANTS(:,2) = 310;
    CONSTANTS(:,3) = 96485.3415;
    CONSTANTS(:,4) = 5.5e-5;
    CONSTANTS(:,5) = 0.00344;
    STATES(:,2) = 139.9988;
    CONSTANTS(:,6) = 0;
    STATES(:,3) = 0.250113;
    STATES(:,4) = 0.001386897;
    STATES(:,5) = 0.002065463;
    CONSTANTS(:,7) = 0.02115;
    STATES(:,6) = 3e-3;
    CONSTANTS(:,8) = 46.4;
    STATES(:,7) = 0.002572773;
    STATES(:,8) = 0.98651;
    CONSTANTS(:,9) = 0.02521;
    CONSTANTS(:,10) = 45;
    STATES(:,9) = 0.02012114;
    STATES(:,10) = 0.1945111;
    CONSTANTS(:,11) = 5.4;
    STATES(:,11) = 0.02302278;
    STATES(:,12) = 0.3777728;
    CONSTANTS(:,12) = 0.00016;
    CONSTANTS(:,13) = 0.0000364;
    CONSTANTS(:,14) = 0.0000694;
    CONSTANTS(:,15) = 0.0067478;
    CONSTANTS(:,16) = 0.0128821;
    STATES(:,13) = 0.09227776;
    CONSTANTS(:,17) = 5.46;
    CONSTANTS(:,18) = 0.621;
    CONSTANTS(:,19) = 0.2192;
    STATES(:,14) = 9.701621;
    STATES(:,15) = 5.389014;
    STATES(:,16) = 3.787018e-4;
    CONSTANTS(:,20) = 0.02869;
    CONSTANTS(:,21) = 0.00001248;
    CONSTANTS(:,22) = 0.0001;
    CONSTANTS(:,23) = 0.5;
    STATES(:,17) = 2.00474;
    CONSTANTS(:,24) = 7.833e-3;
    STATES(:,18) = 0;
    CONSTANTS(:,25) = 200;
    STATES(:,19) = 1.407347e2;
    STATES(:,20) = 0.1411678;
    STATES(:,21) = 0.07331396;
    STATES(:,22) = 0.7618549;
    STATES(:,23) = 0.2097049;
    CONSTANTS(:,26) = 2.5;
    CONSTANTS(:,27) = 3.497e-6;
    CONSTANTS(:,28) = 140;
    CONSTANTS(:,29) = 2;
    CONSTANTS(:,30) = 0.01;
    STATES(:,24) = 16.95311;
    CONSTANTS(:,31) = 0.08;
    CONSTANTS(:,32) = 0.072;
    STATES(:,25) = 16.85024;
    CONSTANTS(:,33) = 0.5;
    CONSTANTS(:,34) = 0.00005;
    CONSTANTS(:,35) = 0.9;
    CONSTANTS(:,36) = 22;
    CONSTANTS(:,37) = 0.004;
    STATES(:,26) = 0.9528726;
    STATES(:,27) = 0.1133251;
    STATES(:,28) = 0.0007594214;
    STATES(:,29) = 0.8859153;
    CONSTANTS(:,38) = 2e-3;
    CONSTANTS(:,39) = 0;
    CONSTANTS(:,40) = 0.14e-3;
    CONSTANTS(:,41) = 0.14e-3;
    CONSTANTS(:,42) = 6;
    CONSTANTS(:,43) = 8e-3;
    CONSTANTS(:,44) = 20;
    CONSTANTS(:,45) = 0.02;
    CONSTANTS(:,46) = 1.00000 - CONSTANTS(:,6)./(CONSTANTS(:,6)+0.00100000);
    CONSTANTS(:,47) = 1.00000 - CONSTANTS(:,6)./(CONSTANTS(:,6)+0.500000);
    CONSTANTS(:,48) = piecewise({CONSTANTS(:,25)<100.000&CONSTANTS(:,25)>25.0000, 1.02600./(1.00000+exp((CONSTANTS(:,25)+11.0500)./ - 7.50950)) - 0.990000 }, 0.000600000);
    CONSTANTS(:,49) = 12.3200./(1.00000+0.00420000./CONSTANTS(:,6));
    CONSTANTS(:,50) =  0.465000.*CONSTANTS(:,27);
    CONSTANTS(:,51) =  0.136000.*CONSTANTS(:,27);
    CONSTANTS(:,52) = ( CONSTANTS(:,34).*CONSTANTS(:,35))./CONSTANTS(:,36);
    CONSTANTS(:,53) =  CONSTANTS(:,48).*CONSTANTS(:,24);
    CONSTANTS(:,54) =  0.0116600.*CONSTANTS(:,50);
    CONSTANTS(:,55) =  0.00129600.*CONSTANTS(:,50);
    if (isempty(STATES)), warning('Initial values for states not set');, end
end

function [RATES, ALGEBRAIC] = computeRates(VOI, STATES, CONSTANTS)
    global algebraicVariableCount;
    statesSize = size(STATES);
    statesColumnCount = statesSize(2);
    if ( statesColumnCount == 1)
        STATES = STATES';
        ALGEBRAIC = zeros(1, algebraicVariableCount);
        utilOnes = 1;
    else
        statesRowCount = statesSize(1);
        ALGEBRAIC = zeros(statesRowCount, algebraicVariableCount);
        RATES = zeros(statesRowCount, statesColumnCount);
        utilOnes = ones(statesRowCount, 1);
    end
    RATES(:,6) =  1.00000.*( CONSTANTS(:,43).*((1.00000+CONSTANTS(:,39)./(CONSTANTS(:,39)+CONSTANTS(:,40))) - ( CONSTANTS(:,45).*CONSTANTS(:,6))./( CONSTANTS(:,45).*CONSTANTS(:,6)+CONSTANTS(:,41))) - ( CONSTANTS(:,44).*CONSTANTS(:,38).*STATES(:,6))./(STATES(:,6)+ CONSTANTS(:,42).*CONSTANTS(:,38)));
    ALGEBRAIC(:,9) =  17.0000.*exp( 0.0133000.*(STATES(:,1)+40.0000));
    RATES(:,18) =  CONSTANTS(:,49).*(1.00000 - STATES(:,18)) -  ALGEBRAIC(:,9).*STATES(:,18);
    ALGEBRAIC(:,11) =  1290.00.*CONSTANTS(:,26).*(1.00000 - (STATES(:,22)+STATES(:,23))) -  429.000.*STATES(:,23);
    RATES(:,23) = ALGEBRAIC(:,11);
    ALGEBRAIC(:,12) =  240.000.*exp( (STATES(:,1) - 40.0000).*0.0800000)+ 240.000.*power(STATES(:,16)./(STATES(:,16)+CONSTANTS(:,37)), 4.00000);
    RATES(:,27) =  0.960000.*STATES(:,29) -  ALGEBRAIC(:,12).*STATES(:,27);
    ALGEBRAIC(:,18) = 1.00000./( 17.0000.*exp( 0.0398000.*STATES(:,1))+ 2.11000.*exp(  - 0.0510000.*STATES(:,1)));
    ALGEBRAIC(:,6) = 1.00000./(1.00000+exp((STATES(:,1)+5.10000)./ - 7.40000));
    RATES(:,11) = (ALGEBRAIC(:,6) - STATES(:,11))./ALGEBRAIC(:,18);
    ALGEBRAIC(:,7) =  100.000.*exp(  - 0.0183000.*STATES(:,1));
    ALGEBRAIC(:,19) =  656.000.*exp( 0.00942000.*STATES(:,1));
    RATES(:,12) =  ALGEBRAIC(:,7).*(1.00000 - STATES(:,12)) -  ALGEBRAIC(:,19).*STATES(:,12);
    ALGEBRAIC(:,22) = 40.0000+ 240.000.*power(STATES(:,16)./(STATES(:,16)+CONSTANTS(:,37)), 4.00000);
    RATES(:,28) =  ALGEBRAIC(:,12).*STATES(:,27) -  ALGEBRAIC(:,22).*STATES(:,28);
    RATES(:,29) =  ALGEBRAIC(:,22).*STATES(:,28) -  0.960000.*STATES(:,29);
    ALGEBRAIC(:,8) = 20.5000./(1.00000+exp((STATES(:,6) - 0.00340000)./ - 0.000500000)) - 78.5600;
    ALGEBRAIC(:,20) = 1.00000./(1.00000+exp((STATES(:,1) - ALGEBRAIC(:,8))./9.00000));
    ALGEBRAIC(:,28) = 1.00000./( 1.64830.*exp((STATES(:,1)+54.0600)./ - 24.3300)+14.0106./(0.700000+exp((STATES(:,1)+60.0000)./ - 5.50000)));
    RATES(:,13) = (ALGEBRAIC(:,20) - STATES(:,13))./ALGEBRAIC(:,28);
    ALGEBRAIC(:,1) = (  - 824.000.*(STATES(:,1)+51.9000))./(exp((STATES(:,1)+51.9000)./ - 8.90000) - 1.00000);
    ALGEBRAIC(:,13) =  32960.0.*exp((STATES(:,1)+51.9000)./ - 8.90000);
    ALGEBRAIC(:,23) = ALGEBRAIC(:,1)./(ALGEBRAIC(:,1)+ALGEBRAIC(:,13));
    ALGEBRAIC(:,30) = 1.00000./(ALGEBRAIC(:,1)+ALGEBRAIC(:,13))+1.50000e-05;
    RATES(:,3) = (ALGEBRAIC(:,23) - STATES(:,3))./ALGEBRAIC(:,30);
    ALGEBRAIC(:,2) =  165.000.*exp((STATES(:,1)+101.300)./ - 12.6000);
    ALGEBRAIC(:,14) = 12360.0./( 320.000.*exp((STATES(:,1)+101.300)./ - 12.6000)+1.00000);
    ALGEBRAIC(:,24) = ALGEBRAIC(:,2)./(ALGEBRAIC(:,2)+ALGEBRAIC(:,14));
    ALGEBRAIC(:,31) = 1.00000./(ALGEBRAIC(:,2)+ALGEBRAIC(:,14));
    RATES(:,4) = (ALGEBRAIC(:,24) - STATES(:,4))./ALGEBRAIC(:,31);
    ALGEBRAIC(:,32) = 1.00000./(1.00000+exp((STATES(:,1)+30.0000)./5.00000));
    ALGEBRAIC(:,3) = ( 3.75000.*(STATES(:,1)+28.0000))./(exp((STATES(:,1)+28.0000)./4.00000) - 1.00000);
    ALGEBRAIC(:,15) = 30.0000./(1.00000+exp((STATES(:,1)+28.0000)./ - 4.00000));
    ALGEBRAIC(:,25) = 1.00000./(ALGEBRAIC(:,3)+ALGEBRAIC(:,15));
    RATES(:,8) = (ALGEBRAIC(:,32) - STATES(:,8))./ALGEBRAIC(:,25);
    ALGEBRAIC(:,33) = 1.00000./(1.00000+exp((STATES(:,1)+26.3000)./ - 6.00000));
    ALGEBRAIC(:,4) =  1068.00.*exp((STATES(:,1)+26.3000)./30.0000);
    ALGEBRAIC(:,16) =  1068.00.*exp((STATES(:,1)+26.3000)./ - 30.0000);
    ALGEBRAIC(:,26) = 1.00000./(ALGEBRAIC(:,4)+ALGEBRAIC(:,16));
    RATES(:,9) = (ALGEBRAIC(:,33) - STATES(:,9))./ALGEBRAIC(:,26);
    ALGEBRAIC(:,34) = 1.00000./(1.00000+exp((STATES(:,1)+61.7000)./5.60000));
    ALGEBRAIC(:,5) =  15.3000.*exp((STATES(:,1)+61.7000)./ - 83.3000);
    ALGEBRAIC(:,17) =  15.0000.*exp((STATES(:,1)+61.7000)./15.3800);
    ALGEBRAIC(:,27) = 1.00000./(ALGEBRAIC(:,5)+ALGEBRAIC(:,17));
    RATES(:,10) = (ALGEBRAIC(:,34) - STATES(:,10))./ALGEBRAIC(:,27);
    ALGEBRAIC(:,36) = ALGEBRAIC(:,24);
    ALGEBRAIC(:,38) =  20.0000.*ALGEBRAIC(:,31);
    RATES(:,5) = (ALGEBRAIC(:,36) - STATES(:,5))./ALGEBRAIC(:,38);
    ALGEBRAIC(:,39) = 1.00000./(1.00000+exp((STATES(:,1)+14.1000)./ - 6.00000));
    ALGEBRAIC(:,29) = (  - 28.3900.*(STATES(:,1)+35.0000))./(exp((STATES(:,1)+35.0000)./ - 2.50000) - 1.00000)+(  - 84.9000.*STATES(:,1))./(exp(  - 0.208000.*STATES(:,1)) - 1.00000);
    ALGEBRAIC(:,35) = ( 11.4300.*(STATES(:,1) - 5.00000))./(exp( 0.400000.*(STATES(:,1) - 5.00000)) - 1.00000);
    ALGEBRAIC(:,37) = 1.00000./(ALGEBRAIC(:,29)+ALGEBRAIC(:,35));
    RATES(:,7) = (ALGEBRAIC(:,39) - STATES(:,7))./ALGEBRAIC(:,37);
    ALGEBRAIC(:,51) =  129000..*STATES(:,16).*(1.00000 - STATES(:,20)) -  307.000.*STATES(:,20);
    RATES(:,20) = ALGEBRAIC(:,51);
    ALGEBRAIC(:,52) =  50500.0.*STATES(:,16).*(1.00000 - STATES(:,21)) -  252.000.*STATES(:,21);
    RATES(:,21) = ALGEBRAIC(:,52);
    ALGEBRAIC(:,53) =  129000..*STATES(:,16).*(1.00000 - (STATES(:,22)+STATES(:,23))) -  4.25000.*STATES(:,22);
    RATES(:,22) = ALGEBRAIC(:,53);
    ALGEBRAIC(:,59) =  770.000.*STATES(:,25).*(1.00000 - STATES(:,26)) -  641.000.*STATES(:,26);
    RATES(:,26) = ALGEBRAIC(:,59);
    ALGEBRAIC(:,60) =  CONSTANTS(:,33).*power(STATES(:,28)./(STATES(:,28)+0.250000), 2.00000).*STATES(:,25);
    ALGEBRAIC(:,61) = ( (STATES(:,24) - STATES(:,25)).*2.00000.*CONSTANTS(:,3).*CONSTANTS(:,54))./0.0641800;
    RATES(:,25) = (ALGEBRAIC(:,61) - ALGEBRAIC(:,60))./( 2.00000.*CONSTANTS(:,55).*CONSTANTS(:,3)) -  11.4800.*ALGEBRAIC(:,59);
    ALGEBRAIC(:,58) = STATES(:,16)+ STATES(:,24).*CONSTANTS(:,52)+ CONSTANTS(:,34).*CONSTANTS(:,35)+CONSTANTS(:,34);
    ALGEBRAIC(:,62) = ( CONSTANTS(:,31).*STATES(:,16) -  CONSTANTS(:,32).*STATES(:,24).*CONSTANTS(:,52))./ALGEBRAIC(:,58);
    RATES(:,24) = (ALGEBRAIC(:,62) - ALGEBRAIC(:,61))./( 2.00000.*CONSTANTS(:,54).*CONSTANTS(:,3));
    ALGEBRAIC(:,63) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(STATES(:,2)./STATES(:,14));
    ALGEBRAIC(:,64) = ( (( CONSTANTS(:,46).*CONSTANTS(:,5).*power(STATES(:,3), 3.00000).*STATES(:,4).*STATES(:,5).*STATES(:,2).*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*(exp(( (STATES(:,1) - ALGEBRAIC(:,63)).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000))./(exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000);
    ALGEBRAIC(:,47) = 1.60000./(1.00000+exp((STATES(:,6) - 0.00375000)./ - 0.000150000))+0.990000;
    ALGEBRAIC(:,48) = piecewise({STATES(:,16)<0.000150000, ( (2.00000 - ALGEBRAIC(:,47)).*CONSTANTS(:,19).*power(STATES(:,14)./(CONSTANTS(:,17)+STATES(:,14)), 3.00000).*power(STATES(:,15)./(CONSTANTS(:,18)+STATES(:,15)), 2.00000).*1.60000)./(1.50000+exp((STATES(:,1)+60.0000)./ - 40.0000)) }, ( ALGEBRAIC(:,47).*CONSTANTS(:,19).*power(STATES(:,14)./(CONSTANTS(:,17)+STATES(:,14)), 3.00000).*power(STATES(:,15)./(CONSTANTS(:,18)+STATES(:,15)), 2.00000).*1.60000)./(1.50000+exp((STATES(:,1)+60.0000)./ - 40.0000)));
    ALGEBRAIC(:,50) = ( CONSTANTS(:,21).*( power(STATES(:,14), 3.00000).*STATES(:,17).*exp( 0.0374300.*STATES(:,1).*CONSTANTS(:,23)) -  power(STATES(:,2), 3.00000).*STATES(:,16).*exp( 0.0374300.*STATES(:,1).*(CONSTANTS(:,23) - 1.00000))))./(1.00000+ CONSTANTS(:,22).*( STATES(:,16).*power(STATES(:,2), 3.00000)+ STATES(:,17).*power(STATES(:,14), 3.00000)));
    ALGEBRAIC(:,65) =  CONSTANTS(:,47).*CONSTANTS(:,12).*(STATES(:,1) - ALGEBRAIC(:,63));
    ALGEBRAIC(:,44) =  CONSTANTS(:,15).*power(STATES(:,13), 2.00000).*(STATES(:,1) - 75.0000);
    RATES(:,14) =  - ( 3.00000.*ALGEBRAIC(:,48)+ 3.00000.*ALGEBRAIC(:,50)+ALGEBRAIC(:,65)+ALGEBRAIC(:,44)+ALGEBRAIC(:,64))./( CONSTANTS(:,3).*CONSTANTS(:,50));
    RATES(:,2) = (CONSTANTS(:,28) - STATES(:,2))./CONSTANTS(:,30)+(ALGEBRAIC(:,64)+ 3.00000.*ALGEBRAIC(:,50)+ 3.00000.*ALGEBRAIC(:,48)+ALGEBRAIC(:,65)+ALGEBRAIC(:,44))./( CONSTANTS(:,3).*CONSTANTS(:,51));
    ALGEBRAIC(:,42) =  0.620000.*(1.00000+( 2.61290.*STATES(:,6))./(STATES(:,6)+0.00900000)) - 0.0250000;
    ALGEBRAIC(:,43) =  ALGEBRAIC(:,42).*0.00693000.*power(CONSTANTS(:,11)./1.00000, 0.590000);
    ALGEBRAIC(:,66) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(STATES(:,15)./STATES(:,19));
    ALGEBRAIC(:,67) =  ALGEBRAIC(:,43).*STATES(:,11).*STATES(:,12).*(STATES(:,1) - ALGEBRAIC(:,66));
    ALGEBRAIC(:,68) =  CONSTANTS(:,14).*(STATES(:,1) - ALGEBRAIC(:,66));
    ALGEBRAIC(:,45) =  CONSTANTS(:,16).*power(STATES(:,13), 2.00000).*(STATES(:,1)+85.0000);
    RATES(:,19) = ( 2.00000.*ALGEBRAIC(:,48) - (ALGEBRAIC(:,67)+ALGEBRAIC(:,45)+ALGEBRAIC(:,68)))./( CONSTANTS(:,3).*CONSTANTS(:,50));
    RATES(:,15) = (CONSTANTS(:,11) - STATES(:,15))./CONSTANTS(:,30)+(  - 2.00000.*ALGEBRAIC(:,48)+ALGEBRAIC(:,67)+ALGEBRAIC(:,68)+ALGEBRAIC(:,45))./( CONSTANTS(:,3).*CONSTANTS(:,51));
    ALGEBRAIC(:,41) =  CONSTANTS(:,9).*STATES(:,9).*STATES(:,10).*(STATES(:,1) - CONSTANTS(:,10));
    ALGEBRAIC(:,10) =  0.400000.*(1.00000+( 4.50000.*STATES(:,6))./(STATES(:,6)+0.00650000))+0.0315700;
    ALGEBRAIC(:,21) =  CONSTANTS(:,7).*ALGEBRAIC(:,10);
    ALGEBRAIC(:,40) =  ALGEBRAIC(:,21).*( STATES(:,8).*STATES(:,7)+ 0.0950000.*ALGEBRAIC(:,39)).*(STATES(:,1) - CONSTANTS(:,8));
    ALGEBRAIC(:,49) = ( CONSTANTS(:,20).*STATES(:,16))./(STATES(:,16)+0.000400000);
    ALGEBRAIC(:,71) =  (( 0.500000.*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(STATES(:,17)./STATES(:,16));
    ALGEBRAIC(:,72) =  CONSTANTS(:,13).*(STATES(:,1) - ALGEBRAIC(:,71));
    ALGEBRAIC(:,54) =  0.0900000.*ALGEBRAIC(:,51);
    ALGEBRAIC(:,55) =  0.0310000.*ALGEBRAIC(:,52);
    ALGEBRAIC(:,56) =  0.0620000.*ALGEBRAIC(:,53);
    ALGEBRAIC(:,57) = ALGEBRAIC(:,54)+ALGEBRAIC(:,55)+ALGEBRAIC(:,56);
    RATES(:,16) = (( 2.00000.*ALGEBRAIC(:,50)+ALGEBRAIC(:,60)) - (ALGEBRAIC(:,40)+ALGEBRAIC(:,41)+ALGEBRAIC(:,49)+ALGEBRAIC(:,72)+ALGEBRAIC(:,62)))./( 2.00000.*CONSTANTS(:,50).*CONSTANTS(:,3)) - ALGEBRAIC(:,57);
    RATES(:,17) = (CONSTANTS(:,29) - STATES(:,17))./CONSTANTS(:,30)+(  - 2.00000.*ALGEBRAIC(:,50)+ALGEBRAIC(:,40)+ALGEBRAIC(:,41)+ALGEBRAIC(:,49)+ALGEBRAIC(:,72))./( 2.00000.*CONSTANTS(:,3).*CONSTANTS(:,51));
    ALGEBRAIC(:,46) = ALGEBRAIC(:,44)+ALGEBRAIC(:,45);
    ALGEBRAIC(:,73) = ALGEBRAIC(:,65)+ALGEBRAIC(:,72)+ALGEBRAIC(:,68);
    ALGEBRAIC(:,69) =  CONSTANTS(:,53).*(STATES(:,1) - ALGEBRAIC(:,66));
    ALGEBRAIC(:,70) =  STATES(:,18).*ALGEBRAIC(:,69);
    RATES(:,1) =  - (ALGEBRAIC(:,64)+ALGEBRAIC(:,41)+ALGEBRAIC(:,40)+ALGEBRAIC(:,67)+ALGEBRAIC(:,46)+ALGEBRAIC(:,73)+ALGEBRAIC(:,48)+ALGEBRAIC(:,50)+ALGEBRAIC(:,49)+ALGEBRAIC(:,70))./CONSTANTS(:,4);
   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) =  17.0000.*exp( 0.0133000.*(STATES(:,1)+40.0000));
    ALGEBRAIC(:,11) =  1290.00.*CONSTANTS(:,26).*(1.00000 - (STATES(:,22)+STATES(:,23))) -  429.000.*STATES(:,23);
    ALGEBRAIC(:,12) =  240.000.*exp( (STATES(:,1) - 40.0000).*0.0800000)+ 240.000.*power(STATES(:,16)./(STATES(:,16)+CONSTANTS(:,37)), 4.00000);
    ALGEBRAIC(:,18) = 1.00000./( 17.0000.*exp( 0.0398000.*STATES(:,1))+ 2.11000.*exp(  - 0.0510000.*STATES(:,1)));
    ALGEBRAIC(:,6) = 1.00000./(1.00000+exp((STATES(:,1)+5.10000)./ - 7.40000));
    ALGEBRAIC(:,7) =  100.000.*exp(  - 0.0183000.*STATES(:,1));
    ALGEBRAIC(:,19) =  656.000.*exp( 0.00942000.*STATES(:,1));
    ALGEBRAIC(:,22) = 40.0000+ 240.000.*power(STATES(:,16)./(STATES(:,16)+CONSTANTS(:,37)), 4.00000);
    ALGEBRAIC(:,8) = 20.5000./(1.00000+exp((STATES(:,6) - 0.00340000)./ - 0.000500000)) - 78.5600;
    ALGEBRAIC(:,20) = 1.00000./(1.00000+exp((STATES(:,1) - ALGEBRAIC(:,8))./9.00000));
    ALGEBRAIC(:,28) = 1.00000./( 1.64830.*exp((STATES(:,1)+54.0600)./ - 24.3300)+14.0106./(0.700000+exp((STATES(:,1)+60.0000)./ - 5.50000)));
    ALGEBRAIC(:,1) = (  - 824.000.*(STATES(:,1)+51.9000))./(exp((STATES(:,1)+51.9000)./ - 8.90000) - 1.00000);
    ALGEBRAIC(:,13) =  32960.0.*exp((STATES(:,1)+51.9000)./ - 8.90000);
    ALGEBRAIC(:,23) = ALGEBRAIC(:,1)./(ALGEBRAIC(:,1)+ALGEBRAIC(:,13));
    ALGEBRAIC(:,30) = 1.00000./(ALGEBRAIC(:,1)+ALGEBRAIC(:,13))+1.50000e-05;
    ALGEBRAIC(:,2) =  165.000.*exp((STATES(:,1)+101.300)./ - 12.6000);
    ALGEBRAIC(:,14) = 12360.0./( 320.000.*exp((STATES(:,1)+101.300)./ - 12.6000)+1.00000);
    ALGEBRAIC(:,24) = ALGEBRAIC(:,2)./(ALGEBRAIC(:,2)+ALGEBRAIC(:,14));
    ALGEBRAIC(:,31) = 1.00000./(ALGEBRAIC(:,2)+ALGEBRAIC(:,14));
    ALGEBRAIC(:,32) = 1.00000./(1.00000+exp((STATES(:,1)+30.0000)./5.00000));
    ALGEBRAIC(:,3) = ( 3.75000.*(STATES(:,1)+28.0000))./(exp((STATES(:,1)+28.0000)./4.00000) - 1.00000);
    ALGEBRAIC(:,15) = 30.0000./(1.00000+exp((STATES(:,1)+28.0000)./ - 4.00000));
    ALGEBRAIC(:,25) = 1.00000./(ALGEBRAIC(:,3)+ALGEBRAIC(:,15));
    ALGEBRAIC(:,33) = 1.00000./(1.00000+exp((STATES(:,1)+26.3000)./ - 6.00000));
    ALGEBRAIC(:,4) =  1068.00.*exp((STATES(:,1)+26.3000)./30.0000);
    ALGEBRAIC(:,16) =  1068.00.*exp((STATES(:,1)+26.3000)./ - 30.0000);
    ALGEBRAIC(:,26) = 1.00000./(ALGEBRAIC(:,4)+ALGEBRAIC(:,16));
    ALGEBRAIC(:,34) = 1.00000./(1.00000+exp((STATES(:,1)+61.7000)./5.60000));
    ALGEBRAIC(:,5) =  15.3000.*exp((STATES(:,1)+61.7000)./ - 83.3000);
    ALGEBRAIC(:,17) =  15.0000.*exp((STATES(:,1)+61.7000)./15.3800);
    ALGEBRAIC(:,27) = 1.00000./(ALGEBRAIC(:,5)+ALGEBRAIC(:,17));
    ALGEBRAIC(:,36) = ALGEBRAIC(:,24);
    ALGEBRAIC(:,38) =  20.0000.*ALGEBRAIC(:,31);
    ALGEBRAIC(:,39) = 1.00000./(1.00000+exp((STATES(:,1)+14.1000)./ - 6.00000));
    ALGEBRAIC(:,29) = (  - 28.3900.*(STATES(:,1)+35.0000))./(exp((STATES(:,1)+35.0000)./ - 2.50000) - 1.00000)+(  - 84.9000.*STATES(:,1))./(exp(  - 0.208000.*STATES(:,1)) - 1.00000);
    ALGEBRAIC(:,35) = ( 11.4300.*(STATES(:,1) - 5.00000))./(exp( 0.400000.*(STATES(:,1) - 5.00000)) - 1.00000);
    ALGEBRAIC(:,37) = 1.00000./(ALGEBRAIC(:,29)+ALGEBRAIC(:,35));
    ALGEBRAIC(:,51) =  129000..*STATES(:,16).*(1.00000 - STATES(:,20)) -  307.000.*STATES(:,20);
    ALGEBRAIC(:,52) =  50500.0.*STATES(:,16).*(1.00000 - STATES(:,21)) -  252.000.*STATES(:,21);
    ALGEBRAIC(:,53) =  129000..*STATES(:,16).*(1.00000 - (STATES(:,22)+STATES(:,23))) -  4.25000.*STATES(:,22);
    ALGEBRAIC(:,59) =  770.000.*STATES(:,25).*(1.00000 - STATES(:,26)) -  641.000.*STATES(:,26);
    ALGEBRAIC(:,60) =  CONSTANTS(:,33).*power(STATES(:,28)./(STATES(:,28)+0.250000), 2.00000).*STATES(:,25);
    ALGEBRAIC(:,61) = ( (STATES(:,24) - STATES(:,25)).*2.00000.*CONSTANTS(:,3).*CONSTANTS(:,54))./0.0641800;
    ALGEBRAIC(:,58) = STATES(:,16)+ STATES(:,24).*CONSTANTS(:,52)+ CONSTANTS(:,34).*CONSTANTS(:,35)+CONSTANTS(:,34);
    ALGEBRAIC(:,62) = ( CONSTANTS(:,31).*STATES(:,16) -  CONSTANTS(:,32).*STATES(:,24).*CONSTANTS(:,52))./ALGEBRAIC(:,58);
    ALGEBRAIC(:,63) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(STATES(:,2)./STATES(:,14));
    ALGEBRAIC(:,64) = ( (( CONSTANTS(:,46).*CONSTANTS(:,5).*power(STATES(:,3), 3.00000).*STATES(:,4).*STATES(:,5).*STATES(:,2).*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*(exp(( (STATES(:,1) - ALGEBRAIC(:,63)).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000))./(exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000);
    ALGEBRAIC(:,47) = 1.60000./(1.00000+exp((STATES(:,6) - 0.00375000)./ - 0.000150000))+0.990000;
    ALGEBRAIC(:,48) = piecewise({STATES(:,16)<0.000150000, ( (2.00000 - ALGEBRAIC(:,47)).*CONSTANTS(:,19).*power(STATES(:,14)./(CONSTANTS(:,17)+STATES(:,14)), 3.00000).*power(STATES(:,15)./(CONSTANTS(:,18)+STATES(:,15)), 2.00000).*1.60000)./(1.50000+exp((STATES(:,1)+60.0000)./ - 40.0000)) }, ( ALGEBRAIC(:,47).*CONSTANTS(:,19).*power(STATES(:,14)./(CONSTANTS(:,17)+STATES(:,14)), 3.00000).*power(STATES(:,15)./(CONSTANTS(:,18)+STATES(:,15)), 2.00000).*1.60000)./(1.50000+exp((STATES(:,1)+60.0000)./ - 40.0000)));
    ALGEBRAIC(:,50) = ( CONSTANTS(:,21).*( power(STATES(:,14), 3.00000).*STATES(:,17).*exp( 0.0374300.*STATES(:,1).*CONSTANTS(:,23)) -  power(STATES(:,2), 3.00000).*STATES(:,16).*exp( 0.0374300.*STATES(:,1).*(CONSTANTS(:,23) - 1.00000))))./(1.00000+ CONSTANTS(:,22).*( STATES(:,16).*power(STATES(:,2), 3.00000)+ STATES(:,17).*power(STATES(:,14), 3.00000)));
    ALGEBRAIC(:,65) =  CONSTANTS(:,47).*CONSTANTS(:,12).*(STATES(:,1) - ALGEBRAIC(:,63));
    ALGEBRAIC(:,44) =  CONSTANTS(:,15).*power(STATES(:,13), 2.00000).*(STATES(:,1) - 75.0000);
    ALGEBRAIC(:,42) =  0.620000.*(1.00000+( 2.61290.*STATES(:,6))./(STATES(:,6)+0.00900000)) - 0.0250000;
    ALGEBRAIC(:,43) =  ALGEBRAIC(:,42).*0.00693000.*power(CONSTANTS(:,11)./1.00000, 0.590000);
    ALGEBRAIC(:,66) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(STATES(:,15)./STATES(:,19));
    ALGEBRAIC(:,67) =  ALGEBRAIC(:,43).*STATES(:,11).*STATES(:,12).*(STATES(:,1) - ALGEBRAIC(:,66));
    ALGEBRAIC(:,68) =  CONSTANTS(:,14).*(STATES(:,1) - ALGEBRAIC(:,66));
    ALGEBRAIC(:,45) =  CONSTANTS(:,16).*power(STATES(:,13), 2.00000).*(STATES(:,1)+85.0000);
    ALGEBRAIC(:,41) =  CONSTANTS(:,9).*STATES(:,9).*STATES(:,10).*(STATES(:,1) - CONSTANTS(:,10));
    ALGEBRAIC(:,10) =  0.400000.*(1.00000+( 4.50000.*STATES(:,6))./(STATES(:,6)+0.00650000))+0.0315700;
    ALGEBRAIC(:,21) =  CONSTANTS(:,7).*ALGEBRAIC(:,10);
    ALGEBRAIC(:,40) =  ALGEBRAIC(:,21).*( STATES(:,8).*STATES(:,7)+ 0.0950000.*ALGEBRAIC(:,39)).*(STATES(:,1) - CONSTANTS(:,8));
    ALGEBRAIC(:,49) = ( CONSTANTS(:,20).*STATES(:,16))./(STATES(:,16)+0.000400000);
    ALGEBRAIC(:,71) =  (( 0.500000.*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(STATES(:,17)./STATES(:,16));
    ALGEBRAIC(:,72) =  CONSTANTS(:,13).*(STATES(:,1) - ALGEBRAIC(:,71));
    ALGEBRAIC(:,54) =  0.0900000.*ALGEBRAIC(:,51);
    ALGEBRAIC(:,55) =  0.0310000.*ALGEBRAIC(:,52);
    ALGEBRAIC(:,56) =  0.0620000.*ALGEBRAIC(:,53);
    ALGEBRAIC(:,57) = ALGEBRAIC(:,54)+ALGEBRAIC(:,55)+ALGEBRAIC(:,56);
    ALGEBRAIC(:,46) = ALGEBRAIC(:,44)+ALGEBRAIC(:,45);
    ALGEBRAIC(:,73) = ALGEBRAIC(:,65)+ALGEBRAIC(:,72)+ALGEBRAIC(:,68);
    ALGEBRAIC(:,69) =  CONSTANTS(:,53).*(STATES(:,1) - ALGEBRAIC(:,66));
    ALGEBRAIC(:,70) =  STATES(:,18).*ALGEBRAIC(:,69);
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