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

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

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

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

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

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

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

function [LEGEND_STATES, LEGEND_ALGEBRAIC, LEGEND_VOI, LEGEND_CONSTANTS] = createLegends()
    LEGEND_STATES = ''; LEGEND_ALGEBRAIC = ''; LEGEND_VOI = ''; LEGEND_CONSTANTS = '';
    LEGEND_VOI = strpad('time in component environment (ms)');
    LEGEND_CONSTANTS(:,1) = strpad('lambda in component environment (dimensionless)');
    LEGEND_CONSTANTS(:,2) = strpad('dlambdadt in component environment (per_ms)');
    LEGEND_STATES(:,1) = strpad('V in component membrane (mV)');
    LEGEND_CONSTANTS(:,3) = strpad('R in component membrane (gas_constant_units)');
    LEGEND_CONSTANTS(:,4) = strpad('T in component membrane (kelvin)');
    LEGEND_CONSTANTS(:,5) = strpad('F in component membrane (faradays_constant_units)');
    LEGEND_ALGEBRAIC(:,18) = strpad('i_Na in component fast_sodium_current (uA_per_mm2)');
    LEGEND_ALGEBRAIC(:,23) = strpad('i_Ca_L_Ca in component L_type_Ca_channel (uA_per_mm2)');
    LEGEND_ALGEBRAIC(:,25) = strpad('i_Ca_L_K in component L_type_Ca_channel (uA_per_mm2)');
    LEGEND_ALGEBRAIC(:,29) = strpad('i_K in component time_dependent_potassium_current (uA_per_mm2)');
    LEGEND_ALGEBRAIC(:,35) = strpad('i_K1 in component time_independent_potassium_current (uA_per_mm2)');
    LEGEND_ALGEBRAIC(:,39) = strpad('i_NaCa in component Na_Ca_exchanger (uA_per_mm2)');
    LEGEND_ALGEBRAIC(:,38) = strpad('i_Kp in component plateau_potassium_current (uA_per_mm2)');
    LEGEND_ALGEBRAIC(:,40) = strpad('i_p_Ca in component sarcolemmal_calcium_pump (uA_per_mm2)');
    LEGEND_ALGEBRAIC(:,42) = strpad('i_Na_b in component sodium_background_current (uA_per_mm2)');
    LEGEND_ALGEBRAIC(:,44) = strpad('i_Ca_b in component calcium_background_current (uA_per_mm2)');
    LEGEND_ALGEBRAIC(:,47) = strpad('i_NaK in component sodium_potassium_pump (uA_per_mm2)');
    LEGEND_ALGEBRAIC(:,64) = strpad('i_ns_Ca in component non_specific_calcium_activated_current (uA_per_mm2)');
    LEGEND_CONSTANTS(:,6) = strpad('Cm in component membrane (uF_per_mm2)');
    LEGEND_ALGEBRAIC(:,7) = strpad('I_stim in component membrane (uA_per_mm2)');
    LEGEND_CONSTANTS(:,7) = strpad('stim_start in component membrane (ms)');
    LEGEND_CONSTANTS(:,8) = strpad('stim_end in component membrane (ms)');
    LEGEND_CONSTANTS(:,9) = strpad('stim_period in component membrane (ms)');
    LEGEND_CONSTANTS(:,10) = strpad('stim_duration in component membrane (ms)');
    LEGEND_CONSTANTS(:,11) = strpad('stim_amplitude in component membrane (uA_per_mm2)');
    LEGEND_ALGEBRAIC(:,15) = strpad('E_Na in component fast_sodium_current (mV)');
    LEGEND_CONSTANTS(:,12) = strpad('g_Na in component fast_sodium_current (mS_per_mm2)');
    LEGEND_STATES(:,2) = strpad('Nai in component ionic_concentrations (mM)');
    LEGEND_CONSTANTS(:,13) = strpad('Nao in component ionic_concentrations (mM)');
    LEGEND_STATES(:,3) = strpad('m in component fast_sodium_current_m_gate (dimensionless)');
    LEGEND_STATES(:,4) = strpad('h in component fast_sodium_current_h_gate (dimensionless)');
    LEGEND_STATES(:,5) = strpad('j in component fast_sodium_current_j_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,1) = strpad('alpha_m in component fast_sodium_current_m_gate (per_ms)');
    LEGEND_ALGEBRAIC(:,9) = strpad('beta_m in component fast_sodium_current_m_gate (per_ms)');
    LEGEND_ALGEBRAIC(:,2) = strpad('alpha_h in component fast_sodium_current_h_gate (per_ms)');
    LEGEND_ALGEBRAIC(:,10) = strpad('beta_h in component fast_sodium_current_h_gate (per_ms)');
    LEGEND_ALGEBRAIC(:,3) = strpad('alpha_j in component fast_sodium_current_j_gate (per_ms)');
    LEGEND_ALGEBRAIC(:,11) = strpad('beta_j in component fast_sodium_current_j_gate (per_ms)');
    LEGEND_CONSTANTS(:,14) = strpad('P_Ca in component L_type_Ca_channel (mm_per_ms)');
    LEGEND_CONSTANTS(:,15) = strpad('P_K in component L_type_Ca_channel (mm_per_ms)');
    LEGEND_ALGEBRAIC(:,24) = strpad('p_k in component L_type_Ca_channel (mm_per_ms)');
    LEGEND_CONSTANTS(:,16) = strpad('i_Ca_L_Ca_half in component L_type_Ca_channel (uA_per_mm2)');
    LEGEND_ALGEBRAIC(:,21) = strpad('i_Ca_L_Ca_max in component L_type_Ca_channel (uA_per_mm2)');
    LEGEND_STATES(:,6) = strpad('O in component L_type_Ca_channel (dimensionless)');
    LEGEND_STATES(:,7) = strpad('O_Ca in component L_type_Ca_channel (dimensionless)');
    LEGEND_ALGEBRAIC(:,4) = strpad('alpha in component L_type_Ca_channel (per_ms)');
    LEGEND_ALGEBRAIC(:,12) = strpad('beta in component L_type_Ca_channel (per_ms)');
    LEGEND_ALGEBRAIC(:,22) = strpad('gamma in component L_type_Ca_channel (per_ms)');
    LEGEND_ALGEBRAIC(:,17) = strpad('alpha_a in component L_type_Ca_channel (per_ms)');
    LEGEND_ALGEBRAIC(:,20) = strpad('beta_b in component L_type_Ca_channel (per_ms)');
    LEGEND_CONSTANTS(:,17) = strpad('a in component L_type_Ca_channel (dimensionless)');
    LEGEND_CONSTANTS(:,18) = strpad('b in component L_type_Ca_channel (dimensionless)');
    LEGEND_CONSTANTS(:,19) = strpad('g in component L_type_Ca_channel (per_ms)');
    LEGEND_CONSTANTS(:,20) = strpad('f in component L_type_Ca_channel (per_ms)');
    LEGEND_CONSTANTS(:,21) = strpad('g_ in component L_type_Ca_channel (per_ms)');
    LEGEND_CONSTANTS(:,22) = strpad('f_ in component L_type_Ca_channel (per_ms)');
    LEGEND_CONSTANTS(:,23) = strpad('omega in component L_type_Ca_channel (per_ms)');
    LEGEND_STATES(:,8) = strpad('C0 in component L_type_Ca_channel (dimensionless)');
    LEGEND_STATES(:,9) = strpad('C1 in component L_type_Ca_channel (dimensionless)');
    LEGEND_STATES(:,10) = strpad('C2 in component L_type_Ca_channel (dimensionless)');
    LEGEND_STATES(:,11) = strpad('C3 in component L_type_Ca_channel (dimensionless)');
    LEGEND_STATES(:,12) = strpad('C4 in component L_type_Ca_channel (dimensionless)');
    LEGEND_STATES(:,13) = strpad('C_Ca0 in component L_type_Ca_channel (dimensionless)');
    LEGEND_STATES(:,14) = strpad('C_Ca1 in component L_type_Ca_channel (dimensionless)');
    LEGEND_STATES(:,15) = strpad('C_Ca2 in component L_type_Ca_channel (dimensionless)');
    LEGEND_STATES(:,16) = strpad('C_Ca3 in component L_type_Ca_channel (dimensionless)');
    LEGEND_STATES(:,17) = strpad('C_Ca4 in component L_type_Ca_channel (dimensionless)');
    LEGEND_STATES(:,18) = strpad('Ca_SS in component calcium_subsystem (mM)');
    LEGEND_CONSTANTS(:,24) = strpad('Cao in component ionic_concentrations (mM)');
    LEGEND_STATES(:,19) = strpad('Ko in component ionic_concentrations (mM)');
    LEGEND_STATES(:,20) = strpad('Ki in component ionic_concentrations (mM)');
    LEGEND_STATES(:,21) = strpad('y in component L_type_Ca_channel_y_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,5) = strpad('y_infinity in component L_type_Ca_channel_y_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,13) = strpad('tau_y in component L_type_Ca_channel_y_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,26) = strpad('g_K in component time_dependent_potassium_current (mS_per_mm2)');
    LEGEND_CONSTANTS(:,25) = strpad('g_K_max in component time_dependent_potassium_current (mS_per_mm2)');
    LEGEND_ALGEBRAIC(:,27) = strpad('E_K in component time_dependent_potassium_current (mV)');
    LEGEND_CONSTANTS(:,26) = strpad('P_NaK in component time_dependent_potassium_current (dimensionless)');
    LEGEND_STATES(:,22) = strpad('X in component time_dependent_potassium_current_X_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,28) = strpad('Xi in component time_dependent_potassium_current_Xi_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,6) = strpad('alpha_X in component time_dependent_potassium_current_X_gate (per_ms)');
    LEGEND_ALGEBRAIC(:,14) = strpad('beta_X in component time_dependent_potassium_current_X_gate (per_ms)');
    LEGEND_ALGEBRAIC(:,31) = strpad('E_K1 in component time_independent_potassium_current (mV)');
    LEGEND_ALGEBRAIC(:,30) = strpad('g_K1 in component time_independent_potassium_current (mS_per_mm2)');
    LEGEND_CONSTANTS(:,27) = strpad('g_K1_max in component time_independent_potassium_current (mS_per_mm2)');
    LEGEND_ALGEBRAIC(:,34) = strpad('K1_infinity in component time_independent_potassium_current_K1_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,32) = strpad('alpha_K1 in component time_independent_potassium_current_K1_gate (per_ms)');
    LEGEND_ALGEBRAIC(:,33) = strpad('beta_K1 in component time_independent_potassium_current_K1_gate (per_ms)');
    LEGEND_ALGEBRAIC(:,36) = strpad('E_Kp in component plateau_potassium_current (mV)');
    LEGEND_CONSTANTS(:,28) = strpad('g_Kp in component plateau_potassium_current (mS_per_mm2)');
    LEGEND_ALGEBRAIC(:,37) = strpad('Kp in component plateau_potassium_current (dimensionless)');
    LEGEND_CONSTANTS(:,29) = strpad('k_NaCa in component Na_Ca_exchanger (uA_per_mm2)');
    LEGEND_CONSTANTS(:,30) = strpad('K_mNa in component Na_Ca_exchanger (mM)');
    LEGEND_CONSTANTS(:,31) = strpad('K_mCa in component Na_Ca_exchanger (mM)');
    LEGEND_CONSTANTS(:,32) = strpad('k_sat in component Na_Ca_exchanger (dimensionless)');
    LEGEND_CONSTANTS(:,33) = strpad('eta in component Na_Ca_exchanger (dimensionless)');
    LEGEND_STATES(:,23) = strpad('Cai in component calcium_subsystem (mM)');
    LEGEND_CONSTANTS(:,34) = strpad('K_mpCa in component sarcolemmal_calcium_pump (mM)');
    LEGEND_CONSTANTS(:,35) = strpad('I_pCa in component sarcolemmal_calcium_pump (uA_per_mm2)');
    LEGEND_CONSTANTS(:,36) = strpad('g_Nab in component sodium_background_current (mS_per_mm2)');
    LEGEND_ALGEBRAIC(:,41) = strpad('E_NaN in component sodium_background_current (mV)');
    LEGEND_CONSTANTS(:,37) = strpad('g_Cab in component calcium_background_current (mS_per_mm2)');
    LEGEND_ALGEBRAIC(:,43) = strpad('E_CaN in component calcium_background_current (mV)');
    LEGEND_CONSTANTS(:,38) = strpad('I_NaK in component sodium_potassium_pump (uA_per_mm2)');
    LEGEND_ALGEBRAIC(:,45) = strpad('f_NaK in component sodium_potassium_pump (dimensionless)');
    LEGEND_CONSTANTS(:,39) = strpad('K_mNai in component sodium_potassium_pump (mM)');
    LEGEND_CONSTANTS(:,40) = strpad('K_mKo in component sodium_potassium_pump (mM)');
    LEGEND_CONSTANTS(:,91) = strpad('sigma in component sodium_potassium_pump (dimensionless)');
    LEGEND_ALGEBRAIC(:,56) = strpad('i_ns_Na in component non_specific_calcium_activated_current (uA_per_mm2)');
    LEGEND_ALGEBRAIC(:,62) = strpad('i_ns_K in component non_specific_calcium_activated_current (uA_per_mm2)');
    LEGEND_ALGEBRAIC(:,53) = strpad('I_ns_Na in component non_specific_calcium_activated_current (uA_per_mm2)');
    LEGEND_ALGEBRAIC(:,60) = strpad('I_ns_K in component non_specific_calcium_activated_current (uA_per_mm2)');
    LEGEND_CONSTANTS(:,41) = strpad('K_m_ns_Ca in component non_specific_calcium_activated_current (mM)');
    LEGEND_CONSTANTS(:,42) = strpad('P_ns_Ca in component non_specific_calcium_activated_current (mm_per_ms)');
    LEGEND_ALGEBRAIC(:,49) = strpad('EnsCa in component non_specific_calcium_activated_current (mV)');
    LEGEND_ALGEBRAIC(:,51) = strpad('VnsCa in component non_specific_calcium_activated_current (mV)');
    LEGEND_CONSTANTS(:,43) = strpad('Am in component calcium_subsystem (per_mm)');
    LEGEND_CONSTANTS(:,44) = strpad('V_myo in component calcium_subsystem (dimensionless)');
    LEGEND_ALGEBRAIC(:,46) = strpad('RyR_open in component calcium_subsystem (dimensionless)');
    LEGEND_STATES(:,24) = strpad('P_O1 in component calcium_subsystem (dimensionless)');
    LEGEND_STATES(:,25) = strpad('P_O2 in component calcium_subsystem (dimensionless)');
    LEGEND_STATES(:,26) = strpad('P_C1 in component calcium_subsystem (dimensionless)');
    LEGEND_STATES(:,27) = strpad('P_C2 in component calcium_subsystem (dimensionless)');
    LEGEND_CONSTANTS(:,45) = strpad('v1 in component calcium_subsystem (per_ms)');
    LEGEND_CONSTANTS(:,46) = strpad('v2 in component calcium_subsystem (per_ms)');
    LEGEND_CONSTANTS(:,47) = strpad('v3 in component calcium_subsystem (mM_per_ms)');
    LEGEND_CONSTANTS(:,48) = strpad('nCa in component calcium_subsystem (dimensionless)');
    LEGEND_CONSTANTS(:,49) = strpad('mCa in component calcium_subsystem (dimensionless)');
    LEGEND_CONSTANTS(:,50) = strpad('k_a_plus in component calcium_subsystem (per_mM4_per_ms)');
    LEGEND_CONSTANTS(:,51) = strpad('k_a_minus in component calcium_subsystem (per_ms)');
    LEGEND_CONSTANTS(:,52) = strpad('k_b_plus in component calcium_subsystem (per_mM3_per_ms)');
    LEGEND_CONSTANTS(:,53) = strpad('k_b_minus in component calcium_subsystem (per_ms)');
    LEGEND_CONSTANTS(:,54) = strpad('k_c_plus in component calcium_subsystem (per_ms)');
    LEGEND_CONSTANTS(:,55) = strpad('k_c_minus in component calcium_subsystem (per_ms)');
    LEGEND_CONSTANTS(:,56) = strpad('k_htrpn_plus in component calcium_subsystem (per_mM_per_ms)');
    LEGEND_CONSTANTS(:,57) = strpad('k_htrpn_minus in component calcium_subsystem (per_ms)');
    LEGEND_CONSTANTS(:,58) = strpad('k_ltrpn_plus in component calcium_subsystem (per_mM_per_ms)');
    LEGEND_CONSTANTS(:,59) = strpad('k_ltrpn_minus in component calcium_subsystem (per_ms)');
    LEGEND_CONSTANTS(:,60) = strpad('tau_tr in component calcium_subsystem (ms)');
    LEGEND_STATES(:,28) = strpad('Ca_JSR in component calcium_subsystem (mM)');
    LEGEND_STATES(:,29) = strpad('Ca_NSR in component calcium_subsystem (mM)');
    LEGEND_CONSTANTS(:,97) = strpad('V_JSR in component calcium_subsystem (dimensionless)');
    LEGEND_CONSTANTS(:,95) = strpad('V_NSR in component calcium_subsystem (dimensionless)');
    LEGEND_CONSTANTS(:,92) = strpad('V_SS in component calcium_subsystem (dimensionless)');
    LEGEND_CONSTANTS(:,61) = strpad('K_mup in component calcium_subsystem (mM)');
    LEGEND_CONSTANTS(:,62) = strpad('K_mCMDN in component calcium_subsystem (mM)');
    LEGEND_CONSTANTS(:,63) = strpad('K_mCSQN in component calcium_subsystem (mM)');
    LEGEND_CONSTANTS(:,64) = strpad('tau_xfer in component calcium_subsystem (ms)');
    LEGEND_CONSTANTS(:,65) = strpad('HTRPN_tot in component calcium_subsystem (mM)');
    LEGEND_CONSTANTS(:,66) = strpad('LTRPN_tot in component calcium_subsystem (mM)');
    LEGEND_STATES(:,30) = strpad('HTRPNCa in component calcium_subsystem (mM)');
    LEGEND_STATES(:,31) = strpad('LTRPNCa in component calcium_subsystem (mM)');
    LEGEND_CONSTANTS(:,67) = strpad('CSQN_tot in component calcium_subsystem (mM)');
    LEGEND_CONSTANTS(:,68) = strpad('CMDN_tot in component calcium_subsystem (mM)');
    LEGEND_ALGEBRAIC(:,65) = strpad('Bi in component calcium_subsystem (dimensionless)');
    LEGEND_ALGEBRAIC(:,57) = strpad('B_SS in component calcium_subsystem (dimensionless)');
    LEGEND_ALGEBRAIC(:,58) = strpad('B_JSR in component calcium_subsystem (dimensionless)');
    LEGEND_ALGEBRAIC(:,48) = strpad('J_rel in component calcium_subsystem (mM_per_ms)');
    LEGEND_ALGEBRAIC(:,50) = strpad('J_leak in component calcium_subsystem (mM_per_ms)');
    LEGEND_ALGEBRAIC(:,52) = strpad('J_up in component calcium_subsystem (mM_per_ms)');
    LEGEND_ALGEBRAIC(:,54) = strpad('J_tr in component calcium_subsystem (mM_per_ms)');
    LEGEND_ALGEBRAIC(:,55) = strpad('J_xfer in component calcium_subsystem (mM_per_ms)');
    LEGEND_ALGEBRAIC(:,63) = strpad('J_trpn in component calcium_subsystem (mM_per_ms)');
    LEGEND_ALGEBRAIC(:,59) = strpad('J_htrpn in component calcium_subsystem (mM_per_ms)');
    LEGEND_ALGEBRAIC(:,61) = strpad('J_ltrpn in component calcium_subsystem (mM_per_ms)');
    LEGEND_CONSTANTS(:,69) = strpad('Tref in component Myofilaments (N_per_mm2)');
    LEGEND_CONSTANTS(:,70) = strpad('beta0 in component Myofilaments (dimensionless)');
    LEGEND_CONSTANTS(:,71) = strpad('a in component Myofilaments (dimensionless)');
    LEGEND_STATES(:,32) = strpad('Q1 in component Myofilaments (dimensionless)');
    LEGEND_STATES(:,33) = strpad('Q2 in component Myofilaments (dimensionless)');
    LEGEND_STATES(:,34) = strpad('Q3 in component Myofilaments (dimensionless)');
    LEGEND_CONSTANTS(:,72) = strpad('A1 in component Myofilaments (dimensionless)');
    LEGEND_CONSTANTS(:,73) = strpad('A2 in component Myofilaments (dimensionless)');
    LEGEND_CONSTANTS(:,74) = strpad('A3 in component Myofilaments (dimensionless)');
    LEGEND_CONSTANTS(:,75) = strpad('alpha1 in component Myofilaments (dimensionless)');
    LEGEND_CONSTANTS(:,76) = strpad('alpha2 in component Myofilaments (dimensionless)');
    LEGEND_CONSTANTS(:,77) = strpad('alpha3 in component Myofilaments (dimensionless)');
    LEGEND_CONSTANTS(:,78) = strpad('Ca50ref in component Myofilaments (mM)');
    LEGEND_CONSTANTS(:,79) = strpad('zp in component Myofilaments (dimensionless)');
    LEGEND_CONSTANTS(:,80) = strpad('beta1 in component Myofilaments (dimensionless)');
    LEGEND_CONSTANTS(:,81) = strpad('alpha0 in component Myofilaments (per_ms)');
    LEGEND_CONSTANTS(:,82) = strpad('alphar1 in component Myofilaments (per_ms)');
    LEGEND_CONSTANTS(:,83) = strpad('alphar2 in component Myofilaments (per_ms)');
    LEGEND_CONSTANTS(:,84) = strpad('nRel in component Myofilaments (dimensionless)');
    LEGEND_CONSTANTS(:,85) = strpad('Kz in component Myofilaments (dimensionless)');
    LEGEND_CONSTANTS(:,86) = strpad('nHill in component Myofilaments (dimensionless)');
    LEGEND_CONSTANTS(:,87) = strpad('kon in component Myofilaments (per_mM_per_ms)');
    LEGEND_CONSTANTS(:,88) = strpad('koff in component Myofilaments (per_ms)');
    LEGEND_CONSTANTS(:,89) = strpad('gamma_trpn in component Myofilaments (dimensionless)');
    LEGEND_CONSTANTS(:,90) = strpad('TRPN_tot in component Myofilaments (mM)');
    LEGEND_ALGEBRAIC(:,8) = strpad('T0 in component Myofilaments (N_per_mm2)');
    LEGEND_CONSTANTS(:,93) = strpad('T0max in component Myofilaments (N_per_mm2)');
    LEGEND_STATES(:,35) = strpad('z in component Myofilaments (dimensionless)');
    LEGEND_CONSTANTS(:,100) = strpad('z_max in component Myofilaments (dimensionless)');
    LEGEND_ALGEBRAIC(:,16) = strpad('Q in component Myofilaments (dimensionless)');
    LEGEND_STATES(:,36) = strpad('Cab in component Myofilaments (mM)');
    LEGEND_CONSTANTS(:,98) = strpad('Ca50 in component Myofilaments (mM)');
    LEGEND_CONSTANTS(:,99) = strpad('CaTRPN50 in component Myofilaments (mM)');
    LEGEND_CONSTANTS(:,94) = strpad('K_2 in component Myofilaments (dimensionless)');
    LEGEND_CONSTANTS(:,96) = strpad('K_1 in component Myofilaments (dimensionless)');
    LEGEND_ALGEBRAIC(:,19) = strpad('Tension in component Myofilaments (N_per_mm2)');
    LEGEND_RATES(:,1) = strpad('d/dt V in component membrane (mV)');
    LEGEND_RATES(:,3) = strpad('d/dt m in component fast_sodium_current_m_gate (dimensionless)');
    LEGEND_RATES(:,4) = strpad('d/dt h in component fast_sodium_current_h_gate (dimensionless)');
    LEGEND_RATES(:,5) = strpad('d/dt j in component fast_sodium_current_j_gate (dimensionless)');
    LEGEND_RATES(:,8) = strpad('d/dt C0 in component L_type_Ca_channel (dimensionless)');
    LEGEND_RATES(:,9) = strpad('d/dt C1 in component L_type_Ca_channel (dimensionless)');
    LEGEND_RATES(:,10) = strpad('d/dt C2 in component L_type_Ca_channel (dimensionless)');
    LEGEND_RATES(:,11) = strpad('d/dt C3 in component L_type_Ca_channel (dimensionless)');
    LEGEND_RATES(:,12) = strpad('d/dt C4 in component L_type_Ca_channel (dimensionless)');
    LEGEND_RATES(:,6) = strpad('d/dt O in component L_type_Ca_channel (dimensionless)');
    LEGEND_RATES(:,13) = strpad('d/dt C_Ca0 in component L_type_Ca_channel (dimensionless)');
    LEGEND_RATES(:,14) = strpad('d/dt C_Ca1 in component L_type_Ca_channel (dimensionless)');
    LEGEND_RATES(:,15) = strpad('d/dt C_Ca2 in component L_type_Ca_channel (dimensionless)');
    LEGEND_RATES(:,16) = strpad('d/dt C_Ca3 in component L_type_Ca_channel (dimensionless)');
    LEGEND_RATES(:,17) = strpad('d/dt C_Ca4 in component L_type_Ca_channel (dimensionless)');
    LEGEND_RATES(:,7) = strpad('d/dt O_Ca in component L_type_Ca_channel (dimensionless)');
    LEGEND_RATES(:,21) = strpad('d/dt y in component L_type_Ca_channel_y_gate (dimensionless)');
    LEGEND_RATES(:,22) = strpad('d/dt X in component time_dependent_potassium_current_X_gate (dimensionless)');
    LEGEND_RATES(:,26) = strpad('d/dt P_C1 in component calcium_subsystem (dimensionless)');
    LEGEND_RATES(:,24) = strpad('d/dt P_O1 in component calcium_subsystem (dimensionless)');
    LEGEND_RATES(:,25) = strpad('d/dt P_O2 in component calcium_subsystem (dimensionless)');
    LEGEND_RATES(:,27) = strpad('d/dt P_C2 in component calcium_subsystem (dimensionless)');
    LEGEND_RATES(:,30) = strpad('d/dt HTRPNCa in component calcium_subsystem (mM)');
    LEGEND_RATES(:,31) = strpad('d/dt LTRPNCa in component calcium_subsystem (mM)');
    LEGEND_RATES(:,23) = strpad('d/dt Cai in component calcium_subsystem (mM)');
    LEGEND_RATES(:,18) = strpad('d/dt Ca_SS in component calcium_subsystem (mM)');
    LEGEND_RATES(:,28) = strpad('d/dt Ca_JSR in component calcium_subsystem (mM)');
    LEGEND_RATES(:,29) = strpad('d/dt Ca_NSR in component calcium_subsystem (mM)');
    LEGEND_RATES(:,2) = strpad('d/dt Nai in component ionic_concentrations (mM)');
    LEGEND_RATES(:,20) = strpad('d/dt Ki in component ionic_concentrations (mM)');
    LEGEND_RATES(:,19) = strpad('d/dt Ko in component ionic_concentrations (mM)');
    LEGEND_RATES(:,36) = strpad('d/dt Cab in component Myofilaments (mM)');
    LEGEND_RATES(:,35) = strpad('d/dt z in component Myofilaments (dimensionless)');
    LEGEND_RATES(:,32) = strpad('d/dt Q1 in component Myofilaments (dimensionless)');
    LEGEND_RATES(:,33) = strpad('d/dt Q2 in component Myofilaments (dimensionless)');
    LEGEND_RATES(:,34) = strpad('d/dt Q3 in component Myofilaments (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) = -84.1638;
    CONSTANTS(:,3) = 8.3145e3;
    CONSTANTS(:,4) = 310;
    CONSTANTS(:,5) = 9.6845e4;
    CONSTANTS(:,6) = 0.01;
    CONSTANTS(:,7) = 100;
    CONSTANTS(:,8) = 9000;
    CONSTANTS(:,9) = 750;
    CONSTANTS(:,10) = 1;
    CONSTANTS(:,11) = -100;
    CONSTANTS(:,12) = 0.128;
    STATES(:,2) = 10.2042;
    CONSTANTS(:,13) = 140;
    STATES(:,3) = 0.0328302;
    STATES(:,4) = 0.988354;
    STATES(:,5) = 0.99254;
    CONSTANTS(:,14) = 33.75e-6;
    CONSTANTS(:,15) = 1e-9;
    CONSTANTS(:,16) = -4.58e-3;
    STATES(:,6) = 9.84546e-21;
    STATES(:,7) = 0;
    CONSTANTS(:,17) = 2;
    CONSTANTS(:,18) = 2;
    CONSTANTS(:,19) = 2;
    CONSTANTS(:,20) = 0.3;
    CONSTANTS(:,21) = 0;
    CONSTANTS(:,22) = 0;
    CONSTANTS(:,23) = 0.01;
    STATES(:,8) = 0.997208;
    STATES(:,9) = 6.38897e-5;
    STATES(:,10) = 1.535e-9;
    STATES(:,11) = 1.63909e-14;
    STATES(:,12) = 6.56337e-20;
    STATES(:,13) = 2.72826e-3;
    STATES(:,14) = 6.99215e-7;
    STATES(:,15) = 6.71989e-11;
    STATES(:,16) = 2.87031e-15;
    STATES(:,17) = 4.59752e-20;
    STATES(:,18) = 1.36058e-4;
    CONSTANTS(:,24) = 1.8;
    STATES(:,19) = 5.4;
    STATES(:,20) = 143.727;
    STATES(:,21) = 0.998983;
    CONSTANTS(:,25) = 0.001128;
    CONSTANTS(:,26) = 0.01833;
    STATES(:,22) = 0.000928836;
    CONSTANTS(:,27) = 7.5e-3;
    CONSTANTS(:,28) = 8.28e-5;
    CONSTANTS(:,29) = 50;
    CONSTANTS(:,30) = 87.5;
    CONSTANTS(:,31) = 1.38;
    CONSTANTS(:,32) = 0.1;
    CONSTANTS(:,33) = 0.35;
    STATES(:,23) = 9.94893e-11;
    CONSTANTS(:,34) = 0.5e-3;
    CONSTANTS(:,35) = 1.15e-2;
    CONSTANTS(:,36) = 1.41e-5;
    CONSTANTS(:,37) = 6.032e-5;
    CONSTANTS(:,38) = 0.013;
    CONSTANTS(:,39) = 10;
    CONSTANTS(:,40) = 1.5;
    CONSTANTS(:,41) = 1.2e-3;
    CONSTANTS(:,42) = 1.75e-9;
    CONSTANTS(:,43) = 546.69;
    CONSTANTS(:,44) = 0.92;
    STATES(:,24) = 1.19168e-3;
    STATES(:,25) = 6.30613e-9;
    STATES(:,26) = 0.762527;
    STATES(:,27) = 0.236283;
    CONSTANTS(:,45) = 1.8;
    CONSTANTS(:,46) = 0.58e-4;
    CONSTANTS(:,47) = 1.8e-3;
    CONSTANTS(:,48) = 4;
    CONSTANTS(:,49) = 3;
    CONSTANTS(:,50) = 1.215e10;
    CONSTANTS(:,51) = 0.1425;
    CONSTANTS(:,52) = 4.05e7;
    CONSTANTS(:,53) = 1.93;
    CONSTANTS(:,54) = 0.018;
    CONSTANTS(:,55) = 0.0008;
    CONSTANTS(:,56) = 20;
    CONSTANTS(:,57) = 0.066e-3;
    CONSTANTS(:,58) = 40;
    CONSTANTS(:,59) = 0.04;
    CONSTANTS(:,60) = 34.48;
    STATES(:,28) = 1.17504;
    STATES(:,29) = 1.243891;
    CONSTANTS(:,61) = 0.5e-3;
    CONSTANTS(:,62) = 2.38e-3;
    CONSTANTS(:,63) = 0.8;
    CONSTANTS(:,64) = 3.125;
    CONSTANTS(:,65) = 0.14;
    CONSTANTS(:,66) = 0.07;
    STATES(:,30) = 0.13598;
    STATES(:,31) = 0.00635;
    CONSTANTS(:,67) = 15;
    CONSTANTS(:,68) = 0.05;
    CONSTANTS(:,69) = 56.2;
    CONSTANTS(:,70) = 4.9;
    CONSTANTS(:,71) = 0.35;
    STATES(:,32) = 0;
    STATES(:,33) = 0;
    STATES(:,34) = 0;
    CONSTANTS(:,72) = -29;
    CONSTANTS(:,73) = 138;
    CONSTANTS(:,74) = 129;
    CONSTANTS(:,75) = 0.03;
    CONSTANTS(:,76) = 0.13;
    CONSTANTS(:,77) = 0.625;
    CONSTANTS(:,78) = 1.05e-3;
    CONSTANTS(:,79) = 0.85;
    CONSTANTS(:,80) = -4;
    CONSTANTS(:,81) = 8e-3;
    CONSTANTS(:,82) = 2e-3;
    CONSTANTS(:,83) = 1.75e-3;
    CONSTANTS(:,84) = 3;
    CONSTANTS(:,85) = 0.15;
    CONSTANTS(:,86) = 3;
    CONSTANTS(:,87) = 100;
    CONSTANTS(:,88) = 0.2;
    CONSTANTS(:,89) = 2;
    CONSTANTS(:,90) = 0.07;
    STATES(:,35) = 0;
    STATES(:,36) = 0;
    CONSTANTS(:,91) =  (1.00000./7.00000).*(exp(CONSTANTS(:,13)./67.3000) - 1.00000);
    CONSTANTS(:,92) =  5.82800e-05.*CONSTANTS(:,44);
    CONSTANTS(:,93) =  CONSTANTS(:,69).*(1.00000+ CONSTANTS(:,70).*(CONSTANTS(:,1) - 1.00000));
    CONSTANTS(:,94) =  (( CONSTANTS(:,83).*power(CONSTANTS(:,79), CONSTANTS(:,84)))./(power(CONSTANTS(:,79), CONSTANTS(:,84))+power(CONSTANTS(:,85), CONSTANTS(:,84)))).*(1.00000 - ( CONSTANTS(:,84).*power(CONSTANTS(:,85), CONSTANTS(:,84)))./(power(CONSTANTS(:,79), CONSTANTS(:,84))+power(CONSTANTS(:,85), CONSTANTS(:,84))));
    CONSTANTS(:,95) =  0.0810000.*CONSTANTS(:,44);
    CONSTANTS(:,96) = ( CONSTANTS(:,83).*power(CONSTANTS(:,79), CONSTANTS(:,84) - 1.00000).*CONSTANTS(:,84).*power(CONSTANTS(:,85), CONSTANTS(:,84)))./power(power(CONSTANTS(:,79), CONSTANTS(:,84))+power(CONSTANTS(:,85), CONSTANTS(:,84)), 2.00000);
    CONSTANTS(:,97) =  0.00464000.*CONSTANTS(:,44);
    CONSTANTS(:,98) =  CONSTANTS(:,78).*(1.00000+ CONSTANTS(:,80).*(CONSTANTS(:,1) - 1.00000));
    CONSTANTS(:,99) = ( CONSTANTS(:,98).*CONSTANTS(:,90))./(CONSTANTS(:,98)+ (CONSTANTS(:,88)./CONSTANTS(:,87)).*(1.00000 - ( (1.00000+ CONSTANTS(:,70).*(CONSTANTS(:,1) - 1.00000)).*0.500000)./CONSTANTS(:,89)));
    CONSTANTS(:,100) = (CONSTANTS(:,81)./power(CONSTANTS(:,99)./CONSTANTS(:,90), CONSTANTS(:,86)) - CONSTANTS(:,94))./(CONSTANTS(:,82)+CONSTANTS(:,96)+CONSTANTS(:,81)./power(CONSTANTS(:,99)./CONSTANTS(:,90), CONSTANTS(:,86)));
    if (isempty(STATES)), warning('Initial values for states not set');, end
end

function [RATES, ALGEBRAIC] = computeRates(VOI, STATES, CONSTANTS)
    global algebraicVariableCount;
    statesSize = size(STATES);
    statesColumnCount = statesSize(2);
    if ( statesColumnCount == 1)
        STATES = STATES';
        ALGEBRAIC = zeros(1, algebraicVariableCount);
        utilOnes = 1;
    else
        statesRowCount = statesSize(1);
        ALGEBRAIC = zeros(statesRowCount, algebraicVariableCount);
        RATES = zeros(statesRowCount, statesColumnCount);
        utilOnes = ones(statesRowCount, 1);
    end
    RATES(:,6) =  CONSTANTS(:,20).*STATES(:,12) -  CONSTANTS(:,19).*STATES(:,6);
    RATES(:,7) =  CONSTANTS(:,22).*STATES(:,17) -  CONSTANTS(:,21).*STATES(:,7);
    RATES(:,26) =   - CONSTANTS(:,50).*power(STATES(:,18), CONSTANTS(:,48)).*STATES(:,26)+ CONSTANTS(:,51).*STATES(:,24);
    RATES(:,24) = ( CONSTANTS(:,50).*power(STATES(:,18), CONSTANTS(:,48)).*STATES(:,26) - ( CONSTANTS(:,51).*STATES(:,24)+ CONSTANTS(:,52).*power(STATES(:,18), CONSTANTS(:,49)).*STATES(:,24)+ CONSTANTS(:,54).*STATES(:,24)))+ CONSTANTS(:,53).*STATES(:,25)+ CONSTANTS(:,55).*STATES(:,27);
    RATES(:,25) =  CONSTANTS(:,52).*power(STATES(:,18), CONSTANTS(:,49)).*STATES(:,24) -  CONSTANTS(:,53).*STATES(:,25);
    RATES(:,27) =  CONSTANTS(:,54).*STATES(:,24) -  CONSTANTS(:,55).*STATES(:,27);
    RATES(:,35) =  CONSTANTS(:,81).*power(STATES(:,36)./CONSTANTS(:,99), CONSTANTS(:,86)).*(1.00000 - STATES(:,35))+  - STATES(:,35).*CONSTANTS(:,82)+(  - CONSTANTS(:,83).*power(STATES(:,35), CONSTANTS(:,84)))./(power(STATES(:,35), CONSTANTS(:,84))+power(CONSTANTS(:,85), CONSTANTS(:,84)));
    RATES(:,32) =  CONSTANTS(:,72).*CONSTANTS(:,2) -  CONSTANTS(:,75).*STATES(:,32);
    RATES(:,33) =  CONSTANTS(:,73).*CONSTANTS(:,2) -  CONSTANTS(:,76).*STATES(:,33);
    RATES(:,34) =  CONSTANTS(:,74).*CONSTANTS(:,2) -  CONSTANTS(:,77).*STATES(:,34);
    ALGEBRAIC(:,1) = ( 0.320000.*(STATES(:,1)+47.1300))./(1.00000 - exp(  - 0.100000.*(STATES(:,1)+47.1300)));
    ALGEBRAIC(:,9) =  0.0800000.*exp( - STATES(:,1)./11.0000);
    RATES(:,3) =  ALGEBRAIC(:,1).*(1.00000 - STATES(:,3)) -  ALGEBRAIC(:,9).*STATES(:,3);
    ALGEBRAIC(:,2) = piecewise({STATES(:,1)< - 40.0000,  0.135000.*exp((80.0000+STATES(:,1))./ - 6.80000) }, 0.00000);
    ALGEBRAIC(:,10) = piecewise({STATES(:,1)< - 40.0000,  3.56000.*exp( 0.0790000.*STATES(:,1))+ 310000..*exp( 0.350000.*STATES(:,1)) }, 1.00000./( 0.130000.*(1.00000+exp((STATES(:,1)+10.6600)./ - 11.1000))));
    RATES(:,4) =  ALGEBRAIC(:,2).*(1.00000 - STATES(:,4)) -  ALGEBRAIC(:,10).*STATES(:,4);
    ALGEBRAIC(:,3) = piecewise({STATES(:,1)< - 40.0000, ( (  - 127140..*exp( 0.244400.*STATES(:,1)) -  3.47400e-05.*exp(  - 0.0439100.*STATES(:,1))).*(STATES(:,1)+37.7800))./(1.00000+exp( 0.311000.*(STATES(:,1)+79.2300))) }, 0.00000);
    ALGEBRAIC(:,11) = piecewise({STATES(:,1)< - 40.0000, ( 0.121200.*exp(  - 0.0105200.*STATES(:,1)))./(1.00000+exp(  - 0.137800.*(STATES(:,1)+40.1400))) }, ( 0.300000.*exp(  - 2.53500e-07.*STATES(:,1)))./(1.00000+exp(  - 0.100000.*(STATES(:,1)+32.0000))));
    RATES(:,5) =  ALGEBRAIC(:,3).*(1.00000 - STATES(:,5)) -  ALGEBRAIC(:,11).*STATES(:,5);
    ALGEBRAIC(:,5) = 1.00000./(1.00000+exp((STATES(:,1)+55.0000)./7.50000))+0.100000./(1.00000+exp(( - STATES(:,1)+21.0000)./6.00000));
    ALGEBRAIC(:,13) = 20.0000+600.000./(1.00000+exp((STATES(:,1)+30.0000)./9.50000));
    RATES(:,21) = (ALGEBRAIC(:,5) - STATES(:,21))./ALGEBRAIC(:,13);
    ALGEBRAIC(:,6) = ( 7.19000e-05.*(STATES(:,1)+30.0000))./(1.00000 - exp(  - 0.148000.*(STATES(:,1)+30.0000)));
    ALGEBRAIC(:,14) = ( 0.000131000.*(STATES(:,1)+30.0000))./( - 1.00000+exp( 0.0687000.*(STATES(:,1)+30.0000)));
    RATES(:,22) =  ALGEBRAIC(:,6).*(1.00000 - STATES(:,22)) -  ALGEBRAIC(:,14).*STATES(:,22);
    ALGEBRAIC(:,8) = ( CONSTANTS(:,93).*STATES(:,35))./CONSTANTS(:,100);
    ALGEBRAIC(:,16) = STATES(:,32)+STATES(:,33)+STATES(:,34);
    ALGEBRAIC(:,19) = piecewise({ALGEBRAIC(:,16)<0.00000, ( ALGEBRAIC(:,8).*( CONSTANTS(:,71).*ALGEBRAIC(:,16)+1.00000))./(1.00000 - ALGEBRAIC(:,16)) }, ( ALGEBRAIC(:,8).*(1.00000 -  (CONSTANTS(:,71)+2.00000).*ALGEBRAIC(:,16)))./(1.00000+ALGEBRAIC(:,16)));
    RATES(:,36) =  CONSTANTS(:,87).*STATES(:,23).*(CONSTANTS(:,90) - STATES(:,36)) -  CONSTANTS(:,88).*(1.00000 - ALGEBRAIC(:,19)./( CONSTANTS(:,89).*CONSTANTS(:,69))).*STATES(:,36);
    ALGEBRAIC(:,4) =  0.400000.*exp((STATES(:,1)+12.0000)./10.0000);
    ALGEBRAIC(:,12) =  0.0500000.*exp((STATES(:,1)+12.0000)./ - 13.0000);
    ALGEBRAIC(:,22) =  0.187500.*STATES(:,18);
    RATES(:,8) = ( ALGEBRAIC(:,12).*STATES(:,9)+ CONSTANTS(:,23).*STATES(:,13)) -  ( 4.00000.*ALGEBRAIC(:,4)+ALGEBRAIC(:,22)).*STATES(:,8);
    RATES(:,9) = ( 4.00000.*ALGEBRAIC(:,4).*STATES(:,8)+ 2.00000.*ALGEBRAIC(:,12).*STATES(:,10)+ (CONSTANTS(:,23)./CONSTANTS(:,18)).*STATES(:,14)) -  (ALGEBRAIC(:,12)+ 3.00000.*ALGEBRAIC(:,4)+ ALGEBRAIC(:,22).*CONSTANTS(:,17)).*STATES(:,9);
    RATES(:,10) = ( 3.00000.*ALGEBRAIC(:,4).*STATES(:,9)+ 3.00000.*ALGEBRAIC(:,12).*STATES(:,11)+ (CONSTANTS(:,23)./power(CONSTANTS(:,18), 2.00000)).*STATES(:,15)) -  ( ALGEBRAIC(:,12).*2.00000+ 2.00000.*ALGEBRAIC(:,4)+ ALGEBRAIC(:,22).*power(CONSTANTS(:,17), 2.00000)).*STATES(:,10);
    RATES(:,11) = ( 2.00000.*ALGEBRAIC(:,4).*STATES(:,10)+ 4.00000.*ALGEBRAIC(:,12).*STATES(:,12)+ (CONSTANTS(:,23)./power(CONSTANTS(:,18), 3.00000)).*STATES(:,16)) -  ( ALGEBRAIC(:,12).*3.00000+ALGEBRAIC(:,4)+ ALGEBRAIC(:,22).*power(CONSTANTS(:,17), 3.00000)).*STATES(:,11);
    RATES(:,12) = ( ALGEBRAIC(:,4).*STATES(:,11)+ CONSTANTS(:,19).*STATES(:,6)+ (CONSTANTS(:,23)./power(CONSTANTS(:,18), 4.00000)).*STATES(:,17)) -  ( ALGEBRAIC(:,12).*4.00000+CONSTANTS(:,20)+ ALGEBRAIC(:,22).*power(CONSTANTS(:,17), 4.00000)).*STATES(:,12);
    ALGEBRAIC(:,17) =  ALGEBRAIC(:,4).*CONSTANTS(:,17);
    ALGEBRAIC(:,20) = ALGEBRAIC(:,12)./CONSTANTS(:,18);
    RATES(:,13) = ( ALGEBRAIC(:,20).*STATES(:,14)+ ALGEBRAIC(:,22).*STATES(:,13)) -  ( 4.00000.*ALGEBRAIC(:,17)+CONSTANTS(:,23)).*STATES(:,13);
    RATES(:,14) = ( 4.00000.*ALGEBRAIC(:,17).*STATES(:,13)+ 2.00000.*ALGEBRAIC(:,20).*STATES(:,15)+ ALGEBRAIC(:,22).*CONSTANTS(:,17).*STATES(:,9)) -  (ALGEBRAIC(:,20)+ 3.00000.*ALGEBRAIC(:,17)+CONSTANTS(:,23)./CONSTANTS(:,18)).*STATES(:,14);
    RATES(:,15) = ( 3.00000.*ALGEBRAIC(:,17).*STATES(:,14)+ 3.00000.*ALGEBRAIC(:,20).*STATES(:,16)+ ALGEBRAIC(:,22).*power(CONSTANTS(:,17), 2.00000).*STATES(:,10)) -  ( ALGEBRAIC(:,20).*2.00000+ 2.00000.*ALGEBRAIC(:,17)+CONSTANTS(:,23)./power(CONSTANTS(:,18), 2.00000)).*STATES(:,15);
    RATES(:,16) = ( 2.00000.*ALGEBRAIC(:,17).*STATES(:,15)+ 4.00000.*ALGEBRAIC(:,20).*STATES(:,17)+ ALGEBRAIC(:,22).*power(CONSTANTS(:,17), 3.00000).*STATES(:,11)) -  ( ALGEBRAIC(:,20).*3.00000+ALGEBRAIC(:,17)+CONSTANTS(:,23)./power(CONSTANTS(:,18), 3.00000)).*STATES(:,16);
    RATES(:,17) = ( ALGEBRAIC(:,17).*STATES(:,16)+ CONSTANTS(:,21).*STATES(:,7)+ ALGEBRAIC(:,22).*power(CONSTANTS(:,17), 4.00000).*STATES(:,12)) -  ( ALGEBRAIC(:,20).*4.00000+CONSTANTS(:,22)+CONSTANTS(:,23)./power(CONSTANTS(:,18), 4.00000)).*STATES(:,17);
    ALGEBRAIC(:,50) =  CONSTANTS(:,46).*(STATES(:,29) - STATES(:,23));
    ALGEBRAIC(:,52) = ( CONSTANTS(:,47).*power(STATES(:,23), 2.00000))./(power(CONSTANTS(:,61), 2.00000)+power(STATES(:,23), 2.00000));
    ALGEBRAIC(:,54) = (STATES(:,29) - STATES(:,28))./CONSTANTS(:,60);
    RATES(:,29) = ( (ALGEBRAIC(:,52) - ALGEBRAIC(:,50)).*CONSTANTS(:,44))./CONSTANTS(:,95) - ( ALGEBRAIC(:,54).*CONSTANTS(:,97))./CONSTANTS(:,95);
    ALGEBRAIC(:,59) =  CONSTANTS(:,56).*STATES(:,23).*(CONSTANTS(:,65) - STATES(:,30)) -  CONSTANTS(:,57).*STATES(:,30);
    RATES(:,30) = ALGEBRAIC(:,59);
    ALGEBRAIC(:,21) = ( (( CONSTANTS(:,14).*4.00000.*STATES(:,1).*power(CONSTANTS(:,5), 2.00000))./( CONSTANTS(:,3).*CONSTANTS(:,4))).*( 0.00100000.*exp(( 2.00000.*STATES(:,1).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))) -  0.341000.*CONSTANTS(:,24)))./(exp(( 2.00000.*STATES(:,1).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))) - 1.00000);
    ALGEBRAIC(:,23) =  ALGEBRAIC(:,21).*STATES(:,21).*(STATES(:,6)+STATES(:,7));
    ALGEBRAIC(:,57) = 1.00000./(1.00000+( CONSTANTS(:,68).*CONSTANTS(:,62))./power(CONSTANTS(:,62)+STATES(:,18), 2.00000));
    ALGEBRAIC(:,46) = STATES(:,24)+STATES(:,25);
    ALGEBRAIC(:,48) =  CONSTANTS(:,45).*ALGEBRAIC(:,46).*(STATES(:,28) - STATES(:,18));
    ALGEBRAIC(:,55) = (STATES(:,18) - STATES(:,23))./CONSTANTS(:,64);
    RATES(:,18) =  ALGEBRAIC(:,57).*((( ALGEBRAIC(:,48).*CONSTANTS(:,97))./CONSTANTS(:,92) - ( ALGEBRAIC(:,55).*CONSTANTS(:,44))./CONSTANTS(:,92)) - ( ALGEBRAIC(:,23).*CONSTANTS(:,43))./( 2.00000.*CONSTANTS(:,92).*CONSTANTS(:,5)));
    ALGEBRAIC(:,58) = 1.00000./(1.00000+( CONSTANTS(:,67).*CONSTANTS(:,63))./power(CONSTANTS(:,63)+STATES(:,28), 2.00000));
    RATES(:,28) =  ALGEBRAIC(:,58).*(ALGEBRAIC(:,54) - ALGEBRAIC(:,48));
    ALGEBRAIC(:,15) =  (( CONSTANTS(:,3).*CONSTANTS(:,4))./CONSTANTS(:,5)).*log(CONSTANTS(:,13)./STATES(:,2));
    ALGEBRAIC(:,18) =  CONSTANTS(:,12).*power(STATES(:,3), 3.00000).*STATES(:,4).*STATES(:,5).*(STATES(:,1) - ALGEBRAIC(:,15));
    ALGEBRAIC(:,39) =  (( (( (( CONSTANTS(:,29).*1.00000)./(power(CONSTANTS(:,30), 3.00000)+power(CONSTANTS(:,13), 3.00000))).*1.00000)./(CONSTANTS(:,31)+CONSTANTS(:,24))).*1.00000)./(1.00000+ CONSTANTS(:,32).*exp(( (CONSTANTS(:,33) - 1.00000).*STATES(:,1).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))))).*( exp(( CONSTANTS(:,33).*STATES(:,1).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))).*power(STATES(:,2), 3.00000).*CONSTANTS(:,24) -  exp(( (CONSTANTS(:,33) - 1.00000).*STATES(:,1).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))).*power(CONSTANTS(:,13), 3.00000).*STATES(:,23));
    ALGEBRAIC(:,41) = ALGEBRAIC(:,15);
    ALGEBRAIC(:,42) =  CONSTANTS(:,36).*(STATES(:,1) - ALGEBRAIC(:,41));
    ALGEBRAIC(:,45) = 1.00000./(1.00000+ 0.124500.*exp((  - 0.100000.*STATES(:,1).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4)))+ 0.0365000.*CONSTANTS(:,91).*exp((  - STATES(:,1).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))));
    ALGEBRAIC(:,47) = ( (( CONSTANTS(:,38).*ALGEBRAIC(:,45).*1.00000)./(1.00000+power(CONSTANTS(:,39)./STATES(:,2), 1.50000))).*STATES(:,19))./(STATES(:,19)+CONSTANTS(:,40));
    ALGEBRAIC(:,49) =  (( CONSTANTS(:,3).*CONSTANTS(:,4))./CONSTANTS(:,5)).*log((STATES(:,19)+CONSTANTS(:,13))./(STATES(:,20)+STATES(:,2)));
    ALGEBRAIC(:,51) = STATES(:,1) - ALGEBRAIC(:,49);
    ALGEBRAIC(:,53) = ( (( CONSTANTS(:,42).*power(1.00000, 2.00000).*ALGEBRAIC(:,51).*power(CONSTANTS(:,5), 2.00000))./( CONSTANTS(:,3).*CONSTANTS(:,4))).*( 0.750000.*STATES(:,2).*exp(( ALGEBRAIC(:,51).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))) -  0.750000.*CONSTANTS(:,13)))./(exp(( ALGEBRAIC(:,51).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))) - 1.00000);
    ALGEBRAIC(:,56) = ( ALGEBRAIC(:,53).*1.00000)./(1.00000+power(CONSTANTS(:,41)./STATES(:,23), 3.00000));
    RATES(:,2) = (  - (ALGEBRAIC(:,18)+ALGEBRAIC(:,42)+ALGEBRAIC(:,56)+ ALGEBRAIC(:,39).*3.00000+ ALGEBRAIC(:,47).*3.00000).*CONSTANTS(:,43))./( CONSTANTS(:,44).*CONSTANTS(:,5));
    ALGEBRAIC(:,61) =  CONSTANTS(:,58).*STATES(:,23).*(CONSTANTS(:,66) - STATES(:,31)) -  CONSTANTS(:,59).*STATES(:,31);
    RATES(:,31) = ALGEBRAIC(:,61);
    ALGEBRAIC(:,24) = CONSTANTS(:,15)./(1.00000+ALGEBRAIC(:,21)./CONSTANTS(:,16));
    ALGEBRAIC(:,25) = ( (( ALGEBRAIC(:,24).*STATES(:,21).*(STATES(:,6)+STATES(:,7)).*STATES(:,1).*power(CONSTANTS(:,5), 2.00000))./( CONSTANTS(:,3).*CONSTANTS(:,4))).*( STATES(:,20).*exp(( STATES(:,1).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))) - STATES(:,19)))./(exp(( STATES(:,1).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))) - 1.00000);
    ALGEBRAIC(:,26) =  CONSTANTS(:,25).*power((STATES(:,19)./5.40000), 1.0 ./ 2);
    ALGEBRAIC(:,27) =  (( CONSTANTS(:,3).*CONSTANTS(:,4))./CONSTANTS(:,5)).*log((STATES(:,19)+ CONSTANTS(:,26).*CONSTANTS(:,13))./(STATES(:,20)+ CONSTANTS(:,26).*STATES(:,2)));
    ALGEBRAIC(:,28) = 1.00000./(1.00000+exp((STATES(:,1) - 56.2600)./32.1000));
    ALGEBRAIC(:,29) =  ALGEBRAIC(:,26).*ALGEBRAIC(:,28).*power(STATES(:,22), 2.00000).*(STATES(:,1) - ALGEBRAIC(:,27));
    ALGEBRAIC(:,31) =  (( CONSTANTS(:,3).*CONSTANTS(:,4))./CONSTANTS(:,5)).*log(STATES(:,19)./STATES(:,20));
    ALGEBRAIC(:,30) =  CONSTANTS(:,27).*power((STATES(:,19)./5.40000), 1.0 ./ 2);
    ALGEBRAIC(:,32) = 1.02000./(1.00000+exp( 0.238500.*((STATES(:,1) - ALGEBRAIC(:,31)) - 59.2150)));
    ALGEBRAIC(:,33) = ( 0.491240.*exp( 0.0803200.*((STATES(:,1)+5.47600) - ALGEBRAIC(:,31)))+exp( 0.0617500.*(STATES(:,1) - (ALGEBRAIC(:,31)+594.310))))./(1.00000+exp(  - 0.514300.*((STATES(:,1) - ALGEBRAIC(:,31))+4.75300)));
    ALGEBRAIC(:,34) = ALGEBRAIC(:,32)./(ALGEBRAIC(:,32)+ALGEBRAIC(:,33));
    ALGEBRAIC(:,35) =  ALGEBRAIC(:,30).*ALGEBRAIC(:,34).*(STATES(:,1) - ALGEBRAIC(:,31));
    ALGEBRAIC(:,36) = ALGEBRAIC(:,31);
    ALGEBRAIC(:,37) = 1.00000./(1.00000+exp((7.48800 - STATES(:,1))./5.98000));
    ALGEBRAIC(:,38) =  CONSTANTS(:,28).*ALGEBRAIC(:,37).*(STATES(:,1) - ALGEBRAIC(:,36));
    ALGEBRAIC(:,60) = ( (( CONSTANTS(:,42).*power(1.00000, 2.00000).*ALGEBRAIC(:,51).*power(CONSTANTS(:,5), 2.00000))./( CONSTANTS(:,3).*CONSTANTS(:,4))).*( 0.750000.*STATES(:,20).*exp(( ALGEBRAIC(:,51).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))) -  0.750000.*STATES(:,19)))./(exp(( ALGEBRAIC(:,51).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))) - 1.00000);
    ALGEBRAIC(:,62) = ( ALGEBRAIC(:,60).*1.00000)./(1.00000+power(CONSTANTS(:,41)./STATES(:,23), 3.00000));
    RATES(:,20) = (  - (ALGEBRAIC(:,25)+ALGEBRAIC(:,29)+ALGEBRAIC(:,35)+ALGEBRAIC(:,38)+ALGEBRAIC(:,62)+  - ALGEBRAIC(:,47).*2.00000).*CONSTANTS(:,43))./( CONSTANTS(:,44).*CONSTANTS(:,5));
    RATES(:,19) = ( (ALGEBRAIC(:,25)+ALGEBRAIC(:,29)+ALGEBRAIC(:,35)+ALGEBRAIC(:,38)+ALGEBRAIC(:,62)+  - ALGEBRAIC(:,47).*2.00000).*CONSTANTS(:,43))./( CONSTANTS(:,44).*CONSTANTS(:,5));
    ALGEBRAIC(:,40) = ( CONSTANTS(:,35).*STATES(:,23))./(CONSTANTS(:,34)+STATES(:,23));
    ALGEBRAIC(:,43) =  (( CONSTANTS(:,3).*CONSTANTS(:,4))./( 2.00000.*CONSTANTS(:,5))).*log(CONSTANTS(:,24)./STATES(:,23));
    ALGEBRAIC(:,44) =  CONSTANTS(:,37).*(STATES(:,1) - ALGEBRAIC(:,43));
    ALGEBRAIC(:,64) = ALGEBRAIC(:,56)+ALGEBRAIC(:,62);
    ALGEBRAIC(:,7) = 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) = (ALGEBRAIC(:,18)+ALGEBRAIC(:,23)+ALGEBRAIC(:,25)+ALGEBRAIC(:,29)+ALGEBRAIC(:,39)+ALGEBRAIC(:,35)+ALGEBRAIC(:,38)+ALGEBRAIC(:,40)+ALGEBRAIC(:,42)+ALGEBRAIC(:,44)+ALGEBRAIC(:,47)+ALGEBRAIC(:,64)+ALGEBRAIC(:,7))./CONSTANTS(:,6);
    ALGEBRAIC(:,65) = 1.00000./(1.00000+( CONSTANTS(:,68).*CONSTANTS(:,62))./power(CONSTANTS(:,62)+STATES(:,23), 2.00000));
    ALGEBRAIC(:,63) = ALGEBRAIC(:,59)+ALGEBRAIC(:,61);
    RATES(:,23) =  ALGEBRAIC(:,65).*((ALGEBRAIC(:,50)+ALGEBRAIC(:,55)) - (ALGEBRAIC(:,52)+ALGEBRAIC(:,63)+( ((ALGEBRAIC(:,44) -  2.00000.*ALGEBRAIC(:,39))+ALGEBRAIC(:,40)).*CONSTANTS(:,43))./( 2.00000.*CONSTANTS(:,44).*CONSTANTS(:,5))));
   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) = ( 0.320000.*(STATES(:,1)+47.1300))./(1.00000 - exp(  - 0.100000.*(STATES(:,1)+47.1300)));
    ALGEBRAIC(:,9) =  0.0800000.*exp( - STATES(:,1)./11.0000);
    ALGEBRAIC(:,2) = piecewise({STATES(:,1)< - 40.0000,  0.135000.*exp((80.0000+STATES(:,1))./ - 6.80000) }, 0.00000);
    ALGEBRAIC(:,10) = piecewise({STATES(:,1)< - 40.0000,  3.56000.*exp( 0.0790000.*STATES(:,1))+ 310000..*exp( 0.350000.*STATES(:,1)) }, 1.00000./( 0.130000.*(1.00000+exp((STATES(:,1)+10.6600)./ - 11.1000))));
    ALGEBRAIC(:,3) = piecewise({STATES(:,1)< - 40.0000, ( (  - 127140..*exp( 0.244400.*STATES(:,1)) -  3.47400e-05.*exp(  - 0.0439100.*STATES(:,1))).*(STATES(:,1)+37.7800))./(1.00000+exp( 0.311000.*(STATES(:,1)+79.2300))) }, 0.00000);
    ALGEBRAIC(:,11) = piecewise({STATES(:,1)< - 40.0000, ( 0.121200.*exp(  - 0.0105200.*STATES(:,1)))./(1.00000+exp(  - 0.137800.*(STATES(:,1)+40.1400))) }, ( 0.300000.*exp(  - 2.53500e-07.*STATES(:,1)))./(1.00000+exp(  - 0.100000.*(STATES(:,1)+32.0000))));
    ALGEBRAIC(:,5) = 1.00000./(1.00000+exp((STATES(:,1)+55.0000)./7.50000))+0.100000./(1.00000+exp(( - STATES(:,1)+21.0000)./6.00000));
    ALGEBRAIC(:,13) = 20.0000+600.000./(1.00000+exp((STATES(:,1)+30.0000)./9.50000));
    ALGEBRAIC(:,6) = ( 7.19000e-05.*(STATES(:,1)+30.0000))./(1.00000 - exp(  - 0.148000.*(STATES(:,1)+30.0000)));
    ALGEBRAIC(:,14) = ( 0.000131000.*(STATES(:,1)+30.0000))./( - 1.00000+exp( 0.0687000.*(STATES(:,1)+30.0000)));
    ALGEBRAIC(:,8) = ( CONSTANTS(:,93).*STATES(:,35))./CONSTANTS(:,100);
    ALGEBRAIC(:,16) = STATES(:,32)+STATES(:,33)+STATES(:,34);
    ALGEBRAIC(:,19) = piecewise({ALGEBRAIC(:,16)<0.00000, ( ALGEBRAIC(:,8).*( CONSTANTS(:,71).*ALGEBRAIC(:,16)+1.00000))./(1.00000 - ALGEBRAIC(:,16)) }, ( ALGEBRAIC(:,8).*(1.00000 -  (CONSTANTS(:,71)+2.00000).*ALGEBRAIC(:,16)))./(1.00000+ALGEBRAIC(:,16)));
    ALGEBRAIC(:,4) =  0.400000.*exp((STATES(:,1)+12.0000)./10.0000);
    ALGEBRAIC(:,12) =  0.0500000.*exp((STATES(:,1)+12.0000)./ - 13.0000);
    ALGEBRAIC(:,22) =  0.187500.*STATES(:,18);
    ALGEBRAIC(:,17) =  ALGEBRAIC(:,4).*CONSTANTS(:,17);
    ALGEBRAIC(:,20) = ALGEBRAIC(:,12)./CONSTANTS(:,18);
    ALGEBRAIC(:,50) =  CONSTANTS(:,46).*(STATES(:,29) - STATES(:,23));
    ALGEBRAIC(:,52) = ( CONSTANTS(:,47).*power(STATES(:,23), 2.00000))./(power(CONSTANTS(:,61), 2.00000)+power(STATES(:,23), 2.00000));
    ALGEBRAIC(:,54) = (STATES(:,29) - STATES(:,28))./CONSTANTS(:,60);
    ALGEBRAIC(:,59) =  CONSTANTS(:,56).*STATES(:,23).*(CONSTANTS(:,65) - STATES(:,30)) -  CONSTANTS(:,57).*STATES(:,30);
    ALGEBRAIC(:,21) = ( (( CONSTANTS(:,14).*4.00000.*STATES(:,1).*power(CONSTANTS(:,5), 2.00000))./( CONSTANTS(:,3).*CONSTANTS(:,4))).*( 0.00100000.*exp(( 2.00000.*STATES(:,1).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))) -  0.341000.*CONSTANTS(:,24)))./(exp(( 2.00000.*STATES(:,1).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))) - 1.00000);
    ALGEBRAIC(:,23) =  ALGEBRAIC(:,21).*STATES(:,21).*(STATES(:,6)+STATES(:,7));
    ALGEBRAIC(:,57) = 1.00000./(1.00000+( CONSTANTS(:,68).*CONSTANTS(:,62))./power(CONSTANTS(:,62)+STATES(:,18), 2.00000));
    ALGEBRAIC(:,46) = STATES(:,24)+STATES(:,25);
    ALGEBRAIC(:,48) =  CONSTANTS(:,45).*ALGEBRAIC(:,46).*(STATES(:,28) - STATES(:,18));
    ALGEBRAIC(:,55) = (STATES(:,18) - STATES(:,23))./CONSTANTS(:,64);
    ALGEBRAIC(:,58) = 1.00000./(1.00000+( CONSTANTS(:,67).*CONSTANTS(:,63))./power(CONSTANTS(:,63)+STATES(:,28), 2.00000));
    ALGEBRAIC(:,15) =  (( CONSTANTS(:,3).*CONSTANTS(:,4))./CONSTANTS(:,5)).*log(CONSTANTS(:,13)./STATES(:,2));
    ALGEBRAIC(:,18) =  CONSTANTS(:,12).*power(STATES(:,3), 3.00000).*STATES(:,4).*STATES(:,5).*(STATES(:,1) - ALGEBRAIC(:,15));
    ALGEBRAIC(:,39) =  (( (( (( CONSTANTS(:,29).*1.00000)./(power(CONSTANTS(:,30), 3.00000)+power(CONSTANTS(:,13), 3.00000))).*1.00000)./(CONSTANTS(:,31)+CONSTANTS(:,24))).*1.00000)./(1.00000+ CONSTANTS(:,32).*exp(( (CONSTANTS(:,33) - 1.00000).*STATES(:,1).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))))).*( exp(( CONSTANTS(:,33).*STATES(:,1).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))).*power(STATES(:,2), 3.00000).*CONSTANTS(:,24) -  exp(( (CONSTANTS(:,33) - 1.00000).*STATES(:,1).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))).*power(CONSTANTS(:,13), 3.00000).*STATES(:,23));
    ALGEBRAIC(:,41) = ALGEBRAIC(:,15);
    ALGEBRAIC(:,42) =  CONSTANTS(:,36).*(STATES(:,1) - ALGEBRAIC(:,41));
    ALGEBRAIC(:,45) = 1.00000./(1.00000+ 0.124500.*exp((  - 0.100000.*STATES(:,1).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4)))+ 0.0365000.*CONSTANTS(:,91).*exp((  - STATES(:,1).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))));
    ALGEBRAIC(:,47) = ( (( CONSTANTS(:,38).*ALGEBRAIC(:,45).*1.00000)./(1.00000+power(CONSTANTS(:,39)./STATES(:,2), 1.50000))).*STATES(:,19))./(STATES(:,19)+CONSTANTS(:,40));
    ALGEBRAIC(:,49) =  (( CONSTANTS(:,3).*CONSTANTS(:,4))./CONSTANTS(:,5)).*log((STATES(:,19)+CONSTANTS(:,13))./(STATES(:,20)+STATES(:,2)));
    ALGEBRAIC(:,51) = STATES(:,1) - ALGEBRAIC(:,49);
    ALGEBRAIC(:,53) = ( (( CONSTANTS(:,42).*power(1.00000, 2.00000).*ALGEBRAIC(:,51).*power(CONSTANTS(:,5), 2.00000))./( CONSTANTS(:,3).*CONSTANTS(:,4))).*( 0.750000.*STATES(:,2).*exp(( ALGEBRAIC(:,51).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))) -  0.750000.*CONSTANTS(:,13)))./(exp(( ALGEBRAIC(:,51).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))) - 1.00000);
    ALGEBRAIC(:,56) = ( ALGEBRAIC(:,53).*1.00000)./(1.00000+power(CONSTANTS(:,41)./STATES(:,23), 3.00000));
    ALGEBRAIC(:,61) =  CONSTANTS(:,58).*STATES(:,23).*(CONSTANTS(:,66) - STATES(:,31)) -  CONSTANTS(:,59).*STATES(:,31);
    ALGEBRAIC(:,24) = CONSTANTS(:,15)./(1.00000+ALGEBRAIC(:,21)./CONSTANTS(:,16));
    ALGEBRAIC(:,25) = ( (( ALGEBRAIC(:,24).*STATES(:,21).*(STATES(:,6)+STATES(:,7)).*STATES(:,1).*power(CONSTANTS(:,5), 2.00000))./( CONSTANTS(:,3).*CONSTANTS(:,4))).*( STATES(:,20).*exp(( STATES(:,1).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))) - STATES(:,19)))./(exp(( STATES(:,1).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))) - 1.00000);
    ALGEBRAIC(:,26) =  CONSTANTS(:,25).*power((STATES(:,19)./5.40000), 1.0 ./ 2);
    ALGEBRAIC(:,27) =  (( CONSTANTS(:,3).*CONSTANTS(:,4))./CONSTANTS(:,5)).*log((STATES(:,19)+ CONSTANTS(:,26).*CONSTANTS(:,13))./(STATES(:,20)+ CONSTANTS(:,26).*STATES(:,2)));
    ALGEBRAIC(:,28) = 1.00000./(1.00000+exp((STATES(:,1) - 56.2600)./32.1000));
    ALGEBRAIC(:,29) =  ALGEBRAIC(:,26).*ALGEBRAIC(:,28).*power(STATES(:,22), 2.00000).*(STATES(:,1) - ALGEBRAIC(:,27));
    ALGEBRAIC(:,31) =  (( CONSTANTS(:,3).*CONSTANTS(:,4))./CONSTANTS(:,5)).*log(STATES(:,19)./STATES(:,20));
    ALGEBRAIC(:,30) =  CONSTANTS(:,27).*power((STATES(:,19)./5.40000), 1.0 ./ 2);
    ALGEBRAIC(:,32) = 1.02000./(1.00000+exp( 0.238500.*((STATES(:,1) - ALGEBRAIC(:,31)) - 59.2150)));
    ALGEBRAIC(:,33) = ( 0.491240.*exp( 0.0803200.*((STATES(:,1)+5.47600) - ALGEBRAIC(:,31)))+exp( 0.0617500.*(STATES(:,1) - (ALGEBRAIC(:,31)+594.310))))./(1.00000+exp(  - 0.514300.*((STATES(:,1) - ALGEBRAIC(:,31))+4.75300)));
    ALGEBRAIC(:,34) = ALGEBRAIC(:,32)./(ALGEBRAIC(:,32)+ALGEBRAIC(:,33));
    ALGEBRAIC(:,35) =  ALGEBRAIC(:,30).*ALGEBRAIC(:,34).*(STATES(:,1) - ALGEBRAIC(:,31));
    ALGEBRAIC(:,36) = ALGEBRAIC(:,31);
    ALGEBRAIC(:,37) = 1.00000./(1.00000+exp((7.48800 - STATES(:,1))./5.98000));
    ALGEBRAIC(:,38) =  CONSTANTS(:,28).*ALGEBRAIC(:,37).*(STATES(:,1) - ALGEBRAIC(:,36));
    ALGEBRAIC(:,60) = ( (( CONSTANTS(:,42).*power(1.00000, 2.00000).*ALGEBRAIC(:,51).*power(CONSTANTS(:,5), 2.00000))./( CONSTANTS(:,3).*CONSTANTS(:,4))).*( 0.750000.*STATES(:,20).*exp(( ALGEBRAIC(:,51).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))) -  0.750000.*STATES(:,19)))./(exp(( ALGEBRAIC(:,51).*CONSTANTS(:,5))./( CONSTANTS(:,3).*CONSTANTS(:,4))) - 1.00000);
    ALGEBRAIC(:,62) = ( ALGEBRAIC(:,60).*1.00000)./(1.00000+power(CONSTANTS(:,41)./STATES(:,23), 3.00000));
    ALGEBRAIC(:,40) = ( CONSTANTS(:,35).*STATES(:,23))./(CONSTANTS(:,34)+STATES(:,23));
    ALGEBRAIC(:,43) =  (( CONSTANTS(:,3).*CONSTANTS(:,4))./( 2.00000.*CONSTANTS(:,5))).*log(CONSTANTS(:,24)./STATES(:,23));
    ALGEBRAIC(:,44) =  CONSTANTS(:,37).*(STATES(:,1) - ALGEBRAIC(:,43));
    ALGEBRAIC(:,64) = ALGEBRAIC(:,56)+ALGEBRAIC(:,62);
    ALGEBRAIC(:,7) = 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(:,65) = 1.00000./(1.00000+( CONSTANTS(:,68).*CONSTANTS(:,62))./power(CONSTANTS(:,62)+STATES(:,23), 2.00000));
    ALGEBRAIC(:,63) = ALGEBRAIC(:,59)+ALGEBRAIC(:,61);
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