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

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

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

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

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

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

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

function [LEGEND_STATES, LEGEND_ALGEBRAIC, LEGEND_VOI, LEGEND_CONSTANTS] = createLegends()
    LEGEND_STATES = ''; LEGEND_ALGEBRAIC = ''; LEGEND_VOI = ''; LEGEND_CONSTANTS = '';
    LEGEND_VOI = strpad('time in component environment (second)');
    LEGEND_CONSTANTS(:,1) = strpad('CT in component environment (dimensionless)');
    LEGEND_CONSTANTS(:,2) = strpad('PM in component environment (dimensionless)');
    LEGEND_STATES(:,1) = strpad('V in component membrane (millivolt)');
    LEGEND_CONSTANTS(:,3) = strpad('R in component membrane (millijoule_per_mole_kelvin)');
    LEGEND_CONSTANTS(:,4) = strpad('T in component membrane (kelvin)');
    LEGEND_CONSTANTS(:,5) = strpad('F in component membrane (coulomb_per_mole)');
    LEGEND_CONSTANTS(:,6) = strpad('Cm in component membrane (nanoF)');
    LEGEND_ALGEBRAIC(:,31) = strpad('i_Na in component sodium_current (picoA)');
    LEGEND_ALGEBRAIC(:,53) = strpad('i_Ca_L in component L_type_Ca_channel (picoA)');
    LEGEND_ALGEBRAIC(:,58) = strpad('i_Ca_T in component T_type_Ca_channel (picoA)');
    LEGEND_ALGEBRAIC(:,62) = strpad('i_to in component Ca_independent_transient_outward_K_current (picoA)');
    LEGEND_ALGEBRAIC(:,63) = strpad('i_sus in component Ca_independent_transient_outward_K_current (picoA)');
    LEGEND_ALGEBRAIC(:,66) = strpad('i_K1 in component inward_rectifier (picoA)');
    LEGEND_ALGEBRAIC(:,65) = strpad('i_Kr in component delayed_rectifier_K_current (picoA)');
    LEGEND_ALGEBRAIC(:,64) = strpad('i_Ks in component delayed_rectifier_K_current (picoA)');
    LEGEND_ALGEBRAIC(:,68) = strpad('i_B_Na in component background_currents (picoA)');
    LEGEND_ALGEBRAIC(:,69) = strpad('i_B_Ca in component background_currents (picoA)');
    LEGEND_ALGEBRAIC(:,70) = strpad('i_p in component sodium_potassium_pump (picoA)');
    LEGEND_ALGEBRAIC(:,71) = strpad('i_CaP in component sarcolemmal_calcium_pump_current (picoA)');
    LEGEND_ALGEBRAIC(:,72) = strpad('i_NaCa in component Na_Ca_ion_exchanger_current (picoA)');
    LEGEND_ALGEBRAIC(:,1) = strpad('i_Stim in component membrane (picoA)');
    LEGEND_CONSTANTS(:,7) = strpad('stim_start in component membrane (second)');
    LEGEND_CONSTANTS(:,8) = strpad('stim_end in component membrane (second)');
    LEGEND_CONSTANTS(:,9) = strpad('stim_period in component membrane (second)');
    LEGEND_CONSTANTS(:,10) = strpad('stim_duration in component membrane (second)');
    LEGEND_CONSTANTS(:,11) = strpad('stim_amplitude in component membrane (picoA)');
    LEGEND_ALGEBRAIC(:,16) = strpad('E_Na in component sodium_current (millivolt)');
    LEGEND_CONSTANTS(:,12) = strpad('P_Na in component sodium_current (nanolitre_per_second)');
    LEGEND_CONSTANTS(:,13) = strpad('Na_c in component cleft_space_ion_concentrations (millimolar)');
    LEGEND_STATES(:,2) = strpad('Na_i in component intracellular_ion_concentrations (millimolar)');
    LEGEND_STATES(:,3) = strpad('m in component sodium_current_m_gate (dimensionless)');
    LEGEND_STATES(:,4) = strpad('h1 in component sodium_current_h1_gate (dimensionless)');
    LEGEND_STATES(:,5) = strpad('h2 in component sodium_current_h2_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,2) = strpad('E0_m in component sodium_current_m_gate (millivolt)');
    LEGEND_ALGEBRAIC(:,17) = strpad('alpha_m in component sodium_current_m_gate (per_second)');
    LEGEND_ALGEBRAIC(:,32) = strpad('beta_m in component sodium_current_m_gate (per_second)');
    LEGEND_ALGEBRAIC(:,3) = strpad('alpha_h in component sodium_current_h1_gate (per_second)');
    LEGEND_ALGEBRAIC(:,18) = strpad('beta_h in component sodium_current_h1_gate (per_second)');
    LEGEND_ALGEBRAIC(:,33) = strpad('h_infinity in component sodium_current_h1_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,43) = strpad('tau_h1 in component sodium_current_h1_gate (second)');
    LEGEND_ALGEBRAIC(:,44) = strpad('tau_h2 in component sodium_current_h2_gate (second)');
    LEGEND_CONSTANTS(:,14) = strpad('g_Ca_L in component L_type_Ca_channel (nanoS)');
    LEGEND_CONSTANTS(:,15) = strpad('E_Ca_app in component L_type_Ca_channel (millivolt)');
    LEGEND_ALGEBRAIC(:,42) = strpad('d_prime in component L_type_Ca_channel (dimensionless)');
    LEGEND_STATES(:,6) = strpad('d_L in component L_type_Ca_channel_d_L_gate (dimensionless)');
    LEGEND_STATES(:,7) = strpad('f_L in component L_type_Ca_channel_f_L_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,4) = strpad('E0_alpha_d_L in component L_type_Ca_channel_d_L_gate (millivolt)');
    LEGEND_ALGEBRAIC(:,19) = strpad('E0_beta_d_L in component L_type_Ca_channel_d_L_gate (millivolt)');
    LEGEND_ALGEBRAIC(:,34) = strpad('E10 in component L_type_Ca_channel_d_L_gate (millivolt)');
    LEGEND_ALGEBRAIC(:,45) = strpad('alpha_d_L in component L_type_Ca_channel_d_L_gate (per_second)');
    LEGEND_ALGEBRAIC(:,54) = strpad('beta_d_L in component L_type_Ca_channel_d_L_gate (per_second)');
    LEGEND_ALGEBRAIC(:,59) = strpad('d_L_infinity in component L_type_Ca_channel_d_L_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,61) = strpad('tau_d_L in component L_type_Ca_channel_d_L_gate (second)');
    LEGEND_ALGEBRAIC(:,5) = strpad('E0_f_L in component L_type_Ca_channel_f_L_gate (millivolt)');
    LEGEND_ALGEBRAIC(:,20) = strpad('alpha_f_L in component L_type_Ca_channel_f_L_gate (per_second)');
    LEGEND_ALGEBRAIC(:,35) = strpad('beta_f_L in component L_type_Ca_channel_f_L_gate (per_second)');
    LEGEND_ALGEBRAIC(:,46) = strpad('f_L_infinity in component L_type_Ca_channel_f_L_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,55) = strpad('tau_f_L in component L_type_Ca_channel_f_L_gate (second)');
    LEGEND_CONSTANTS(:,16) = strpad('g_Ca_T in component T_type_Ca_channel (nanoS)');
    LEGEND_CONSTANTS(:,17) = strpad('E_Ca_T in component T_type_Ca_channel (millivolt)');
    LEGEND_STATES(:,8) = strpad('d_T in component T_type_Ca_channel_d_T_gate (dimensionless)');
    LEGEND_STATES(:,9) = strpad('f_T in component T_type_Ca_channel_f_T_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,6) = strpad('E0_d_T in component T_type_Ca_channel_d_T_gate (millivolt)');
    LEGEND_ALGEBRAIC(:,21) = strpad('alpha_d_T in component T_type_Ca_channel_d_T_gate (per_second)');
    LEGEND_ALGEBRAIC(:,36) = strpad('beta_d_T in component T_type_Ca_channel_d_T_gate (per_second)');
    LEGEND_ALGEBRAIC(:,47) = strpad('d_T_infinity in component T_type_Ca_channel_d_T_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,56) = strpad('tau_d_T in component T_type_Ca_channel_d_T_gate (second)');
    LEGEND_ALGEBRAIC(:,7) = strpad('E0_f_T in component T_type_Ca_channel_f_T_gate (millivolt)');
    LEGEND_ALGEBRAIC(:,22) = strpad('alpha_f_T in component T_type_Ca_channel_f_T_gate (per_second)');
    LEGEND_ALGEBRAIC(:,37) = strpad('beta_f_T in component T_type_Ca_channel_f_T_gate (per_second)');
    LEGEND_ALGEBRAIC(:,48) = strpad('f_T_infinity in component T_type_Ca_channel_f_T_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,57) = strpad('tau_f_T in component T_type_Ca_channel_f_T_gate (second)');
    LEGEND_ALGEBRAIC(:,60) = strpad('E_K in component Ca_independent_transient_outward_K_current (millivolt)');
    LEGEND_CONSTANTS(:,18) = strpad('g_to in component Ca_independent_transient_outward_K_current (nanoS)');
    LEGEND_STATES(:,10) = strpad('K_c in component cleft_space_ion_concentrations (millimolar)');
    LEGEND_STATES(:,11) = strpad('K_i in component intracellular_ion_concentrations (millimolar)');
    LEGEND_STATES(:,12) = strpad('r in component Ca_independent_transient_outward_K_current_r_gate (dimensionless)');
    LEGEND_STATES(:,13) = strpad('s1 in component Ca_independent_transient_outward_K_current_s1_gate (dimensionless)');
    LEGEND_STATES(:,14) = strpad('s2 in component Ca_independent_transient_outward_K_current_s2_gate (dimensionless)');
    LEGEND_STATES(:,15) = strpad('s3 in component Ca_independent_transient_outward_K_current_s3_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,8) = strpad('alpha_r in component Ca_independent_transient_outward_K_current_r_gate (per_second)');
    LEGEND_ALGEBRAIC(:,23) = strpad('beta_r in component Ca_independent_transient_outward_K_current_r_gate (per_second)');
    LEGEND_ALGEBRAIC(:,49) = strpad('tau_r in component Ca_independent_transient_outward_K_current_r_gate (second)');
    LEGEND_ALGEBRAIC(:,38) = strpad('r_infinity in component Ca_independent_transient_outward_K_current_r_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,24) = strpad('tau_s1 in component Ca_independent_transient_outward_K_current_s1_gate (second)');
    LEGEND_ALGEBRAIC(:,9) = strpad('s1_infinity in component Ca_independent_transient_outward_K_current_s1_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,25) = strpad('tau_s2 in component Ca_independent_transient_outward_K_current_s2_gate (second)');
    LEGEND_ALGEBRAIC(:,10) = strpad('s2_infinity in component Ca_independent_transient_outward_K_current_s2_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,26) = strpad('tau_s3 in component Ca_independent_transient_outward_K_current_s3_gate (second)');
    LEGEND_ALGEBRAIC(:,11) = strpad('s3_infinity in component Ca_independent_transient_outward_K_current_s3_gate (dimensionless)');
    LEGEND_CONSTANTS(:,19) = strpad('g_Ks in component delayed_rectifier_K_current (nanoS)');
    LEGEND_CONSTANTS(:,20) = strpad('g_Kr in component delayed_rectifier_K_current (nanoS)');
    LEGEND_STATES(:,16) = strpad('z in component delayed_rectifier_K_current_z_gate (dimensionless)');
    LEGEND_STATES(:,17) = strpad('p_a in component delayed_rectifier_K_current_pa_gate (dimensionless)');
    LEGEND_STATES(:,18) = strpad('p_i in component delayed_rectifier_K_current_pi_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,12) = strpad('alpha_z in component delayed_rectifier_K_current_z_gate (per_second)');
    LEGEND_ALGEBRAIC(:,27) = strpad('beta_z in component delayed_rectifier_K_current_z_gate (per_second)');
    LEGEND_ALGEBRAIC(:,50) = strpad('tau_z in component delayed_rectifier_K_current_z_gate (second)');
    LEGEND_ALGEBRAIC(:,39) = strpad('z_infinity in component delayed_rectifier_K_current_z_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,13) = strpad('alpha_p_a in component delayed_rectifier_K_current_pa_gate (per_second)');
    LEGEND_ALGEBRAIC(:,28) = strpad('beta_p_a in component delayed_rectifier_K_current_pa_gate (per_second)');
    LEGEND_ALGEBRAIC(:,51) = strpad('tau_p_a in component delayed_rectifier_K_current_pa_gate (second)');
    LEGEND_ALGEBRAIC(:,40) = strpad('p_a_infinity in component delayed_rectifier_K_current_pa_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,14) = strpad('alpha_p_i in component delayed_rectifier_K_current_pi_gate (per_second)');
    LEGEND_ALGEBRAIC(:,29) = strpad('beta_p_i in component delayed_rectifier_K_current_pi_gate (per_second)');
    LEGEND_ALGEBRAIC(:,52) = strpad('tau_p_i in component delayed_rectifier_K_current_pi_gate (second)');
    LEGEND_ALGEBRAIC(:,41) = strpad('p_i_infinity in component delayed_rectifier_K_current_pi_gate (dimensionless)');
    LEGEND_CONSTANTS(:,21) = strpad('g_K1 in component inward_rectifier (nanoS)');
    LEGEND_CONSTANTS(:,22) = strpad('KmK1 in component inward_rectifier (millimolar)');
    LEGEND_CONSTANTS(:,23) = strpad('steepK1 in component inward_rectifier (dimensionless)');
    LEGEND_CONSTANTS(:,24) = strpad('shiftK1 in component inward_rectifier (millivolt)');
    LEGEND_CONSTANTS(:,25) = strpad('g_B_Na in component background_currents (nanoS)');
    LEGEND_CONSTANTS(:,26) = strpad('g_B_Ca in component background_currents (nanoS)');
    LEGEND_ALGEBRAIC(:,67) = strpad('E_Ca in component background_currents (millivolt)');
    LEGEND_CONSTANTS(:,27) = strpad('Ca_c in component cleft_space_ion_concentrations (millimolar)');
    LEGEND_STATES(:,19) = strpad('Ca_i in component intracellular_ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,28) = strpad('k_NaK_K in component sodium_potassium_pump (millimolar)');
    LEGEND_CONSTANTS(:,29) = strpad('k_NaK_Na in component sodium_potassium_pump (millimolar)');
    LEGEND_CONSTANTS(:,30) = strpad('i_NaK_max in component sodium_potassium_pump (picoA)');
    LEGEND_CONSTANTS(:,31) = strpad('i_CaP_max in component sarcolemmal_calcium_pump_current (picoA)');
    LEGEND_CONSTANTS(:,32) = strpad('k_CaP in component sarcolemmal_calcium_pump_current (millimolar)');
    LEGEND_CONSTANTS(:,33) = strpad('k_NaCa in component Na_Ca_ion_exchanger_current (picoA_per_millimolar_4)');
    LEGEND_CONSTANTS(:,34) = strpad('d_NaCa in component Na_Ca_ion_exchanger_current (per_millimolar_4)');
    LEGEND_CONSTANTS(:,35) = strpad('gamma in component Na_Ca_ion_exchanger_current (dimensionless)');
    LEGEND_CONSTANTS(:,36) = strpad('Vol_i in component intracellular_ion_concentrations (nanolitre)');
    LEGEND_CONSTANTS(:,37) = strpad('Vol_Ca in component intracellular_ion_concentrations (nanolitre)');
    LEGEND_ALGEBRAIC(:,76) = strpad('i_up in component Ca_handling_by_the_SR (picoA)');
    LEGEND_ALGEBRAIC(:,78) = strpad('i_rel in component Ca_handling_by_the_SR (picoA)');
    LEGEND_ALGEBRAIC(:,73) = strpad('dOCdt in component intracellular_Ca_buffering (per_second)');
    LEGEND_ALGEBRAIC(:,74) = strpad('dOTCdt in component intracellular_Ca_buffering (per_second)');
    LEGEND_ALGEBRAIC(:,75) = strpad('dOTMgCdt in component intracellular_Ca_buffering (per_second)');
    LEGEND_STATES(:,20) = strpad('O_C in component intracellular_Ca_buffering (dimensionless)');
    LEGEND_STATES(:,21) = strpad('O_TC in component intracellular_Ca_buffering (dimensionless)');
    LEGEND_STATES(:,22) = strpad('O_TMgC in component intracellular_Ca_buffering (dimensionless)');
    LEGEND_STATES(:,23) = strpad('O_TMgMg in component intracellular_Ca_buffering (dimensionless)');
    LEGEND_CONSTANTS(:,38) = strpad('Mg_i in component intracellular_Ca_buffering (millimolar)');
    LEGEND_CONSTANTS(:,39) = strpad('Vol_c in component cleft_space_ion_concentrations (nanolitre)');
    LEGEND_ALGEBRAIC(:,77) = strpad('i_tr in component Ca_handling_by_the_SR (picoA)');
    LEGEND_CONSTANTS(:,40) = strpad('I_up_max in component Ca_handling_by_the_SR (picoA)');
    LEGEND_CONSTANTS(:,41) = strpad('k_cyca in component Ca_handling_by_the_SR (millimolar)');
    LEGEND_CONSTANTS(:,42) = strpad('k_srca in component Ca_handling_by_the_SR (millimolar)');
    LEGEND_CONSTANTS(:,43) = strpad('k_xcs in component Ca_handling_by_the_SR (dimensionless)');
    LEGEND_CONSTANTS(:,44) = strpad('alpha_rel in component Ca_handling_by_the_SR (picoA_per_millimolar)');
    LEGEND_STATES(:,24) = strpad('Ca_rel in component Ca_handling_by_the_SR (millimolar)');
    LEGEND_STATES(:,25) = strpad('Ca_up in component Ca_handling_by_the_SR (millimolar)');
    LEGEND_CONSTANTS(:,45) = strpad('Vol_up in component Ca_handling_by_the_SR (nanolitre)');
    LEGEND_CONSTANTS(:,46) = strpad('Vol_rel in component Ca_handling_by_the_SR (nanolitre)');
    LEGEND_ALGEBRAIC(:,15) = strpad('r_act in component Ca_handling_by_the_SR (per_second)');
    LEGEND_ALGEBRAIC(:,30) = strpad('r_inact in component Ca_handling_by_the_SR (per_second)');
    LEGEND_STATES(:,26) = strpad('O_Calse in component Ca_handling_by_the_SR (dimensionless)');
    LEGEND_STATES(:,27) = strpad('F1 in component Ca_handling_by_the_SR (dimensionless)');
    LEGEND_STATES(:,28) = strpad('F2 in component Ca_handling_by_the_SR (dimensionless)');
    LEGEND_STATES(:,29) = strpad('F3 in component Ca_handling_by_the_SR (dimensionless)');
    LEGEND_CONSTANTS(:,47) = strpad('tau_tr in component Ca_handling_by_the_SR (second)');
    LEGEND_CONSTANTS(:,48) = strpad('k_rel in component Ca_handling_by_the_SR (millimolar)');
    LEGEND_CONSTANTS(:,49) = strpad('k_F3 in component Ca_handling_by_the_SR (per_second)');
    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_h1_gate (dimensionless)');
    LEGEND_RATES(:,5) = strpad('d/dt h2 in component sodium_current_h2_gate (dimensionless)');
    LEGEND_RATES(:,6) = strpad('d/dt d_L in component L_type_Ca_channel_d_L_gate (dimensionless)');
    LEGEND_RATES(:,7) = strpad('d/dt f_L in component L_type_Ca_channel_f_L_gate (dimensionless)');
    LEGEND_RATES(:,8) = strpad('d/dt d_T in component T_type_Ca_channel_d_T_gate (dimensionless)');
    LEGEND_RATES(:,9) = strpad('d/dt f_T in component T_type_Ca_channel_f_T_gate (dimensionless)');
    LEGEND_RATES(:,12) = strpad('d/dt r in component Ca_independent_transient_outward_K_current_r_gate (dimensionless)');
    LEGEND_RATES(:,13) = strpad('d/dt s1 in component Ca_independent_transient_outward_K_current_s1_gate (dimensionless)');
    LEGEND_RATES(:,14) = strpad('d/dt s2 in component Ca_independent_transient_outward_K_current_s2_gate (dimensionless)');
    LEGEND_RATES(:,15) = strpad('d/dt s3 in component Ca_independent_transient_outward_K_current_s3_gate (dimensionless)');
    LEGEND_RATES(:,16) = strpad('d/dt z in component delayed_rectifier_K_current_z_gate (dimensionless)');
    LEGEND_RATES(:,17) = strpad('d/dt p_a in component delayed_rectifier_K_current_pa_gate (dimensionless)');
    LEGEND_RATES(:,18) = strpad('d/dt p_i in component delayed_rectifier_K_current_pi_gate (dimensionless)');
    LEGEND_RATES(:,2) = strpad('d/dt Na_i in component intracellular_ion_concentrations (millimolar)');
    LEGEND_RATES(:,11) = strpad('d/dt K_i in component intracellular_ion_concentrations (millimolar)');
    LEGEND_RATES(:,19) = strpad('d/dt Ca_i in component intracellular_ion_concentrations (millimolar)');
    LEGEND_RATES(:,20) = strpad('d/dt O_C in component intracellular_Ca_buffering (dimensionless)');
    LEGEND_RATES(:,21) = strpad('d/dt O_TC in component intracellular_Ca_buffering (dimensionless)');
    LEGEND_RATES(:,22) = strpad('d/dt O_TMgC in component intracellular_Ca_buffering (dimensionless)');
    LEGEND_RATES(:,23) = strpad('d/dt O_TMgMg in component intracellular_Ca_buffering (dimensionless)');
    LEGEND_RATES(:,10) = strpad('d/dt K_c in component cleft_space_ion_concentrations (millimolar)');
    LEGEND_RATES(:,26) = strpad('d/dt O_Calse in component Ca_handling_by_the_SR (dimensionless)');
    LEGEND_RATES(:,24) = strpad('d/dt Ca_rel in component Ca_handling_by_the_SR (millimolar)');
    LEGEND_RATES(:,25) = strpad('d/dt Ca_up in component Ca_handling_by_the_SR (millimolar)');
    LEGEND_RATES(:,27) = strpad('d/dt F1 in component Ca_handling_by_the_SR (dimensionless)');
    LEGEND_RATES(:,28) = strpad('d/dt F2 in component Ca_handling_by_the_SR (dimensionless)');
    LEGEND_RATES(:,29) = strpad('d/dt F3 in component Ca_handling_by_the_SR (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 = [];
    CONSTANTS(:,1) = 1;
    CONSTANTS(:,2) = 0;
    STATES(:,1) = -80;
    CONSTANTS(:,3) = 8314;
    CONSTANTS(:,4) = 308;
    CONSTANTS(:,5) = 96487;
    CONSTANTS(:,6) = 0.00005;
    CONSTANTS(:,7) = 0.01;
    CONSTANTS(:,8) = 100;
    CONSTANTS(:,9) = 0.5;
    CONSTANTS(:,10) = 0.0002;
    CONSTANTS(:,11) = -20;
    CONSTANTS(:,12) = 0.0000014;
    CONSTANTS(:,13) = 140;
    STATES(:,2) = 8.4;
    STATES(:,3) = 0.01309;
    STATES(:,4) = 0.706;
    STATES(:,5) = 0.61493;
    CONSTANTS(:,14) = 0.004;
    CONSTANTS(:,15) = 50;
    STATES(:,6) = 0.00003;
    STATES(:,7) = 0.99981;
    CONSTANTS(:,16) = 0.006;
    CONSTANTS(:,17) = 38;
    STATES(:,8) = 0.00046;
    STATES(:,9) = 0.30752;
    CONSTANTS(:,18) = 0.050002;
    STATES(:,10) = 5;
    STATES(:,11) = 100;
    STATES(:,12) = 0.00006;
    STATES(:,13) = 0.5753;
    STATES(:,14) = 0.39871;
    STATES(:,15) = 0.57363;
    CONSTANTS(:,19) = 0.0025;
    CONSTANTS(:,20) = 0.0035;
    STATES(:,16) = 0.02032;
    STATES(:,17) = 0.00016;
    STATES(:,18) = 0.76898;
    CONSTANTS(:,21) = 0.00508;
    CONSTANTS(:,22) = 0.59;
    CONSTANTS(:,23) = 1.393;
    CONSTANTS(:,24) = -3.6;
    CONSTANTS(:,25) = 6.4e-5;
    CONSTANTS(:,26) = 3.1e-5;
    CONSTANTS(:,27) = 2.5;
    STATES(:,19) = 0.000071;
    CONSTANTS(:,28) = 1;
    CONSTANTS(:,29) = 11;
    CONSTANTS(:,30) = 0.06441;
    CONSTANTS(:,31) = 0.009509;
    CONSTANTS(:,32) = 2e-4;
    CONSTANTS(:,33) = 2e-5;
    CONSTANTS(:,34) = 3e-4;
    CONSTANTS(:,35) = 0.45;
    CONSTANTS(:,36) = 1.26e-5;
    CONSTANTS(:,37) = 5.884e-6;
    STATES(:,20) = 0.029108;
    STATES(:,21) = 0.014071;
    STATES(:,22) = 0.214036;
    STATES(:,23) = 0.693565;
    CONSTANTS(:,38) = 2.5;
    CONSTANTS(:,39) = 0.0000025;
    CONSTANTS(:,40) = 2.8;
    CONSTANTS(:,41) = 0.0003;
    CONSTANTS(:,42) = 0.5;
    CONSTANTS(:,43) = 0.4;
    CONSTANTS(:,44) = 200;
    STATES(:,24) = 0.726776;
    STATES(:,25) = 0.730866;
    CONSTANTS(:,45) = 3.969e-7;
    CONSTANTS(:,46) = 4.4e-8;
    STATES(:,26) = 0.465921;
    STATES(:,27) = 0.288039;
    STATES(:,28) = 0.002262;
    STATES(:,29) = 0.612697;
    CONSTANTS(:,47) = 0.01;
    CONSTANTS(:,48) = 0.0003;
    CONSTANTS(:,49) = 0.815;
    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(:,23) =  2000.00.*CONSTANTS(:,38).*((1.00000 - STATES(:,22)) - STATES(:,23)) -  666.000.*STATES(:,23);
    ALGEBRAIC(:,15) =  240.000.*exp( 0.0800000.*(STATES(:,1) - 20.0000))+ 203.800.*power(STATES(:,19)./(STATES(:,19)+CONSTANTS(:,48)), 4.00000);
    RATES(:,27) =  CONSTANTS(:,49).*STATES(:,29) -  ALGEBRAIC(:,15).*STATES(:,27);
    ALGEBRAIC(:,24) = 0.546600./(1.00000+exp((STATES(:,1)+32.8000)./0.100000))+0.0204000;
    ALGEBRAIC(:,9) = 1.00000./(1.00000+exp((STATES(:,1)+28.2900)./7.06000));
    RATES(:,13) = (ALGEBRAIC(:,9) - STATES(:,13))./ALGEBRAIC(:,24);
    ALGEBRAIC(:,25) = 5.75000./(1.00000+exp((STATES(:,1)+32.8000)./0.100000))+0.450000./(1.00000+exp((STATES(:,1) - 13.5400)./ - 13.9700));
    ALGEBRAIC(:,10) = 1.00000./(1.00000+exp((STATES(:,1)+28.2900)./7.06000));
    RATES(:,14) = (ALGEBRAIC(:,10) - STATES(:,14))./ALGEBRAIC(:,25);
    ALGEBRAIC(:,26) = 7.50000./(1.00000+exp((STATES(:,1)+23.0000)./0.500000))+0.500000;
    ALGEBRAIC(:,11) = (1.00000./(1.00000+exp((STATES(:,1)+50.6700)./27.3800))+0.666000)./1.66600;
    RATES(:,15) = (ALGEBRAIC(:,11) - STATES(:,15))./ALGEBRAIC(:,26);
    ALGEBRAIC(:,30) = 33.9600+ 339.600.*power(STATES(:,19)./(STATES(:,19)+CONSTANTS(:,48)), 4.00000);
    RATES(:,28) =  ALGEBRAIC(:,15).*STATES(:,27) -  ALGEBRAIC(:,30).*STATES(:,28);
    RATES(:,29) =  STATES(:,28).*ALGEBRAIC(:,30) -  CONSTANTS(:,49).*STATES(:,29);
    ALGEBRAIC(:,2) = STATES(:,1)+44.4000;
    ALGEBRAIC(:,17) = (  - 460.000.*ALGEBRAIC(:,2))./(exp(ALGEBRAIC(:,2)./ - 12.6730) - 1.00000);
    ALGEBRAIC(:,32) =  18400.0.*exp(ALGEBRAIC(:,2)./ - 12.6730);
    RATES(:,3) =  ALGEBRAIC(:,17).*(1.00000 - STATES(:,3)) -  ALGEBRAIC(:,32).*STATES(:,3);
    ALGEBRAIC(:,3) =  44.9000.*exp((STATES(:,1)+66.9000)./ - 5.57000);
    ALGEBRAIC(:,18) = 1491.00./(1.00000+ 323.300.*exp((STATES(:,1)+94.6000)./ - 12.9000));
    ALGEBRAIC(:,33) = ALGEBRAIC(:,3)./(ALGEBRAIC(:,3)+ALGEBRAIC(:,18));
    ALGEBRAIC(:,43) = 0.0300000./(1.00000+exp((STATES(:,1)+40.0000)./6.00000))+0.000150000;
    RATES(:,4) = (ALGEBRAIC(:,33) - STATES(:,4))./ALGEBRAIC(:,43);
    ALGEBRAIC(:,44) = 0.120000./(1.00000+exp((STATES(:,1)+60.0000)./2.00000))+0.000450000;
    RATES(:,5) = (ALGEBRAIC(:,33) - STATES(:,5))./ALGEBRAIC(:,44);
    ALGEBRAIC(:,8) =  386.600.*exp(STATES(:,1)./12.0000);
    ALGEBRAIC(:,23) =  8.01100.*exp(STATES(:,1)./ - 7.20000);
    ALGEBRAIC(:,49) = 1.00000./(ALGEBRAIC(:,8)+ALGEBRAIC(:,23))+0.000400000;
    ALGEBRAIC(:,38) = 1.00000./(1.00000+exp((STATES(:,1)+15.0000)./ - 5.63300));
    RATES(:,12) = (ALGEBRAIC(:,38) - STATES(:,12))./ALGEBRAIC(:,49);
    ALGEBRAIC(:,12) =  1.66000.*exp(STATES(:,1)./69.4520);
    ALGEBRAIC(:,27) =  0.300000.*exp(STATES(:,1)./ - 21.8260);
    ALGEBRAIC(:,50) = 1.00000./(ALGEBRAIC(:,12)+ALGEBRAIC(:,27))+0.0600000;
    ALGEBRAIC(:,39) = 1.00000./(1.00000+exp((STATES(:,1) - 0.900000)./ - 13.8000));
    RATES(:,16) = (ALGEBRAIC(:,39) - STATES(:,16))./ALGEBRAIC(:,50);
    ALGEBRAIC(:,13) =  9.00000.*exp(STATES(:,1)./25.3710);
    ALGEBRAIC(:,28) =  1.30000.*exp(STATES(:,1)./ - 13.0260);
    ALGEBRAIC(:,51) = 1.00000./(ALGEBRAIC(:,13)+ALGEBRAIC(:,28));
    ALGEBRAIC(:,40) = 1.00000./(1.00000+exp((STATES(:,1)+5.10000)./ - 7.40000));
    RATES(:,17) = (ALGEBRAIC(:,40) - STATES(:,17))./ALGEBRAIC(:,51);
    ALGEBRAIC(:,14) =  100.000.*exp(STATES(:,1)./ - 54.6450);
    ALGEBRAIC(:,29) =  656.000.*exp(STATES(:,1)./106.157);
    ALGEBRAIC(:,52) = 1.00000./(ALGEBRAIC(:,14)+ALGEBRAIC(:,29));
    ALGEBRAIC(:,41) = 1.00000./(1.00000+exp((STATES(:,1)+47.3921)./18.6603));
    RATES(:,18) = (ALGEBRAIC(:,41) - STATES(:,18))./ALGEBRAIC(:,52);
    ALGEBRAIC(:,5) = STATES(:,1)+18.0000;
    ALGEBRAIC(:,20) = ( 8.49000.*ALGEBRAIC(:,5))./(exp(ALGEBRAIC(:,5)./4.00000) - 1.00000);
    ALGEBRAIC(:,35) = 67.9220./(1.00000+exp(ALGEBRAIC(:,5)./ - 4.00000));
    ALGEBRAIC(:,46) = ALGEBRAIC(:,20)./(ALGEBRAIC(:,20)+ALGEBRAIC(:,35));
    ALGEBRAIC(:,55) = 1.00000./(ALGEBRAIC(:,20)+ALGEBRAIC(:,35));
    RATES(:,7) = (ALGEBRAIC(:,46) - STATES(:,7))./ALGEBRAIC(:,55);
    ALGEBRAIC(:,6) = STATES(:,1)+23.3000;
    ALGEBRAIC(:,47) = 1.00000./(1.00000+exp((ALGEBRAIC(:,6) - 0.300000)./ - 6.10000));
    ALGEBRAIC(:,21) =  674.173.*exp(ALGEBRAIC(:,6)./30.0000);
    ALGEBRAIC(:,36) =  674.173.*exp(ALGEBRAIC(:,6)./ - 30.0000);
    ALGEBRAIC(:,56) = 1.00000./(ALGEBRAIC(:,21)+ALGEBRAIC(:,36));
    RATES(:,8) = (ALGEBRAIC(:,47) - STATES(:,8))./ALGEBRAIC(:,56);
    ALGEBRAIC(:,7) = STATES(:,1)+75.0000;
    ALGEBRAIC(:,22) =  9.63700.*exp(ALGEBRAIC(:,7)./ - 83.3000);
    ALGEBRAIC(:,37) =  9.63700.*exp(ALGEBRAIC(:,7)./15.3800);
    ALGEBRAIC(:,48) = ALGEBRAIC(:,22)./(ALGEBRAIC(:,22)+ALGEBRAIC(:,37));
    ALGEBRAIC(:,57) = 1.00000./(ALGEBRAIC(:,22)+ALGEBRAIC(:,37));
    RATES(:,9) = (ALGEBRAIC(:,48) - STATES(:,9))./ALGEBRAIC(:,57);
    ALGEBRAIC(:,34) = STATES(:,1)+10.0000;
    ALGEBRAIC(:,59) = 1.00000./(1.00000+exp((ALGEBRAIC(:,34)+0.950000)./ - 6.60000));
    ALGEBRAIC(:,4) = STATES(:,1)+45.0000;
    ALGEBRAIC(:,45) = (  - 16.7200.*ALGEBRAIC(:,4))./(exp(ALGEBRAIC(:,4)./ - 2.50000) - 1.00000)+(  - 50.0000.*ALGEBRAIC(:,34))./(exp(ALGEBRAIC(:,34)./ - 4.80800) - 1.00000);
    ALGEBRAIC(:,19) = STATES(:,1)+5.00000;
    ALGEBRAIC(:,54) = ( 4.48000.*ALGEBRAIC(:,19))./(exp(ALGEBRAIC(:,19)./2.50000) - 1.00000);
    ALGEBRAIC(:,61) = 1.00000./(ALGEBRAIC(:,45)+ALGEBRAIC(:,54));
    RATES(:,6) = (ALGEBRAIC(:,59) - STATES(:,6))./ALGEBRAIC(:,61);
    ALGEBRAIC(:,60) =  (( CONSTANTS(:,3).*CONSTANTS(:,4))./CONSTANTS(:,5)).*log(STATES(:,10)./STATES(:,11));
    ALGEBRAIC(:,62) = piecewise({CONSTANTS(:,1)==1.00000&CONSTANTS(:,2)==0.00000,  0.200000.*CONSTANTS(:,18).*STATES(:,12).*( 0.590000.*power(STATES(:,13), 3.00000)+ 0.410000.*power(STATES(:,14), 3.00000)).*( 0.600000.*power(STATES(:,15), 6.00000)+0.400000).*(STATES(:,1) - ALGEBRAIC(:,60)) , CONSTANTS(:,1)==0.00000&CONSTANTS(:,2)==1.00000,  0.350000.*CONSTANTS(:,18).*STATES(:,12).*( 0.590000.*power(STATES(:,13), 3.00000)+ 0.410000.*power(STATES(:,14), 3.00000)).*( 0.600000.*power(STATES(:,15), 6.00000)+0.400000).*(STATES(:,1) - ALGEBRAIC(:,60)) },  CONSTANTS(:,18).*STATES(:,12).*( 0.590000.*power(STATES(:,13), 3.00000)+ 0.410000.*power(STATES(:,14), 3.00000)).*( 0.600000.*power(STATES(:,15), 6.00000)+0.400000).*(STATES(:,1) - ALGEBRAIC(:,60)));
    ALGEBRAIC(:,63) = piecewise({CONSTANTS(:,1)==1.00000&CONSTANTS(:,2)==0.00000,  0.00140000.*(STATES(:,1)+70.0000) , CONSTANTS(:,1)==0.00000&CONSTANTS(:,2)==1.00000,  0.00240000.*(STATES(:,1)+70.0000) },  0.00100000.*(STATES(:,1)+70.0000));
    ALGEBRAIC(:,66) = piecewise({CONSTANTS(:,1)==1.00000&CONSTANTS(:,2)==0.00000, ( 2.00000.*CONSTANTS(:,21).*(STATES(:,1) - ALGEBRAIC(:,60)).*power(STATES(:,10)./(STATES(:,10)+CONSTANTS(:,22)), 3.00000).*1.00000)./(1.00000+exp(( CONSTANTS(:,23).*CONSTANTS(:,5).*((STATES(:,1) - ALGEBRAIC(:,60)) - CONSTANTS(:,24)))./( CONSTANTS(:,3).*CONSTANTS(:,4)))) , CONSTANTS(:,1)==0.00000&CONSTANTS(:,2)==1.00000, ( 2.50000.*CONSTANTS(:,21).*(STATES(:,1) - ALGEBRAIC(:,60)).*power(STATES(:,10)./(STATES(:,10)+CONSTANTS(:,22)), 3.00000).*1.00000)./(1.00000+exp(( CONSTANTS(:,23).*CONSTANTS(:,5).*((STATES(:,1) - ALGEBRAIC(:,60)) - CONSTANTS(:,24)))./( CONSTANTS(:,3).*CONSTANTS(:,4)))) }, ( CONSTANTS(:,21).*(STATES(:,1) - ALGEBRAIC(:,60)).*power(STATES(:,10)./(STATES(:,10)+CONSTANTS(:,22)), 3.00000).*1.00000)./(1.00000+exp(( CONSTANTS(:,23).*CONSTANTS(:,5).*((STATES(:,1) - ALGEBRAIC(:,60)) - CONSTANTS(:,24)))./( CONSTANTS(:,3).*CONSTANTS(:,4)))));
    ALGEBRAIC(:,65) =  CONSTANTS(:,20).*STATES(:,17).*STATES(:,18).*(STATES(:,1) - ALGEBRAIC(:,60));
    ALGEBRAIC(:,64) =  CONSTANTS(:,19).*STATES(:,16).*(STATES(:,1) - ALGEBRAIC(:,60));
    ALGEBRAIC(:,70) = ( (( (( CONSTANTS(:,30).*STATES(:,10))./(STATES(:,10)+CONSTANTS(:,28))).*power(STATES(:,2), 1.50000))./(power(STATES(:,2), 1.50000)+power(CONSTANTS(:,29), 1.50000))).*1.60000)./(1.50000+exp((STATES(:,1)+60.0000)./ - 40.0000));
    RATES(:,11) =  - ((ALGEBRAIC(:,62)+ALGEBRAIC(:,63)+ALGEBRAIC(:,66)+ALGEBRAIC(:,65)+ALGEBRAIC(:,64)) -  2.00000.*ALGEBRAIC(:,70))./( CONSTANTS(:,36).*CONSTANTS(:,5));
    RATES(:,10) = ((ALGEBRAIC(:,62)+ALGEBRAIC(:,63)+ALGEBRAIC(:,66)+ALGEBRAIC(:,65)+ALGEBRAIC(:,64)) -  2.00000.*ALGEBRAIC(:,70))./( CONSTANTS(:,39).*CONSTANTS(:,5));
    ALGEBRAIC(:,16) =  (( CONSTANTS(:,3).*CONSTANTS(:,4))./CONSTANTS(:,5)).*log(CONSTANTS(:,13)./STATES(:,2));
    ALGEBRAIC(:,31) = ( (( CONSTANTS(:,12).*power(STATES(:,3), 3.00000).*( 0.635000.*STATES(:,4)+ 0.365000.*STATES(:,5)).*CONSTANTS(:,13).*STATES(:,1).*power(CONSTANTS(:,5), 2.00000))./( CONSTANTS(:,3).*CONSTANTS(:,4))).*(exp(( (STATES(:,1) - ALGEBRAIC(:,16)).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))) - 1.00000))./(exp(( STATES(:,1).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))) - 1.00000);
    ALGEBRAIC(:,42) = 1.00000./(1.00000+exp((STATES(:,1) - 23.0000)./ - 12.0000));
    ALGEBRAIC(:,53) = piecewise({CONSTANTS(:,1)==1.00000&CONSTANTS(:,2)==0.00000,  1.80000.*CONSTANTS(:,14).*( STATES(:,6).*STATES(:,7)+ALGEBRAIC(:,42)).*(STATES(:,1) - CONSTANTS(:,15)) , CONSTANTS(:,1)==0.00000&CONSTANTS(:,2)==1.00000,  2.10000.*CONSTANTS(:,14).*( STATES(:,6).*STATES(:,7)+ALGEBRAIC(:,42)).*(STATES(:,1) - CONSTANTS(:,15)) },  CONSTANTS(:,14).*( STATES(:,6).*STATES(:,7)+ALGEBRAIC(:,42)).*(STATES(:,1) - CONSTANTS(:,15)));
    ALGEBRAIC(:,58) =  CONSTANTS(:,16).*STATES(:,8).*STATES(:,9).*(STATES(:,1) - CONSTANTS(:,17));
    ALGEBRAIC(:,68) = piecewise({CONSTANTS(:,1)==1.00000&CONSTANTS(:,2)==0.00000,  2.00000e-05.*(STATES(:,1) - ALGEBRAIC(:,16)) , CONSTANTS(:,1)==0.00000&CONSTANTS(:,2)==1.00000,  3.00000e-05.*(STATES(:,1) - ALGEBRAIC(:,16)) },  CONSTANTS(:,25).*(STATES(:,1) - ALGEBRAIC(:,16)));
    ALGEBRAIC(:,67) =  (( CONSTANTS(:,3).*CONSTANTS(:,4))./( 2.00000.*CONSTANTS(:,5))).*log(CONSTANTS(:,27)./STATES(:,19));
    ALGEBRAIC(:,69) = piecewise({CONSTANTS(:,1)==1.00000&CONSTANTS(:,2)==0.00000,  2.00000e-05.*(STATES(:,1) - ALGEBRAIC(:,67)) , CONSTANTS(:,1)==0.00000&CONSTANTS(:,2)==1.00000,  3.00000e-05.*(STATES(:,1) - ALGEBRAIC(:,67)) },  CONSTANTS(:,26).*(STATES(:,1) - ALGEBRAIC(:,67)));
    ALGEBRAIC(:,71) = ( CONSTANTS(:,31).*STATES(:,19))./(STATES(:,19)+CONSTANTS(:,32));
    ALGEBRAIC(:,72) = ( CONSTANTS(:,33).*( power(STATES(:,2), 3.00000).*CONSTANTS(:,27).*exp(( CONSTANTS(:,35).*CONSTANTS(:,5).*STATES(:,1))./( CONSTANTS(:,3).*CONSTANTS(:,4))) -  power(CONSTANTS(:,13), 3.00000).*STATES(:,19).*exp(( (CONSTANTS(:,35) - 1.00000).*STATES(:,1).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4)))))./(1.00000+ CONSTANTS(:,34).*( power(CONSTANTS(:,13), 3.00000).*STATES(:,19)+ power(STATES(:,2), 3.00000).*CONSTANTS(:,27)));
    ALGEBRAIC(:,1) = piecewise({VOI>=CONSTANTS(:,7)&VOI<=CONSTANTS(:,8)&(VOI - CONSTANTS(:,7)) -  floor((VOI - CONSTANTS(:,7))./CONSTANTS(:,9)).*CONSTANTS(:,9)<=CONSTANTS(:,10), CONSTANTS(:,11) }, 0.00000);
    RATES(:,1) =  ( - 1.00000./CONSTANTS(:,6)).*(ALGEBRAIC(:,65)+ALGEBRAIC(:,64)+ALGEBRAIC(:,31)+ALGEBRAIC(:,53)+ALGEBRAIC(:,58)+ALGEBRAIC(:,62)+ALGEBRAIC(:,63)+ALGEBRAIC(:,66)+ALGEBRAIC(:,68)+ALGEBRAIC(:,69)+ALGEBRAIC(:,70)+ALGEBRAIC(:,71)+ALGEBRAIC(:,72)+ALGEBRAIC(:,1));
    RATES(:,2) =  - (ALGEBRAIC(:,31)+ALGEBRAIC(:,68)+ 3.00000.*ALGEBRAIC(:,70)+ 3.00000.*ALGEBRAIC(:,72))./( CONSTANTS(:,36).*CONSTANTS(:,5));
    ALGEBRAIC(:,73) =  200000..*STATES(:,19).*(1.00000 - STATES(:,20)) -  476.000.*STATES(:,20);
    RATES(:,20) = ALGEBRAIC(:,73);
    ALGEBRAIC(:,74) =  78400.0.*STATES(:,19).*(1.00000 - STATES(:,21)) -  392.000.*STATES(:,21);
    RATES(:,21) = ALGEBRAIC(:,74);
    RATES(:,26) =  480.000.*STATES(:,24).*(1.00000 - STATES(:,26)) -  400.000.*STATES(:,26);
    ALGEBRAIC(:,75) =  200000..*STATES(:,19).*((1.00000 - STATES(:,22)) - STATES(:,23)) -  6.60000.*STATES(:,22);
    RATES(:,22) = ALGEBRAIC(:,75);
    ALGEBRAIC(:,76) = ( CONSTANTS(:,40).*(STATES(:,19)./CONSTANTS(:,41) - ( power(CONSTANTS(:,43), 2.00000).*STATES(:,25))./CONSTANTS(:,42)))./((STATES(:,19)+CONSTANTS(:,41))./CONSTANTS(:,41)+( CONSTANTS(:,43).*(STATES(:,25)+CONSTANTS(:,42)))./CONSTANTS(:,42));
    ALGEBRAIC(:,77) = ( (STATES(:,25) - STATES(:,24)).*2.00000.*CONSTANTS(:,5).*CONSTANTS(:,46))./CONSTANTS(:,47);
    RATES(:,25) = (ALGEBRAIC(:,76) - ALGEBRAIC(:,77))./( 2.00000.*CONSTANTS(:,45).*CONSTANTS(:,5));
    ALGEBRAIC(:,78) =  CONSTANTS(:,44).*power(STATES(:,28)./(STATES(:,28)+0.250000), 2.00000).*(STATES(:,24) - STATES(:,19));
    RATES(:,19) =  - ((((ALGEBRAIC(:,53)+ALGEBRAIC(:,58)+ALGEBRAIC(:,69)+ALGEBRAIC(:,71)) -  2.00000.*ALGEBRAIC(:,72))+ALGEBRAIC(:,76)) - ALGEBRAIC(:,78))./( 2.00000.*CONSTANTS(:,37).*CONSTANTS(:,5)) - ( 0.0800000.*ALGEBRAIC(:,74)+ 0.160000.*ALGEBRAIC(:,75)+ 0.0450000.*ALGEBRAIC(:,73));
    RATES(:,24) = (ALGEBRAIC(:,77) - ALGEBRAIC(:,78))./( 2.00000.*CONSTANTS(:,46).*CONSTANTS(:,5)) -  31.0000.*RATES(:,26);
   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(:,15) =  240.000.*exp( 0.0800000.*(STATES(:,1) - 20.0000))+ 203.800.*power(STATES(:,19)./(STATES(:,19)+CONSTANTS(:,48)), 4.00000);
    ALGEBRAIC(:,24) = 0.546600./(1.00000+exp((STATES(:,1)+32.8000)./0.100000))+0.0204000;
    ALGEBRAIC(:,9) = 1.00000./(1.00000+exp((STATES(:,1)+28.2900)./7.06000));
    ALGEBRAIC(:,25) = 5.75000./(1.00000+exp((STATES(:,1)+32.8000)./0.100000))+0.450000./(1.00000+exp((STATES(:,1) - 13.5400)./ - 13.9700));
    ALGEBRAIC(:,10) = 1.00000./(1.00000+exp((STATES(:,1)+28.2900)./7.06000));
    ALGEBRAIC(:,26) = 7.50000./(1.00000+exp((STATES(:,1)+23.0000)./0.500000))+0.500000;
    ALGEBRAIC(:,11) = (1.00000./(1.00000+exp((STATES(:,1)+50.6700)./27.3800))+0.666000)./1.66600;
    ALGEBRAIC(:,30) = 33.9600+ 339.600.*power(STATES(:,19)./(STATES(:,19)+CONSTANTS(:,48)), 4.00000);
    ALGEBRAIC(:,2) = STATES(:,1)+44.4000;
    ALGEBRAIC(:,17) = (  - 460.000.*ALGEBRAIC(:,2))./(exp(ALGEBRAIC(:,2)./ - 12.6730) - 1.00000);
    ALGEBRAIC(:,32) =  18400.0.*exp(ALGEBRAIC(:,2)./ - 12.6730);
    ALGEBRAIC(:,3) =  44.9000.*exp((STATES(:,1)+66.9000)./ - 5.57000);
    ALGEBRAIC(:,18) = 1491.00./(1.00000+ 323.300.*exp((STATES(:,1)+94.6000)./ - 12.9000));
    ALGEBRAIC(:,33) = ALGEBRAIC(:,3)./(ALGEBRAIC(:,3)+ALGEBRAIC(:,18));
    ALGEBRAIC(:,43) = 0.0300000./(1.00000+exp((STATES(:,1)+40.0000)./6.00000))+0.000150000;
    ALGEBRAIC(:,44) = 0.120000./(1.00000+exp((STATES(:,1)+60.0000)./2.00000))+0.000450000;
    ALGEBRAIC(:,8) =  386.600.*exp(STATES(:,1)./12.0000);
    ALGEBRAIC(:,23) =  8.01100.*exp(STATES(:,1)./ - 7.20000);
    ALGEBRAIC(:,49) = 1.00000./(ALGEBRAIC(:,8)+ALGEBRAIC(:,23))+0.000400000;
    ALGEBRAIC(:,38) = 1.00000./(1.00000+exp((STATES(:,1)+15.0000)./ - 5.63300));
    ALGEBRAIC(:,12) =  1.66000.*exp(STATES(:,1)./69.4520);
    ALGEBRAIC(:,27) =  0.300000.*exp(STATES(:,1)./ - 21.8260);
    ALGEBRAIC(:,50) = 1.00000./(ALGEBRAIC(:,12)+ALGEBRAIC(:,27))+0.0600000;
    ALGEBRAIC(:,39) = 1.00000./(1.00000+exp((STATES(:,1) - 0.900000)./ - 13.8000));
    ALGEBRAIC(:,13) =  9.00000.*exp(STATES(:,1)./25.3710);
    ALGEBRAIC(:,28) =  1.30000.*exp(STATES(:,1)./ - 13.0260);
    ALGEBRAIC(:,51) = 1.00000./(ALGEBRAIC(:,13)+ALGEBRAIC(:,28));
    ALGEBRAIC(:,40) = 1.00000./(1.00000+exp((STATES(:,1)+5.10000)./ - 7.40000));
    ALGEBRAIC(:,14) =  100.000.*exp(STATES(:,1)./ - 54.6450);
    ALGEBRAIC(:,29) =  656.000.*exp(STATES(:,1)./106.157);
    ALGEBRAIC(:,52) = 1.00000./(ALGEBRAIC(:,14)+ALGEBRAIC(:,29));
    ALGEBRAIC(:,41) = 1.00000./(1.00000+exp((STATES(:,1)+47.3921)./18.6603));
    ALGEBRAIC(:,5) = STATES(:,1)+18.0000;
    ALGEBRAIC(:,20) = ( 8.49000.*ALGEBRAIC(:,5))./(exp(ALGEBRAIC(:,5)./4.00000) - 1.00000);
    ALGEBRAIC(:,35) = 67.9220./(1.00000+exp(ALGEBRAIC(:,5)./ - 4.00000));
    ALGEBRAIC(:,46) = ALGEBRAIC(:,20)./(ALGEBRAIC(:,20)+ALGEBRAIC(:,35));
    ALGEBRAIC(:,55) = 1.00000./(ALGEBRAIC(:,20)+ALGEBRAIC(:,35));
    ALGEBRAIC(:,6) = STATES(:,1)+23.3000;
    ALGEBRAIC(:,47) = 1.00000./(1.00000+exp((ALGEBRAIC(:,6) - 0.300000)./ - 6.10000));
    ALGEBRAIC(:,21) =  674.173.*exp(ALGEBRAIC(:,6)./30.0000);
    ALGEBRAIC(:,36) =  674.173.*exp(ALGEBRAIC(:,6)./ - 30.0000);
    ALGEBRAIC(:,56) = 1.00000./(ALGEBRAIC(:,21)+ALGEBRAIC(:,36));
    ALGEBRAIC(:,7) = STATES(:,1)+75.0000;
    ALGEBRAIC(:,22) =  9.63700.*exp(ALGEBRAIC(:,7)./ - 83.3000);
    ALGEBRAIC(:,37) =  9.63700.*exp(ALGEBRAIC(:,7)./15.3800);
    ALGEBRAIC(:,48) = ALGEBRAIC(:,22)./(ALGEBRAIC(:,22)+ALGEBRAIC(:,37));
    ALGEBRAIC(:,57) = 1.00000./(ALGEBRAIC(:,22)+ALGEBRAIC(:,37));
    ALGEBRAIC(:,34) = STATES(:,1)+10.0000;
    ALGEBRAIC(:,59) = 1.00000./(1.00000+exp((ALGEBRAIC(:,34)+0.950000)./ - 6.60000));
    ALGEBRAIC(:,4) = STATES(:,1)+45.0000;
    ALGEBRAIC(:,45) = (  - 16.7200.*ALGEBRAIC(:,4))./(exp(ALGEBRAIC(:,4)./ - 2.50000) - 1.00000)+(  - 50.0000.*ALGEBRAIC(:,34))./(exp(ALGEBRAIC(:,34)./ - 4.80800) - 1.00000);
    ALGEBRAIC(:,19) = STATES(:,1)+5.00000;
    ALGEBRAIC(:,54) = ( 4.48000.*ALGEBRAIC(:,19))./(exp(ALGEBRAIC(:,19)./2.50000) - 1.00000);
    ALGEBRAIC(:,61) = 1.00000./(ALGEBRAIC(:,45)+ALGEBRAIC(:,54));
    ALGEBRAIC(:,60) =  (( CONSTANTS(:,3).*CONSTANTS(:,4))./CONSTANTS(:,5)).*log(STATES(:,10)./STATES(:,11));
    ALGEBRAIC(:,62) = piecewise({CONSTANTS(:,1)==1.00000&CONSTANTS(:,2)==0.00000,  0.200000.*CONSTANTS(:,18).*STATES(:,12).*( 0.590000.*power(STATES(:,13), 3.00000)+ 0.410000.*power(STATES(:,14), 3.00000)).*( 0.600000.*power(STATES(:,15), 6.00000)+0.400000).*(STATES(:,1) - ALGEBRAIC(:,60)) , CONSTANTS(:,1)==0.00000&CONSTANTS(:,2)==1.00000,  0.350000.*CONSTANTS(:,18).*STATES(:,12).*( 0.590000.*power(STATES(:,13), 3.00000)+ 0.410000.*power(STATES(:,14), 3.00000)).*( 0.600000.*power(STATES(:,15), 6.00000)+0.400000).*(STATES(:,1) - ALGEBRAIC(:,60)) },  CONSTANTS(:,18).*STATES(:,12).*( 0.590000.*power(STATES(:,13), 3.00000)+ 0.410000.*power(STATES(:,14), 3.00000)).*( 0.600000.*power(STATES(:,15), 6.00000)+0.400000).*(STATES(:,1) - ALGEBRAIC(:,60)));
    ALGEBRAIC(:,63) = piecewise({CONSTANTS(:,1)==1.00000&CONSTANTS(:,2)==0.00000,  0.00140000.*(STATES(:,1)+70.0000) , CONSTANTS(:,1)==0.00000&CONSTANTS(:,2)==1.00000,  0.00240000.*(STATES(:,1)+70.0000) },  0.00100000.*(STATES(:,1)+70.0000));
    ALGEBRAIC(:,66) = piecewise({CONSTANTS(:,1)==1.00000&CONSTANTS(:,2)==0.00000, ( 2.00000.*CONSTANTS(:,21).*(STATES(:,1) - ALGEBRAIC(:,60)).*power(STATES(:,10)./(STATES(:,10)+CONSTANTS(:,22)), 3.00000).*1.00000)./(1.00000+exp(( CONSTANTS(:,23).*CONSTANTS(:,5).*((STATES(:,1) - ALGEBRAIC(:,60)) - CONSTANTS(:,24)))./( CONSTANTS(:,3).*CONSTANTS(:,4)))) , CONSTANTS(:,1)==0.00000&CONSTANTS(:,2)==1.00000, ( 2.50000.*CONSTANTS(:,21).*(STATES(:,1) - ALGEBRAIC(:,60)).*power(STATES(:,10)./(STATES(:,10)+CONSTANTS(:,22)), 3.00000).*1.00000)./(1.00000+exp(( CONSTANTS(:,23).*CONSTANTS(:,5).*((STATES(:,1) - ALGEBRAIC(:,60)) - CONSTANTS(:,24)))./( CONSTANTS(:,3).*CONSTANTS(:,4)))) }, ( CONSTANTS(:,21).*(STATES(:,1) - ALGEBRAIC(:,60)).*power(STATES(:,10)./(STATES(:,10)+CONSTANTS(:,22)), 3.00000).*1.00000)./(1.00000+exp(( CONSTANTS(:,23).*CONSTANTS(:,5).*((STATES(:,1) - ALGEBRAIC(:,60)) - CONSTANTS(:,24)))./( CONSTANTS(:,3).*CONSTANTS(:,4)))));
    ALGEBRAIC(:,65) =  CONSTANTS(:,20).*STATES(:,17).*STATES(:,18).*(STATES(:,1) - ALGEBRAIC(:,60));
    ALGEBRAIC(:,64) =  CONSTANTS(:,19).*STATES(:,16).*(STATES(:,1) - ALGEBRAIC(:,60));
    ALGEBRAIC(:,70) = ( (( (( CONSTANTS(:,30).*STATES(:,10))./(STATES(:,10)+CONSTANTS(:,28))).*power(STATES(:,2), 1.50000))./(power(STATES(:,2), 1.50000)+power(CONSTANTS(:,29), 1.50000))).*1.60000)./(1.50000+exp((STATES(:,1)+60.0000)./ - 40.0000));
    ALGEBRAIC(:,16) =  (( CONSTANTS(:,3).*CONSTANTS(:,4))./CONSTANTS(:,5)).*log(CONSTANTS(:,13)./STATES(:,2));
    ALGEBRAIC(:,31) = ( (( CONSTANTS(:,12).*power(STATES(:,3), 3.00000).*( 0.635000.*STATES(:,4)+ 0.365000.*STATES(:,5)).*CONSTANTS(:,13).*STATES(:,1).*power(CONSTANTS(:,5), 2.00000))./( CONSTANTS(:,3).*CONSTANTS(:,4))).*(exp(( (STATES(:,1) - ALGEBRAIC(:,16)).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))) - 1.00000))./(exp(( STATES(:,1).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))) - 1.00000);
    ALGEBRAIC(:,42) = 1.00000./(1.00000+exp((STATES(:,1) - 23.0000)./ - 12.0000));
    ALGEBRAIC(:,53) = piecewise({CONSTANTS(:,1)==1.00000&CONSTANTS(:,2)==0.00000,  1.80000.*CONSTANTS(:,14).*( STATES(:,6).*STATES(:,7)+ALGEBRAIC(:,42)).*(STATES(:,1) - CONSTANTS(:,15)) , CONSTANTS(:,1)==0.00000&CONSTANTS(:,2)==1.00000,  2.10000.*CONSTANTS(:,14).*( STATES(:,6).*STATES(:,7)+ALGEBRAIC(:,42)).*(STATES(:,1) - CONSTANTS(:,15)) },  CONSTANTS(:,14).*( STATES(:,6).*STATES(:,7)+ALGEBRAIC(:,42)).*(STATES(:,1) - CONSTANTS(:,15)));
    ALGEBRAIC(:,58) =  CONSTANTS(:,16).*STATES(:,8).*STATES(:,9).*(STATES(:,1) - CONSTANTS(:,17));
    ALGEBRAIC(:,68) = piecewise({CONSTANTS(:,1)==1.00000&CONSTANTS(:,2)==0.00000,  2.00000e-05.*(STATES(:,1) - ALGEBRAIC(:,16)) , CONSTANTS(:,1)==0.00000&CONSTANTS(:,2)==1.00000,  3.00000e-05.*(STATES(:,1) - ALGEBRAIC(:,16)) },  CONSTANTS(:,25).*(STATES(:,1) - ALGEBRAIC(:,16)));
    ALGEBRAIC(:,67) =  (( CONSTANTS(:,3).*CONSTANTS(:,4))./( 2.00000.*CONSTANTS(:,5))).*log(CONSTANTS(:,27)./STATES(:,19));
    ALGEBRAIC(:,69) = piecewise({CONSTANTS(:,1)==1.00000&CONSTANTS(:,2)==0.00000,  2.00000e-05.*(STATES(:,1) - ALGEBRAIC(:,67)) , CONSTANTS(:,1)==0.00000&CONSTANTS(:,2)==1.00000,  3.00000e-05.*(STATES(:,1) - ALGEBRAIC(:,67)) },  CONSTANTS(:,26).*(STATES(:,1) - ALGEBRAIC(:,67)));
    ALGEBRAIC(:,71) = ( CONSTANTS(:,31).*STATES(:,19))./(STATES(:,19)+CONSTANTS(:,32));
    ALGEBRAIC(:,72) = ( CONSTANTS(:,33).*( power(STATES(:,2), 3.00000).*CONSTANTS(:,27).*exp(( CONSTANTS(:,35).*CONSTANTS(:,5).*STATES(:,1))./( CONSTANTS(:,3).*CONSTANTS(:,4))) -  power(CONSTANTS(:,13), 3.00000).*STATES(:,19).*exp(( (CONSTANTS(:,35) - 1.00000).*STATES(:,1).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4)))))./(1.00000+ CONSTANTS(:,34).*( power(CONSTANTS(:,13), 3.00000).*STATES(:,19)+ power(STATES(:,2), 3.00000).*CONSTANTS(:,27)));
    ALGEBRAIC(:,1) = piecewise({VOI>=CONSTANTS(:,7)&VOI<=CONSTANTS(:,8)&(VOI - CONSTANTS(:,7)) -  floor((VOI - CONSTANTS(:,7))./CONSTANTS(:,9)).*CONSTANTS(:,9)<=CONSTANTS(:,10), CONSTANTS(:,11) }, 0.00000);
    ALGEBRAIC(:,73) =  200000..*STATES(:,19).*(1.00000 - STATES(:,20)) -  476.000.*STATES(:,20);
    ALGEBRAIC(:,74) =  78400.0.*STATES(:,19).*(1.00000 - STATES(:,21)) -  392.000.*STATES(:,21);
    ALGEBRAIC(:,75) =  200000..*STATES(:,19).*((1.00000 - STATES(:,22)) - STATES(:,23)) -  6.60000.*STATES(:,22);
    ALGEBRAIC(:,76) = ( CONSTANTS(:,40).*(STATES(:,19)./CONSTANTS(:,41) - ( power(CONSTANTS(:,43), 2.00000).*STATES(:,25))./CONSTANTS(:,42)))./((STATES(:,19)+CONSTANTS(:,41))./CONSTANTS(:,41)+( CONSTANTS(:,43).*(STATES(:,25)+CONSTANTS(:,42)))./CONSTANTS(:,42));
    ALGEBRAIC(:,77) = ( (STATES(:,25) - STATES(:,24)).*2.00000.*CONSTANTS(:,5).*CONSTANTS(:,46))./CONSTANTS(:,47);
    ALGEBRAIC(:,78) =  CONSTANTS(:,44).*power(STATES(:,28)./(STATES(:,28)+0.250000), 2.00000).*(STATES(:,24) - STATES(:,19));
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