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

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

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

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

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

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

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

function [LEGEND_STATES, LEGEND_ALGEBRAIC, LEGEND_VOI, LEGEND_CONSTANTS] = createLegends()
    LEGEND_STATES = ''; LEGEND_ALGEBRAIC = ''; LEGEND_VOI = ''; LEGEND_CONSTANTS = '';
    LEGEND_VOI = strpad('time in component environment (second)');
    LEGEND_STATES(:,1) = strpad('V in component membrane (millivolt)');
    LEGEND_CONSTANTS(:,1) = strpad('R in component membrane (joule_per_kilomole_kelvin)');
    LEGEND_CONSTANTS(:,2) = strpad('T in component membrane (kelvin)');
    LEGEND_CONSTANTS(:,3) = strpad('F in component membrane (coulomb_per_mole)');
    LEGEND_CONSTANTS(:,4) = strpad('Cm in component membrane (microF)');
    LEGEND_ALGEBRAIC(:,12) = strpad('I_st in component membrane (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,31) = strpad('i_Na in component fast_sodium_current (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,54) = strpad('i_Ca_L in component L_type_Ca_channel (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,79) = strpad('i_Ca_T in component T_type_Ca_channel (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,58) = strpad('i_Kr in component rapid_delayed_rectifier_potassium_current (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,62) = strpad('i_Ks in component slow_delayed_rectifier_potassium_current (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,72) = strpad('i_K_Na in component sodium_activated_potassium_current (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,73) = strpad('i_K_ATP in component ATP_sensitive_potassium_current (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,75) = strpad('i_to in component transient_outward_current (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,88) = strpad('i_NaCa in component Na_Ca_exchanger (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,67) = strpad('i_K1 in component time_independent_potassium_current (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,69) = strpad('i_Kp in component plateau_potassium_current (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,76) = strpad('i_p_Ca in component sarcolemmal_calcium_pump (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,77) = strpad('i_Na_b in component sodium_background_current (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,80) = strpad('i_Ca_b in component calcium_background_current (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,82) = strpad('i_NaK in component sodium_potassium_pump (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,87) = strpad('i_ns_Ca in component non_specific_calcium_activated_current (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,89) = strpad('dVdt in component membrane (dimensionless)');
    LEGEND_CONSTANTS(:,5) = strpad('stim_start in component membrane (second)');
    LEGEND_CONSTANTS(:,6) = strpad('stim_end in component membrane (second)');
    LEGEND_CONSTANTS(:,7) = strpad('stim_period in component membrane (dimensionless)');
    LEGEND_CONSTANTS(:,8) = strpad('stim_duration in component membrane (second)');
    LEGEND_CONSTANTS(:,9) = strpad('stim_amplitude in component membrane (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,24) = strpad('E_Na in component fast_sodium_current (millivolt)');
    LEGEND_CONSTANTS(:,10) = strpad('g_Na in component fast_sodium_current (milliS_per_microF)');
    LEGEND_CONSTANTS(:,11) = strpad('Nao in component ionic_concentrations (millimolar)');
    LEGEND_STATES(:,2) = strpad('Nai in component ionic_concentrations (millimolar)');
    LEGEND_STATES(:,3) = strpad('P_O_Na in component Na_channel_states (dimensionless)');
    LEGEND_STATES(:,4) = strpad('P_C1 in component Na_channel_states (dimensionless)');
    LEGEND_STATES(:,5) = strpad('P_C2 in component Na_channel_states (dimensionless)');
    LEGEND_STATES(:,6) = strpad('P_C3 in component Na_channel_states (dimensionless)');
    LEGEND_STATES(:,7) = strpad('P_IF in component Na_channel_states (dimensionless)');
    LEGEND_STATES(:,8) = strpad('P_IC3 in component Na_channel_states (dimensionless)');
    LEGEND_STATES(:,9) = strpad('P_IC2 in component Na_channel_states (dimensionless)');
    LEGEND_STATES(:,10) = strpad('P_IM1 in component Na_channel_states (dimensionless)');
    LEGEND_STATES(:,11) = strpad('P_IM2 in component Na_channel_states (dimensionless)');
    LEGEND_ALGEBRAIC(:,1) = strpad('alpha_11 in component Na_channel_states (per_second)');
    LEGEND_ALGEBRAIC(:,32) = strpad('beta_11 in component Na_channel_states (per_second)');
    LEGEND_ALGEBRAIC(:,13) = strpad('alpha_12 in component Na_channel_states (per_second)');
    LEGEND_ALGEBRAIC(:,39) = strpad('beta_12 in component Na_channel_states (per_second)');
    LEGEND_ALGEBRAIC(:,25) = strpad('alpha_13 in component Na_channel_states (per_second)');
    LEGEND_ALGEBRAIC(:,43) = strpad('beta_13 in component Na_channel_states (per_second)');
    LEGEND_ALGEBRAIC(:,45) = strpad('alpha_2 in component Na_channel_states (per_second)');
    LEGEND_ALGEBRAIC(:,51) = strpad('beta_2 in component Na_channel_states (per_second)');
    LEGEND_ALGEBRAIC(:,47) = strpad('alpha_3 in component Na_channel_states (per_second)');
    LEGEND_ALGEBRAIC(:,49) = strpad('beta_3 in component Na_channel_states (per_second)');
    LEGEND_ALGEBRAIC(:,53) = strpad('alpha_4 in component Na_channel_states (per_second)');
    LEGEND_ALGEBRAIC(:,55) = strpad('beta_4 in component Na_channel_states (per_second)');
    LEGEND_ALGEBRAIC(:,57) = strpad('alpha_5 in component Na_channel_states (per_second)');
    LEGEND_ALGEBRAIC(:,59) = strpad('beta_5 in component Na_channel_states (per_second)');
    LEGEND_ALGEBRAIC(:,48) = strpad('i_CaCa in component L_type_Ca_channel (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,52) = strpad('i_CaK in component L_type_Ca_channel (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,50) = strpad('i_CaNa in component L_type_Ca_channel (microA_per_microF)');
    LEGEND_CONSTANTS(:,12) = strpad('gamma_Nai in component L_type_Ca_channel (dimensionless)');
    LEGEND_CONSTANTS(:,13) = strpad('gamma_Nao in component L_type_Ca_channel (dimensionless)');
    LEGEND_CONSTANTS(:,14) = strpad('gamma_Ki in component L_type_Ca_channel (dimensionless)');
    LEGEND_CONSTANTS(:,15) = strpad('gamma_Ko in component L_type_Ca_channel (dimensionless)');
    LEGEND_ALGEBRAIC(:,38) = strpad('I_CaCa in component L_type_Ca_channel (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,44) = strpad('I_CaK in component L_type_Ca_channel (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,42) = strpad('I_CaNa in component L_type_Ca_channel (microA_per_microF)');
    LEGEND_CONSTANTS(:,16) = strpad('P_Ca in component L_type_Ca_channel (cm_per_second)');
    LEGEND_CONSTANTS(:,17) = strpad('P_Na in component L_type_Ca_channel (cm_per_second)');
    LEGEND_CONSTANTS(:,18) = strpad('P_K in component L_type_Ca_channel (cm_per_second)');
    LEGEND_CONSTANTS(:,19) = strpad('gamma_Cai in component L_type_Ca_channel (dimensionless)');
    LEGEND_CONSTANTS(:,20) = strpad('gamma_Cao in component L_type_Ca_channel (dimensionless)');
    LEGEND_STATES(:,12) = strpad('Cai in component calcium_dynamics (millimolar)');
    LEGEND_CONSTANTS(:,21) = strpad('Cao in component calcium_dynamics (millimolar)');
    LEGEND_CONSTANTS(:,22) = strpad('Ko in component ionic_concentrations (millimolar)');
    LEGEND_STATES(:,13) = strpad('Ki in component ionic_concentrations (millimolar)');
    LEGEND_STATES(:,14) = strpad('d in component L_type_Ca_channel_d_gate (dimensionless)');
    LEGEND_STATES(:,15) = strpad('f in component L_type_Ca_channel_f_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,46) = strpad('f_Ca in component L_type_Ca_channel_f_Ca_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,33) = strpad('alpha_d in component L_type_Ca_channel_d_gate (per_second)');
    LEGEND_ALGEBRAIC(:,40) = strpad('beta_d in component L_type_Ca_channel_d_gate (per_second)');
    LEGEND_ALGEBRAIC(:,14) = strpad('d_infinity in component L_type_Ca_channel_d_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,26) = strpad('tau_d in component L_type_Ca_channel_d_gate (second)');
    LEGEND_ALGEBRAIC(:,2) = strpad('E0_d in component L_type_Ca_channel_d_gate (millivolt)');
    LEGEND_ALGEBRAIC(:,27) = strpad('alpha_f in component L_type_Ca_channel_f_gate (per_second)');
    LEGEND_ALGEBRAIC(:,34) = strpad('beta_f in component L_type_Ca_channel_f_gate (per_second)');
    LEGEND_ALGEBRAIC(:,3) = strpad('f_infinity in component L_type_Ca_channel_f_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,15) = strpad('tau_f in component L_type_Ca_channel_f_gate (second)');
    LEGEND_CONSTANTS(:,23) = strpad('Km_Ca in component L_type_Ca_channel_f_Ca_gate (millimolar)');
    LEGEND_CONSTANTS(:,24) = strpad('g_CaT in component T_type_Ca_channel (milliS_per_microF)');
    LEGEND_ALGEBRAIC(:,78) = strpad('E_Ca in component calcium_background_current (millivolt)');
    LEGEND_STATES(:,16) = strpad('b in component T_type_Ca_channel_b_gate (dimensionless)');
    LEGEND_STATES(:,17) = strpad('g in component T_type_Ca_channel_g_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,4) = strpad('b_inf in component T_type_Ca_channel_b_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,16) = strpad('tau_b in component T_type_Ca_channel_b_gate (second)');
    LEGEND_ALGEBRAIC(:,5) = strpad('g_inf in component T_type_Ca_channel_g_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,17) = strpad('tau_g in component T_type_Ca_channel_g_gate (second)');
    LEGEND_CONSTANTS(:,67) = strpad('g_Kr in component rapid_delayed_rectifier_potassium_current (milliS_per_microF)');
    LEGEND_ALGEBRAIC(:,56) = strpad('E_Kr in component rapid_delayed_rectifier_potassium_current (millivolt)');
    LEGEND_STATES(:,18) = strpad('P_O in component Kr_channel_states (dimensionless)');
    LEGEND_STATES(:,19) = strpad('P_C1 in component Kr_channel_states (dimensionless)');
    LEGEND_STATES(:,20) = strpad('P_C2 in component Kr_channel_states (dimensionless)');
    LEGEND_STATES(:,21) = strpad('P_C3 in component Kr_channel_states (dimensionless)');
    LEGEND_STATES(:,22) = strpad('P_I in component Kr_channel_states (dimensionless)');
    LEGEND_ALGEBRAIC(:,6) = strpad('alpha in component Kr_channel_states (per_second)');
    LEGEND_ALGEBRAIC(:,18) = strpad('beta in component Kr_channel_states (per_second)');
    LEGEND_CONSTANTS(:,25) = strpad('alpha_in in component Kr_channel_states (per_second)');
    LEGEND_CONSTANTS(:,26) = strpad('beta_in in component Kr_channel_states (per_second)');
    LEGEND_ALGEBRAIC(:,7) = strpad('alpha_alpha in component Kr_channel_states (per_second)');
    LEGEND_ALGEBRAIC(:,19) = strpad('beta_beta in component Kr_channel_states (per_second)');
    LEGEND_ALGEBRAIC(:,28) = strpad('alpha_i in component Kr_channel_states (per_second)');
    LEGEND_ALGEBRAIC(:,35) = strpad('beta_i in component Kr_channel_states (per_second)');
    LEGEND_ALGEBRAIC(:,41) = strpad('mu in component Kr_channel_states (per_second)');
    LEGEND_ALGEBRAIC(:,61) = strpad('g_Ks in component slow_delayed_rectifier_potassium_current (milliS_per_microF)');
    LEGEND_ALGEBRAIC(:,60) = strpad('E_Ks in component slow_delayed_rectifier_potassium_current (millivolt)');
    LEGEND_CONSTANTS(:,27) = strpad('PNaK in component slow_delayed_rectifier_potassium_current (dimensionless)');
    LEGEND_STATES(:,23) = strpad('xs1 in component slow_delayed_rectifier_potassium_current_xs1_gate (dimensionless)');
    LEGEND_STATES(:,24) = strpad('xs2 in component slow_delayed_rectifier_potassium_current_xs2_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,8) = strpad('xs1_infinity in component slow_delayed_rectifier_potassium_current_xs1_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,20) = strpad('tau_xs1 in component slow_delayed_rectifier_potassium_current_xs1_gate (second)');
    LEGEND_ALGEBRAIC(:,9) = strpad('xs2_infinity in component slow_delayed_rectifier_potassium_current_xs2_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,21) = strpad('tau_xs2 in component slow_delayed_rectifier_potassium_current_xs2_gate (second)');
    LEGEND_ALGEBRAIC(:,63) = strpad('E_K in component time_independent_potassium_current (millivolt)');
    LEGEND_CONSTANTS(:,68) = strpad('g_K1 in component time_independent_potassium_current (milliS_per_cm2)');
    LEGEND_ALGEBRAIC(:,66) = strpad('K1_infinity in component time_independent_potassium_current_K1_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,64) = strpad('alpha_K1 in component time_independent_potassium_current_K1_gate (per_second)');
    LEGEND_ALGEBRAIC(:,65) = strpad('beta_K1 in component time_independent_potassium_current_K1_gate (per_second)');
    LEGEND_CONSTANTS(:,28) = strpad('g_Kp in component plateau_potassium_current (milliS_per_microF)');
    LEGEND_ALGEBRAIC(:,68) = strpad('Kp in component plateau_potassium_current (dimensionless)');
    LEGEND_CONSTANTS(:,69) = strpad('g_K_Na in component sodium_activated_potassium_current (milliS_per_microF)');
    LEGEND_CONSTANTS(:,29) = strpad('nKNa in component sodium_activated_potassium_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,70) = strpad('pona in component sodium_activated_potassium_current (dimensionless)');
    LEGEND_ALGEBRAIC(:,71) = strpad('pov in component sodium_activated_potassium_current (dimensionless)');
    LEGEND_CONSTANTS(:,30) = strpad('kdKNa in component sodium_activated_potassium_current (millimolar)');
    LEGEND_CONSTANTS(:,70) = strpad('g_K_ATP in component ATP_sensitive_potassium_current (milliS_per_microF)');
    LEGEND_CONSTANTS(:,31) = strpad('i_K_ATP_on in component ATP_sensitive_potassium_current (dimensionless)');
    LEGEND_CONSTANTS(:,32) = strpad('nATP in component ATP_sensitive_potassium_current (dimensionless)');
    LEGEND_CONSTANTS(:,33) = strpad('nicholsarea in component ATP_sensitive_potassium_current (dimensionless)');
    LEGEND_CONSTANTS(:,34) = strpad('ATPi in component ATP_sensitive_potassium_current (millimolar)');
    LEGEND_CONSTANTS(:,35) = strpad('hATP in component ATP_sensitive_potassium_current (dimensionless)');
    LEGEND_CONSTANTS(:,36) = strpad('kATP in component ATP_sensitive_potassium_current (millimolar)');
    LEGEND_CONSTANTS(:,76) = strpad('pATP in component ATP_sensitive_potassium_current (dimensionless)');
    LEGEND_CONSTANTS(:,78) = strpad('GKbaraATP in component ATP_sensitive_potassium_current (milliS_per_microF)');
    LEGEND_CONSTANTS(:,71) = strpad('g_to in component transient_outward_current (milliS_per_microF)');
    LEGEND_ALGEBRAIC(:,74) = strpad('rvdv in component transient_outward_current (dimensionless)');
    LEGEND_STATES(:,25) = strpad('zdv in component transient_outward_current_zdv_gate (dimensionless)');
    LEGEND_STATES(:,26) = strpad('ydv in component transient_outward_current_ydv_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,10) = strpad('alpha_zdv in component transient_outward_current_zdv_gate (per_second)');
    LEGEND_ALGEBRAIC(:,22) = strpad('beta_zdv in component transient_outward_current_zdv_gate (per_second)');
    LEGEND_ALGEBRAIC(:,29) = strpad('tau_zdv in component transient_outward_current_zdv_gate (second)');
    LEGEND_ALGEBRAIC(:,36) = strpad('zdv_ss in component transient_outward_current_zdv_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,11) = strpad('alpha_ydv in component transient_outward_current_ydv_gate (per_second)');
    LEGEND_ALGEBRAIC(:,23) = strpad('beta_ydv in component transient_outward_current_ydv_gate (per_second)');
    LEGEND_ALGEBRAIC(:,30) = strpad('tau_ydv in component transient_outward_current_ydv_gate (second)');
    LEGEND_ALGEBRAIC(:,37) = strpad('ydv_ss in component transient_outward_current_ydv_gate (dimensionless)');
    LEGEND_CONSTANTS(:,37) = strpad('K_mpCa in component sarcolemmal_calcium_pump (millimolar)');
    LEGEND_CONSTANTS(:,38) = strpad('I_pCa in component sarcolemmal_calcium_pump (microA_per_microF)');
    LEGEND_CONSTANTS(:,39) = strpad('g_Nab in component sodium_background_current (milliS_per_microF)');
    LEGEND_CONSTANTS(:,40) = strpad('g_Cab in component calcium_background_current (milliS_per_microF)');
    LEGEND_CONSTANTS(:,41) = strpad('I_NaK in component sodium_potassium_pump (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,81) = strpad('f_NaK in component sodium_potassium_pump (dimensionless)');
    LEGEND_CONSTANTS(:,42) = strpad('K_mNai in component sodium_potassium_pump (millimolar)');
    LEGEND_CONSTANTS(:,43) = strpad('K_mKo in component sodium_potassium_pump (millimolar)');
    LEGEND_CONSTANTS(:,72) = strpad('sigma in component sodium_potassium_pump (dimensionless)');
    LEGEND_ALGEBRAIC(:,85) = strpad('i_ns_Na in component non_specific_calcium_activated_current (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,86) = strpad('i_ns_K in component non_specific_calcium_activated_current (microA_per_microF)');
    LEGEND_CONSTANTS(:,73) = strpad('P_ns_Ca in component non_specific_calcium_activated_current (cm_per_second)');
    LEGEND_ALGEBRAIC(:,83) = strpad('I_ns_Na in component non_specific_calcium_activated_current (microA_per_microF)');
    LEGEND_ALGEBRAIC(:,84) = strpad('I_ns_K in component non_specific_calcium_activated_current (microA_per_microF)');
    LEGEND_CONSTANTS(:,44) = strpad('K_m_ns_Ca in component non_specific_calcium_activated_current (millimolar)');
    LEGEND_CONSTANTS(:,45) = strpad('c1 in component Na_Ca_exchanger (microA_per_microF)');
    LEGEND_CONSTANTS(:,46) = strpad('c2 in component Na_Ca_exchanger (millimolar)');
    LEGEND_CONSTANTS(:,47) = strpad('gamma in component Na_Ca_exchanger (dimensionless)');
    LEGEND_ALGEBRAIC(:,91) = strpad('i_rel in component calcium_dynamics (millimolar_per_second)');
    LEGEND_ALGEBRAIC(:,92) = strpad('i_up in component calcium_dynamics (millimolar_per_second)');
    LEGEND_ALGEBRAIC(:,93) = strpad('i_leak in component calcium_dynamics (millimolar_per_second)');
    LEGEND_ALGEBRAIC(:,94) = strpad('i_tr in component calcium_dynamics (millimolar_per_second)');
    LEGEND_ALGEBRAIC(:,90) = strpad('G_rel in component calcium_dynamics (per_second)');
    LEGEND_CONSTANTS(:,48) = strpad('G_rel_max in component calcium_dynamics (per_second)');
    LEGEND_CONSTANTS(:,49) = strpad('G_rel_overload in component calcium_dynamics (per_second)');
    LEGEND_CONSTANTS(:,50) = strpad('tau_tr in component calcium_dynamics (second)');
    LEGEND_CONSTANTS(:,51) = strpad('K_mrel in component calcium_dynamics (millimolar)');
    LEGEND_CONSTANTS(:,52) = strpad('delta_Ca_ith in component calcium_dynamics (millimolar)');
    LEGEND_CONSTANTS(:,53) = strpad('CSQN_max in component calcium_dynamics (millimolar)');
    LEGEND_CONSTANTS(:,54) = strpad('K_mCSQN in component calcium_dynamics (millimolar)');
    LEGEND_CONSTANTS(:,55) = strpad('K_mup in component calcium_dynamics (millimolar)');
    LEGEND_CONSTANTS(:,74) = strpad('K_leak in component calcium_dynamics (per_second)');
    LEGEND_CONSTANTS(:,56) = strpad('I_up in component calcium_dynamics (millimolar_per_second)');
    LEGEND_CONSTANTS(:,57) = strpad('Ca_NSR_max in component calcium_dynamics (millimolar)');
    LEGEND_STATES(:,27) = strpad('Ca_JSR in component calcium_dynamics (millimolar)');
    LEGEND_STATES(:,28) = strpad('Ca_NSR in component calcium_dynamics (millimolar)');
    LEGEND_CONSTANTS(:,77) = strpad('V_myo in component ionic_concentrations (micro_litre)');
    LEGEND_CONSTANTS(:,58) = strpad('A_cap in component ionic_concentrations (mm2)');
    LEGEND_CONSTANTS(:,79) = strpad('V_JSR in component calcium_dynamics (micro_litre)');
    LEGEND_CONSTANTS(:,80) = strpad('V_NSR in component calcium_dynamics (micro_litre)');
    LEGEND_CONSTANTS(:,59) = strpad('K_mTn in component calcium_dynamics (millimolar)');
    LEGEND_CONSTANTS(:,60) = strpad('K_mCMDN in component calcium_dynamics (millimolar)');
    LEGEND_CONSTANTS(:,61) = strpad('Tn_max in component calcium_dynamics (millimolar)');
    LEGEND_CONSTANTS(:,62) = strpad('CMDN_max in component calcium_dynamics (millimolar)');
    LEGEND_STATES(:,29) = strpad('APtrack in component calcium_dynamics (dimensionless)');
    LEGEND_STATES(:,30) = strpad('APtrack2 in component calcium_dynamics (dimensionless)');
    LEGEND_STATES(:,31) = strpad('APtrack3 in component calcium_dynamics (dimensionless)');
    LEGEND_STATES(:,32) = strpad('Cainfluxtrack in component calcium_dynamics (dimensionless)');
    LEGEND_STATES(:,33) = strpad('OVRLDtrack in component calcium_dynamics (dimensionless)');
    LEGEND_STATES(:,34) = strpad('OVRLDtrack2 in component calcium_dynamics (dimensionless)');
    LEGEND_STATES(:,35) = strpad('OVRLDtrack3 in component calcium_dynamics (dimensionless)');
    LEGEND_CONSTANTS(:,63) = strpad('CSQNthresh in component calcium_dynamics (millimolar)');
    LEGEND_CONSTANTS(:,64) = strpad('Logicthresh in component calcium_dynamics (dimensionless)');
    LEGEND_CONSTANTS(:,65) = strpad('preplength in component ionic_concentrations (mm)');
    LEGEND_CONSTANTS(:,66) = strpad('radius in component ionic_concentrations (mm)');
    LEGEND_CONSTANTS(:,75) = strpad('volume in component ionic_concentrations (micro_litre)');
    LEGEND_RATES(:,1) = strpad('d/dt V in component membrane (millivolt)');
    LEGEND_RATES(:,6) = strpad('d/dt P_C3 in component Na_channel_states (dimensionless)');
    LEGEND_RATES(:,5) = strpad('d/dt P_C2 in component Na_channel_states (dimensionless)');
    LEGEND_RATES(:,4) = strpad('d/dt P_C1 in component Na_channel_states (dimensionless)');
    LEGEND_RATES(:,3) = strpad('d/dt P_O_Na in component Na_channel_states (dimensionless)');
    LEGEND_RATES(:,7) = strpad('d/dt P_IF in component Na_channel_states (dimensionless)');
    LEGEND_RATES(:,8) = strpad('d/dt P_IC3 in component Na_channel_states (dimensionless)');
    LEGEND_RATES(:,9) = strpad('d/dt P_IC2 in component Na_channel_states (dimensionless)');
    LEGEND_RATES(:,10) = strpad('d/dt P_IM1 in component Na_channel_states (dimensionless)');
    LEGEND_RATES(:,11) = strpad('d/dt P_IM2 in component Na_channel_states (dimensionless)');
    LEGEND_RATES(:,14) = strpad('d/dt d in component L_type_Ca_channel_d_gate (dimensionless)');
    LEGEND_RATES(:,15) = strpad('d/dt f in component L_type_Ca_channel_f_gate (dimensionless)');
    LEGEND_RATES(:,16) = strpad('d/dt b in component T_type_Ca_channel_b_gate (dimensionless)');
    LEGEND_RATES(:,17) = strpad('d/dt g in component T_type_Ca_channel_g_gate (dimensionless)');
    LEGEND_RATES(:,21) = strpad('d/dt P_C3 in component Kr_channel_states (dimensionless)');
    LEGEND_RATES(:,20) = strpad('d/dt P_C2 in component Kr_channel_states (dimensionless)');
    LEGEND_RATES(:,19) = strpad('d/dt P_C1 in component Kr_channel_states (dimensionless)');
    LEGEND_RATES(:,18) = strpad('d/dt P_O in component Kr_channel_states (dimensionless)');
    LEGEND_RATES(:,22) = strpad('d/dt P_I in component Kr_channel_states (dimensionless)');
    LEGEND_RATES(:,23) = strpad('d/dt xs1 in component slow_delayed_rectifier_potassium_current_xs1_gate (dimensionless)');
    LEGEND_RATES(:,24) = strpad('d/dt xs2 in component slow_delayed_rectifier_potassium_current_xs2_gate (dimensionless)');
    LEGEND_RATES(:,25) = strpad('d/dt zdv in component transient_outward_current_zdv_gate (dimensionless)');
    LEGEND_RATES(:,26) = strpad('d/dt ydv in component transient_outward_current_ydv_gate (dimensionless)');
    LEGEND_RATES(:,29) = strpad('d/dt APtrack in component calcium_dynamics (dimensionless)');
    LEGEND_RATES(:,30) = strpad('d/dt APtrack2 in component calcium_dynamics (dimensionless)');
    LEGEND_RATES(:,31) = strpad('d/dt APtrack3 in component calcium_dynamics (dimensionless)');
    LEGEND_RATES(:,32) = strpad('d/dt Cainfluxtrack in component calcium_dynamics (dimensionless)');
    LEGEND_RATES(:,33) = strpad('d/dt OVRLDtrack in component calcium_dynamics (dimensionless)');
    LEGEND_RATES(:,34) = strpad('d/dt OVRLDtrack2 in component calcium_dynamics (dimensionless)');
    LEGEND_RATES(:,35) = strpad('d/dt OVRLDtrack3 in component calcium_dynamics (dimensionless)');
    LEGEND_RATES(:,27) = strpad('d/dt Ca_JSR in component calcium_dynamics (millimolar)');
    LEGEND_RATES(:,28) = strpad('d/dt Ca_NSR in component calcium_dynamics (millimolar)');
    LEGEND_RATES(:,12) = strpad('d/dt Cai in component calcium_dynamics (millimolar)');
    LEGEND_RATES(:,2) = strpad('d/dt Nai in component ionic_concentrations (millimolar)');
    LEGEND_RATES(:,13) = strpad('d/dt Ki in component ionic_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) = -89.179;
    CONSTANTS(:,1) = 8314;
    CONSTANTS(:,2) = 310;
    CONSTANTS(:,3) = 96485;
    CONSTANTS(:,4) = 0.001;
    CONSTANTS(:,5) = 3;
    CONSTANTS(:,6) = 9;
    CONSTANTS(:,7) = 1;
    CONSTANTS(:,8) = 0.002;
    CONSTANTS(:,9) = -50;
    CONSTANTS(:,10) = 23.5;
    CONSTANTS(:,11) = 132;
    STATES(:,2) = 12.306;
    STATES(:,3) = 3.286e-13;
    STATES(:,4) = 4.376e-10;
    STATES(:,5) = 9.443e-8;
    STATES(:,6) = 7.645e-6;
    STATES(:,7) = 7.126e-11;
    STATES(:,8) = 1.245e-6;
    STATES(:,9) = 1.538e-8;
    STATES(:,10) = 7.977e-12;
    STATES(:,11) = 4.722e-14;
    CONSTANTS(:,12) = 0.75;
    CONSTANTS(:,13) = 0.75;
    CONSTANTS(:,14) = 0.75;
    CONSTANTS(:,15) = 0.75;
    CONSTANTS(:,16) = 0.00054;
    CONSTANTS(:,17) = 6.75e-7;
    CONSTANTS(:,18) = 1.93e-7;
    CONSTANTS(:,19) = 1;
    CONSTANTS(:,20) = 0.341;
    STATES(:,12) = 0.000123;
    CONSTANTS(:,21) = 1.8;
    CONSTANTS(:,22) = 4.5;
    STATES(:,13) = 140.22;
    STATES(:,14) = 3.085e-6;
    STATES(:,15) = 0.9998;
    CONSTANTS(:,23) = 0.0006;
    CONSTANTS(:,24) = 0.05;
    STATES(:,16) = 0.000947;
    STATES(:,17) = 0.99457;
    STATES(:,18) = 1.032e-10;
    STATES(:,19) = 3.2864e-8;
    STATES(:,20) = 1.63e-8;
    STATES(:,21) = 4.951e-6;
    STATES(:,22) = 3.135e-11;
    CONSTANTS(:,25) = 2172;
    CONSTANTS(:,26) = 1077;
    CONSTANTS(:,27) = 0.01833;
    STATES(:,23) = 0.00437;
    STATES(:,24) = 0.00437;
    CONSTANTS(:,28) = 0.00552;
    CONSTANTS(:,29) = 2.8;
    CONSTANTS(:,30) = 66;
    CONSTANTS(:,31) = 1;
    CONSTANTS(:,32) = 0.24;
    CONSTANTS(:,33) = 5e-5;
    CONSTANTS(:,34) = 3;
    CONSTANTS(:,35) = 2;
    CONSTANTS(:,36) = 0.00025;
    STATES(:,25) = 0.0114;
    STATES(:,26) = 0.99998;
    CONSTANTS(:,37) = 0.0005;
    CONSTANTS(:,38) = 1.15;
    CONSTANTS(:,39) = 0.004;
    CONSTANTS(:,40) = 0.003016;
    CONSTANTS(:,41) = 2.25;
    CONSTANTS(:,42) = 10;
    CONSTANTS(:,43) = 1.5;
    CONSTANTS(:,44) = 0.0012;
    CONSTANTS(:,45) = 0.00025;
    CONSTANTS(:,46) = 0.0001;
    CONSTANTS(:,47) = 0.15;
    CONSTANTS(:,48) = 60000;
    CONSTANTS(:,49) = 4000;
    CONSTANTS(:,50) = 0.18;
    CONSTANTS(:,51) = 0.0008;
    CONSTANTS(:,52) = 0.00018;
    CONSTANTS(:,53) = 10;
    CONSTANTS(:,54) = 0.8;
    CONSTANTS(:,55) = 0.00092;
    CONSTANTS(:,56) = 8.75;
    CONSTANTS(:,57) = 15;
    STATES(:,27) = 1.763;
    STATES(:,28) = 1.764;
    CONSTANTS(:,58) = 1.434e-7;
    CONSTANTS(:,59) = 0.0005;
    CONSTANTS(:,60) = 0.00238;
    CONSTANTS(:,61) = 0.07;
    CONSTANTS(:,62) = 0.05;
    STATES(:,29) = 0;
    STATES(:,30) = 0;
    STATES(:,31) = 0;
    STATES(:,32) = 0;
    STATES(:,33) = 0;
    STATES(:,34) = 0;
    STATES(:,35) = 0;
    CONSTANTS(:,63) = 0.7;
    CONSTANTS(:,64) = 0.98;
    CONSTANTS(:,65) = 0.001;
    CONSTANTS(:,66) = 1.1e-4;
    CONSTANTS(:,67) =  0.0135000.*power(CONSTANTS(:,22), 0.590000);
    CONSTANTS(:,68) =  0.750000.*power((CONSTANTS(:,22)./5.40000), 1.0 ./ 2);
    CONSTANTS(:,69) =  0.00000.*0.128480;
    CONSTANTS(:,70) = ( CONSTANTS(:,31).*0.000193000)./CONSTANTS(:,33);
    CONSTANTS(:,71) = 0.0500000;
    CONSTANTS(:,72) =  (1.00000./7.00000).*(exp(CONSTANTS(:,11)./67.3000) - 1.00000);
    CONSTANTS(:,73) =  0.00000.*1.75000e-07;
    CONSTANTS(:,74) = CONSTANTS(:,56)./CONSTANTS(:,57);
    CONSTANTS(:,75) =   pi.*CONSTANTS(:,65).*power(CONSTANTS(:,66), 2.00000);
    CONSTANTS(:,76) = 1.00000./(1.00000+power(CONSTANTS(:,34)./CONSTANTS(:,36), CONSTANTS(:,35)));
    CONSTANTS(:,77) =  0.680000.*CONSTANTS(:,75);
    CONSTANTS(:,78) =  CONSTANTS(:,70).*CONSTANTS(:,76).*power(CONSTANTS(:,22)./4.00000, CONSTANTS(:,32));
    CONSTANTS(:,79) =  (0.00480000./0.680000).*CONSTANTS(:,77);
    CONSTANTS(:,80) =  (0.0552000./0.680000).*CONSTANTS(:,77);
    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(:,30) = piecewise({STATES(:,29)<0.200000&STATES(:,29)>0.180000,  100000..*(1.00000 - STATES(:,30)) -  500.000.*STATES(:,30) },   - 500.000.*STATES(:,30));
    RATES(:,31) = piecewise({STATES(:,29)<0.200000&STATES(:,29)>0.180000,  100000..*(1.00000 - STATES(:,31)) -  500.000.*STATES(:,31) },   - 10.0000.*STATES(:,31));
    RATES(:,33) = piecewise({1.00000./(1.00000+CONSTANTS(:,54)./STATES(:,28))>CONSTANTS(:,63)&STATES(:,35)<0.370000&STATES(:,31)<0.370000,  50000.0.*(1.00000 - STATES(:,33)) },   - 500.000.*STATES(:,33));
    RATES(:,34) = piecewise({STATES(:,33)>CONSTANTS(:,64)&STATES(:,34)<CONSTANTS(:,64),  50000.0.*(1.00000 - STATES(:,34)) },   - 500.000.*STATES(:,34));
    RATES(:,35) = piecewise({STATES(:,33)>CONSTANTS(:,64)&STATES(:,35)<CONSTANTS(:,64),  50000.0.*(1.00000 - STATES(:,35)) },   - 10.0000.*STATES(:,35));
    ALGEBRAIC(:,4) = 1.00000./(1.00000+exp( - (STATES(:,1)+14.0000)./10.8000));
    ALGEBRAIC(:,16) = 0.00370000+0.00610000./(1.00000+exp((STATES(:,1)+25.0000)./4.50000));
    RATES(:,16) = (ALGEBRAIC(:,4) - STATES(:,16))./ALGEBRAIC(:,16);
    ALGEBRAIC(:,5) = 1.00000./(1.00000+exp((STATES(:,1)+60.0000)./5.60000));
    ALGEBRAIC(:,17) = piecewise({STATES(:,1)<=0.00000,   - 0.000875000.*STATES(:,1)+0.0120000 }, 0.0120000);
    RATES(:,17) = (ALGEBRAIC(:,5) - STATES(:,17))./ALGEBRAIC(:,17);
    ALGEBRAIC(:,6) =  55.5000.*exp( 0.0554715.*(STATES(:,1) - 12.0000));
    ALGEBRAIC(:,18) =  2.35700.*exp(  - 0.0365880.*STATES(:,1));
    RATES(:,21) =  ALGEBRAIC(:,18).*STATES(:,20) -  ALGEBRAIC(:,6).*STATES(:,21);
    RATES(:,20) =   - (ALGEBRAIC(:,18)+CONSTANTS(:,25)).*STATES(:,20)+ ALGEBRAIC(:,6).*STATES(:,21)+ CONSTANTS(:,26).*STATES(:,19);
    ALGEBRAIC(:,8) = 1.00000./(1.00000+exp( - (STATES(:,1) - 1.50000)./16.7000));
    ALGEBRAIC(:,20) = 0.00100000./(( 7.19000e-05.*(STATES(:,1)+30.0000))./(1.00000 - exp(  - 0.148000.*(STATES(:,1)+30.0000)))+( 0.000131000.*(STATES(:,1)+30.0000))./(exp( 0.0687000.*(STATES(:,1)+30.0000)) - 1.00000));
    RATES(:,23) = (ALGEBRAIC(:,8) - STATES(:,23))./ALGEBRAIC(:,20);
    ALGEBRAIC(:,9) = 1.00000./(1.00000+exp( - (STATES(:,1) - 1.50000)./16.7000));
    ALGEBRAIC(:,21) = ( 4.00000.*0.00100000)./(( 7.19000e-05.*(STATES(:,1)+30.0000))./(1.00000 - exp(  - 0.148000.*(STATES(:,1)+30.0000)))+( 0.000131000.*(STATES(:,1)+30.0000))./(exp( 0.0687000.*(STATES(:,1)+30.0000)) - 1.00000));
    RATES(:,24) = (ALGEBRAIC(:,9) - STATES(:,24))./ALGEBRAIC(:,21);
    ALGEBRAIC(:,3) = 1.00000./(1.00000+exp((STATES(:,1)+32.0000)./8.00000))+0.600000./(1.00000+exp((50.0000 - STATES(:,1))./20.0000));
    ALGEBRAIC(:,15) = 0.00100000./( 0.0197000.*exp( - power( 0.0337000.*(STATES(:,1)+10.0000), 2.00000))+0.0200000);
    ALGEBRAIC(:,27) = ALGEBRAIC(:,3)./ALGEBRAIC(:,15);
    ALGEBRAIC(:,34) = (1.00000 - ALGEBRAIC(:,3))./ALGEBRAIC(:,15);
    RATES(:,15) =  ALGEBRAIC(:,27).*(1.00000 - STATES(:,15)) -  ALGEBRAIC(:,34).*STATES(:,15);
    ALGEBRAIC(:,7) =  65.5000.*exp( 0.0554715.*(STATES(:,1) - 36.0000));
    ALGEBRAIC(:,19) =  2.93570.*exp(  - 0.0215800.*STATES(:,1));
    ALGEBRAIC(:,28) = ( 439.000.*exp(  - 0.0235200.*(STATES(:,1)+25.0000)).*4.50000)./CONSTANTS(:,22);
    ALGEBRAIC(:,35) = ( 656.000.*exp( 0.000942000.*STATES(:,1)).*power(4.50000, 0.300000))./power(CONSTANTS(:,22), 0.300000);
    RATES(:,18) =   - (ALGEBRAIC(:,19)+ALGEBRAIC(:,35)).*STATES(:,18)+ ALGEBRAIC(:,7).*STATES(:,19)+ ALGEBRAIC(:,28).*STATES(:,22);
    ALGEBRAIC(:,10) = ( 10000.0.*exp((STATES(:,1) - 40.0000)./25.0000))./(1.00000+exp((STATES(:,1) - 40.0000)./25.0000));
    ALGEBRAIC(:,22) = ( 10000.0.*exp( - (STATES(:,1)+90.0000)./25.0000))./(1.00000+exp( - (STATES(:,1)+90.0000)./25.0000));
    ALGEBRAIC(:,29) = 1.00000./(ALGEBRAIC(:,10)+ALGEBRAIC(:,22));
    ALGEBRAIC(:,36) = ALGEBRAIC(:,10)./(ALGEBRAIC(:,10)+ALGEBRAIC(:,22));
    RATES(:,25) = (ALGEBRAIC(:,36) - STATES(:,25))./ALGEBRAIC(:,29);
    ALGEBRAIC(:,11) = 15.0000./(1.00000+exp((STATES(:,1)+60.0000)./5.00000));
    ALGEBRAIC(:,23) = ( 100.000.*exp((STATES(:,1)+25.0000)./5.00000))./(1.00000+exp((STATES(:,1)+25.0000)./5.00000));
    ALGEBRAIC(:,30) = 1.00000./(ALGEBRAIC(:,11)+ALGEBRAIC(:,23));
    ALGEBRAIC(:,37) = ALGEBRAIC(:,11)./(ALGEBRAIC(:,11)+ALGEBRAIC(:,23));
    RATES(:,26) = (ALGEBRAIC(:,37) - STATES(:,26))./ALGEBRAIC(:,30);
    ALGEBRAIC(:,2) = STATES(:,1)+10.0000;
    ALGEBRAIC(:,14) = 1.00000./(1.00000+exp( - ALGEBRAIC(:,2)./6.24000));
    ALGEBRAIC(:,26) = piecewise({abs(ALGEBRAIC(:,2))<1.00000e-05, 0.00100000./( 0.0350000.*6.24000) }, ( 0.00100000.*ALGEBRAIC(:,14).*(1.00000 - exp( - ALGEBRAIC(:,2)./6.24000)))./( 0.0350000.*ALGEBRAIC(:,2)));
    ALGEBRAIC(:,33) = ALGEBRAIC(:,14)./ALGEBRAIC(:,26);
    ALGEBRAIC(:,40) = (1.00000 - ALGEBRAIC(:,14))./ALGEBRAIC(:,26);
    RATES(:,14) =  ALGEBRAIC(:,33).*(1.00000 - STATES(:,14)) -  ALGEBRAIC(:,40).*STATES(:,14);
    ALGEBRAIC(:,41) = ( ALGEBRAIC(:,28).*ALGEBRAIC(:,19).*ALGEBRAIC(:,7))./( ALGEBRAIC(:,7).*ALGEBRAIC(:,35));
    RATES(:,19) =   - (CONSTANTS(:,26)+ALGEBRAIC(:,7)+ALGEBRAIC(:,7)).*STATES(:,19)+ CONSTANTS(:,25).*STATES(:,20)+ ALGEBRAIC(:,19).*STATES(:,18)+ ALGEBRAIC(:,41).*STATES(:,22);
    RATES(:,22) =   - (ALGEBRAIC(:,41)+ALGEBRAIC(:,28)).*STATES(:,22)+ ALGEBRAIC(:,7).*STATES(:,19)+ ALGEBRAIC(:,35).*STATES(:,18);
    ALGEBRAIC(:,1) = 3802.00./( 0.102700.*exp( - STATES(:,1)./17.0000)+ 0.200000.*exp( - STATES(:,1)./150.000));
    ALGEBRAIC(:,32) =  191.700.*exp( - STATES(:,1)./20.3000);
    ALGEBRAIC(:,47) =  0.000379330.*exp( - STATES(:,1)./7.70000);
    ALGEBRAIC(:,49) = 8.40000+ 0.0200000.*STATES(:,1);
    RATES(:,6) =   - (ALGEBRAIC(:,49)+ALGEBRAIC(:,1)).*STATES(:,6)+ ALGEBRAIC(:,47).*STATES(:,8)+ ALGEBRAIC(:,32).*STATES(:,5);
    ALGEBRAIC(:,13) = 3802.00./( 0.102700.*exp( - STATES(:,1)./15.0000)+ 0.230000.*exp( - STATES(:,1)./150.000));
    ALGEBRAIC(:,39) =  200.000.*exp( - (STATES(:,1) - 5.00000)./20.3000);
    RATES(:,5) =   - (ALGEBRAIC(:,32)+ALGEBRAIC(:,49)+ALGEBRAIC(:,13)).*STATES(:,5)+ ALGEBRAIC(:,1).*STATES(:,6)+ ALGEBRAIC(:,39).*STATES(:,4)+ ALGEBRAIC(:,47).*STATES(:,9);
    ALGEBRAIC(:,25) = 3802.00./( 0.102700.*exp( - STATES(:,1)./12.0000)+ 0.250000.*exp( - STATES(:,1)./150.000));
    ALGEBRAIC(:,43) =  220.000.*exp( - (STATES(:,1) - 10.0000)./20.3000);
    RATES(:,4) =   - (ALGEBRAIC(:,39)+ALGEBRAIC(:,25)+ALGEBRAIC(:,49)).*STATES(:,4)+ ALGEBRAIC(:,13).*STATES(:,5)+ ALGEBRAIC(:,43).*STATES(:,3)+ ALGEBRAIC(:,47).*STATES(:,7);
    RATES(:,8) =   - (ALGEBRAIC(:,47)+ALGEBRAIC(:,1)).*STATES(:,8)+ ALGEBRAIC(:,49).*STATES(:,6)+ ALGEBRAIC(:,32).*STATES(:,9);
    RATES(:,9) =   - (ALGEBRAIC(:,47)+ALGEBRAIC(:,13)+ALGEBRAIC(:,32)).*STATES(:,9)+ ALGEBRAIC(:,49).*STATES(:,5)+ ALGEBRAIC(:,39).*STATES(:,7)+ ALGEBRAIC(:,1).*STATES(:,8);
    ALGEBRAIC(:,45) =  9178.00.*exp(STATES(:,1)./29.6800);
    ALGEBRAIC(:,51) = ( ALGEBRAIC(:,25).*ALGEBRAIC(:,45).*ALGEBRAIC(:,47))./( ALGEBRAIC(:,43).*ALGEBRAIC(:,49));
    RATES(:,3) =   - (ALGEBRAIC(:,45)+ALGEBRAIC(:,43)).*STATES(:,3)+ ALGEBRAIC(:,51).*STATES(:,7)+ ALGEBRAIC(:,25).*STATES(:,4);
    ALGEBRAIC(:,53) = ALGEBRAIC(:,45)./100.000;
    ALGEBRAIC(:,55) = ALGEBRAIC(:,47);
    RATES(:,7) =   - (ALGEBRAIC(:,51)+ALGEBRAIC(:,47)+ALGEBRAIC(:,53)+ALGEBRAIC(:,39)).*STATES(:,7)+ ALGEBRAIC(:,49).*STATES(:,4)+ ALGEBRAIC(:,55).*STATES(:,10)+ ALGEBRAIC(:,45).*STATES(:,3)+ ALGEBRAIC(:,13).*STATES(:,9);
    ALGEBRAIC(:,57) = ALGEBRAIC(:,45)./95000.0;
    ALGEBRAIC(:,59) = ALGEBRAIC(:,47)./50.0000;
    RATES(:,10) =   - (ALGEBRAIC(:,57)+ALGEBRAIC(:,55)).*STATES(:,10)+ ALGEBRAIC(:,59).*STATES(:,11)+ ALGEBRAIC(:,53).*STATES(:,7);
    RATES(:,11) =  ALGEBRAIC(:,57).*STATES(:,10) -  ALGEBRAIC(:,59).*STATES(:,11);
    ALGEBRAIC(:,56) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,22)./STATES(:,13));
    ALGEBRAIC(:,58) =  CONSTANTS(:,67).*STATES(:,18).*(STATES(:,1) - ALGEBRAIC(:,56));
    ALGEBRAIC(:,61) =  0.968000.*0.433000.*(1.00000+0.600000./(1.00000+power(3.80000e-05./STATES(:,12), 1.40000)));
    ALGEBRAIC(:,60) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log((CONSTANTS(:,22)+ CONSTANTS(:,27).*CONSTANTS(:,11))./(STATES(:,13)+ CONSTANTS(:,27).*STATES(:,2)));
    ALGEBRAIC(:,62) =  ALGEBRAIC(:,61).*STATES(:,23).*STATES(:,24).*(STATES(:,1) - ALGEBRAIC(:,60));
    ALGEBRAIC(:,63) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,22)./STATES(:,13));
    ALGEBRAIC(:,70) = 0.850000./(1.00000+power(CONSTANTS(:,30)./STATES(:,2), CONSTANTS(:,29)));
    ALGEBRAIC(:,71) = 0.800000 - 0.650000./(1.00000+exp((STATES(:,1)+125.000)./15.0000));
    ALGEBRAIC(:,72) =  CONSTANTS(:,69).*ALGEBRAIC(:,70).*ALGEBRAIC(:,71).*(STATES(:,1) - ALGEBRAIC(:,63));
    ALGEBRAIC(:,73) =  CONSTANTS(:,78).*(STATES(:,1) - ALGEBRAIC(:,63));
    ALGEBRAIC(:,74) = exp(STATES(:,1)./100.000);
    ALGEBRAIC(:,75) =  CONSTANTS(:,71).*power(STATES(:,25), 3.00000).*STATES(:,26).*ALGEBRAIC(:,74).*(STATES(:,1) - ALGEBRAIC(:,63));
    ALGEBRAIC(:,64) = 1020.00./(1.00000+exp( 0.238500.*((STATES(:,1) - ALGEBRAIC(:,63)) - 59.2150)));
    ALGEBRAIC(:,65) = ( 1000.00.*( 0.491240.*exp( 0.0803200.*((STATES(:,1) - ALGEBRAIC(:,63))+5.47600))+exp( 0.0617500.*((STATES(:,1) - ALGEBRAIC(:,63)) - 594.310))))./(1.00000+exp(  - 0.514300.*((STATES(:,1) - ALGEBRAIC(:,63))+4.75300)));
    ALGEBRAIC(:,66) = ALGEBRAIC(:,64)./(ALGEBRAIC(:,64)+ALGEBRAIC(:,65));
    ALGEBRAIC(:,67) =  CONSTANTS(:,68).*ALGEBRAIC(:,66).*(STATES(:,1) - ALGEBRAIC(:,63));
    ALGEBRAIC(:,68) = 1.00000./(1.00000+exp((7.48800 - STATES(:,1))./5.98000));
    ALGEBRAIC(:,69) =  CONSTANTS(:,28).*ALGEBRAIC(:,68).*(STATES(:,1) - ALGEBRAIC(:,63));
    ALGEBRAIC(:,81) = 1.00000./(1.00000+ 0.124500.*exp((  - 0.100000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))+ 0.0365000.*CONSTANTS(:,72).*exp((  - STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,82) = ( (( CONSTANTS(:,41).*ALGEBRAIC(:,81).*1.00000)./(1.00000+power(CONSTANTS(:,42)./STATES(:,2), 2.00000))).*CONSTANTS(:,22))./(CONSTANTS(:,22)+CONSTANTS(:,43));
    ALGEBRAIC(:,44) = ( (( CONSTANTS(:,18).*power(1.00000, 2.00000).*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( CONSTANTS(:,14).*STATES(:,13).*exp(( 1.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,15).*CONSTANTS(:,22)))./(exp(( 1.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000);
    ALGEBRAIC(:,46) = 1.00000./(1.00000+STATES(:,12)./CONSTANTS(:,23));
    ALGEBRAIC(:,52) =  STATES(:,14).*STATES(:,15).*ALGEBRAIC(:,46).*ALGEBRAIC(:,44);
    ALGEBRAIC(:,84) = ( (( CONSTANTS(:,73).*power(1.00000, 2.00000).*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( CONSTANTS(:,14).*STATES(:,13).*exp(( 1.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,15).*CONSTANTS(:,22)))./(exp(( 1.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000);
    ALGEBRAIC(:,86) = ( ALGEBRAIC(:,84).*1.00000)./(1.00000+power(CONSTANTS(:,44)./STATES(:,12), 3.00000));
    RATES(:,13) = (  - (ALGEBRAIC(:,52)+ALGEBRAIC(:,58)+ALGEBRAIC(:,62)+ALGEBRAIC(:,67)+ALGEBRAIC(:,69)+ALGEBRAIC(:,72)+ALGEBRAIC(:,73)+ALGEBRAIC(:,75)+ALGEBRAIC(:,86)+  - ALGEBRAIC(:,82).*2.00000).*CONSTANTS(:,58))./( CONSTANTS(:,77).*CONSTANTS(:,3));
    ALGEBRAIC(:,12) = piecewise({VOI>=CONSTANTS(:,5)&VOI<=CONSTANTS(:,6)&(VOI - CONSTANTS(:,5)) -  floor((VOI - CONSTANTS(:,5))./CONSTANTS(:,7)).*CONSTANTS(:,7)<=CONSTANTS(:,8), CONSTANTS(:,9) }, 0.00000);
    ALGEBRAIC(:,24) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,11)./STATES(:,2));
    ALGEBRAIC(:,31) =  CONSTANTS(:,10).*STATES(:,3).*(STATES(:,1) - ALGEBRAIC(:,24));
    ALGEBRAIC(:,38) = ( (( CONSTANTS(:,16).*power(2.00000, 2.00000).*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( CONSTANTS(:,19).*STATES(:,12).*exp(( 2.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,20).*CONSTANTS(:,21)))./(exp(( 2.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000);
    ALGEBRAIC(:,48) =  STATES(:,14).*STATES(:,15).*ALGEBRAIC(:,46).*ALGEBRAIC(:,38);
    ALGEBRAIC(:,42) = ( (( CONSTANTS(:,17).*power(1.00000, 2.00000).*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( CONSTANTS(:,12).*STATES(:,2).*exp(( 1.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,13).*CONSTANTS(:,11)))./(exp(( 1.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000);
    ALGEBRAIC(:,50) =  STATES(:,14).*STATES(:,15).*ALGEBRAIC(:,46).*ALGEBRAIC(:,42);
    ALGEBRAIC(:,54) = ALGEBRAIC(:,48)+ALGEBRAIC(:,52)+ALGEBRAIC(:,50);
    ALGEBRAIC(:,78) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./( 2.00000.*CONSTANTS(:,3))).*log(CONSTANTS(:,21)./STATES(:,12));
    ALGEBRAIC(:,79) =  CONSTANTS(:,24).*STATES(:,16).*STATES(:,16).*STATES(:,17).*(STATES(:,1) - ALGEBRAIC(:,78));
    ALGEBRAIC(:,88) = ( CONSTANTS(:,45).*exp(( (CONSTANTS(:,47) - 1.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(STATES(:,2), 3.00000).*CONSTANTS(:,21) -  power(CONSTANTS(:,11), 3.00000).*STATES(:,12)))./(1.00000+ CONSTANTS(:,46).*exp(( (CONSTANTS(:,47) - 1.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(STATES(:,2), 3.00000).*CONSTANTS(:,21)+ power(CONSTANTS(:,11), 3.00000).*STATES(:,12)));
    ALGEBRAIC(:,76) = ( CONSTANTS(:,38).*STATES(:,12))./(CONSTANTS(:,37)+STATES(:,12));
    ALGEBRAIC(:,77) =  CONSTANTS(:,39).*(STATES(:,1) - ALGEBRAIC(:,24));
    ALGEBRAIC(:,80) =  CONSTANTS(:,40).*(STATES(:,1) - ALGEBRAIC(:,78));
    ALGEBRAIC(:,83) = ( (( CONSTANTS(:,73).*power(1.00000, 2.00000).*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( CONSTANTS(:,12).*STATES(:,2).*exp(( 1.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,13).*CONSTANTS(:,11)))./(exp(( 1.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000);
    ALGEBRAIC(:,85) = ( ALGEBRAIC(:,83).*1.00000)./(1.00000+power(CONSTANTS(:,44)./STATES(:,12), 3.00000));
    ALGEBRAIC(:,87) = ALGEBRAIC(:,85)+ALGEBRAIC(:,86);
    RATES(:,1) =  ( - 1.00000./CONSTANTS(:,4)).*(ALGEBRAIC(:,31)+ALGEBRAIC(:,54)+ALGEBRAIC(:,79)+ALGEBRAIC(:,58)+ALGEBRAIC(:,62)+ALGEBRAIC(:,72)+ALGEBRAIC(:,73)+ALGEBRAIC(:,75)+ALGEBRAIC(:,67)+ALGEBRAIC(:,69)+ALGEBRAIC(:,88)+ALGEBRAIC(:,76)+ALGEBRAIC(:,77)+ALGEBRAIC(:,80)+ALGEBRAIC(:,82)+ALGEBRAIC(:,87)+ALGEBRAIC(:,12));
    RATES(:,32) = piecewise({STATES(:,29)>0.200000, (  - CONSTANTS(:,58).*(((ALGEBRAIC(:,48)+ALGEBRAIC(:,79)) - ALGEBRAIC(:,88))+ALGEBRAIC(:,76)+ALGEBRAIC(:,80)))./( 2.00000.*CONSTANTS(:,77).*CONSTANTS(:,3)) , STATES(:,30)>0.0100000&STATES(:,29)<=0.200000, 0.00000 },   - 500.000.*STATES(:,32));
    RATES(:,2) = (  - (ALGEBRAIC(:,31)+ALGEBRAIC(:,50)+ALGEBRAIC(:,77)+ALGEBRAIC(:,85)+ ALGEBRAIC(:,88).*3.00000+ ALGEBRAIC(:,82).*3.00000).*CONSTANTS(:,58))./( CONSTANTS(:,77).*CONSTANTS(:,3));
    ALGEBRAIC(:,89) =  ( - 1.00000./CONSTANTS(:,4)).*(ALGEBRAIC(:,31)+ALGEBRAIC(:,54)+ALGEBRAIC(:,79)+ALGEBRAIC(:,58)+ALGEBRAIC(:,62)+ALGEBRAIC(:,72)+ALGEBRAIC(:,73)+ALGEBRAIC(:,75)+ALGEBRAIC(:,67)+ALGEBRAIC(:,69)+ALGEBRAIC(:,88)+ALGEBRAIC(:,76)+ALGEBRAIC(:,77)+ALGEBRAIC(:,80)+ALGEBRAIC(:,82)+ALGEBRAIC(:,87)+ALGEBRAIC(:,12));
    RATES(:,29) = piecewise({ALGEBRAIC(:,89)>150000.,  100000..*(1.00000 - STATES(:,29)) -  500.000.*STATES(:,29) },   - 500.000.*STATES(:,29));
    ALGEBRAIC(:,90) = piecewise({STATES(:,32)>CONSTANTS(:,52),  (( CONSTANTS(:,48).*(STATES(:,32) - CONSTANTS(:,52)))./((CONSTANTS(:,51)+STATES(:,32)) - CONSTANTS(:,52))).*(1.00000 - STATES(:,30)).*STATES(:,30) , STATES(:,32)<=CONSTANTS(:,52)&STATES(:,34)>0.00000,  CONSTANTS(:,49).*(1.00000 - STATES(:,34)).*STATES(:,34) }, 0.00000);
    ALGEBRAIC(:,91) =  ALGEBRAIC(:,90).*(STATES(:,27) - STATES(:,12));
    ALGEBRAIC(:,92) = ( CONSTANTS(:,56).*STATES(:,12))./(STATES(:,12)+CONSTANTS(:,55));
    ALGEBRAIC(:,93) =  CONSTANTS(:,74).*STATES(:,28);
    RATES(:,12) =  (1.00000./(1.00000+( CONSTANTS(:,62).*CONSTANTS(:,60))./power(CONSTANTS(:,60)+STATES(:,12), 2.00000)+( CONSTANTS(:,61).*CONSTANTS(:,59))./power(CONSTANTS(:,59)+STATES(:,12), 2.00000))).*((  - CONSTANTS(:,58).*(((ALGEBRAIC(:,48)+ALGEBRAIC(:,79)) -  2.00000.*ALGEBRAIC(:,88))+ALGEBRAIC(:,76)+ALGEBRAIC(:,80)))./( 2.00000.*CONSTANTS(:,77).*CONSTANTS(:,3))+( ALGEBRAIC(:,91).*CONSTANTS(:,79))./CONSTANTS(:,77)+( (ALGEBRAIC(:,93) - ALGEBRAIC(:,92)).*CONSTANTS(:,80))./CONSTANTS(:,77));
    ALGEBRAIC(:,94) = (STATES(:,28) - STATES(:,27))./CONSTANTS(:,50);
    RATES(:,27) =  (1.00000./(1.00000+( CONSTANTS(:,53).*CONSTANTS(:,54))./power(CONSTANTS(:,54)+STATES(:,27), 2.00000))).*(ALGEBRAIC(:,94) - ALGEBRAIC(:,91));
    RATES(:,28) = ((  - ALGEBRAIC(:,94).*CONSTANTS(:,79))./CONSTANTS(:,80) - ALGEBRAIC(:,93))+ALGEBRAIC(:,92);
   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(:,4) = 1.00000./(1.00000+exp( - (STATES(:,1)+14.0000)./10.8000));
    ALGEBRAIC(:,16) = 0.00370000+0.00610000./(1.00000+exp((STATES(:,1)+25.0000)./4.50000));
    ALGEBRAIC(:,5) = 1.00000./(1.00000+exp((STATES(:,1)+60.0000)./5.60000));
    ALGEBRAIC(:,17) = piecewise({STATES(:,1)<=0.00000,   - 0.000875000.*STATES(:,1)+0.0120000 }, 0.0120000);
    ALGEBRAIC(:,6) =  55.5000.*exp( 0.0554715.*(STATES(:,1) - 12.0000));
    ALGEBRAIC(:,18) =  2.35700.*exp(  - 0.0365880.*STATES(:,1));
    ALGEBRAIC(:,8) = 1.00000./(1.00000+exp( - (STATES(:,1) - 1.50000)./16.7000));
    ALGEBRAIC(:,20) = 0.00100000./(( 7.19000e-05.*(STATES(:,1)+30.0000))./(1.00000 - exp(  - 0.148000.*(STATES(:,1)+30.0000)))+( 0.000131000.*(STATES(:,1)+30.0000))./(exp( 0.0687000.*(STATES(:,1)+30.0000)) - 1.00000));
    ALGEBRAIC(:,9) = 1.00000./(1.00000+exp( - (STATES(:,1) - 1.50000)./16.7000));
    ALGEBRAIC(:,21) = ( 4.00000.*0.00100000)./(( 7.19000e-05.*(STATES(:,1)+30.0000))./(1.00000 - exp(  - 0.148000.*(STATES(:,1)+30.0000)))+( 0.000131000.*(STATES(:,1)+30.0000))./(exp( 0.0687000.*(STATES(:,1)+30.0000)) - 1.00000));
    ALGEBRAIC(:,3) = 1.00000./(1.00000+exp((STATES(:,1)+32.0000)./8.00000))+0.600000./(1.00000+exp((50.0000 - STATES(:,1))./20.0000));
    ALGEBRAIC(:,15) = 0.00100000./( 0.0197000.*exp( - power( 0.0337000.*(STATES(:,1)+10.0000), 2.00000))+0.0200000);
    ALGEBRAIC(:,27) = ALGEBRAIC(:,3)./ALGEBRAIC(:,15);
    ALGEBRAIC(:,34) = (1.00000 - ALGEBRAIC(:,3))./ALGEBRAIC(:,15);
    ALGEBRAIC(:,7) =  65.5000.*exp( 0.0554715.*(STATES(:,1) - 36.0000));
    ALGEBRAIC(:,19) =  2.93570.*exp(  - 0.0215800.*STATES(:,1));
    ALGEBRAIC(:,28) = ( 439.000.*exp(  - 0.0235200.*(STATES(:,1)+25.0000)).*4.50000)./CONSTANTS(:,22);
    ALGEBRAIC(:,35) = ( 656.000.*exp( 0.000942000.*STATES(:,1)).*power(4.50000, 0.300000))./power(CONSTANTS(:,22), 0.300000);
    ALGEBRAIC(:,10) = ( 10000.0.*exp((STATES(:,1) - 40.0000)./25.0000))./(1.00000+exp((STATES(:,1) - 40.0000)./25.0000));
    ALGEBRAIC(:,22) = ( 10000.0.*exp( - (STATES(:,1)+90.0000)./25.0000))./(1.00000+exp( - (STATES(:,1)+90.0000)./25.0000));
    ALGEBRAIC(:,29) = 1.00000./(ALGEBRAIC(:,10)+ALGEBRAIC(:,22));
    ALGEBRAIC(:,36) = ALGEBRAIC(:,10)./(ALGEBRAIC(:,10)+ALGEBRAIC(:,22));
    ALGEBRAIC(:,11) = 15.0000./(1.00000+exp((STATES(:,1)+60.0000)./5.00000));
    ALGEBRAIC(:,23) = ( 100.000.*exp((STATES(:,1)+25.0000)./5.00000))./(1.00000+exp((STATES(:,1)+25.0000)./5.00000));
    ALGEBRAIC(:,30) = 1.00000./(ALGEBRAIC(:,11)+ALGEBRAIC(:,23));
    ALGEBRAIC(:,37) = ALGEBRAIC(:,11)./(ALGEBRAIC(:,11)+ALGEBRAIC(:,23));
    ALGEBRAIC(:,2) = STATES(:,1)+10.0000;
    ALGEBRAIC(:,14) = 1.00000./(1.00000+exp( - ALGEBRAIC(:,2)./6.24000));
    ALGEBRAIC(:,26) = piecewise({abs(ALGEBRAIC(:,2))<1.00000e-05, 0.00100000./( 0.0350000.*6.24000) }, ( 0.00100000.*ALGEBRAIC(:,14).*(1.00000 - exp( - ALGEBRAIC(:,2)./6.24000)))./( 0.0350000.*ALGEBRAIC(:,2)));
    ALGEBRAIC(:,33) = ALGEBRAIC(:,14)./ALGEBRAIC(:,26);
    ALGEBRAIC(:,40) = (1.00000 - ALGEBRAIC(:,14))./ALGEBRAIC(:,26);
    ALGEBRAIC(:,41) = ( ALGEBRAIC(:,28).*ALGEBRAIC(:,19).*ALGEBRAIC(:,7))./( ALGEBRAIC(:,7).*ALGEBRAIC(:,35));
    ALGEBRAIC(:,1) = 3802.00./( 0.102700.*exp( - STATES(:,1)./17.0000)+ 0.200000.*exp( - STATES(:,1)./150.000));
    ALGEBRAIC(:,32) =  191.700.*exp( - STATES(:,1)./20.3000);
    ALGEBRAIC(:,47) =  0.000379330.*exp( - STATES(:,1)./7.70000);
    ALGEBRAIC(:,49) = 8.40000+ 0.0200000.*STATES(:,1);
    ALGEBRAIC(:,13) = 3802.00./( 0.102700.*exp( - STATES(:,1)./15.0000)+ 0.230000.*exp( - STATES(:,1)./150.000));
    ALGEBRAIC(:,39) =  200.000.*exp( - (STATES(:,1) - 5.00000)./20.3000);
    ALGEBRAIC(:,25) = 3802.00./( 0.102700.*exp( - STATES(:,1)./12.0000)+ 0.250000.*exp( - STATES(:,1)./150.000));
    ALGEBRAIC(:,43) =  220.000.*exp( - (STATES(:,1) - 10.0000)./20.3000);
    ALGEBRAIC(:,45) =  9178.00.*exp(STATES(:,1)./29.6800);
    ALGEBRAIC(:,51) = ( ALGEBRAIC(:,25).*ALGEBRAIC(:,45).*ALGEBRAIC(:,47))./( ALGEBRAIC(:,43).*ALGEBRAIC(:,49));
    ALGEBRAIC(:,53) = ALGEBRAIC(:,45)./100.000;
    ALGEBRAIC(:,55) = ALGEBRAIC(:,47);
    ALGEBRAIC(:,57) = ALGEBRAIC(:,45)./95000.0;
    ALGEBRAIC(:,59) = ALGEBRAIC(:,47)./50.0000;
    ALGEBRAIC(:,56) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,22)./STATES(:,13));
    ALGEBRAIC(:,58) =  CONSTANTS(:,67).*STATES(:,18).*(STATES(:,1) - ALGEBRAIC(:,56));
    ALGEBRAIC(:,61) =  0.968000.*0.433000.*(1.00000+0.600000./(1.00000+power(3.80000e-05./STATES(:,12), 1.40000)));
    ALGEBRAIC(:,60) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log((CONSTANTS(:,22)+ CONSTANTS(:,27).*CONSTANTS(:,11))./(STATES(:,13)+ CONSTANTS(:,27).*STATES(:,2)));
    ALGEBRAIC(:,62) =  ALGEBRAIC(:,61).*STATES(:,23).*STATES(:,24).*(STATES(:,1) - ALGEBRAIC(:,60));
    ALGEBRAIC(:,63) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,22)./STATES(:,13));
    ALGEBRAIC(:,70) = 0.850000./(1.00000+power(CONSTANTS(:,30)./STATES(:,2), CONSTANTS(:,29)));
    ALGEBRAIC(:,71) = 0.800000 - 0.650000./(1.00000+exp((STATES(:,1)+125.000)./15.0000));
    ALGEBRAIC(:,72) =  CONSTANTS(:,69).*ALGEBRAIC(:,70).*ALGEBRAIC(:,71).*(STATES(:,1) - ALGEBRAIC(:,63));
    ALGEBRAIC(:,73) =  CONSTANTS(:,78).*(STATES(:,1) - ALGEBRAIC(:,63));
    ALGEBRAIC(:,74) = exp(STATES(:,1)./100.000);
    ALGEBRAIC(:,75) =  CONSTANTS(:,71).*power(STATES(:,25), 3.00000).*STATES(:,26).*ALGEBRAIC(:,74).*(STATES(:,1) - ALGEBRAIC(:,63));
    ALGEBRAIC(:,64) = 1020.00./(1.00000+exp( 0.238500.*((STATES(:,1) - ALGEBRAIC(:,63)) - 59.2150)));
    ALGEBRAIC(:,65) = ( 1000.00.*( 0.491240.*exp( 0.0803200.*((STATES(:,1) - ALGEBRAIC(:,63))+5.47600))+exp( 0.0617500.*((STATES(:,1) - ALGEBRAIC(:,63)) - 594.310))))./(1.00000+exp(  - 0.514300.*((STATES(:,1) - ALGEBRAIC(:,63))+4.75300)));
    ALGEBRAIC(:,66) = ALGEBRAIC(:,64)./(ALGEBRAIC(:,64)+ALGEBRAIC(:,65));
    ALGEBRAIC(:,67) =  CONSTANTS(:,68).*ALGEBRAIC(:,66).*(STATES(:,1) - ALGEBRAIC(:,63));
    ALGEBRAIC(:,68) = 1.00000./(1.00000+exp((7.48800 - STATES(:,1))./5.98000));
    ALGEBRAIC(:,69) =  CONSTANTS(:,28).*ALGEBRAIC(:,68).*(STATES(:,1) - ALGEBRAIC(:,63));
    ALGEBRAIC(:,81) = 1.00000./(1.00000+ 0.124500.*exp((  - 0.100000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))+ 0.0365000.*CONSTANTS(:,72).*exp((  - STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,82) = ( (( CONSTANTS(:,41).*ALGEBRAIC(:,81).*1.00000)./(1.00000+power(CONSTANTS(:,42)./STATES(:,2), 2.00000))).*CONSTANTS(:,22))./(CONSTANTS(:,22)+CONSTANTS(:,43));
    ALGEBRAIC(:,44) = ( (( CONSTANTS(:,18).*power(1.00000, 2.00000).*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( CONSTANTS(:,14).*STATES(:,13).*exp(( 1.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,15).*CONSTANTS(:,22)))./(exp(( 1.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000);
    ALGEBRAIC(:,46) = 1.00000./(1.00000+STATES(:,12)./CONSTANTS(:,23));
    ALGEBRAIC(:,52) =  STATES(:,14).*STATES(:,15).*ALGEBRAIC(:,46).*ALGEBRAIC(:,44);
    ALGEBRAIC(:,84) = ( (( CONSTANTS(:,73).*power(1.00000, 2.00000).*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( CONSTANTS(:,14).*STATES(:,13).*exp(( 1.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,15).*CONSTANTS(:,22)))./(exp(( 1.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000);
    ALGEBRAIC(:,86) = ( ALGEBRAIC(:,84).*1.00000)./(1.00000+power(CONSTANTS(:,44)./STATES(:,12), 3.00000));
    ALGEBRAIC(:,12) = piecewise({VOI>=CONSTANTS(:,5)&VOI<=CONSTANTS(:,6)&(VOI - CONSTANTS(:,5)) -  floor((VOI - CONSTANTS(:,5))./CONSTANTS(:,7)).*CONSTANTS(:,7)<=CONSTANTS(:,8), CONSTANTS(:,9) }, 0.00000);
    ALGEBRAIC(:,24) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,11)./STATES(:,2));
    ALGEBRAIC(:,31) =  CONSTANTS(:,10).*STATES(:,3).*(STATES(:,1) - ALGEBRAIC(:,24));
    ALGEBRAIC(:,38) = ( (( CONSTANTS(:,16).*power(2.00000, 2.00000).*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( CONSTANTS(:,19).*STATES(:,12).*exp(( 2.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,20).*CONSTANTS(:,21)))./(exp(( 2.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000);
    ALGEBRAIC(:,48) =  STATES(:,14).*STATES(:,15).*ALGEBRAIC(:,46).*ALGEBRAIC(:,38);
    ALGEBRAIC(:,42) = ( (( CONSTANTS(:,17).*power(1.00000, 2.00000).*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( CONSTANTS(:,12).*STATES(:,2).*exp(( 1.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,13).*CONSTANTS(:,11)))./(exp(( 1.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000);
    ALGEBRAIC(:,50) =  STATES(:,14).*STATES(:,15).*ALGEBRAIC(:,46).*ALGEBRAIC(:,42);
    ALGEBRAIC(:,54) = ALGEBRAIC(:,48)+ALGEBRAIC(:,52)+ALGEBRAIC(:,50);
    ALGEBRAIC(:,78) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./( 2.00000.*CONSTANTS(:,3))).*log(CONSTANTS(:,21)./STATES(:,12));
    ALGEBRAIC(:,79) =  CONSTANTS(:,24).*STATES(:,16).*STATES(:,16).*STATES(:,17).*(STATES(:,1) - ALGEBRAIC(:,78));
    ALGEBRAIC(:,88) = ( CONSTANTS(:,45).*exp(( (CONSTANTS(:,47) - 1.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(STATES(:,2), 3.00000).*CONSTANTS(:,21) -  power(CONSTANTS(:,11), 3.00000).*STATES(:,12)))./(1.00000+ CONSTANTS(:,46).*exp(( (CONSTANTS(:,47) - 1.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(STATES(:,2), 3.00000).*CONSTANTS(:,21)+ power(CONSTANTS(:,11), 3.00000).*STATES(:,12)));
    ALGEBRAIC(:,76) = ( CONSTANTS(:,38).*STATES(:,12))./(CONSTANTS(:,37)+STATES(:,12));
    ALGEBRAIC(:,77) =  CONSTANTS(:,39).*(STATES(:,1) - ALGEBRAIC(:,24));
    ALGEBRAIC(:,80) =  CONSTANTS(:,40).*(STATES(:,1) - ALGEBRAIC(:,78));
    ALGEBRAIC(:,83) = ( (( CONSTANTS(:,73).*power(1.00000, 2.00000).*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( CONSTANTS(:,12).*STATES(:,2).*exp(( 1.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,13).*CONSTANTS(:,11)))./(exp(( 1.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000);
    ALGEBRAIC(:,85) = ( ALGEBRAIC(:,83).*1.00000)./(1.00000+power(CONSTANTS(:,44)./STATES(:,12), 3.00000));
    ALGEBRAIC(:,87) = ALGEBRAIC(:,85)+ALGEBRAIC(:,86);
    ALGEBRAIC(:,89) =  ( - 1.00000./CONSTANTS(:,4)).*(ALGEBRAIC(:,31)+ALGEBRAIC(:,54)+ALGEBRAIC(:,79)+ALGEBRAIC(:,58)+ALGEBRAIC(:,62)+ALGEBRAIC(:,72)+ALGEBRAIC(:,73)+ALGEBRAIC(:,75)+ALGEBRAIC(:,67)+ALGEBRAIC(:,69)+ALGEBRAIC(:,88)+ALGEBRAIC(:,76)+ALGEBRAIC(:,77)+ALGEBRAIC(:,80)+ALGEBRAIC(:,82)+ALGEBRAIC(:,87)+ALGEBRAIC(:,12));
    ALGEBRAIC(:,90) = piecewise({STATES(:,32)>CONSTANTS(:,52),  (( CONSTANTS(:,48).*(STATES(:,32) - CONSTANTS(:,52)))./((CONSTANTS(:,51)+STATES(:,32)) - CONSTANTS(:,52))).*(1.00000 - STATES(:,30)).*STATES(:,30) , STATES(:,32)<=CONSTANTS(:,52)&STATES(:,34)>0.00000,  CONSTANTS(:,49).*(1.00000 - STATES(:,34)).*STATES(:,34) }, 0.00000);
    ALGEBRAIC(:,91) =  ALGEBRAIC(:,90).*(STATES(:,27) - STATES(:,12));
    ALGEBRAIC(:,92) = ( CONSTANTS(:,56).*STATES(:,12))./(STATES(:,12)+CONSTANTS(:,55));
    ALGEBRAIC(:,93) =  CONSTANTS(:,74).*STATES(:,28);
    ALGEBRAIC(:,94) = (STATES(:,28) - STATES(:,27))./CONSTANTS(:,50);
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

Source
Derived from workspace Clancy, Rudy, 2002 at changeset 2bd2a331ca0c.
Collaboration
To begin collaborating on this work, please use your git client and issue this command:
License

This work is licensed under a Creative Commons Attribution 3.0 Unported License.