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 =118;
end
% There are a total of 39 entries in each of the rate and state variable arrays.
% There are a total of 111 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('t in component environment (millisecond)');
    LEGEND_STATES(:,1) = strpad('V in component membrane (millivolt)');
    LEGEND_CONSTANTS(:,1) = strpad('R in component membrane (joule_per_kmole_kelvin)');
    LEGEND_CONSTANTS(:,2) = strpad('T in component membrane (kelvin)');
    LEGEND_CONSTANTS(:,3) = strpad('Frdy in component membrane (coulomb_per_mole)');
    LEGEND_CONSTANTS(:,96) = strpad('FoRT in component membrane (per_milliV)');
    LEGEND_CONSTANTS(:,4) = strpad('C_mem in component membrane (farad)');
    LEGEND_ALGEBRAIC(:,97) = strpad('I_Na_tot_junc in component Sodium_Concentrations (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,103) = strpad('I_Na_tot_sl in component Sodium_Concentrations (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,58) = strpad('I_ClCa in component Ca_Activated_Cl_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,59) = strpad('I_Cl_Bk in component Background_Cl_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,112) = strpad('I_Ca_tot_junc in component Calcium_Concentrations (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,115) = strpad('I_Ca_tot_sl in component Calcium_Concentrations (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,109) = strpad('I_K_tot in component Potassium_Concentrations (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,104) = strpad('I_Na_tot in component membrane (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,60) = strpad('I_Cl_tot in component membrane (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,117) = strpad('I_Ca_tot in component membrane (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,118) = strpad('I_tot in component membrane (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,11) = strpad('I_Stim in component membrane (picoA_per_picoF)');
    LEGEND_CONSTANTS(:,5) = strpad('I_Stim_Start in component membrane (millisecond)');
    LEGEND_CONSTANTS(:,6) = strpad('I_Stim_End in component membrane (millisecond)');
    LEGEND_CONSTANTS(:,7) = strpad('I_Stim_Amplitude in component membrane (picoA_per_picoF)');
    LEGEND_CONSTANTS(:,8) = strpad('I_Stim_Period in component membrane (millisecond)');
    LEGEND_CONSTANTS(:,9) = strpad('I_Stim_PulseDuration in component membrane (millisecond)');
    LEGEND_CONSTANTS(:,10) = strpad('F_junc in component membrane (dimensionless)');
    LEGEND_CONSTANTS(:,97) = strpad('F_sl in component membrane (dimensionless)');
    LEGEND_CONSTANTS(:,11) = strpad('F_junc_Ca_L in component membrane (dimensionless)');
    LEGEND_CONSTANTS(:,98) = strpad('F_sl_Ca_L in component membrane (dimensionless)');
    LEGEND_CONSTANTS(:,99) = strpad('V_cell in component membrane (litre)');
    LEGEND_CONSTANTS(:,12) = strpad('Length_cell in component membrane (decimetre)');
    LEGEND_CONSTANTS(:,13) = strpad('Radius_cell in component membrane (decimetre)');
    LEGEND_CONSTANTS(:,101) = strpad('V_myo in component membrane (litre)');
    LEGEND_CONSTANTS(:,104) = strpad('V_sl in component membrane (litre)');
    LEGEND_CONSTANTS(:,105) = strpad('V_sr in component membrane (litre)');
    LEGEND_CONSTANTS(:,106) = strpad('V_junc in component membrane (litre)');
    LEGEND_CONSTANTS(:,14) = strpad('J_Ca_juncsl in component membrane (L_per_millis)');
    LEGEND_CONSTANTS(:,15) = strpad('J_Ca_slmyo in component membrane (L_per_millis)');
    LEGEND_CONSTANTS(:,16) = strpad('J_Na_juncsl in component membrane (L_per_millis)');
    LEGEND_CONSTANTS(:,17) = strpad('J_Na_slmyo in component membrane (L_per_millis)');
    LEGEND_ALGEBRAIC(:,95) = strpad('I_Na_junc in component Fast_Na_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,99) = strpad('I_Na_sl in component Fast_Na_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,100) = strpad('I_Na in component Fast_Na_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,98) = strpad('E_Na_sl in component Nerst_Potentials (millivolt)');
    LEGEND_ALGEBRAIC(:,94) = strpad('E_Na_junc in component Nerst_Potentials (millivolt)');
    LEGEND_CONSTANTS(:,18) = strpad('G_Na in component Fast_Na_Current (milliS_per_microF)');
    LEGEND_STATES(:,2) = strpad('m in component Fast_Na_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,1) = strpad('m_ss in component Fast_Na_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,13) = strpad('tau_m in component Fast_Na_Current (millisecond)');
    LEGEND_ALGEBRAIC(:,2) = strpad('a_h in component Fast_Na_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,14) = strpad('b_h in component Fast_Na_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,27) = strpad('tau_h in component Fast_Na_Current (millisecond)');
    LEGEND_STATES(:,3) = strpad('h in component Fast_Na_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,34) = strpad('h_ss in component Fast_Na_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,3) = strpad('a_j in component Fast_Na_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,15) = strpad('b_j in component Fast_Na_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,28) = strpad('tau_j in component Fast_Na_Current (millisecond)');
    LEGEND_STATES(:,4) = strpad('j in component Fast_Na_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,35) = strpad('j_ss in component Fast_Na_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,96) = strpad('I_Na_Bk_junc in component Background_Na_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,101) = strpad('I_Na_Bk_sl in component Background_Na_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,102) = strpad('I_Na_Bk in component Background_Na_Current (picoA_per_picoF)');
    LEGEND_CONSTANTS(:,19) = strpad('G_Na_B in component Background_Na_Current (milliS_per_microF)');
    LEGEND_CONSTANTS(:,20) = strpad('Na_o in component Sodium_Concentrations (millimolar)');
    LEGEND_CONSTANTS(:,100) = strpad('sigma in component Na_K_Pump_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,25) = strpad('f_NaK in component Na_K_Pump_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,32) = strpad('I_NaK_junc in component Na_K_Pump_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,39) = strpad('I_NaK_sl in component Na_K_Pump_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,44) = strpad('I_NaK in component Na_K_Pump_Current (picoA_per_picoF)');
    LEGEND_CONSTANTS(:,21) = strpad('Ibar_NaK in component Na_K_Pump_Current (picoA_per_picoF)');
    LEGEND_CONSTANTS(:,22) = strpad('K_o in component Potassium_Concentrations (millimolar)');
    LEGEND_STATES(:,5) = strpad('Na_j in component Sodium_Concentrations (millimolar)');
    LEGEND_STATES(:,6) = strpad('Na_sl in component Sodium_Concentrations (millimolar)');
    LEGEND_CONSTANTS(:,23) = strpad('Km_Ko in component Na_K_Pump_Current (millimolar)');
    LEGEND_CONSTANTS(:,24) = strpad('Km_Naip in component Na_K_Pump_Current (millimolar)');
    LEGEND_ALGEBRAIC(:,4) = strpad('x_r_ss in component Rapidly_Activating_K_Current (dimensionless)');
    LEGEND_STATES(:,7) = strpad('x_Kr in component Rapidly_Activating_K_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,45) = strpad('r_Kr in component Rapidly_Activating_K_Current (dimensionless)');
    LEGEND_CONSTANTS(:,102) = strpad('E_K in component Nerst_Potentials (millivolt)');
    LEGEND_CONSTANTS(:,25) = strpad('G_Kr in component Rapidly_Activating_K_Current (milliS_per_microF)');
    LEGEND_ALGEBRAIC(:,16) = strpad('tau_xr in component Rapidly_Activating_K_Current (millisecond)');
    LEGEND_ALGEBRAIC(:,46) = strpad('I_Kr in component Rapidly_Activating_K_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,5) = strpad('x_s_ss in component Slowly_Activating_K_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,17) = strpad('tau_xs in component Slowly_Activating_K_Current (millisecond)');
    LEGEND_STATES(:,8) = strpad('x_Ks in component Slowly_Activating_K_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,105) = strpad('E_Ks in component Nerst_Potentials (millivolt)');
    LEGEND_CONSTANTS(:,26) = strpad('G_Ks_junc in component Slowly_Activating_K_Current (milliS_per_microF)');
    LEGEND_CONSTANTS(:,27) = strpad('G_Ks_sl in component Slowly_Activating_K_Current (milliS_per_microF)');
    LEGEND_ALGEBRAIC(:,106) = strpad('I_Ks_junc in component Slowly_Activating_K_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,107) = strpad('I_Ks_sl in component Slowly_Activating_K_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,108) = strpad('I_Ks in component Slowly_Activating_K_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,47) = strpad('kp_Kp in component Plateau_K_Current (dimensionless)');
    LEGEND_CONSTANTS(:,28) = strpad('G_Kp in component Plateau_K_Current (milliS_per_microF)');
    LEGEND_ALGEBRAIC(:,48) = strpad('I_Kp in component Plateau_K_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,6) = strpad('x_to_ss in component Transient_Outward_K_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,7) = strpad('y_to_ss in component Transient_Outward_K_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,18) = strpad('tau_x_tos in component Transient_Outward_K_Current (millisecond)');
    LEGEND_ALGEBRAIC(:,19) = strpad('tau_y_tos in component Transient_Outward_K_Current (millisecond)');
    LEGEND_ALGEBRAIC(:,20) = strpad('tau_x_tof in component Transient_Outward_K_Current (millisecond)');
    LEGEND_ALGEBRAIC(:,21) = strpad('tau_y_tof in component Transient_Outward_K_Current (millisecond)');
    LEGEND_STATES(:,9) = strpad('x_to_s in component Transient_Outward_K_Current (dimensionless)');
    LEGEND_STATES(:,10) = strpad('y_to_s in component Transient_Outward_K_Current (dimensionless)');
    LEGEND_STATES(:,11) = strpad('x_to_f in component Transient_Outward_K_Current (dimensionless)');
    LEGEND_STATES(:,12) = strpad('y_to_f in component Transient_Outward_K_Current (dimensionless)');
    LEGEND_CONSTANTS(:,29) = strpad('G_to_s in component Transient_Outward_K_Current (milliS_per_microF)');
    LEGEND_CONSTANTS(:,30) = strpad('G_to_f in component Transient_Outward_K_Current (milliS_per_microF)');
    LEGEND_ALGEBRAIC(:,49) = strpad('I_to_s in component Transient_Outward_K_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,50) = strpad('I_to_f in component Transient_Outward_K_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,51) = strpad('I_to in component Transient_Outward_K_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,52) = strpad('a_K1 in component Inward_Rectifier_K_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,53) = strpad('b_K1 in component Inward_Rectifier_K_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,54) = strpad('K1_ss in component Inward_Rectifier_K_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,55) = strpad('I_K1 in component Inward_Rectifier_K_Current (picoA_per_picoF)');
    LEGEND_CONSTANTS(:,31) = strpad('G_K1 in component Inward_Rectifier_K_Current (milliS_per_microF)');
    LEGEND_ALGEBRAIC(:,56) = strpad('I_ClCa_junc in component Ca_Activated_Cl_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,57) = strpad('I_ClCa_sl in component Ca_Activated_Cl_Current (picoA_per_picoF)');
    LEGEND_STATES(:,13) = strpad('Ca_j in component Calcium_Concentrations (millimolar)');
    LEGEND_STATES(:,14) = strpad('Ca_sl in component Calcium_Concentrations (millimolar)');
    LEGEND_CONSTANTS(:,103) = strpad('E_Cl in component Nerst_Potentials (millivolt)');
    LEGEND_CONSTANTS(:,32) = strpad('G_ClCa in component Ca_Activated_Cl_Current (milliS_per_microF)');
    LEGEND_CONSTANTS(:,33) = strpad('Kd_ClCa in component Ca_Activated_Cl_Current (millimolar)');
    LEGEND_CONSTANTS(:,34) = strpad('G_Cl_B in component Background_Cl_Current (milliS_per_microF)');
    LEGEND_ALGEBRAIC(:,8) = strpad('d_ss in component L_Type_Calcium_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,22) = strpad('alpha_d in component L_Type_Calcium_Current (millisecond)');
    LEGEND_ALGEBRAIC(:,29) = strpad('beta_d in component L_Type_Calcium_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,36) = strpad('gamma_d in component L_Type_Calcium_Current (millisecond)');
    LEGEND_ALGEBRAIC(:,41) = strpad('tau_d in component L_Type_Calcium_Current (millisecond)');
    LEGEND_ALGEBRAIC(:,9) = strpad('f_ss in component L_Type_Calcium_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,23) = strpad('alpha_f in component L_Type_Calcium_Current (millisecond)');
    LEGEND_ALGEBRAIC(:,30) = strpad('beta_f in component L_Type_Calcium_Current (millisecond)');
    LEGEND_ALGEBRAIC(:,37) = strpad('gamma_f in component L_Type_Calcium_Current (millisecond)');
    LEGEND_ALGEBRAIC(:,42) = strpad('tau_f in component L_Type_Calcium_Current (millisecond)');
    LEGEND_ALGEBRAIC(:,10) = strpad('f_2_ss in component L_Type_Calcium_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,24) = strpad('alpha_f_2 in component L_Type_Calcium_Current (millisecond)');
    LEGEND_ALGEBRAIC(:,31) = strpad('beta_f_2 in component L_Type_Calcium_Current (millisecond)');
    LEGEND_ALGEBRAIC(:,38) = strpad('gamma_f_2 in component L_Type_Calcium_Current (millisecond)');
    LEGEND_ALGEBRAIC(:,43) = strpad('tau_f_2 in component L_Type_Calcium_Current (millisecond)');
    LEGEND_STATES(:,15) = strpad('d in component L_Type_Calcium_Current (dimensionless)');
    LEGEND_STATES(:,16) = strpad('f in component L_Type_Calcium_Current (dimensionless)');
    LEGEND_STATES(:,17) = strpad('f_2 in component L_Type_Calcium_Current (dimensionless)');
    LEGEND_STATES(:,18) = strpad('f_Ca_B_j in component L_Type_Calcium_Current (dimensionless)');
    LEGEND_STATES(:,19) = strpad('f_Ca_B_sl in component L_Type_Calcium_Current (dimensionless)');
    LEGEND_CONSTANTS(:,35) = strpad('K_i in component Potassium_Concentrations (millimolar)');
    LEGEND_CONSTANTS(:,36) = strpad('Ca_o in component Calcium_Concentrations (millimolar)');
    LEGEND_ALGEBRAIC(:,61) = strpad('Ibar_Ca_j in component L_Type_Calcium_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,62) = strpad('Ibar_Ca_sl in component L_Type_Calcium_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,63) = strpad('Ibar_K in component L_Type_Calcium_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,64) = strpad('Ibar_Na_j in component L_Type_Calcium_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,65) = strpad('Ibar_Na_sl in component L_Type_Calcium_Current (picoA_per_picoF)');
    LEGEND_CONSTANTS(:,37) = strpad('p_Ca in component L_Type_Calcium_Current (litre_per_farad_millisecond)');
    LEGEND_CONSTANTS(:,38) = strpad('p_Na in component L_Type_Calcium_Current (litre_per_farad_millisecond)');
    LEGEND_CONSTANTS(:,39) = strpad('p_K in component L_Type_Calcium_Current (litre_per_farad_millisecond)');
    LEGEND_ALGEBRAIC(:,66) = strpad('I_Ca_junc in component L_Type_Calcium_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,67) = strpad('I_Ca_sl in component L_Type_Calcium_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,68) = strpad('I_Ca in component L_Type_Calcium_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,70) = strpad('I_Ca_Na_junc in component L_Type_Calcium_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,71) = strpad('I_Ca_Na_sl in component L_Type_Calcium_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,73) = strpad('I_Ca_Na in component L_Type_Calcium_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,69) = strpad('I_Ca_K in component L_Type_Calcium_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,75) = strpad('I_Ca_L in component L_Type_Calcium_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,72) = strpad('Ka_junc in component Na_Ca_Exchanger_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,74) = strpad('Ka_sl in component Na_Ca_Exchanger_Current (dimensionless)');
    LEGEND_CONSTANTS(:,40) = strpad('Kd_act in component Na_Ca_Exchanger_Current (millimolar)');
    LEGEND_CONSTANTS(:,41) = strpad('Km_Ca_i in component Na_Ca_Exchanger_Current (millimolar)');
    LEGEND_CONSTANTS(:,42) = strpad('Km_Ca_o in component Na_Ca_Exchanger_Current (millimolar)');
    LEGEND_CONSTANTS(:,43) = strpad('Km_Na_i in component Na_Ca_Exchanger_Current (millimolar)');
    LEGEND_CONSTANTS(:,44) = strpad('Km_Na_o in component Na_Ca_Exchanger_Current (millimolar)');
    LEGEND_CONSTANTS(:,45) = strpad('k_sat in component Na_Ca_Exchanger_Current (dimensionless)');
    LEGEND_CONSTANTS(:,46) = strpad('nu in component Na_Ca_Exchanger_Current (dimensionless)');
    LEGEND_ALGEBRAIC(:,76) = strpad('s1_junc in component Na_Ca_Exchanger_Current (millimolar4)');
    LEGEND_ALGEBRAIC(:,78) = strpad('s2_junc in component Na_Ca_Exchanger_Current (millimolar4)');
    LEGEND_ALGEBRAIC(:,80) = strpad('s3_junc in component Na_Ca_Exchanger_Current (millimolar4)');
    LEGEND_ALGEBRAIC(:,77) = strpad('s1_sl in component Na_Ca_Exchanger_Current (millimolar4)');
    LEGEND_ALGEBRAIC(:,79) = strpad('s2_sl in component Na_Ca_Exchanger_Current (millimolar4)');
    LEGEND_ALGEBRAIC(:,81) = strpad('s3_sl in component Na_Ca_Exchanger_Current (millimolar4)');
    LEGEND_CONSTANTS(:,47) = strpad('Ibar_NCX in component Na_Ca_Exchanger_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,83) = strpad('I_ncx_sl in component Na_Ca_Exchanger_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,82) = strpad('I_ncx_junc in component Na_Ca_Exchanger_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,85) = strpad('I_ncx in component Na_Ca_Exchanger_Current (picoA_per_picoF)');
    LEGEND_CONSTANTS(:,48) = strpad('Km_P_Ca in component Sarcolemmal_Ca_Pump_Current (millimolar)');
    LEGEND_CONSTANTS(:,49) = strpad('Ibar_PMCA in component Sarcolemmal_Ca_Pump_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,84) = strpad('I_pCa_junc in component Sarcolemmal_Ca_Pump_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,86) = strpad('I_pCa_sl in component Sarcolemmal_Ca_Pump_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,88) = strpad('I_pCa in component Sarcolemmal_Ca_Pump_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,113) = strpad('E_Ca_sl in component Nerst_Potentials (millivolt)');
    LEGEND_ALGEBRAIC(:,110) = strpad('E_Ca_junc in component Nerst_Potentials (millivolt)');
    LEGEND_CONSTANTS(:,50) = strpad('G_Ca_B in component Background_Ca_Current (milliS_per_microF)');
    LEGEND_ALGEBRAIC(:,114) = strpad('I_Ca_Bk_sl in component Background_Ca_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,111) = strpad('I_Ca_Bk_junc in component Background_Ca_Current (picoA_per_picoF)');
    LEGEND_ALGEBRAIC(:,116) = strpad('I_Ca_Bk in component Background_Ca_Current (picoA_per_picoF)');
    LEGEND_CONSTANTS(:,51) = strpad('Max_SR in component SR_Fluxes (dimensionless)');
    LEGEND_CONSTANTS(:,52) = strpad('Min_SR in component SR_Fluxes (dimensionless)');
    LEGEND_STATES(:,20) = strpad('Ca_SR in component Calcium_Concentrations (millimolar)');
    LEGEND_CONSTANTS(:,53) = strpad('ec50_SR in component SR_Fluxes (millimolar)');
    LEGEND_ALGEBRAIC(:,12) = strpad('k_Ca_SR in component SR_Fluxes (dimensionless)');
    LEGEND_CONSTANTS(:,54) = strpad('ko_Ca in component SR_Fluxes (per_milliM2_per_millis)');
    LEGEND_ALGEBRAIC(:,26) = strpad('ko_SR_Ca in component SR_Fluxes (per_milliM2_per_millis)');
    LEGEND_CONSTANTS(:,55) = strpad('ki_Ca in component SR_Fluxes (per_milliM_per_millis)');
    LEGEND_ALGEBRAIC(:,33) = strpad('ki_SR_Ca in component SR_Fluxes (per_milliM_per_millis)');
    LEGEND_CONSTANTS(:,56) = strpad('ki_m in component SR_Fluxes (per_millis)');
    LEGEND_CONSTANTS(:,57) = strpad('ko_m in component SR_Fluxes (per_millis)');
    LEGEND_CONSTANTS(:,58) = strpad('ks in component SR_Fluxes (per_millis)');
    LEGEND_CONSTANTS(:,59) = strpad('Km_f in component SR_Fluxes (millimolar)');
    LEGEND_CONSTANTS(:,60) = strpad('Km_r in component SR_Fluxes (millimolar)');
    LEGEND_ALGEBRAIC(:,87) = strpad('J_SR_Ca_rel in component SR_Fluxes (milliM_per_millis)');
    LEGEND_ALGEBRAIC(:,90) = strpad('J_SR_leak in component SR_Fluxes (milliM_per_millis)');
    LEGEND_ALGEBRAIC(:,89) = strpad('J_ser_Ca in component SR_Fluxes (milliM_per_millis)');
    LEGEND_ALGEBRAIC(:,40) = strpad('RI in component SR_Fluxes (dimensionless)');
    LEGEND_STATES(:,21) = strpad('Ry_Rr in component SR_Fluxes (dimensionless)');
    LEGEND_STATES(:,22) = strpad('Ry_Ro in component SR_Fluxes (dimensionless)');
    LEGEND_STATES(:,23) = strpad('Ry_Ri in component SR_Fluxes (dimensionless)');
    LEGEND_STATES(:,24) = strpad('Ca_i in component Calcium_Concentrations (millimolar)');
    LEGEND_CONSTANTS(:,61) = strpad('V_max_SR_CaP in component SR_Fluxes (milliM_per_millis)');
    LEGEND_CONSTANTS(:,62) = strpad('hill_SR_CaP in component SR_Fluxes (dimensionless)');
    LEGEND_CONSTANTS(:,63) = strpad('Mg_i in component Magnesium_Concentrations (millimolar)');
    LEGEND_STATES(:,25) = strpad('TnC_l in component Cytosolic_Ca_Buffers (millimolar)');
    LEGEND_STATES(:,26) = strpad('TnC_h_c in component Cytosolic_Ca_Buffers (millimolar)');
    LEGEND_STATES(:,27) = strpad('TnC_h_m in component Cytosolic_Ca_Buffers (millimolar)');
    LEGEND_STATES(:,28) = strpad('CaM in component Cytosolic_Ca_Buffers (millimolar)');
    LEGEND_STATES(:,29) = strpad('Myo_c in component Cytosolic_Ca_Buffers (millimolar)');
    LEGEND_STATES(:,30) = strpad('Myo_m in component Cytosolic_Ca_Buffers (millimolar)');
    LEGEND_STATES(:,31) = strpad('SRB in component Cytosolic_Ca_Buffers (millimolar)');
    LEGEND_CONSTANTS(:,64) = strpad('k_off_TnC_l in component Cytosolic_Ca_Buffers (per_millis)');
    LEGEND_CONSTANTS(:,65) = strpad('k_off_TnC_h_Ca in component Cytosolic_Ca_Buffers (per_millis)');
    LEGEND_CONSTANTS(:,66) = strpad('k_off_TnC_h_Mg in component Cytosolic_Ca_Buffers (per_millis)');
    LEGEND_CONSTANTS(:,67) = strpad('k_off_CaM in component Cytosolic_Ca_Buffers (per_millis)');
    LEGEND_CONSTANTS(:,68) = strpad('k_off_myo_Ca in component Cytosolic_Ca_Buffers (per_millis)');
    LEGEND_CONSTANTS(:,69) = strpad('k_off_myo_Mg in component Cytosolic_Ca_Buffers (per_millis)');
    LEGEND_CONSTANTS(:,70) = strpad('k_off_SR in component Cytosolic_Ca_Buffers (per_millis)');
    LEGEND_CONSTANTS(:,71) = strpad('k_on_TnC_l in component Cytosolic_Ca_Buffers (per_milliM_per_millis)');
    LEGEND_CONSTANTS(:,72) = strpad('k_on_TnC_h_Ca in component Cytosolic_Ca_Buffers (per_milliM_per_millis)');
    LEGEND_CONSTANTS(:,73) = strpad('k_on_TnC_h_Mg in component Cytosolic_Ca_Buffers (per_milliM_per_millis)');
    LEGEND_CONSTANTS(:,74) = strpad('k_on_CaM in component Cytosolic_Ca_Buffers (per_milliM_per_millis)');
    LEGEND_CONSTANTS(:,75) = strpad('k_on_myo_Ca in component Cytosolic_Ca_Buffers (per_milliM_per_millis)');
    LEGEND_CONSTANTS(:,76) = strpad('k_on_myo_Mg in component Cytosolic_Ca_Buffers (per_milliM_per_millis)');
    LEGEND_CONSTANTS(:,77) = strpad('k_on_SR in component Cytosolic_Ca_Buffers (per_milliM_per_millis)');
    LEGEND_CONSTANTS(:,78) = strpad('B_max_TnC_low in component Cytosolic_Ca_Buffers (millimolar)');
    LEGEND_CONSTANTS(:,79) = strpad('B_max_TnC_high in component Cytosolic_Ca_Buffers (millimolar)');
    LEGEND_CONSTANTS(:,80) = strpad('B_max_CaM in component Cytosolic_Ca_Buffers (millimolar)');
    LEGEND_CONSTANTS(:,81) = strpad('B_max_myosin in component Cytosolic_Ca_Buffers (millimolar)');
    LEGEND_CONSTANTS(:,82) = strpad('B_max_SR in component Cytosolic_Ca_Buffers (millimolar)');
    LEGEND_ALGEBRAIC(:,93) = strpad('J_Ca_B_cytosol in component Cytosolic_Ca_Buffers (milliM_per_millis)');
    LEGEND_CONSTANTS(:,107) = strpad('B_max_SL_low_j in component Junctional_and_SL_Ca_Buffers (millimolar)');
    LEGEND_CONSTANTS(:,108) = strpad('B_max_SL_low_sl in component Junctional_and_SL_Ca_Buffers (millimolar)');
    LEGEND_CONSTANTS(:,109) = strpad('B_max_SL_high_j in component Junctional_and_SL_Ca_Buffers (millimolar)');
    LEGEND_CONSTANTS(:,110) = strpad('B_max_SL_high_sl in component Junctional_and_SL_Ca_Buffers (millimolar)');
    LEGEND_CONSTANTS(:,83) = strpad('k_off_sl_l in component Junctional_and_SL_Ca_Buffers (per_millis)');
    LEGEND_CONSTANTS(:,84) = strpad('k_off_sl_h in component Junctional_and_SL_Ca_Buffers (per_millis)');
    LEGEND_CONSTANTS(:,85) = strpad('k_on_sl_l in component Junctional_and_SL_Ca_Buffers (per_milliM_per_millis)');
    LEGEND_CONSTANTS(:,86) = strpad('k_on_sl_h in component Junctional_and_SL_Ca_Buffers (per_milliM_per_millis)');
    LEGEND_STATES(:,32) = strpad('SLL_j in component Junctional_and_SL_Ca_Buffers (millimolar)');
    LEGEND_STATES(:,33) = strpad('SLL_sl in component Junctional_and_SL_Ca_Buffers (millimolar)');
    LEGEND_STATES(:,34) = strpad('SLH_j in component Junctional_and_SL_Ca_Buffers (millimolar)');
    LEGEND_STATES(:,35) = strpad('SLH_sl in component Junctional_and_SL_Ca_Buffers (millimolar)');
    LEGEND_ALGEBRAIC(:,91) = strpad('J_Ca_B_junction in component Junctional_and_SL_Ca_Buffers (milliM_per_millis)');
    LEGEND_ALGEBRAIC(:,92) = strpad('J_Ca_B_sl in component Junctional_and_SL_Ca_Buffers (milliM_per_millis)');
    LEGEND_CONSTANTS(:,87) = strpad('B_max_Na_j in component Sodium_Concentrations (millimolar)');
    LEGEND_CONSTANTS(:,88) = strpad('B_max_Na_sl in component Sodium_Concentrations (millimolar)');
    LEGEND_CONSTANTS(:,89) = strpad('k_off_Na in component Sodium_Concentrations (per_millis)');
    LEGEND_CONSTANTS(:,90) = strpad('k_on_Na in component Sodium_Concentrations (per_milliM_per_millis)');
    LEGEND_STATES(:,36) = strpad('Na_i in component Sodium_Concentrations (millimolar)');
    LEGEND_STATES(:,37) = strpad('Na_B_j in component Sodium_Concentrations (millimolar)');
    LEGEND_STATES(:,38) = strpad('Na_B_sl in component Sodium_Concentrations (millimolar)');
    LEGEND_CONSTANTS(:,111) = strpad('B_max_csqn in component Calcium_Concentrations (millimolar)');
    LEGEND_STATES(:,39) = strpad('Csqn_b in component Calcium_Concentrations (millimolar)');
    LEGEND_CONSTANTS(:,91) = strpad('k_off_csqn in component Calcium_Concentrations (per_millis)');
    LEGEND_CONSTANTS(:,92) = strpad('k_on_csqn in component Calcium_Concentrations (per_milliM_per_millis)');
    LEGEND_CONSTANTS(:,93) = strpad('Cl_i in component Chlorine_Concentrations (millimolar)');
    LEGEND_CONSTANTS(:,94) = strpad('Cl_o in component Chlorine_Concentrations (millimolar)');
    LEGEND_CONSTANTS(:,95) = strpad('p_Na_K in component Nerst_Potentials (dimensionless)');
    LEGEND_RATES(:,1) = strpad('d/dt V in component membrane (millivolt)');
    LEGEND_RATES(:,2) = strpad('d/dt m in component Fast_Na_Current (dimensionless)');
    LEGEND_RATES(:,3) = strpad('d/dt h in component Fast_Na_Current (dimensionless)');
    LEGEND_RATES(:,4) = strpad('d/dt j in component Fast_Na_Current (dimensionless)');
    LEGEND_RATES(:,7) = strpad('d/dt x_Kr in component Rapidly_Activating_K_Current (dimensionless)');
    LEGEND_RATES(:,8) = strpad('d/dt x_Ks in component Slowly_Activating_K_Current (dimensionless)');
    LEGEND_RATES(:,9) = strpad('d/dt x_to_s in component Transient_Outward_K_Current (dimensionless)');
    LEGEND_RATES(:,10) = strpad('d/dt y_to_s in component Transient_Outward_K_Current (dimensionless)');
    LEGEND_RATES(:,11) = strpad('d/dt x_to_f in component Transient_Outward_K_Current (dimensionless)');
    LEGEND_RATES(:,12) = strpad('d/dt y_to_f in component Transient_Outward_K_Current (dimensionless)');
    LEGEND_RATES(:,15) = strpad('d/dt d in component L_Type_Calcium_Current (dimensionless)');
    LEGEND_RATES(:,16) = strpad('d/dt f in component L_Type_Calcium_Current (dimensionless)');
    LEGEND_RATES(:,17) = strpad('d/dt f_2 in component L_Type_Calcium_Current (dimensionless)');
    LEGEND_RATES(:,18) = strpad('d/dt f_Ca_B_j in component L_Type_Calcium_Current (dimensionless)');
    LEGEND_RATES(:,19) = strpad('d/dt f_Ca_B_sl in component L_Type_Calcium_Current (dimensionless)');
    LEGEND_RATES(:,21) = strpad('d/dt Ry_Rr in component SR_Fluxes (dimensionless)');
    LEGEND_RATES(:,22) = strpad('d/dt Ry_Ro in component SR_Fluxes (dimensionless)');
    LEGEND_RATES(:,23) = strpad('d/dt Ry_Ri in component SR_Fluxes (dimensionless)');
    LEGEND_RATES(:,25) = strpad('d/dt TnC_l in component Cytosolic_Ca_Buffers (millimolar)');
    LEGEND_RATES(:,26) = strpad('d/dt TnC_h_c in component Cytosolic_Ca_Buffers (millimolar)');
    LEGEND_RATES(:,27) = strpad('d/dt TnC_h_m in component Cytosolic_Ca_Buffers (millimolar)');
    LEGEND_RATES(:,28) = strpad('d/dt CaM in component Cytosolic_Ca_Buffers (millimolar)');
    LEGEND_RATES(:,29) = strpad('d/dt Myo_c in component Cytosolic_Ca_Buffers (millimolar)');
    LEGEND_RATES(:,30) = strpad('d/dt Myo_m in component Cytosolic_Ca_Buffers (millimolar)');
    LEGEND_RATES(:,31) = strpad('d/dt SRB in component Cytosolic_Ca_Buffers (millimolar)');
    LEGEND_RATES(:,32) = strpad('d/dt SLL_j in component Junctional_and_SL_Ca_Buffers (millimolar)');
    LEGEND_RATES(:,33) = strpad('d/dt SLL_sl in component Junctional_and_SL_Ca_Buffers (millimolar)');
    LEGEND_RATES(:,34) = strpad('d/dt SLH_j in component Junctional_and_SL_Ca_Buffers (millimolar)');
    LEGEND_RATES(:,35) = strpad('d/dt SLH_sl in component Junctional_and_SL_Ca_Buffers (millimolar)');
    LEGEND_RATES(:,5) = strpad('d/dt Na_j in component Sodium_Concentrations (millimolar)');
    LEGEND_RATES(:,37) = strpad('d/dt Na_B_j in component Sodium_Concentrations (millimolar)');
    LEGEND_RATES(:,6) = strpad('d/dt Na_sl in component Sodium_Concentrations (millimolar)');
    LEGEND_RATES(:,38) = strpad('d/dt Na_B_sl in component Sodium_Concentrations (millimolar)');
    LEGEND_RATES(:,36) = strpad('d/dt Na_i in component Sodium_Concentrations (millimolar)');
    LEGEND_RATES(:,39) = strpad('d/dt Csqn_b in component Calcium_Concentrations (millimolar)');
    LEGEND_RATES(:,13) = strpad('d/dt Ca_j in component Calcium_Concentrations (millimolar)');
    LEGEND_RATES(:,14) = strpad('d/dt Ca_sl in component Calcium_Concentrations (millimolar)');
    LEGEND_RATES(:,24) = strpad('d/dt Ca_i in component Calcium_Concentrations (millimolar)');
    LEGEND_RATES(:,20) = strpad('d/dt Ca_SR in component Calcium_Concentrations (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) = -8.410546e1;
    CONSTANTS(:,1) = 8314;
    CONSTANTS(:,2) = 310;
    CONSTANTS(:,3) = 96485;
    CONSTANTS(:,4) = 1.381e-10;
    CONSTANTS(:,5) = 0;
    CONSTANTS(:,6) = 100000;
    CONSTANTS(:,7) = 40;
    CONSTANTS(:,8) = 1000;
    CONSTANTS(:,9) = 1;
    CONSTANTS(:,10) = 0.11;
    CONSTANTS(:,11) = 0.9;
    CONSTANTS(:,12) = 100e-5;
    CONSTANTS(:,13) = 10.25e-5;
    CONSTANTS(:,14) = 8.2413e-13;
    CONSTANTS(:,15) = 3.7243e-12;
    CONSTANTS(:,16) = 1.8313e-14;
    CONSTANTS(:,17) = 1.6386e-12;
    CONSTANTS(:,18) = 18.86;
    STATES(:,2) = 2.176608e-3;
    STATES(:,3) = 7.126555e-1;
    STATES(:,4) = 7.119893e-1;
    CONSTANTS(:,19) = 0.597e-3;
    CONSTANTS(:,20) = 140;
    CONSTANTS(:,21) = 0.99;
    CONSTANTS(:,22) = 5.4;
    STATES(:,5) = 1.00211e1;
    STATES(:,6) = 1.001974e1;
    CONSTANTS(:,23) = 1.5;
    CONSTANTS(:,24) = 11;
    STATES(:,7) = 1.896559e-2;
    CONSTANTS(:,25) = 0.035;
    STATES(:,8) = 3.55636e-3;
    CONSTANTS(:,26) = 0.0035;
    CONSTANTS(:,27) = 0.0035;
    CONSTANTS(:,28) = 0.002;
    STATES(:,9) = 3.592503e-4;
    STATES(:,10) = 8.161309e-1;
    STATES(:,11) = 3.592405e-4;
    STATES(:,12) = 9.999976e-1;
    CONSTANTS(:,29) = 3.7596e-2;
    CONSTANTS(:,30) = 1.404e-3;
    CONSTANTS(:,31) = 0.57153;
    STATES(:,13) = 2.048633e-4;
    STATES(:,14) = 1.188246e-4;
    CONSTANTS(:,32) = 0.054813;
    CONSTANTS(:,33) = 100e-3;
    CONSTANTS(:,34) = 9e-3;
    STATES(:,15) = 1.879996e-6;
    STATES(:,16) = 9.789409e-1;
    STATES(:,17) = 9.993986e-1;
    STATES(:,18) = 2.861794e-2;
    STATES(:,19) = 1.69833e-2;
    CONSTANTS(:,35) = 138;
    CONSTANTS(:,36) = 1.8;
    CONSTANTS(:,37) = 1.9887e-4;
    CONSTANTS(:,38) = 3.0375e-9;
    CONSTANTS(:,39) = 5.4675e-8;
    CONSTANTS(:,40) = 0.15e-3;
    CONSTANTS(:,41) = 3.59e-3;
    CONSTANTS(:,42) = 1.3;
    CONSTANTS(:,43) = 12.29;
    CONSTANTS(:,44) = 87.5;
    CONSTANTS(:,45) = 0.32;
    CONSTANTS(:,46) = 0.27;
    CONSTANTS(:,47) = 4.5;
    CONSTANTS(:,48) = 0.5e-3;
    CONSTANTS(:,49) = 0.0673;
    CONSTANTS(:,50) = 5.513e-4;
    CONSTANTS(:,51) = 15;
    CONSTANTS(:,52) = 1;
    STATES(:,20) = 6.138856e-1;
    CONSTANTS(:,53) = 0.45;
    CONSTANTS(:,54) = 10;
    CONSTANTS(:,55) = 0.5;
    CONSTANTS(:,56) = 0.005;
    CONSTANTS(:,57) = 0.06;
    CONSTANTS(:,58) = 25;
    CONSTANTS(:,59) = 0.246e-3;
    CONSTANTS(:,60) = 1.7;
    STATES(:,21) = 8.888214e-1;
    STATES(:,22) = 1.149876e-6;
    STATES(:,23) = 1.43831e-7;
    STATES(:,24) = 9.719632e-5;
    CONSTANTS(:,61) = 5.3114e-3;
    CONSTANTS(:,62) = 1.787;
    CONSTANTS(:,63) = 1;
    STATES(:,25) = 9.811535e-3;
    STATES(:,26) = 1.225802e-1;
    STATES(:,27) = 8.128604e-3;
    STATES(:,28) = 3.288063e-4;
    STATES(:,29) = 2.522168e-3;
    STATES(:,30) = 1.369514e-1;
    STATES(:,31) = 2.38683e-3;
    CONSTANTS(:,64) = 19.6e-3;
    CONSTANTS(:,65) = 0.032e-3;
    CONSTANTS(:,66) = 3.33e-3;
    CONSTANTS(:,67) = 238e-3;
    CONSTANTS(:,68) = 0.46e-3;
    CONSTANTS(:,69) = 0.057e-3;
    CONSTANTS(:,70) = 60e-3;
    CONSTANTS(:,71) = 32.7;
    CONSTANTS(:,72) = 2.37;
    CONSTANTS(:,73) = 3e-3;
    CONSTANTS(:,74) = 34;
    CONSTANTS(:,75) = 13.8;
    CONSTANTS(:,76) = 0.0157;
    CONSTANTS(:,77) = 100;
    CONSTANTS(:,78) = 70e-3;
    CONSTANTS(:,79) = 140e-3;
    CONSTANTS(:,80) = 24e-3;
    CONSTANTS(:,81) = 140e-3;
    CONSTANTS(:,82) = 17.1e-3;
    CONSTANTS(:,83) = 1.3;
    CONSTANTS(:,84) = 30e-3;
    CONSTANTS(:,85) = 100;
    CONSTANTS(:,86) = 100;
    STATES(:,32) = 8.606485e-3;
    STATES(:,33) = 1.101044e-2;
    STATES(:,34) = 8.078504e-2;
    STATES(:,35) = 1.238366e-1;
    CONSTANTS(:,87) = 7.561;
    CONSTANTS(:,88) = 1.65;
    CONSTANTS(:,89) = 1e-3;
    CONSTANTS(:,90) = 0.1e-3;
    STATES(:,36) = 1.001989e1;
    STATES(:,37) = 3.785209e0;
    STATES(:,38) = 8.259271e-1;
    STATES(:,39) = 1.262853;
    CONSTANTS(:,91) = 65;
    CONSTANTS(:,92) = 100;
    CONSTANTS(:,93) = 15;
    CONSTANTS(:,94) = 150;
    CONSTANTS(:,95) = 0.01833;
    CONSTANTS(:,96) = CONSTANTS(:,3)./( CONSTANTS(:,1).*CONSTANTS(:,2));
    CONSTANTS(:,97) = 1.00000 - CONSTANTS(:,10);
    CONSTANTS(:,98) = 1.00000 - CONSTANTS(:,11);
    CONSTANTS(:,99) =   pi.*power(CONSTANTS(:,13), 2.00000).*CONSTANTS(:,12);
    CONSTANTS(:,100) = (exp(CONSTANTS(:,20)./67.3000) - 1.00000)./7.00000;
    CONSTANTS(:,101) =  0.650000.*CONSTANTS(:,99);
    CONSTANTS(:,102) =  (1.00000./CONSTANTS(:,96)).*log(CONSTANTS(:,22)./CONSTANTS(:,35));
    CONSTANTS(:,103) =  (1.00000./CONSTANTS(:,96)).*log(CONSTANTS(:,93)./CONSTANTS(:,94));
    CONSTANTS(:,104) =  0.0200000.*CONSTANTS(:,99);
    CONSTANTS(:,105) =  0.0350000.*CONSTANTS(:,99);
    CONSTANTS(:,106) =  0.000539000.*CONSTANTS(:,99);
    CONSTANTS(:,107) = ( 0.000460000.*CONSTANTS(:,101))./CONSTANTS(:,106);
    CONSTANTS(:,108) = ( 0.0374000.*CONSTANTS(:,101))./CONSTANTS(:,104);
    CONSTANTS(:,109) = ( 0.000165000.*CONSTANTS(:,101))./CONSTANTS(:,106);
    CONSTANTS(:,110) = ( 0.0134000.*CONSTANTS(:,101))./CONSTANTS(:,104);
    CONSTANTS(:,111) = ( 0.140000.*CONSTANTS(:,101))./CONSTANTS(:,105);
    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(:,18) =  1.70000.*STATES(:,13).*(1.00000 - STATES(:,18)) -  0.0119000.*STATES(:,18);
    RATES(:,19) =  1.70000.*STATES(:,14).*(1.00000 - STATES(:,19)) -  0.0119000.*STATES(:,19);
    RATES(:,36) =  (CONSTANTS(:,17)./CONSTANTS(:,101)).*(STATES(:,6) - STATES(:,36));
    ALGEBRAIC(:,1) = 1.00000./power(1.00000+exp( - (56.8600+STATES(:,1))./9.03000), 2.00000);
    ALGEBRAIC(:,13) =  0.129200.*exp( - power((STATES(:,1)+45.7900)./15.5400, 2.00000))+ 0.0648700.*exp( - power((STATES(:,1) - 4.82300)./51.1200, 2.00000));
    RATES(:,2) = (ALGEBRAIC(:,1) - STATES(:,2))./ALGEBRAIC(:,13);
    ALGEBRAIC(:,4) = 1.00000./(1.00000+exp( - (STATES(:,1)+10.0000)./5.00000));
    ALGEBRAIC(:,16) = 3300.00./( (1.00000+exp(( - 22.0000 - STATES(:,1))./9.00000)).*(1.00000+exp((STATES(:,1)+11.0000)./9.00000)))+230.000./(1.00000+exp((STATES(:,1)+40.0000)./20.0000));
    RATES(:,7) = (ALGEBRAIC(:,4) - STATES(:,7))./ALGEBRAIC(:,16);
    ALGEBRAIC(:,5) = 1.00000./(1.00000+exp( - (STATES(:,1)+3.80000)./14.2500));
    ALGEBRAIC(:,17) = 990.100./(1.00000+exp( - (STATES(:,1)+2.43600)./14.1200));
    RATES(:,8) = (ALGEBRAIC(:,5) - STATES(:,8))./ALGEBRAIC(:,17);
    ALGEBRAIC(:,6) = 1.00000./(1.00000+exp( - (STATES(:,1) - 19.0000)./13.0000));
    ALGEBRAIC(:,18) = 9.00000./(1.00000+exp((STATES(:,1)+3.00000)./15.0000))+0.500000;
    RATES(:,9) = (ALGEBRAIC(:,6) - STATES(:,9))./ALGEBRAIC(:,18);
    ALGEBRAIC(:,7) = 1.00000./(1.00000+exp((STATES(:,1)+19.5000)./5.00000));
    ALGEBRAIC(:,19) = 800.000./(1.00000+exp((STATES(:,1)+60.0000)./10.0000))+30.0000;
    RATES(:,10) = (ALGEBRAIC(:,7) - STATES(:,10))./ALGEBRAIC(:,19);
    ALGEBRAIC(:,20) =  8.50000.*exp( - power((STATES(:,1)+45.0000)./50.0000, 2.00000))+0.500000;
    RATES(:,11) = (ALGEBRAIC(:,6) - STATES(:,11))./ALGEBRAIC(:,20);
    ALGEBRAIC(:,21) =  85.0000.*exp( - power(STATES(:,1)+40.0000, 2.00000)./220.000)+7.00000;
    RATES(:,12) = (ALGEBRAIC(:,7) - STATES(:,12))./ALGEBRAIC(:,21);
    ALGEBRAIC(:,12) = CONSTANTS(:,51) - (CONSTANTS(:,51) - CONSTANTS(:,52))./(1.00000+power(CONSTANTS(:,53)./STATES(:,20), 2.50000));
    ALGEBRAIC(:,26) = CONSTANTS(:,54)./ALGEBRAIC(:,12);
    ALGEBRAIC(:,33) =  CONSTANTS(:,55).*ALGEBRAIC(:,12);
    RATES(:,22) = ( ALGEBRAIC(:,26).*power(STATES(:,13), 2.00000).*STATES(:,21) -  CONSTANTS(:,57).*STATES(:,22)) - ( ALGEBRAIC(:,33).*STATES(:,13).*STATES(:,22) -  CONSTANTS(:,56).*STATES(:,23));
    ALGEBRAIC(:,2) = piecewise({STATES(:,1)>= - 40.0000, 0.00000 },  0.0570000.*exp( - (STATES(:,1)+80.0000)./6.80000));
    ALGEBRAIC(:,14) = piecewise({STATES(:,1)>= - 40.0000, 5.92310./(1.00000+exp( - (STATES(:,1)+10.6600)./11.1000)) },  2.70000.*exp( 0.0790000.*STATES(:,1))+ 310000..*exp( 0.348500.*STATES(:,1)));
    ALGEBRAIC(:,27) = 1.00000./(ALGEBRAIC(:,2)+ALGEBRAIC(:,14));
    ALGEBRAIC(:,34) = 1.00000./power(1.00000+exp((STATES(:,1)+71.5500)./7.43000), 2.00000);
    RATES(:,3) = (ALGEBRAIC(:,34) - STATES(:,3))./ALGEBRAIC(:,27);
    ALGEBRAIC(:,3) = piecewise({STATES(:,1)>= - 40.0000, 0.00000 }, ( (  - 25428.0.*exp( 0.244400.*STATES(:,1)) -  6.94800e-06.*exp(  - 0.0439100.*STATES(:,1))).*(STATES(:,1)+37.7800))./(1.00000+exp( 0.311000.*(STATES(:,1)+79.2300))));
    ALGEBRAIC(:,15) = piecewise({STATES(:,1)>= - 40.0000, ( 0.600000.*exp( 0.0570000.*STATES(:,1)))./(1.00000+exp(  - 0.100000.*(STATES(:,1)+32.0000))) }, ( 0.0242400.*exp(  - 0.0105200.*STATES(:,1)))./(1.00000+exp(  - 0.137800.*(STATES(:,1)+40.1400))));
    ALGEBRAIC(:,28) = 1.00000./(ALGEBRAIC(:,3)+ALGEBRAIC(:,15));
    ALGEBRAIC(:,35) = 1.00000./power(1.00000+exp((STATES(:,1)+71.5500)./7.43000), 2.00000);
    RATES(:,4) = (ALGEBRAIC(:,35) - STATES(:,4))./ALGEBRAIC(:,28);
    ALGEBRAIC(:,40) = ((1.00000 - STATES(:,21)) - STATES(:,22)) - STATES(:,23);
    RATES(:,21) = ( CONSTANTS(:,56).*ALGEBRAIC(:,40) -  ALGEBRAIC(:,33).*STATES(:,13).*STATES(:,21)) - ( ALGEBRAIC(:,26).*power(STATES(:,13), 2.00000).*STATES(:,21) -  CONSTANTS(:,57).*STATES(:,22));
    RATES(:,23) = ( ALGEBRAIC(:,33).*STATES(:,13).*STATES(:,22) -  CONSTANTS(:,56).*STATES(:,23)) - ( CONSTANTS(:,57).*STATES(:,23) -  ALGEBRAIC(:,26).*power(STATES(:,13), 2.00000).*ALGEBRAIC(:,40));
    ALGEBRAIC(:,8) = 1.00000./(1.00000+exp( - (STATES(:,1)+5.00000)./6.00000));
    ALGEBRAIC(:,22) = 1.40000./(1.00000+exp(( - 35.0000 - STATES(:,1))./13.0000))+0.250000;
    ALGEBRAIC(:,29) = 1.40000./(1.00000+exp((STATES(:,1)+5.00000)./5.00000));
    ALGEBRAIC(:,36) = 1.00000./(1.00000+exp((50.0000 - STATES(:,1))./20.0000));
    ALGEBRAIC(:,41) =  ALGEBRAIC(:,22).*ALGEBRAIC(:,29)+ALGEBRAIC(:,36);
    RATES(:,15) = (ALGEBRAIC(:,8) - STATES(:,15))./ALGEBRAIC(:,41);
    ALGEBRAIC(:,9) = 1.00000./(1.00000+exp((STATES(:,1)+20.0000)./7.00000));
    ALGEBRAIC(:,23) =  1102.50.*exp( - power((STATES(:,1)+27.0000)./15.0000, 2.00000));
    ALGEBRAIC(:,30) = 200.000./(1.00000+exp((13.0000 - STATES(:,1))./10.0000));
    ALGEBRAIC(:,37) = 180.000./(1.00000+exp((STATES(:,1)+30.0000)./10.0000))+20.0000;
    ALGEBRAIC(:,42) = ALGEBRAIC(:,23)+ALGEBRAIC(:,30)+ALGEBRAIC(:,37);
    RATES(:,16) = (ALGEBRAIC(:,9) - STATES(:,16))./ALGEBRAIC(:,42);
    ALGEBRAIC(:,10) = 0.670000./(1.00000+exp((STATES(:,1)+35.0000)./7.00000))+0.330000;
    ALGEBRAIC(:,24) =  300.000.*exp( - power(STATES(:,1)+25.0000, 2.00000)./170.000);
    ALGEBRAIC(:,31) = 31.0000./(1.00000+exp((25.0000 - STATES(:,1))./10.0000));
    ALGEBRAIC(:,38) = 16.0000./(1.00000+exp((STATES(:,1)+30.0000)./10.0000));
    ALGEBRAIC(:,43) = ALGEBRAIC(:,24)+ALGEBRAIC(:,31)+ALGEBRAIC(:,38);
    RATES(:,17) = (ALGEBRAIC(:,10) - STATES(:,17))./ALGEBRAIC(:,43);
    RATES(:,25) =  CONSTANTS(:,71).*STATES(:,24).*(CONSTANTS(:,78) - STATES(:,25)) -  CONSTANTS(:,64).*STATES(:,25);
    RATES(:,32) =  CONSTANTS(:,85).*STATES(:,13).*(CONSTANTS(:,107) - STATES(:,32)) -  CONSTANTS(:,83).*STATES(:,32);
    RATES(:,26) =  CONSTANTS(:,72).*STATES(:,24).*((CONSTANTS(:,79) - STATES(:,26)) - STATES(:,27)) -  CONSTANTS(:,65).*STATES(:,26);
    RATES(:,39) =  CONSTANTS(:,92).*STATES(:,20).*(CONSTANTS(:,111) - STATES(:,39)) -  CONSTANTS(:,91).*STATES(:,39);
    RATES(:,33) =  CONSTANTS(:,85).*STATES(:,14).*(CONSTANTS(:,108) - STATES(:,33)) -  CONSTANTS(:,83).*STATES(:,33);
    RATES(:,27) =  CONSTANTS(:,73).*CONSTANTS(:,63).*((CONSTANTS(:,79) - STATES(:,26)) - STATES(:,27)) -  CONSTANTS(:,66).*STATES(:,27);
    ALGEBRAIC(:,87) =  CONSTANTS(:,58).*STATES(:,22).*(STATES(:,20) - STATES(:,13));
    ALGEBRAIC(:,90) =  5.34800e-06.*(STATES(:,20) - STATES(:,13));
    ALGEBRAIC(:,89) = ( CONSTANTS(:,61).*(power(STATES(:,24)./CONSTANTS(:,59), CONSTANTS(:,62)) - power(STATES(:,20)./CONSTANTS(:,60), CONSTANTS(:,62))))./(1.00000+power(STATES(:,24)./CONSTANTS(:,59), CONSTANTS(:,62))+power(STATES(:,20)./CONSTANTS(:,60), CONSTANTS(:,62)));
    RATES(:,20) = (ALGEBRAIC(:,89) - (( ALGEBRAIC(:,90).*CONSTANTS(:,101))./CONSTANTS(:,105)+ALGEBRAIC(:,87))) - RATES(:,39);
    RATES(:,34) =  CONSTANTS(:,86).*STATES(:,13).*(CONSTANTS(:,109) - STATES(:,34)) -  CONSTANTS(:,84).*STATES(:,34);
    RATES(:,28) =  CONSTANTS(:,74).*STATES(:,24).*(CONSTANTS(:,80) - STATES(:,28)) -  CONSTANTS(:,67).*STATES(:,28);
    RATES(:,35) =  CONSTANTS(:,86).*STATES(:,14).*(CONSTANTS(:,110) - STATES(:,35)) -  CONSTANTS(:,84).*STATES(:,35);
    RATES(:,29) =  CONSTANTS(:,75).*STATES(:,24).*((CONSTANTS(:,81) - STATES(:,29)) - STATES(:,30)) -  CONSTANTS(:,68).*STATES(:,29);
    RATES(:,30) =  CONSTANTS(:,76).*CONSTANTS(:,63).*((CONSTANTS(:,81) - STATES(:,29)) - STATES(:,30)) -  CONSTANTS(:,69).*STATES(:,30);
    RATES(:,31) =  CONSTANTS(:,77).*STATES(:,24).*(CONSTANTS(:,82) - STATES(:,31)) -  CONSTANTS(:,70).*STATES(:,31);
    RATES(:,37) =  CONSTANTS(:,90).*STATES(:,5).*(CONSTANTS(:,87) - STATES(:,37)) -  CONSTANTS(:,89).*STATES(:,37);
    RATES(:,38) =  CONSTANTS(:,90).*STATES(:,6).*(CONSTANTS(:,88) - STATES(:,38)) -  CONSTANTS(:,89).*STATES(:,38);
    ALGEBRAIC(:,93) = RATES(:,25)+RATES(:,26)+RATES(:,27)+RATES(:,28)+RATES(:,29)+RATES(:,30)+RATES(:,31);
    RATES(:,24) = ((  - ALGEBRAIC(:,89).*CONSTANTS(:,105))./CONSTANTS(:,101) - ALGEBRAIC(:,93))+ (CONSTANTS(:,15)./CONSTANTS(:,101)).*(STATES(:,14) - STATES(:,24));
    ALGEBRAIC(:,94) =  (1.00000./CONSTANTS(:,96)).*log(CONSTANTS(:,20)./STATES(:,5));
    ALGEBRAIC(:,95) =  CONSTANTS(:,10).*CONSTANTS(:,18).*power(STATES(:,2), 3.00000).*STATES(:,3).*STATES(:,4).*(STATES(:,1) - ALGEBRAIC(:,94));
    ALGEBRAIC(:,96) =  CONSTANTS(:,10).*CONSTANTS(:,19).*(STATES(:,1) - ALGEBRAIC(:,94));
    ALGEBRAIC(:,25) = 1.00000./(1.00000+ 0.124500.*exp(  - 0.100000.*STATES(:,1).*CONSTANTS(:,96))+ 0.0365000.*CONSTANTS(:,100).*exp(  - STATES(:,1).*CONSTANTS(:,96)));
    ALGEBRAIC(:,32) = ( CONSTANTS(:,10).*CONSTANTS(:,21).*ALGEBRAIC(:,25).*CONSTANTS(:,22))./( (1.00000+power(CONSTANTS(:,24)./STATES(:,5), 4.00000)).*(CONSTANTS(:,22)+CONSTANTS(:,23)));
    ALGEBRAIC(:,64) = ( CONSTANTS(:,38).*STATES(:,1).*CONSTANTS(:,3).*CONSTANTS(:,96).*( STATES(:,5).*exp( STATES(:,1).*CONSTANTS(:,96)) - CONSTANTS(:,20)))./(exp( STATES(:,1).*CONSTANTS(:,96)) - 1.00000);
    ALGEBRAIC(:,70) =  CONSTANTS(:,11).*ALGEBRAIC(:,64).*STATES(:,15).*STATES(:,16).*STATES(:,17).*(1.00000 - STATES(:,18));
    ALGEBRAIC(:,72) = 1.00000./(1.00000+power(CONSTANTS(:,40)./STATES(:,13), 2.00000));
    ALGEBRAIC(:,76) =  exp( CONSTANTS(:,46).*STATES(:,1).*CONSTANTS(:,96)).*power(STATES(:,5), 3.00000).*CONSTANTS(:,36);
    ALGEBRAIC(:,78) =  exp( (CONSTANTS(:,46) - 1.00000).*STATES(:,1).*CONSTANTS(:,96)).*power(CONSTANTS(:,20), 3.00000).*STATES(:,13);
    ALGEBRAIC(:,80) =  CONSTANTS(:,41).*power(CONSTANTS(:,20), 3.00000).*(1.00000+power(STATES(:,5)./CONSTANTS(:,43), 3.00000))+ power(CONSTANTS(:,44), 3.00000).*STATES(:,13).*(1.00000+STATES(:,13)./CONSTANTS(:,41))+ CONSTANTS(:,42).*power(STATES(:,5), 3.00000)+ power(STATES(:,5), 3.00000).*CONSTANTS(:,36)+ power(CONSTANTS(:,20), 3.00000).*STATES(:,13);
    ALGEBRAIC(:,82) = ( CONSTANTS(:,10).*CONSTANTS(:,47).*ALGEBRAIC(:,72).*(ALGEBRAIC(:,76) - ALGEBRAIC(:,78)))./( ALGEBRAIC(:,80).*(1.00000+ CONSTANTS(:,45).*exp( (CONSTANTS(:,46) - 1.00000).*STATES(:,1).*CONSTANTS(:,96))));
    ALGEBRAIC(:,97) = ALGEBRAIC(:,95)+ALGEBRAIC(:,96)+ 3.00000.*ALGEBRAIC(:,82)+ 3.00000.*ALGEBRAIC(:,32)+ALGEBRAIC(:,70);
    RATES(:,5) = ((  - ALGEBRAIC(:,97).*CONSTANTS(:,4))./( CONSTANTS(:,106).*CONSTANTS(:,3))+ (CONSTANTS(:,16)./CONSTANTS(:,106)).*(STATES(:,6) - STATES(:,5))) - RATES(:,37);
    ALGEBRAIC(:,98) =  (1.00000./CONSTANTS(:,96)).*log(CONSTANTS(:,20)./STATES(:,6));
    ALGEBRAIC(:,99) =  CONSTANTS(:,97).*CONSTANTS(:,18).*power(STATES(:,2), 3.00000).*STATES(:,3).*STATES(:,4).*(STATES(:,1) - ALGEBRAIC(:,98));
    ALGEBRAIC(:,101) =  CONSTANTS(:,97).*CONSTANTS(:,19).*(STATES(:,1) - ALGEBRAIC(:,98));
    ALGEBRAIC(:,39) = ( CONSTANTS(:,97).*CONSTANTS(:,21).*ALGEBRAIC(:,25).*CONSTANTS(:,22))./( (1.00000+power(CONSTANTS(:,24)./STATES(:,6), 4.00000)).*(CONSTANTS(:,22)+CONSTANTS(:,23)));
    ALGEBRAIC(:,65) = ( CONSTANTS(:,38).*STATES(:,1).*CONSTANTS(:,3).*CONSTANTS(:,96).*( STATES(:,6).*exp( STATES(:,1).*CONSTANTS(:,96)) - CONSTANTS(:,20)))./(exp( STATES(:,1).*CONSTANTS(:,96)) - 1.00000);
    ALGEBRAIC(:,71) =  CONSTANTS(:,98).*ALGEBRAIC(:,65).*STATES(:,15).*STATES(:,16).*STATES(:,17).*(1.00000 - STATES(:,19));
    ALGEBRAIC(:,74) = 1.00000./(1.00000+power(CONSTANTS(:,40)./STATES(:,14), 2.00000));
    ALGEBRAIC(:,77) =  exp( CONSTANTS(:,46).*STATES(:,1).*CONSTANTS(:,96)).*power(STATES(:,6), 3.00000).*CONSTANTS(:,36);
    ALGEBRAIC(:,79) =  exp( (CONSTANTS(:,46) - 1.00000).*STATES(:,1).*CONSTANTS(:,96)).*power(CONSTANTS(:,20), 3.00000).*STATES(:,14);
    ALGEBRAIC(:,81) =  CONSTANTS(:,41).*power(CONSTANTS(:,20), 3.00000).*(1.00000+power(STATES(:,6)./CONSTANTS(:,43), 3.00000))+ power(CONSTANTS(:,44), 3.00000).*STATES(:,14).*(1.00000+STATES(:,14)./CONSTANTS(:,41))+ CONSTANTS(:,42).*power(STATES(:,6), 3.00000)+ power(STATES(:,6), 3.00000).*CONSTANTS(:,36)+ power(CONSTANTS(:,20), 3.00000).*STATES(:,14);
    ALGEBRAIC(:,83) = ( CONSTANTS(:,97).*CONSTANTS(:,47).*ALGEBRAIC(:,74).*(ALGEBRAIC(:,77) - ALGEBRAIC(:,79)))./( ALGEBRAIC(:,81).*(1.00000+ CONSTANTS(:,45).*exp( (CONSTANTS(:,46) - 1.00000).*STATES(:,1).*CONSTANTS(:,96))));
    ALGEBRAIC(:,103) = ALGEBRAIC(:,99)+ALGEBRAIC(:,101)+ 3.00000.*ALGEBRAIC(:,83)+ 3.00000.*ALGEBRAIC(:,39)+ALGEBRAIC(:,71);
    RATES(:,6) = ((  - ALGEBRAIC(:,103).*CONSTANTS(:,4))./( CONSTANTS(:,104).*CONSTANTS(:,3))+ (CONSTANTS(:,16)./CONSTANTS(:,104)).*(STATES(:,5) - STATES(:,6))+ (CONSTANTS(:,17)./CONSTANTS(:,104)).*(STATES(:,36) - STATES(:,6))) - RATES(:,38);
    ALGEBRAIC(:,61) = ( CONSTANTS(:,37).*STATES(:,1).*CONSTANTS(:,3).*CONSTANTS(:,96).*( STATES(:,13).*exp( 2.00000.*STATES(:,1).*CONSTANTS(:,96)) - CONSTANTS(:,36)))./(exp( 2.00000.*STATES(:,1).*CONSTANTS(:,96)) - 1.00000);
    ALGEBRAIC(:,66) =  CONSTANTS(:,11).*ALGEBRAIC(:,61).*STATES(:,15).*STATES(:,16).*STATES(:,17).*(1.00000 - STATES(:,18));
    ALGEBRAIC(:,84) = ( CONSTANTS(:,10).*CONSTANTS(:,49).*power(STATES(:,13), 1.60000))./(power(CONSTANTS(:,48), 1.60000)+power(STATES(:,13), 1.60000));
    ALGEBRAIC(:,110) =  (1.00000./( 2.00000.*CONSTANTS(:,96))).*log(CONSTANTS(:,36)./STATES(:,13));
    ALGEBRAIC(:,111) =  CONSTANTS(:,10).*CONSTANTS(:,50).*(STATES(:,1) - ALGEBRAIC(:,110));
    ALGEBRAIC(:,112) = (ALGEBRAIC(:,66)+ALGEBRAIC(:,111)+ALGEBRAIC(:,84)) -  2.00000.*ALGEBRAIC(:,82);
    ALGEBRAIC(:,91) = RATES(:,32)+RATES(:,34);
    RATES(:,13) = (((  - ALGEBRAIC(:,112).*CONSTANTS(:,4))./( CONSTANTS(:,106).*2.00000.*CONSTANTS(:,3))+ (CONSTANTS(:,14)./CONSTANTS(:,106)).*(STATES(:,14) - STATES(:,13))) - ALGEBRAIC(:,91))+( ALGEBRAIC(:,87).*CONSTANTS(:,105))./CONSTANTS(:,106)+( ALGEBRAIC(:,90).*CONSTANTS(:,101))./CONSTANTS(:,106);
    ALGEBRAIC(:,62) = ( CONSTANTS(:,37).*STATES(:,1).*CONSTANTS(:,3).*CONSTANTS(:,96).*( STATES(:,14).*exp( 2.00000.*STATES(:,1).*CONSTANTS(:,96)) - CONSTANTS(:,36)))./(exp( 2.00000.*STATES(:,1).*CONSTANTS(:,96)) - 1.00000);
    ALGEBRAIC(:,67) =  CONSTANTS(:,98).*ALGEBRAIC(:,62).*STATES(:,15).*STATES(:,16).*STATES(:,17).*(1.00000 - STATES(:,19));
    ALGEBRAIC(:,86) = ( CONSTANTS(:,97).*CONSTANTS(:,49).*power(STATES(:,14), 1.60000))./(power(CONSTANTS(:,48), 1.60000)+power(STATES(:,14), 1.60000));
    ALGEBRAIC(:,113) =  (1.00000./( 2.00000.*CONSTANTS(:,96))).*log(CONSTANTS(:,36)./STATES(:,14));
    ALGEBRAIC(:,114) =  CONSTANTS(:,97).*CONSTANTS(:,50).*(STATES(:,1) - ALGEBRAIC(:,113));
    ALGEBRAIC(:,115) = (ALGEBRAIC(:,67)+ALGEBRAIC(:,114)+ALGEBRAIC(:,86)) -  2.00000.*ALGEBRAIC(:,83);
    ALGEBRAIC(:,92) = RATES(:,33)+RATES(:,35);
    RATES(:,14) = ((  - ALGEBRAIC(:,115).*CONSTANTS(:,4))./( CONSTANTS(:,104).*2.00000.*CONSTANTS(:,3))+ (CONSTANTS(:,14)./CONSTANTS(:,104)).*(STATES(:,13) - STATES(:,14))+ (CONSTANTS(:,15)./CONSTANTS(:,104)).*(STATES(:,24) - STATES(:,14))) - ALGEBRAIC(:,92);
    ALGEBRAIC(:,44) = ALGEBRAIC(:,32)+ALGEBRAIC(:,39);
    ALGEBRAIC(:,45) = 1.00000./(1.00000+exp((STATES(:,1)+74.0000)./24.0000));
    ALGEBRAIC(:,46) =  CONSTANTS(:,25).*power((CONSTANTS(:,22)./5.40000), 1.0 ./ 2).*STATES(:,7).*ALGEBRAIC(:,45).*(STATES(:,1) - CONSTANTS(:,102));
    ALGEBRAIC(:,105) =  (1.00000./CONSTANTS(:,96)).*log((CONSTANTS(:,22)+ CONSTANTS(:,95).*CONSTANTS(:,20))./(CONSTANTS(:,35)+ CONSTANTS(:,95).*STATES(:,36)));
    ALGEBRAIC(:,106) =  CONSTANTS(:,10).*CONSTANTS(:,26).*power(STATES(:,8), 2.00000).*(STATES(:,1) - ALGEBRAIC(:,105));
    ALGEBRAIC(:,107) =  CONSTANTS(:,97).*CONSTANTS(:,27).*power(STATES(:,8), 2.00000).*(STATES(:,1) - ALGEBRAIC(:,105));
    ALGEBRAIC(:,108) = ALGEBRAIC(:,106)+ALGEBRAIC(:,107);
    ALGEBRAIC(:,47) = 1.00000./(1.00000+exp(7.48800 - STATES(:,1)./5.98000));
    ALGEBRAIC(:,48) =  CONSTANTS(:,28).*ALGEBRAIC(:,47).*(STATES(:,1) - CONSTANTS(:,102));
    ALGEBRAIC(:,49) =  CONSTANTS(:,29).*STATES(:,9).*STATES(:,10).*(STATES(:,1) - CONSTANTS(:,102));
    ALGEBRAIC(:,50) =  CONSTANTS(:,30).*STATES(:,11).*STATES(:,12).*(STATES(:,1) - CONSTANTS(:,102));
    ALGEBRAIC(:,51) = ALGEBRAIC(:,49)+ALGEBRAIC(:,50);
    ALGEBRAIC(:,52) = 4.09380./(1.00000+exp( 0.121650.*((STATES(:,1) - CONSTANTS(:,102)) - 49.9344)));
    ALGEBRAIC(:,53) = ( 15.7197.*exp( 0.0673900.*((STATES(:,1) - CONSTANTS(:,102)) - 3.25710))+exp( 0.0617500.*((STATES(:,1) - CONSTANTS(:,102)) - 594.310)))./(1.00000+exp(  - 0.162850.*((STATES(:,1) - CONSTANTS(:,102))+14.2067)));
    ALGEBRAIC(:,54) = ALGEBRAIC(:,52)./(ALGEBRAIC(:,52)+ALGEBRAIC(:,53));
    ALGEBRAIC(:,55) =  CONSTANTS(:,31).*power((CONSTANTS(:,22)./5.40000), 1.0 ./ 2).*ALGEBRAIC(:,54).*(STATES(:,1) - CONSTANTS(:,102));
    ALGEBRAIC(:,63) = ( CONSTANTS(:,39).*STATES(:,1).*CONSTANTS(:,3).*CONSTANTS(:,96).*( CONSTANTS(:,35).*exp( STATES(:,1).*CONSTANTS(:,96)) - CONSTANTS(:,22)))./(exp( STATES(:,1).*CONSTANTS(:,96)) - 1.00000);
    ALGEBRAIC(:,69) =  ALGEBRAIC(:,63).*STATES(:,15).*STATES(:,16).*STATES(:,17).*( CONSTANTS(:,11).*(1.00000 - STATES(:,18))+ CONSTANTS(:,98).*(1.00000 - STATES(:,19)));
    ALGEBRAIC(:,109) = ((ALGEBRAIC(:,51)+ALGEBRAIC(:,46)+ALGEBRAIC(:,108)+ALGEBRAIC(:,55)) -  2.00000.*ALGEBRAIC(:,44))+ALGEBRAIC(:,69)+ALGEBRAIC(:,48);
    ALGEBRAIC(:,104) = ALGEBRAIC(:,97)+ALGEBRAIC(:,103);
    ALGEBRAIC(:,56) =  (( CONSTANTS(:,10).*CONSTANTS(:,32))./(1.00000+CONSTANTS(:,33)./STATES(:,13))).*(STATES(:,1) - CONSTANTS(:,103));
    ALGEBRAIC(:,57) =  (( CONSTANTS(:,97).*CONSTANTS(:,32))./(1.00000+CONSTANTS(:,33)./STATES(:,14))).*(STATES(:,1) - CONSTANTS(:,103));
    ALGEBRAIC(:,58) = ALGEBRAIC(:,56)+ALGEBRAIC(:,57);
    ALGEBRAIC(:,59) =  CONSTANTS(:,34).*(STATES(:,1) - CONSTANTS(:,103));
    ALGEBRAIC(:,60) = ALGEBRAIC(:,58)+ALGEBRAIC(:,59);
    ALGEBRAIC(:,117) = ALGEBRAIC(:,112)+ALGEBRAIC(:,115);
    ALGEBRAIC(:,118) = ALGEBRAIC(:,104)+ALGEBRAIC(:,60)+ALGEBRAIC(:,117)+ALGEBRAIC(:,109);
    ALGEBRAIC(:,11) = piecewise({VOI>=CONSTANTS(:,5)&VOI<=CONSTANTS(:,6)&(VOI - CONSTANTS(:,5)) -  floor((VOI - CONSTANTS(:,5))./CONSTANTS(:,8)).*CONSTANTS(:,8)<=CONSTANTS(:,9), CONSTANTS(:,7) }, 0.00000);
    RATES(:,1) =  - (ALGEBRAIC(:,118) - ALGEBRAIC(:,11));
   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(:,1) = 1.00000./power(1.00000+exp( - (56.8600+STATES(:,1))./9.03000), 2.00000);
    ALGEBRAIC(:,13) =  0.129200.*exp( - power((STATES(:,1)+45.7900)./15.5400, 2.00000))+ 0.0648700.*exp( - power((STATES(:,1) - 4.82300)./51.1200, 2.00000));
    ALGEBRAIC(:,4) = 1.00000./(1.00000+exp( - (STATES(:,1)+10.0000)./5.00000));
    ALGEBRAIC(:,16) = 3300.00./( (1.00000+exp(( - 22.0000 - STATES(:,1))./9.00000)).*(1.00000+exp((STATES(:,1)+11.0000)./9.00000)))+230.000./(1.00000+exp((STATES(:,1)+40.0000)./20.0000));
    ALGEBRAIC(:,5) = 1.00000./(1.00000+exp( - (STATES(:,1)+3.80000)./14.2500));
    ALGEBRAIC(:,17) = 990.100./(1.00000+exp( - (STATES(:,1)+2.43600)./14.1200));
    ALGEBRAIC(:,6) = 1.00000./(1.00000+exp( - (STATES(:,1) - 19.0000)./13.0000));
    ALGEBRAIC(:,18) = 9.00000./(1.00000+exp((STATES(:,1)+3.00000)./15.0000))+0.500000;
    ALGEBRAIC(:,7) = 1.00000./(1.00000+exp((STATES(:,1)+19.5000)./5.00000));
    ALGEBRAIC(:,19) = 800.000./(1.00000+exp((STATES(:,1)+60.0000)./10.0000))+30.0000;
    ALGEBRAIC(:,20) =  8.50000.*exp( - power((STATES(:,1)+45.0000)./50.0000, 2.00000))+0.500000;
    ALGEBRAIC(:,21) =  85.0000.*exp( - power(STATES(:,1)+40.0000, 2.00000)./220.000)+7.00000;
    ALGEBRAIC(:,12) = CONSTANTS(:,51) - (CONSTANTS(:,51) - CONSTANTS(:,52))./(1.00000+power(CONSTANTS(:,53)./STATES(:,20), 2.50000));
    ALGEBRAIC(:,26) = CONSTANTS(:,54)./ALGEBRAIC(:,12);
    ALGEBRAIC(:,33) =  CONSTANTS(:,55).*ALGEBRAIC(:,12);
    ALGEBRAIC(:,2) = piecewise({STATES(:,1)>= - 40.0000, 0.00000 },  0.0570000.*exp( - (STATES(:,1)+80.0000)./6.80000));
    ALGEBRAIC(:,14) = piecewise({STATES(:,1)>= - 40.0000, 5.92310./(1.00000+exp( - (STATES(:,1)+10.6600)./11.1000)) },  2.70000.*exp( 0.0790000.*STATES(:,1))+ 310000..*exp( 0.348500.*STATES(:,1)));
    ALGEBRAIC(:,27) = 1.00000./(ALGEBRAIC(:,2)+ALGEBRAIC(:,14));
    ALGEBRAIC(:,34) = 1.00000./power(1.00000+exp((STATES(:,1)+71.5500)./7.43000), 2.00000);
    ALGEBRAIC(:,3) = piecewise({STATES(:,1)>= - 40.0000, 0.00000 }, ( (  - 25428.0.*exp( 0.244400.*STATES(:,1)) -  6.94800e-06.*exp(  - 0.0439100.*STATES(:,1))).*(STATES(:,1)+37.7800))./(1.00000+exp( 0.311000.*(STATES(:,1)+79.2300))));
    ALGEBRAIC(:,15) = piecewise({STATES(:,1)>= - 40.0000, ( 0.600000.*exp( 0.0570000.*STATES(:,1)))./(1.00000+exp(  - 0.100000.*(STATES(:,1)+32.0000))) }, ( 0.0242400.*exp(  - 0.0105200.*STATES(:,1)))./(1.00000+exp(  - 0.137800.*(STATES(:,1)+40.1400))));
    ALGEBRAIC(:,28) = 1.00000./(ALGEBRAIC(:,3)+ALGEBRAIC(:,15));
    ALGEBRAIC(:,35) = 1.00000./power(1.00000+exp((STATES(:,1)+71.5500)./7.43000), 2.00000);
    ALGEBRAIC(:,40) = ((1.00000 - STATES(:,21)) - STATES(:,22)) - STATES(:,23);
    ALGEBRAIC(:,8) = 1.00000./(1.00000+exp( - (STATES(:,1)+5.00000)./6.00000));
    ALGEBRAIC(:,22) = 1.40000./(1.00000+exp(( - 35.0000 - STATES(:,1))./13.0000))+0.250000;
    ALGEBRAIC(:,29) = 1.40000./(1.00000+exp((STATES(:,1)+5.00000)./5.00000));
    ALGEBRAIC(:,36) = 1.00000./(1.00000+exp((50.0000 - STATES(:,1))./20.0000));
    ALGEBRAIC(:,41) =  ALGEBRAIC(:,22).*ALGEBRAIC(:,29)+ALGEBRAIC(:,36);
    ALGEBRAIC(:,9) = 1.00000./(1.00000+exp((STATES(:,1)+20.0000)./7.00000));
    ALGEBRAIC(:,23) =  1102.50.*exp( - power((STATES(:,1)+27.0000)./15.0000, 2.00000));
    ALGEBRAIC(:,30) = 200.000./(1.00000+exp((13.0000 - STATES(:,1))./10.0000));
    ALGEBRAIC(:,37) = 180.000./(1.00000+exp((STATES(:,1)+30.0000)./10.0000))+20.0000;
    ALGEBRAIC(:,42) = ALGEBRAIC(:,23)+ALGEBRAIC(:,30)+ALGEBRAIC(:,37);
    ALGEBRAIC(:,10) = 0.670000./(1.00000+exp((STATES(:,1)+35.0000)./7.00000))+0.330000;
    ALGEBRAIC(:,24) =  300.000.*exp( - power(STATES(:,1)+25.0000, 2.00000)./170.000);
    ALGEBRAIC(:,31) = 31.0000./(1.00000+exp((25.0000 - STATES(:,1))./10.0000));
    ALGEBRAIC(:,38) = 16.0000./(1.00000+exp((STATES(:,1)+30.0000)./10.0000));
    ALGEBRAIC(:,43) = ALGEBRAIC(:,24)+ALGEBRAIC(:,31)+ALGEBRAIC(:,38);
    ALGEBRAIC(:,87) =  CONSTANTS(:,58).*STATES(:,22).*(STATES(:,20) - STATES(:,13));
    ALGEBRAIC(:,90) =  5.34800e-06.*(STATES(:,20) - STATES(:,13));
    ALGEBRAIC(:,89) = ( CONSTANTS(:,61).*(power(STATES(:,24)./CONSTANTS(:,59), CONSTANTS(:,62)) - power(STATES(:,20)./CONSTANTS(:,60), CONSTANTS(:,62))))./(1.00000+power(STATES(:,24)./CONSTANTS(:,59), CONSTANTS(:,62))+power(STATES(:,20)./CONSTANTS(:,60), CONSTANTS(:,62)));
    ALGEBRAIC(:,93) = RATES(:,25)+RATES(:,26)+RATES(:,27)+RATES(:,28)+RATES(:,29)+RATES(:,30)+RATES(:,31);
    ALGEBRAIC(:,94) =  (1.00000./CONSTANTS(:,96)).*log(CONSTANTS(:,20)./STATES(:,5));
    ALGEBRAIC(:,95) =  CONSTANTS(:,10).*CONSTANTS(:,18).*power(STATES(:,2), 3.00000).*STATES(:,3).*STATES(:,4).*(STATES(:,1) - ALGEBRAIC(:,94));
    ALGEBRAIC(:,96) =  CONSTANTS(:,10).*CONSTANTS(:,19).*(STATES(:,1) - ALGEBRAIC(:,94));
    ALGEBRAIC(:,25) = 1.00000./(1.00000+ 0.124500.*exp(  - 0.100000.*STATES(:,1).*CONSTANTS(:,96))+ 0.0365000.*CONSTANTS(:,100).*exp(  - STATES(:,1).*CONSTANTS(:,96)));
    ALGEBRAIC(:,32) = ( CONSTANTS(:,10).*CONSTANTS(:,21).*ALGEBRAIC(:,25).*CONSTANTS(:,22))./( (1.00000+power(CONSTANTS(:,24)./STATES(:,5), 4.00000)).*(CONSTANTS(:,22)+CONSTANTS(:,23)));
    ALGEBRAIC(:,64) = ( CONSTANTS(:,38).*STATES(:,1).*CONSTANTS(:,3).*CONSTANTS(:,96).*( STATES(:,5).*exp( STATES(:,1).*CONSTANTS(:,96)) - CONSTANTS(:,20)))./(exp( STATES(:,1).*CONSTANTS(:,96)) - 1.00000);
    ALGEBRAIC(:,70) =  CONSTANTS(:,11).*ALGEBRAIC(:,64).*STATES(:,15).*STATES(:,16).*STATES(:,17).*(1.00000 - STATES(:,18));
    ALGEBRAIC(:,72) = 1.00000./(1.00000+power(CONSTANTS(:,40)./STATES(:,13), 2.00000));
    ALGEBRAIC(:,76) =  exp( CONSTANTS(:,46).*STATES(:,1).*CONSTANTS(:,96)).*power(STATES(:,5), 3.00000).*CONSTANTS(:,36);
    ALGEBRAIC(:,78) =  exp( (CONSTANTS(:,46) - 1.00000).*STATES(:,1).*CONSTANTS(:,96)).*power(CONSTANTS(:,20), 3.00000).*STATES(:,13);
    ALGEBRAIC(:,80) =  CONSTANTS(:,41).*power(CONSTANTS(:,20), 3.00000).*(1.00000+power(STATES(:,5)./CONSTANTS(:,43), 3.00000))+ power(CONSTANTS(:,44), 3.00000).*STATES(:,13).*(1.00000+STATES(:,13)./CONSTANTS(:,41))+ CONSTANTS(:,42).*power(STATES(:,5), 3.00000)+ power(STATES(:,5), 3.00000).*CONSTANTS(:,36)+ power(CONSTANTS(:,20), 3.00000).*STATES(:,13);
    ALGEBRAIC(:,82) = ( CONSTANTS(:,10).*CONSTANTS(:,47).*ALGEBRAIC(:,72).*(ALGEBRAIC(:,76) - ALGEBRAIC(:,78)))./( ALGEBRAIC(:,80).*(1.00000+ CONSTANTS(:,45).*exp( (CONSTANTS(:,46) - 1.00000).*STATES(:,1).*CONSTANTS(:,96))));
    ALGEBRAIC(:,97) = ALGEBRAIC(:,95)+ALGEBRAIC(:,96)+ 3.00000.*ALGEBRAIC(:,82)+ 3.00000.*ALGEBRAIC(:,32)+ALGEBRAIC(:,70);
    ALGEBRAIC(:,98) =  (1.00000./CONSTANTS(:,96)).*log(CONSTANTS(:,20)./STATES(:,6));
    ALGEBRAIC(:,99) =  CONSTANTS(:,97).*CONSTANTS(:,18).*power(STATES(:,2), 3.00000).*STATES(:,3).*STATES(:,4).*(STATES(:,1) - ALGEBRAIC(:,98));
    ALGEBRAIC(:,101) =  CONSTANTS(:,97).*CONSTANTS(:,19).*(STATES(:,1) - ALGEBRAIC(:,98));
    ALGEBRAIC(:,39) = ( CONSTANTS(:,97).*CONSTANTS(:,21).*ALGEBRAIC(:,25).*CONSTANTS(:,22))./( (1.00000+power(CONSTANTS(:,24)./STATES(:,6), 4.00000)).*(CONSTANTS(:,22)+CONSTANTS(:,23)));
    ALGEBRAIC(:,65) = ( CONSTANTS(:,38).*STATES(:,1).*CONSTANTS(:,3).*CONSTANTS(:,96).*( STATES(:,6).*exp( STATES(:,1).*CONSTANTS(:,96)) - CONSTANTS(:,20)))./(exp( STATES(:,1).*CONSTANTS(:,96)) - 1.00000);
    ALGEBRAIC(:,71) =  CONSTANTS(:,98).*ALGEBRAIC(:,65).*STATES(:,15).*STATES(:,16).*STATES(:,17).*(1.00000 - STATES(:,19));
    ALGEBRAIC(:,74) = 1.00000./(1.00000+power(CONSTANTS(:,40)./STATES(:,14), 2.00000));
    ALGEBRAIC(:,77) =  exp( CONSTANTS(:,46).*STATES(:,1).*CONSTANTS(:,96)).*power(STATES(:,6), 3.00000).*CONSTANTS(:,36);
    ALGEBRAIC(:,79) =  exp( (CONSTANTS(:,46) - 1.00000).*STATES(:,1).*CONSTANTS(:,96)).*power(CONSTANTS(:,20), 3.00000).*STATES(:,14);
    ALGEBRAIC(:,81) =  CONSTANTS(:,41).*power(CONSTANTS(:,20), 3.00000).*(1.00000+power(STATES(:,6)./CONSTANTS(:,43), 3.00000))+ power(CONSTANTS(:,44), 3.00000).*STATES(:,14).*(1.00000+STATES(:,14)./CONSTANTS(:,41))+ CONSTANTS(:,42).*power(STATES(:,6), 3.00000)+ power(STATES(:,6), 3.00000).*CONSTANTS(:,36)+ power(CONSTANTS(:,20), 3.00000).*STATES(:,14);
    ALGEBRAIC(:,83) = ( CONSTANTS(:,97).*CONSTANTS(:,47).*ALGEBRAIC(:,74).*(ALGEBRAIC(:,77) - ALGEBRAIC(:,79)))./( ALGEBRAIC(:,81).*(1.00000+ CONSTANTS(:,45).*exp( (CONSTANTS(:,46) - 1.00000).*STATES(:,1).*CONSTANTS(:,96))));
    ALGEBRAIC(:,103) = ALGEBRAIC(:,99)+ALGEBRAIC(:,101)+ 3.00000.*ALGEBRAIC(:,83)+ 3.00000.*ALGEBRAIC(:,39)+ALGEBRAIC(:,71);
    ALGEBRAIC(:,61) = ( CONSTANTS(:,37).*STATES(:,1).*CONSTANTS(:,3).*CONSTANTS(:,96).*( STATES(:,13).*exp( 2.00000.*STATES(:,1).*CONSTANTS(:,96)) - CONSTANTS(:,36)))./(exp( 2.00000.*STATES(:,1).*CONSTANTS(:,96)) - 1.00000);
    ALGEBRAIC(:,66) =  CONSTANTS(:,11).*ALGEBRAIC(:,61).*STATES(:,15).*STATES(:,16).*STATES(:,17).*(1.00000 - STATES(:,18));
    ALGEBRAIC(:,84) = ( CONSTANTS(:,10).*CONSTANTS(:,49).*power(STATES(:,13), 1.60000))./(power(CONSTANTS(:,48), 1.60000)+power(STATES(:,13), 1.60000));
    ALGEBRAIC(:,110) =  (1.00000./( 2.00000.*CONSTANTS(:,96))).*log(CONSTANTS(:,36)./STATES(:,13));
    ALGEBRAIC(:,111) =  CONSTANTS(:,10).*CONSTANTS(:,50).*(STATES(:,1) - ALGEBRAIC(:,110));
    ALGEBRAIC(:,112) = (ALGEBRAIC(:,66)+ALGEBRAIC(:,111)+ALGEBRAIC(:,84)) -  2.00000.*ALGEBRAIC(:,82);
    ALGEBRAIC(:,91) = RATES(:,32)+RATES(:,34);
    ALGEBRAIC(:,62) = ( CONSTANTS(:,37).*STATES(:,1).*CONSTANTS(:,3).*CONSTANTS(:,96).*( STATES(:,14).*exp( 2.00000.*STATES(:,1).*CONSTANTS(:,96)) - CONSTANTS(:,36)))./(exp( 2.00000.*STATES(:,1).*CONSTANTS(:,96)) - 1.00000);
    ALGEBRAIC(:,67) =  CONSTANTS(:,98).*ALGEBRAIC(:,62).*STATES(:,15).*STATES(:,16).*STATES(:,17).*(1.00000 - STATES(:,19));
    ALGEBRAIC(:,86) = ( CONSTANTS(:,97).*CONSTANTS(:,49).*power(STATES(:,14), 1.60000))./(power(CONSTANTS(:,48), 1.60000)+power(STATES(:,14), 1.60000));
    ALGEBRAIC(:,113) =  (1.00000./( 2.00000.*CONSTANTS(:,96))).*log(CONSTANTS(:,36)./STATES(:,14));
    ALGEBRAIC(:,114) =  CONSTANTS(:,97).*CONSTANTS(:,50).*(STATES(:,1) - ALGEBRAIC(:,113));
    ALGEBRAIC(:,115) = (ALGEBRAIC(:,67)+ALGEBRAIC(:,114)+ALGEBRAIC(:,86)) -  2.00000.*ALGEBRAIC(:,83);
    ALGEBRAIC(:,92) = RATES(:,33)+RATES(:,35);
    ALGEBRAIC(:,44) = ALGEBRAIC(:,32)+ALGEBRAIC(:,39);
    ALGEBRAIC(:,45) = 1.00000./(1.00000+exp((STATES(:,1)+74.0000)./24.0000));
    ALGEBRAIC(:,46) =  CONSTANTS(:,25).*power((CONSTANTS(:,22)./5.40000), 1.0 ./ 2).*STATES(:,7).*ALGEBRAIC(:,45).*(STATES(:,1) - CONSTANTS(:,102));
    ALGEBRAIC(:,105) =  (1.00000./CONSTANTS(:,96)).*log((CONSTANTS(:,22)+ CONSTANTS(:,95).*CONSTANTS(:,20))./(CONSTANTS(:,35)+ CONSTANTS(:,95).*STATES(:,36)));
    ALGEBRAIC(:,106) =  CONSTANTS(:,10).*CONSTANTS(:,26).*power(STATES(:,8), 2.00000).*(STATES(:,1) - ALGEBRAIC(:,105));
    ALGEBRAIC(:,107) =  CONSTANTS(:,97).*CONSTANTS(:,27).*power(STATES(:,8), 2.00000).*(STATES(:,1) - ALGEBRAIC(:,105));
    ALGEBRAIC(:,108) = ALGEBRAIC(:,106)+ALGEBRAIC(:,107);
    ALGEBRAIC(:,47) = 1.00000./(1.00000+exp(7.48800 - STATES(:,1)./5.98000));
    ALGEBRAIC(:,48) =  CONSTANTS(:,28).*ALGEBRAIC(:,47).*(STATES(:,1) - CONSTANTS(:,102));
    ALGEBRAIC(:,49) =  CONSTANTS(:,29).*STATES(:,9).*STATES(:,10).*(STATES(:,1) - CONSTANTS(:,102));
    ALGEBRAIC(:,50) =  CONSTANTS(:,30).*STATES(:,11).*STATES(:,12).*(STATES(:,1) - CONSTANTS(:,102));
    ALGEBRAIC(:,51) = ALGEBRAIC(:,49)+ALGEBRAIC(:,50);
    ALGEBRAIC(:,52) = 4.09380./(1.00000+exp( 0.121650.*((STATES(:,1) - CONSTANTS(:,102)) - 49.9344)));
    ALGEBRAIC(:,53) = ( 15.7197.*exp( 0.0673900.*((STATES(:,1) - CONSTANTS(:,102)) - 3.25710))+exp( 0.0617500.*((STATES(:,1) - CONSTANTS(:,102)) - 594.310)))./(1.00000+exp(  - 0.162850.*((STATES(:,1) - CONSTANTS(:,102))+14.2067)));
    ALGEBRAIC(:,54) = ALGEBRAIC(:,52)./(ALGEBRAIC(:,52)+ALGEBRAIC(:,53));
    ALGEBRAIC(:,55) =  CONSTANTS(:,31).*power((CONSTANTS(:,22)./5.40000), 1.0 ./ 2).*ALGEBRAIC(:,54).*(STATES(:,1) - CONSTANTS(:,102));
    ALGEBRAIC(:,63) = ( CONSTANTS(:,39).*STATES(:,1).*CONSTANTS(:,3).*CONSTANTS(:,96).*( CONSTANTS(:,35).*exp( STATES(:,1).*CONSTANTS(:,96)) - CONSTANTS(:,22)))./(exp( STATES(:,1).*CONSTANTS(:,96)) - 1.00000);
    ALGEBRAIC(:,69) =  ALGEBRAIC(:,63).*STATES(:,15).*STATES(:,16).*STATES(:,17).*( CONSTANTS(:,11).*(1.00000 - STATES(:,18))+ CONSTANTS(:,98).*(1.00000 - STATES(:,19)));
    ALGEBRAIC(:,109) = ((ALGEBRAIC(:,51)+ALGEBRAIC(:,46)+ALGEBRAIC(:,108)+ALGEBRAIC(:,55)) -  2.00000.*ALGEBRAIC(:,44))+ALGEBRAIC(:,69)+ALGEBRAIC(:,48);
    ALGEBRAIC(:,104) = ALGEBRAIC(:,97)+ALGEBRAIC(:,103);
    ALGEBRAIC(:,56) =  (( CONSTANTS(:,10).*CONSTANTS(:,32))./(1.00000+CONSTANTS(:,33)./STATES(:,13))).*(STATES(:,1) - CONSTANTS(:,103));
    ALGEBRAIC(:,57) =  (( CONSTANTS(:,97).*CONSTANTS(:,32))./(1.00000+CONSTANTS(:,33)./STATES(:,14))).*(STATES(:,1) - CONSTANTS(:,103));
    ALGEBRAIC(:,58) = ALGEBRAIC(:,56)+ALGEBRAIC(:,57);
    ALGEBRAIC(:,59) =  CONSTANTS(:,34).*(STATES(:,1) - CONSTANTS(:,103));
    ALGEBRAIC(:,60) = ALGEBRAIC(:,58)+ALGEBRAIC(:,59);
    ALGEBRAIC(:,117) = ALGEBRAIC(:,112)+ALGEBRAIC(:,115);
    ALGEBRAIC(:,118) = ALGEBRAIC(:,104)+ALGEBRAIC(:,60)+ALGEBRAIC(:,117)+ALGEBRAIC(:,109);
    ALGEBRAIC(:,11) = piecewise({VOI>=CONSTANTS(:,5)&VOI<=CONSTANTS(:,6)&(VOI - CONSTANTS(:,5)) -  floor((VOI - CONSTANTS(:,5))./CONSTANTS(:,8)).*CONSTANTS(:,8)<=CONSTANTS(:,9), CONSTANTS(:,7) }, 0.00000);
    ALGEBRAIC(:,68) = ALGEBRAIC(:,66)+ALGEBRAIC(:,67);
    ALGEBRAIC(:,73) = ALGEBRAIC(:,70)+ALGEBRAIC(:,71);
    ALGEBRAIC(:,75) = ALGEBRAIC(:,68)+ALGEBRAIC(:,69)+ALGEBRAIC(:,73);
    ALGEBRAIC(:,85) = ALGEBRAIC(:,82)+ALGEBRAIC(:,83);
    ALGEBRAIC(:,88) = ALGEBRAIC(:,84)+ALGEBRAIC(:,86);
    ALGEBRAIC(:,100) = ALGEBRAIC(:,95)+ALGEBRAIC(:,99);
    ALGEBRAIC(:,102) = ALGEBRAIC(:,96)+ALGEBRAIC(:,101);
    ALGEBRAIC(:,116) = ALGEBRAIC(:,111)+ALGEBRAIC(:,114);
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