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 =51;
end
% There are a total of 22 entries in each of the rate and state variable arrays.
% There are a total of 57 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_STATES(:,1) = strpad('V in component cell (mV)');
    LEGEND_CONSTANTS(:,1) = strpad('R in component cell (joule_per_mole_kelvin)');
    LEGEND_CONSTANTS(:,2) = strpad('T in component cell (kelvin)');
    LEGEND_CONSTANTS(:,3) = strpad('F in component cell (coulomb_per_millimole)');
    LEGEND_CONSTANTS(:,44) = strpad('FonRT in component cell (per_mV)');
    LEGEND_CONSTANTS(:,4) = strpad('Cm in component cell (pF)');
    LEGEND_CONSTANTS(:,5) = strpad('failing in component cell (dimensionless)');
    LEGEND_ALGEBRAIC(:,22) = strpad('i_Na in component INa (uA_per_uF)');
    LEGEND_ALGEBRAIC(:,25) = strpad('i_Ca in component ICa (uA_per_uF)');
    LEGEND_ALGEBRAIC(:,27) = strpad('i_to in component Ito (uA_per_uF)');
    LEGEND_ALGEBRAIC(:,32) = strpad('i_Kr in component IKr (uA_per_uF)');
    LEGEND_ALGEBRAIC(:,29) = strpad('i_Ks in component IKs (uA_per_uF)');
    LEGEND_ALGEBRAIC(:,37) = strpad('i_K1 in component IK1 (uA_per_uF)');
    LEGEND_ALGEBRAIC(:,42) = strpad('i_NaCa in component INaCa (uA_per_uF)');
    LEGEND_ALGEBRAIC(:,41) = strpad('i_NaK in component INaK (uA_per_uF)');
    LEGEND_ALGEBRAIC(:,39) = strpad('i_b_Na in component INab (uA_per_uF)');
    LEGEND_ALGEBRAIC(:,38) = strpad('i_b_Ca in component ICab (uA_per_uF)');
    LEGEND_ALGEBRAIC(:,45) = strpad('dVdt in component cell (mV_per_ms)');
    LEGEND_ALGEBRAIC(:,43) = strpad('I_tot in component cell (uA_per_uF)');
    LEGEND_ALGEBRAIC(:,11) = strpad('i_Stim in component cell (uA_per_uF)');
    LEGEND_CONSTANTS(:,6) = strpad('stim_offset in component cell (ms)');
    LEGEND_CONSTANTS(:,7) = strpad('stim_period in component cell (ms)');
    LEGEND_CONSTANTS(:,8) = strpad('stim_duration in component cell (ms)');
    LEGEND_CONSTANTS(:,9) = strpad('stim_amplitude in component cell (uA_per_uF)');
    LEGEND_ALGEBRAIC(:,1) = strpad('past in component cell (ms)');
    LEGEND_CONSTANTS(:,10) = strpad('V_clamp in component cell (dimensionless)');
    LEGEND_CONSTANTS(:,11) = strpad('V_hold in component cell (mV)');
    LEGEND_CONSTANTS(:,12) = strpad('V_step in component cell (mV)');
    LEGEND_ALGEBRAIC(:,21) = strpad('E_Na in component INa (mV)');
    LEGEND_CONSTANTS(:,13) = strpad('g_Na in component INa (mS_per_uF)');
    LEGEND_STATES(:,2) = strpad('Nai in component Ionic_concentrations (mM)');
    LEGEND_CONSTANTS(:,14) = strpad('Nao in component Ionic_concentrations (mM)');
    LEGEND_STATES(:,3) = strpad('m in component INa_m_gate (dimensionless)');
    LEGEND_STATES(:,4) = strpad('h in component INa_h_gate (dimensionless)');
    LEGEND_STATES(:,5) = strpad('j in component INa_j_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,2) = strpad('alpha_m in component INa_m_gate (per_ms)');
    LEGEND_ALGEBRAIC(:,12) = strpad('beta_m in component INa_m_gate (per_ms)');
    LEGEND_ALGEBRAIC(:,3) = strpad('alpha_h in component INa_h_gate (per_ms)');
    LEGEND_ALGEBRAIC(:,13) = strpad('beta_h in component INa_h_gate (per_ms)');
    LEGEND_ALGEBRAIC(:,4) = strpad('alpha_j in component INa_j_gate (per_ms)');
    LEGEND_ALGEBRAIC(:,14) = strpad('beta_j in component INa_j_gate (per_ms)');
    LEGEND_ALGEBRAIC(:,23) = strpad('E_Ca in component ICa (mV)');
    LEGEND_CONSTANTS(:,15) = strpad('g_Ca_max in component ICa (mS_per_uF)');
    LEGEND_STATES(:,6) = strpad('Cai in component Ionic_concentrations (mM)');
    LEGEND_CONSTANTS(:,16) = strpad('Cao in component Ionic_concentrations (mM)');
    LEGEND_STATES(:,7) = strpad('d in component ICa_d_gate (dimensionless)');
    LEGEND_STATES(:,8) = strpad('f in component ICa_f_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,24) = strpad('f_Ca in component ICa_f_Ca_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,5) = strpad('alpha_d in component ICa_d_gate (per_ms)');
    LEGEND_ALGEBRAIC(:,15) = strpad('beta_d in component ICa_d_gate (per_ms)');
    LEGEND_ALGEBRAIC(:,6) = strpad('alpha_f in component ICa_f_gate (per_ms)');
    LEGEND_ALGEBRAIC(:,16) = strpad('beta_f in component ICa_f_gate (per_ms)');
    LEGEND_CONSTANTS(:,17) = strpad('Km_Ca in component ICa_f_Ca_gate (mM)');
    LEGEND_CONSTANTS(:,45) = strpad('g_to_max in component Ito (mS_per_uF)');
    LEGEND_ALGEBRAIC(:,26) = strpad('E_to in component Ito (mV)');
    LEGEND_STATES(:,9) = strpad('Ki in component Ionic_concentrations (mM)');
    LEGEND_CONSTANTS(:,18) = strpad('Ko in component Ionic_concentrations (mM)');
    LEGEND_STATES(:,10) = strpad('t in component Ito_t_gate (dimensionless)');
    LEGEND_STATES(:,11) = strpad('r in component Ito_r_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,7) = strpad('alpha_r in component Ito_r_gate (per_ms)');
    LEGEND_ALGEBRAIC(:,17) = strpad('beta_r in component Ito_r_gate (per_ms)');
    LEGEND_ALGEBRAIC(:,8) = strpad('alpha_t in component Ito_t_gate (per_ms)');
    LEGEND_ALGEBRAIC(:,18) = strpad('beta_t in component Ito_t_gate (per_ms)');
    LEGEND_CONSTANTS(:,19) = strpad('g_Ks_max in component IKs (mS_per_uF)');
    LEGEND_ALGEBRAIC(:,28) = strpad('E_Ks in component IKs (mV)');
    LEGEND_STATES(:,12) = strpad('Xs in component IKs_Xs_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,9) = strpad('alpha_Xs in component IKs_Xs_gate (per_ms)');
    LEGEND_ALGEBRAIC(:,19) = strpad('beta_Xs in component IKs_Xs_gate (per_ms)');
    LEGEND_CONSTANTS(:,20) = strpad('g_Kr_max in component IKr (mS_per_uF)');
    LEGEND_ALGEBRAIC(:,31) = strpad('rik in component IKr (dimensionless)');
    LEGEND_ALGEBRAIC(:,30) = strpad('E_K in component IKr (mV)');
    LEGEND_STATES(:,13) = strpad('Xr in component IKr_Xr_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,10) = strpad('alpha_Xr in component IKr_Xr_gate (per_ms)');
    LEGEND_ALGEBRAIC(:,20) = strpad('beta_Xr in component IKr_Xr_gate (per_ms)');
    LEGEND_ALGEBRAIC(:,33) = strpad('E_K1 in component IK1 (mV)');
    LEGEND_CONSTANTS(:,46) = strpad('g_K1_max in component IK1 (mS_per_uF)');
    LEGEND_ALGEBRAIC(:,36) = strpad('K1_infinity in component IK1_K1_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,34) = strpad('alpha_K1 in component IK1_K1_gate (per_ms)');
    LEGEND_ALGEBRAIC(:,35) = strpad('beta_K1 in component IK1_K1_gate (per_ms)');
    LEGEND_CONSTANTS(:,47) = strpad('g_b_Ca_max in component ICab (mS_per_uF)');
    LEGEND_CONSTANTS(:,48) = strpad('g_b_Na_max in component INab (mS_per_uF)');
    LEGEND_CONSTANTS(:,49) = strpad('I_NaK_max in component INaK (uA_per_uF)');
    LEGEND_ALGEBRAIC(:,40) = strpad('f_NaK in component INaK (dimensionless)');
    LEGEND_CONSTANTS(:,21) = strpad('K_mNai in component INaK (mM)');
    LEGEND_CONSTANTS(:,22) = strpad('K_mKo in component INaK (mM)');
    LEGEND_CONSTANTS(:,50) = strpad('sigma in component INaK (dimensionless)');
    LEGEND_CONSTANTS(:,51) = strpad('K_NaCa in component INaCa (uA_per_uF)');
    LEGEND_CONSTANTS(:,23) = strpad('K_mNa in component INaCa (mM)');
    LEGEND_CONSTANTS(:,24) = strpad('K_mCa in component INaCa (mM)');
    LEGEND_CONSTANTS(:,25) = strpad('K_sat in component INaCa (dimensionless)');
    LEGEND_CONSTANTS(:,26) = strpad('eta in component INaCa (dimensionless)');
    LEGEND_ALGEBRAIC(:,46) = strpad('i_rel in component Irel (mM_per_ms)');
    LEGEND_ALGEBRAIC(:,44) = strpad('G_rel in component Irel (per_ms)');
    LEGEND_CONSTANTS(:,27) = strpad('G_rel_max in component Irel (per_ms)');
    LEGEND_CONSTANTS(:,28) = strpad('G_rel_overload in component Irel (per_ms)');
    LEGEND_CONSTANTS(:,29) = strpad('K_mrel in component Irel (mM)');
    LEGEND_CONSTANTS(:,30) = strpad('delta_Ca_ith in component Irel (mM)');
    LEGEND_CONSTANTS(:,31) = strpad('K_mCSQN in component calcium_buffers_in_the_JSR (mM)');
    LEGEND_STATES(:,14) = strpad('Ca_JSR in component Ionic_concentrations (mM)');
    LEGEND_CONSTANTS(:,55) = strpad('V_myo in component Ionic_concentrations (fL)');
    LEGEND_CONSTANTS(:,57) = strpad('V_JSR in component Ionic_concentrations (fL)');
    LEGEND_STATES(:,15) = strpad('APtrack in component Irel (dimensionless)');
    LEGEND_STATES(:,16) = strpad('APtrack2 in component Irel (dimensionless)');
    LEGEND_STATES(:,17) = strpad('APtrack3 in component Irel (dimensionless)');
    LEGEND_STATES(:,18) = strpad('Cainfluxtrack in component Irel (mM)');
    LEGEND_STATES(:,19) = strpad('OVRLDtrack in component Irel (dimensionless)');
    LEGEND_STATES(:,20) = strpad('OVRLDtrack2 in component Irel (dimensionless)');
    LEGEND_STATES(:,21) = strpad('OVRLDtrack3 in component Irel (dimensionless)');
    LEGEND_CONSTANTS(:,32) = strpad('CSQNthresh in component Irel (mM)');
    LEGEND_CONSTANTS(:,33) = strpad('Logicthresh in component Irel (dimensionless)');
    LEGEND_ALGEBRAIC(:,47) = strpad('i_up in component Iup (mM_per_ms)');
    LEGEND_CONSTANTS(:,52) = strpad('I_up_max in component Iup (mM_per_ms)');
    LEGEND_CONSTANTS(:,34) = strpad('K_mup in component Iup (mM)');
    LEGEND_ALGEBRAIC(:,48) = strpad('i_leak in component Ileak (mM_per_ms)');
    LEGEND_CONSTANTS(:,53) = strpad('K_leak in component Ileak (per_ms)');
    LEGEND_STATES(:,22) = strpad('Ca_NSR in component Ionic_concentrations (mM)');
    LEGEND_ALGEBRAIC(:,50) = strpad('i_tr in component Itr (mM_per_ms)');
    LEGEND_CONSTANTS(:,35) = strpad('tau_tr in component Itr (ms)');
    LEGEND_CONSTANTS(:,36) = strpad('K_mTn in component calcium_buffers_in_the_myoplasm (mM)');
    LEGEND_CONSTANTS(:,37) = strpad('K_mCMDN in component calcium_buffers_in_the_myoplasm (mM)');
    LEGEND_CONSTANTS(:,38) = strpad('Tn_max in component calcium_buffers_in_the_myoplasm (mM)');
    LEGEND_CONSTANTS(:,39) = strpad('CMDN_max in component calcium_buffers_in_the_myoplasm (mM)');
    LEGEND_CONSTANTS(:,40) = strpad('buffon in component calcium_buffers_in_the_myoplasm (dimensionless)');
    LEGEND_ALGEBRAIC(:,49) = strpad('Cai_bufc in component calcium_buffers_in_the_myoplasm (dimensionless)');
    LEGEND_CONSTANTS(:,41) = strpad('CSQN_max in component calcium_buffers_in_the_JSR (mM)');
    LEGEND_ALGEBRAIC(:,51) = strpad('Ca_JSR_bufc in component calcium_buffers_in_the_JSR (dimensionless)');
    LEGEND_CONSTANTS(:,42) = strpad('preplength in component Ionic_concentrations (um)');
    LEGEND_CONSTANTS(:,43) = strpad('radius in component Ionic_concentrations (um)');
    LEGEND_CONSTANTS(:,54) = strpad('volume in component Ionic_concentrations (fL)');
    LEGEND_CONSTANTS(:,56) = strpad('V_NSR in component Ionic_concentrations (fL)');
    LEGEND_RATES(:,1) = strpad('d/dt V in component cell (mV)');
    LEGEND_RATES(:,3) = strpad('d/dt m in component INa_m_gate (dimensionless)');
    LEGEND_RATES(:,4) = strpad('d/dt h in component INa_h_gate (dimensionless)');
    LEGEND_RATES(:,5) = strpad('d/dt j in component INa_j_gate (dimensionless)');
    LEGEND_RATES(:,7) = strpad('d/dt d in component ICa_d_gate (dimensionless)');
    LEGEND_RATES(:,8) = strpad('d/dt f in component ICa_f_gate (dimensionless)');
    LEGEND_RATES(:,11) = strpad('d/dt r in component Ito_r_gate (dimensionless)');
    LEGEND_RATES(:,10) = strpad('d/dt t in component Ito_t_gate (dimensionless)');
    LEGEND_RATES(:,12) = strpad('d/dt Xs in component IKs_Xs_gate (dimensionless)');
    LEGEND_RATES(:,13) = strpad('d/dt Xr in component IKr_Xr_gate (dimensionless)');
    LEGEND_RATES(:,15) = strpad('d/dt APtrack in component Irel (dimensionless)');
    LEGEND_RATES(:,16) = strpad('d/dt APtrack2 in component Irel (dimensionless)');
    LEGEND_RATES(:,17) = strpad('d/dt APtrack3 in component Irel (dimensionless)');
    LEGEND_RATES(:,18) = strpad('d/dt Cainfluxtrack in component Irel (mM)');
    LEGEND_RATES(:,19) = strpad('d/dt OVRLDtrack in component Irel (dimensionless)');
    LEGEND_RATES(:,20) = strpad('d/dt OVRLDtrack2 in component Irel (dimensionless)');
    LEGEND_RATES(:,21) = strpad('d/dt OVRLDtrack3 in component Irel (dimensionless)');
    LEGEND_RATES(:,2) = strpad('d/dt Nai in component Ionic_concentrations (mM)');
    LEGEND_RATES(:,9) = strpad('d/dt Ki in component Ionic_concentrations (mM)');
    LEGEND_RATES(:,6) = strpad('d/dt Cai in component Ionic_concentrations (mM)');
    LEGEND_RATES(:,14) = strpad('d/dt Ca_JSR in component Ionic_concentrations (mM)');
    LEGEND_RATES(:,22) = strpad('d/dt Ca_NSR in component Ionic_concentrations (mM)');
    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) = -90.7796417483135;
    CONSTANTS(:,1) = 8.3143;
    CONSTANTS(:,2) = 310.15;
    CONSTANTS(:,3) = 96.4867;
    CONSTANTS(:,4) = 153.4;
    CONSTANTS(:,5) = 0;
    CONSTANTS(:,6) = 0;
    CONSTANTS(:,7) = 1000;
    CONSTANTS(:,8) = 3;
    CONSTANTS(:,9) = -15;
    CONSTANTS(:,10) = 0;
    CONSTANTS(:,11) = -60;
    CONSTANTS(:,12) = 0;
    CONSTANTS(:,13) = 16;
    STATES(:,2) = 10;
    CONSTANTS(:,14) = 138;
    STATES(:,3) = 0.000585525582501575;
    STATES(:,4) = 0.995865529216237;
    STATES(:,5) = 0.997011204496203;
    CONSTANTS(:,15) = 0.064;
    STATES(:,6) = 0.0002;
    CONSTANTS(:,16) = 2;
    STATES(:,7) = 2.50653215966786e-10;
    STATES(:,8) = 0.92130376850548;
    CONSTANTS(:,17) = 0.0006;
    STATES(:,9) = 140;
    CONSTANTS(:,18) = 4;
    STATES(:,10) = 0.999897251531651;
    STATES(:,11) = 1.75032478501027e-5;
    CONSTANTS(:,19) = 0.02;
    STATES(:,12) = 0.00885658064818147;
    CONSTANTS(:,20) = 0.015;
    STATES(:,13) = 0.000215523048438941;
    CONSTANTS(:,21) = 10;
    CONSTANTS(:,22) = 1.5;
    CONSTANTS(:,23) = 87.5;
    CONSTANTS(:,24) = 1.38;
    CONSTANTS(:,25) = 0.1;
    CONSTANTS(:,26) = 0.35;
    CONSTANTS(:,27) = 22;
    CONSTANTS(:,28) = 3;
    CONSTANTS(:,29) = 0.0008;
    CONSTANTS(:,30) = 5e-6;
    CONSTANTS(:,31) = 0.8;
    STATES(:,14) = 2.5;
    STATES(:,15) = -1.372158997089e-136;
    STATES(:,16) = -7.58517896402761e-136;
    STATES(:,17) = 4.82035353592764e-5;
    STATES(:,18) = -7.71120176147331e-138;
    STATES(:,19) = 1e-6;
    STATES(:,20) = 1e-6;
    STATES(:,21) = 1e-6;
    CONSTANTS(:,32) = 0.7;
    CONSTANTS(:,33) = 0.98;
    CONSTANTS(:,34) = 0.00092;
    STATES(:,22) = 2.5;
    CONSTANTS(:,35) = 180;
    CONSTANTS(:,36) = 0.0005;
    CONSTANTS(:,37) = 0.00238;
    CONSTANTS(:,38) = 0.07;
    CONSTANTS(:,39) = 0.05;
    CONSTANTS(:,40) = 1;
    CONSTANTS(:,41) = 10;
    CONSTANTS(:,42) = 100;
    CONSTANTS(:,43) = 11;
    CONSTANTS(:,44) = CONSTANTS(:,3)./( CONSTANTS(:,1).*CONSTANTS(:,2));
    CONSTANTS(:,45) = piecewise({CONSTANTS(:,5)==0.00000, 0.300000 }, 0.191000);
    CONSTANTS(:,46) = piecewise({CONSTANTS(:,5)==0.00000, 2.50000 }, 2.00000);
    CONSTANTS(:,47) = piecewise({CONSTANTS(:,5)==0.00000, 0.000850000 }, 0.00130000);
    CONSTANTS(:,48) = piecewise({CONSTANTS(:,5)==0.00000, 0.00100000 }, 0.00000);
    CONSTANTS(:,49) = piecewise({CONSTANTS(:,5)==0.00000, 1.30000 }, 0.750000);
    CONSTANTS(:,50) =  (1.00000./7.00000).*(exp(CONSTANTS(:,14)./67.3000) - 1.00000);
    CONSTANTS(:,51) = piecewise({CONSTANTS(:,5)==0.00000, 1000.00 }, 1650.00);
    CONSTANTS(:,52) = piecewise({CONSTANTS(:,5)==0.00000, 0.00450000 }, 0.00150000);
    CONSTANTS(:,53) = piecewise({CONSTANTS(:,5)==0.00000, 0.000260000 }, 0.000170000);
    CONSTANTS(:,54) =   pi.*CONSTANTS(:,42).*power(CONSTANTS(:,43), 2.00000);
    CONSTANTS(:,55) =  0.680000.*CONSTANTS(:,54);
    CONSTANTS(:,56) =  0.0552000.*CONSTANTS(:,54);
    CONSTANTS(:,57) =  0.00480000.*CONSTANTS(:,54);
    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(:,16) = piecewise({STATES(:,15)<0.200000&STATES(:,15)>0.180000,  100.000.*(1.00000 - STATES(:,16)) -  0.500000.*STATES(:,16) },   - 0.500000.*STATES(:,16));
    RATES(:,17) = piecewise({STATES(:,15)<0.200000&STATES(:,15)>0.180000,  100.000.*(1.00000 - STATES(:,17)) -  0.500000.*STATES(:,17) },   - 0.0100000.*STATES(:,17));
    RATES(:,19) = piecewise({1.00000./(1.00000+CONSTANTS(:,31)./STATES(:,14))>CONSTANTS(:,32)&STATES(:,21)<0.370000&STATES(:,17)<0.370000,  0.00000.*50.0000.*(1.00000 - STATES(:,19)) },   - 0.00000.*0.500000.*STATES(:,19));
    RATES(:,20) = piecewise({STATES(:,19)>CONSTANTS(:,33)&STATES(:,20)<CONSTANTS(:,33),  0.00000.*50.0000.*(1.00000 - STATES(:,20)) },   - 0.00000.*0.500000.*STATES(:,20));
    RATES(:,21) = piecewise({STATES(:,19)>CONSTANTS(:,33)&STATES(:,21)<CONSTANTS(:,33),  0.00000.*50.0000.*(1.00000 - STATES(:,21)) },   - 0.00000.*0.0100000.*STATES(:,21));
    ALGEBRAIC(:,2) = piecewise({abs(STATES(:,1)+47.1300)>0.00100000, ( 0.320000.*(STATES(:,1)+47.1300))./(1.00000 - exp(  - 0.100000.*(STATES(:,1)+47.1300))) }, 3.20000);
    ALGEBRAIC(:,12) =  0.0800000.*exp( - STATES(:,1)./11.0000);
    RATES(:,3) =  ALGEBRAIC(:,2).*(1.00000 - STATES(:,3)) -  ALGEBRAIC(:,12).*STATES(:,3);
    ALGEBRAIC(:,3) = piecewise({STATES(:,1)< - 40.0000,  0.135000.*exp((80.0000+STATES(:,1))./ - 6.80000) }, 0.00000);
    ALGEBRAIC(:,13) = 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(:,3).*(1.00000 - STATES(:,4)) -  ALGEBRAIC(:,13).*STATES(:,4);
    ALGEBRAIC(:,4) = piecewise({STATES(:,1)< - 40.0000, ( (  - 127140..*exp( 0.244000.*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(:,14) = 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(:,4).*(1.00000 - STATES(:,5)) -  ALGEBRAIC(:,14).*STATES(:,5);
    ALGEBRAIC(:,5) =  (14.9859./( 16.6813.*power(( 2.00000.* pi), 1.0 ./ 2))).*exp( - power((STATES(:,1) - 22.3600)./16.6813, 2.00000)./2.00000);
    ALGEBRAIC(:,15) = 0.147100 -  (5.30000./( 14.9300.*power(( 2.00000.* pi), 1.0 ./ 2))).*exp( - power((STATES(:,1) - 6.27440)./14.9300, 2.00000)./2.00000);
    RATES(:,7) =  ALGEBRAIC(:,5).*(1.00000 - STATES(:,7)) -  ALGEBRAIC(:,15).*STATES(:,7);
    ALGEBRAIC(:,6) = 0.00687200./(1.00000+exp((STATES(:,1) - 6.15460)./6.12230));
    ALGEBRAIC(:,16) = ( 0.0687000.*exp(  - 0.108100.*(STATES(:,1)+9.82550))+0.0112000)./(1.00000+exp(  - 0.277900.*(STATES(:,1)+9.82550)))+0.000547400;
    RATES(:,8) =  ALGEBRAIC(:,6).*(1.00000 - STATES(:,8)) -  ALGEBRAIC(:,16).*STATES(:,8);
    ALGEBRAIC(:,7) = ( 0.526600.*exp(  - 0.0166000.*(STATES(:,1) - 42.2912)))./(1.00000+exp(  - 0.0943000.*(STATES(:,1) - 42.2912)));
    ALGEBRAIC(:,17) = ( 5.18600e-05.*STATES(:,1)+ 0.514900.*exp(  - 0.134400.*(STATES(:,1) - 5.00270)))./(1.00000+exp(  - 0.134800.*(STATES(:,1) - 5.18600e-05)));
    RATES(:,11) =  ALGEBRAIC(:,7).*(1.00000 - STATES(:,11)) -  ALGEBRAIC(:,17).*STATES(:,11);
    ALGEBRAIC(:,8) = ( 5.61200e-05.*STATES(:,1)+ 0.0721000.*exp(  - 0.173000.*(STATES(:,1)+34.2531)))./(1.00000+exp(  - 0.173200.*(STATES(:,1)+34.2531)));
    ALGEBRAIC(:,18) = ( 0.000121500.*STATES(:,1)+ 0.0767000.*exp(  - 1.66000e-09.*(STATES(:,1)+34.0235)))./(1.00000+exp(  - 0.160400.*(STATES(:,1)+34.0235)));
    RATES(:,10) =  ALGEBRAIC(:,8).*(1.00000 - STATES(:,10)) -  ALGEBRAIC(:,18).*STATES(:,10);
    ALGEBRAIC(:,9) = 0.00301300./(1.00000+exp((7.44540 - (STATES(:,1)+10.0000))./14.3171));
    ALGEBRAIC(:,19) = 0.00587000./(1.00000+exp((5.95000+STATES(:,1)+10.0000)./15.8200));
    RATES(:,12) =  ALGEBRAIC(:,9).*(1.00000 - STATES(:,12)) -  ALGEBRAIC(:,19).*STATES(:,12);
    ALGEBRAIC(:,10) = ( 0.00500000.*exp( 0.000526600.*(STATES(:,1)+4.06700)))./(1.00000+exp(  - 0.126200.*(STATES(:,1)+4.06700)));
    ALGEBRAIC(:,20) = ( 0.0160000.*exp( 0.00160000.*(STATES(:,1)+65.6600)))./(1.00000+exp( 0.0783000.*(STATES(:,1)+65.6600)));
    RATES(:,13) =  ALGEBRAIC(:,10).*(1.00000 - STATES(:,13)) -  ALGEBRAIC(:,20).*STATES(:,13);
    ALGEBRAIC(:,26) = log(( 0.0430000.*CONSTANTS(:,14)+CONSTANTS(:,18))./( 0.0430000.*STATES(:,2)+STATES(:,9)))./CONSTANTS(:,44);
    ALGEBRAIC(:,27) =  CONSTANTS(:,45).*STATES(:,11).*STATES(:,10).*(STATES(:,1) - ALGEBRAIC(:,26));
    ALGEBRAIC(:,31) = 1.00000./(1.00000+exp((STATES(:,1)+26.0000)./23.0000));
    ALGEBRAIC(:,30) = log(CONSTANTS(:,18)./STATES(:,9))./CONSTANTS(:,44);
    ALGEBRAIC(:,32) =  CONSTANTS(:,20).*STATES(:,13).*ALGEBRAIC(:,31).*(STATES(:,1) - ALGEBRAIC(:,30));
    ALGEBRAIC(:,28) = log(( 0.0183300.*CONSTANTS(:,14)+CONSTANTS(:,18))./( 0.0183300.*STATES(:,2)+STATES(:,9)))./CONSTANTS(:,44);
    ALGEBRAIC(:,29) =  CONSTANTS(:,19).*power(STATES(:,12), 2.00000).*(STATES(:,1) - ALGEBRAIC(:,28));
    ALGEBRAIC(:,33) = log(CONSTANTS(:,18)./STATES(:,9))./CONSTANTS(:,44);
    ALGEBRAIC(:,34) = 0.100000./(1.00000+exp( 0.0600000.*(STATES(:,1) - (ALGEBRAIC(:,33)+200.000))));
    ALGEBRAIC(:,35) = ( 3.00000.*exp( 0.000200000.*(STATES(:,1)+100.000+ - ALGEBRAIC(:,33)))+ 1.00000.*exp( 0.100000.*(STATES(:,1) - (10.0000+ALGEBRAIC(:,33)))))./(1.00000+exp(  - 0.500000.*(STATES(:,1) - ALGEBRAIC(:,33))));
    ALGEBRAIC(:,36) = ALGEBRAIC(:,34)./(ALGEBRAIC(:,34)+ALGEBRAIC(:,35));
    ALGEBRAIC(:,37) =  CONSTANTS(:,46).*ALGEBRAIC(:,36).*(STATES(:,1) - ALGEBRAIC(:,33));
    ALGEBRAIC(:,40) = 1.00000./(1.00000+ 0.124500.*exp(  - 0.100000.*STATES(:,1).*CONSTANTS(:,44))+ 0.0365000.*CONSTANTS(:,50).*exp(  - STATES(:,1).*CONSTANTS(:,44)));
    ALGEBRAIC(:,41) = ( (( CONSTANTS(:,49).*ALGEBRAIC(:,40).*1.00000)./(1.00000+power(CONSTANTS(:,21)./STATES(:,2), 1.50000))).*CONSTANTS(:,18))./(CONSTANTS(:,18)+CONSTANTS(:,22));
    ALGEBRAIC(:,1) =  floor(VOI./CONSTANTS(:,7)).*CONSTANTS(:,7);
    ALGEBRAIC(:,11) = piecewise({VOI - ALGEBRAIC(:,1)>=CONSTANTS(:,6)&VOI - ALGEBRAIC(:,1)<=CONSTANTS(:,6)+CONSTANTS(:,8), CONSTANTS(:,9) }, 0.00000);
    RATES(:,9) = (  - 1.00000.*CONSTANTS(:,4).*((ALGEBRAIC(:,27)+ALGEBRAIC(:,32)+ALGEBRAIC(:,37)+ALGEBRAIC(:,11)+ALGEBRAIC(:,29)) -  2.00000.*ALGEBRAIC(:,41)))./( CONSTANTS(:,55).*CONSTANTS(:,3));
    ALGEBRAIC(:,23) = log(CONSTANTS(:,16)./STATES(:,6))./( 2.00000.*CONSTANTS(:,44));
    ALGEBRAIC(:,24) = CONSTANTS(:,17)./(CONSTANTS(:,17)+STATES(:,6));
    ALGEBRAIC(:,25) =  CONSTANTS(:,15).*STATES(:,7).*STATES(:,8).*ALGEBRAIC(:,24).*(STATES(:,1) - ALGEBRAIC(:,23));
    ALGEBRAIC(:,42) =  (( (( (( CONSTANTS(:,51).*1.00000)./(power(CONSTANTS(:,23), 3.00000)+power(CONSTANTS(:,14), 3.00000))).*1.00000)./(CONSTANTS(:,24)+CONSTANTS(:,16))).*1.00000)./(1.00000+ CONSTANTS(:,25).*exp( (CONSTANTS(:,26) - 1.00000).*STATES(:,1).*CONSTANTS(:,44)))).*( exp( CONSTANTS(:,26).*STATES(:,1).*CONSTANTS(:,44)).*power(STATES(:,2), 3.00000).*CONSTANTS(:,16) -  exp( (CONSTANTS(:,26) - 1.00000).*STATES(:,1).*CONSTANTS(:,44)).*power(CONSTANTS(:,14), 3.00000).*STATES(:,6));
    ALGEBRAIC(:,38) =  CONSTANTS(:,47).*(STATES(:,1) - ALGEBRAIC(:,23));
    RATES(:,18) = piecewise({STATES(:,15)>0.200000, (  - CONSTANTS(:,4).*((ALGEBRAIC(:,25) - ALGEBRAIC(:,42))+ALGEBRAIC(:,38)))./( 2.00000.*CONSTANTS(:,55).*CONSTANTS(:,3)) , STATES(:,16)>0.0100000&STATES(:,15)<=0.200000, 0.00000 },   - 0.500000.*STATES(:,18));
    ALGEBRAIC(:,21) = log(CONSTANTS(:,14)./STATES(:,2))./CONSTANTS(:,44);
    ALGEBRAIC(:,22) =  CONSTANTS(:,13).*power(STATES(:,3), 3.00000).*STATES(:,4).*STATES(:,5).*(STATES(:,1) - ALGEBRAIC(:,21));
    ALGEBRAIC(:,39) =  CONSTANTS(:,48).*(STATES(:,1) - ALGEBRAIC(:,21));
    RATES(:,2) = (  - 1.00000.*CONSTANTS(:,4).*(ALGEBRAIC(:,22)+ALGEBRAIC(:,39)+ ALGEBRAIC(:,42).*3.00000+ ALGEBRAIC(:,41).*3.00000))./( CONSTANTS(:,55).*CONSTANTS(:,3));
    ALGEBRAIC(:,43) = ALGEBRAIC(:,22)+ALGEBRAIC(:,25)+ALGEBRAIC(:,27)+ALGEBRAIC(:,32)+ALGEBRAIC(:,29)+ALGEBRAIC(:,37)+ALGEBRAIC(:,42)+ALGEBRAIC(:,41)+ALGEBRAIC(:,39)+ALGEBRAIC(:,38)+ALGEBRAIC(:,11);
    ALGEBRAIC(:,45) = piecewise({CONSTANTS(:,10)==1.00000&(VOI<=500.000||VOI>800.000), (CONSTANTS(:,11) - STATES(:,1))./1.00000 , CONSTANTS(:,10)==1.00000&VOI>500.000&VOI<=800.000, (CONSTANTS(:,12) - STATES(:,1))./1.00000 },   - 1.00000.*ALGEBRAIC(:,43));
    RATES(:,1) = ALGEBRAIC(:,45);
    RATES(:,15) = piecewise({ALGEBRAIC(:,45)>150.000,  100.000.*(1.00000 - STATES(:,15)) -  0.500000.*STATES(:,15) },   - 0.500000.*STATES(:,15));
    ALGEBRAIC(:,44) = piecewise({STATES(:,18)>CONSTANTS(:,30),  (( 1.00000.*CONSTANTS(:,27).*(STATES(:,18) - CONSTANTS(:,30)))./((CONSTANTS(:,29)+STATES(:,18)) - CONSTANTS(:,30))).*(1.00000 - STATES(:,16)).*STATES(:,16) , STATES(:,18)<=CONSTANTS(:,30)&STATES(:,20)>0.00000,  0.00000.*CONSTANTS(:,28).*(1.00000 - STATES(:,20)).*STATES(:,20) }, 0.00000);
    ALGEBRAIC(:,46) =  ALGEBRAIC(:,44).*(STATES(:,14) - STATES(:,6));
    ALGEBRAIC(:,47) = ( CONSTANTS(:,52).*STATES(:,6))./(STATES(:,6)+CONSTANTS(:,34));
    ALGEBRAIC(:,48) =  CONSTANTS(:,53).*STATES(:,22);
    ALGEBRAIC(:,49) = 1.00000./(1.00000+ CONSTANTS(:,40).*(( CONSTANTS(:,39).*CONSTANTS(:,37))./power(CONSTANTS(:,37)+STATES(:,6), 2.00000)+( CONSTANTS(:,38).*CONSTANTS(:,36))./power(CONSTANTS(:,36)+STATES(:,6), 2.00000)));
    RATES(:,6) =  ALGEBRAIC(:,49).*((  - CONSTANTS(:,4).*((ALGEBRAIC(:,25) -  2.00000.*ALGEBRAIC(:,42))+ALGEBRAIC(:,38)))./( 2.00000.*CONSTANTS(:,55).*CONSTANTS(:,3))+( ALGEBRAIC(:,46).*CONSTANTS(:,57))./CONSTANTS(:,55)+( (ALGEBRAIC(:,48) - ALGEBRAIC(:,47)).*CONSTANTS(:,56))./CONSTANTS(:,55));
    ALGEBRAIC(:,50) = ( 1.00000.*(STATES(:,22) - STATES(:,14)))./CONSTANTS(:,35);
    RATES(:,22) =   - 1.00000.*((ALGEBRAIC(:,48)+ (CONSTANTS(:,57)./CONSTANTS(:,56)).*ALGEBRAIC(:,50)) - ALGEBRAIC(:,47));
    ALGEBRAIC(:,51) = 1.00000./(1.00000+( CONSTANTS(:,41).*CONSTANTS(:,31))./power(CONSTANTS(:,31)+STATES(:,14), 2.00000));
    RATES(:,14) =  ALGEBRAIC(:,51).*(ALGEBRAIC(:,50) - ALGEBRAIC(:,46));
   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(:,2) = piecewise({abs(STATES(:,1)+47.1300)>0.00100000, ( 0.320000.*(STATES(:,1)+47.1300))./(1.00000 - exp(  - 0.100000.*(STATES(:,1)+47.1300))) }, 3.20000);
    ALGEBRAIC(:,12) =  0.0800000.*exp( - STATES(:,1)./11.0000);
    ALGEBRAIC(:,3) = piecewise({STATES(:,1)< - 40.0000,  0.135000.*exp((80.0000+STATES(:,1))./ - 6.80000) }, 0.00000);
    ALGEBRAIC(:,13) = 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(:,4) = piecewise({STATES(:,1)< - 40.0000, ( (  - 127140..*exp( 0.244000.*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(:,14) = 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) =  (14.9859./( 16.6813.*power(( 2.00000.* pi), 1.0 ./ 2))).*exp( - power((STATES(:,1) - 22.3600)./16.6813, 2.00000)./2.00000);
    ALGEBRAIC(:,15) = 0.147100 -  (5.30000./( 14.9300.*power(( 2.00000.* pi), 1.0 ./ 2))).*exp( - power((STATES(:,1) - 6.27440)./14.9300, 2.00000)./2.00000);
    ALGEBRAIC(:,6) = 0.00687200./(1.00000+exp((STATES(:,1) - 6.15460)./6.12230));
    ALGEBRAIC(:,16) = ( 0.0687000.*exp(  - 0.108100.*(STATES(:,1)+9.82550))+0.0112000)./(1.00000+exp(  - 0.277900.*(STATES(:,1)+9.82550)))+0.000547400;
    ALGEBRAIC(:,7) = ( 0.526600.*exp(  - 0.0166000.*(STATES(:,1) - 42.2912)))./(1.00000+exp(  - 0.0943000.*(STATES(:,1) - 42.2912)));
    ALGEBRAIC(:,17) = ( 5.18600e-05.*STATES(:,1)+ 0.514900.*exp(  - 0.134400.*(STATES(:,1) - 5.00270)))./(1.00000+exp(  - 0.134800.*(STATES(:,1) - 5.18600e-05)));
    ALGEBRAIC(:,8) = ( 5.61200e-05.*STATES(:,1)+ 0.0721000.*exp(  - 0.173000.*(STATES(:,1)+34.2531)))./(1.00000+exp(  - 0.173200.*(STATES(:,1)+34.2531)));
    ALGEBRAIC(:,18) = ( 0.000121500.*STATES(:,1)+ 0.0767000.*exp(  - 1.66000e-09.*(STATES(:,1)+34.0235)))./(1.00000+exp(  - 0.160400.*(STATES(:,1)+34.0235)));
    ALGEBRAIC(:,9) = 0.00301300./(1.00000+exp((7.44540 - (STATES(:,1)+10.0000))./14.3171));
    ALGEBRAIC(:,19) = 0.00587000./(1.00000+exp((5.95000+STATES(:,1)+10.0000)./15.8200));
    ALGEBRAIC(:,10) = ( 0.00500000.*exp( 0.000526600.*(STATES(:,1)+4.06700)))./(1.00000+exp(  - 0.126200.*(STATES(:,1)+4.06700)));
    ALGEBRAIC(:,20) = ( 0.0160000.*exp( 0.00160000.*(STATES(:,1)+65.6600)))./(1.00000+exp( 0.0783000.*(STATES(:,1)+65.6600)));
    ALGEBRAIC(:,26) = log(( 0.0430000.*CONSTANTS(:,14)+CONSTANTS(:,18))./( 0.0430000.*STATES(:,2)+STATES(:,9)))./CONSTANTS(:,44);
    ALGEBRAIC(:,27) =  CONSTANTS(:,45).*STATES(:,11).*STATES(:,10).*(STATES(:,1) - ALGEBRAIC(:,26));
    ALGEBRAIC(:,31) = 1.00000./(1.00000+exp((STATES(:,1)+26.0000)./23.0000));
    ALGEBRAIC(:,30) = log(CONSTANTS(:,18)./STATES(:,9))./CONSTANTS(:,44);
    ALGEBRAIC(:,32) =  CONSTANTS(:,20).*STATES(:,13).*ALGEBRAIC(:,31).*(STATES(:,1) - ALGEBRAIC(:,30));
    ALGEBRAIC(:,28) = log(( 0.0183300.*CONSTANTS(:,14)+CONSTANTS(:,18))./( 0.0183300.*STATES(:,2)+STATES(:,9)))./CONSTANTS(:,44);
    ALGEBRAIC(:,29) =  CONSTANTS(:,19).*power(STATES(:,12), 2.00000).*(STATES(:,1) - ALGEBRAIC(:,28));
    ALGEBRAIC(:,33) = log(CONSTANTS(:,18)./STATES(:,9))./CONSTANTS(:,44);
    ALGEBRAIC(:,34) = 0.100000./(1.00000+exp( 0.0600000.*(STATES(:,1) - (ALGEBRAIC(:,33)+200.000))));
    ALGEBRAIC(:,35) = ( 3.00000.*exp( 0.000200000.*(STATES(:,1)+100.000+ - ALGEBRAIC(:,33)))+ 1.00000.*exp( 0.100000.*(STATES(:,1) - (10.0000+ALGEBRAIC(:,33)))))./(1.00000+exp(  - 0.500000.*(STATES(:,1) - ALGEBRAIC(:,33))));
    ALGEBRAIC(:,36) = ALGEBRAIC(:,34)./(ALGEBRAIC(:,34)+ALGEBRAIC(:,35));
    ALGEBRAIC(:,37) =  CONSTANTS(:,46).*ALGEBRAIC(:,36).*(STATES(:,1) - ALGEBRAIC(:,33));
    ALGEBRAIC(:,40) = 1.00000./(1.00000+ 0.124500.*exp(  - 0.100000.*STATES(:,1).*CONSTANTS(:,44))+ 0.0365000.*CONSTANTS(:,50).*exp(  - STATES(:,1).*CONSTANTS(:,44)));
    ALGEBRAIC(:,41) = ( (( CONSTANTS(:,49).*ALGEBRAIC(:,40).*1.00000)./(1.00000+power(CONSTANTS(:,21)./STATES(:,2), 1.50000))).*CONSTANTS(:,18))./(CONSTANTS(:,18)+CONSTANTS(:,22));
    ALGEBRAIC(:,1) =  floor(VOI./CONSTANTS(:,7)).*CONSTANTS(:,7);
    ALGEBRAIC(:,11) = piecewise({VOI - ALGEBRAIC(:,1)>=CONSTANTS(:,6)&VOI - ALGEBRAIC(:,1)<=CONSTANTS(:,6)+CONSTANTS(:,8), CONSTANTS(:,9) }, 0.00000);
    ALGEBRAIC(:,23) = log(CONSTANTS(:,16)./STATES(:,6))./( 2.00000.*CONSTANTS(:,44));
    ALGEBRAIC(:,24) = CONSTANTS(:,17)./(CONSTANTS(:,17)+STATES(:,6));
    ALGEBRAIC(:,25) =  CONSTANTS(:,15).*STATES(:,7).*STATES(:,8).*ALGEBRAIC(:,24).*(STATES(:,1) - ALGEBRAIC(:,23));
    ALGEBRAIC(:,42) =  (( (( (( CONSTANTS(:,51).*1.00000)./(power(CONSTANTS(:,23), 3.00000)+power(CONSTANTS(:,14), 3.00000))).*1.00000)./(CONSTANTS(:,24)+CONSTANTS(:,16))).*1.00000)./(1.00000+ CONSTANTS(:,25).*exp( (CONSTANTS(:,26) - 1.00000).*STATES(:,1).*CONSTANTS(:,44)))).*( exp( CONSTANTS(:,26).*STATES(:,1).*CONSTANTS(:,44)).*power(STATES(:,2), 3.00000).*CONSTANTS(:,16) -  exp( (CONSTANTS(:,26) - 1.00000).*STATES(:,1).*CONSTANTS(:,44)).*power(CONSTANTS(:,14), 3.00000).*STATES(:,6));
    ALGEBRAIC(:,38) =  CONSTANTS(:,47).*(STATES(:,1) - ALGEBRAIC(:,23));
    ALGEBRAIC(:,21) = log(CONSTANTS(:,14)./STATES(:,2))./CONSTANTS(:,44);
    ALGEBRAIC(:,22) =  CONSTANTS(:,13).*power(STATES(:,3), 3.00000).*STATES(:,4).*STATES(:,5).*(STATES(:,1) - ALGEBRAIC(:,21));
    ALGEBRAIC(:,39) =  CONSTANTS(:,48).*(STATES(:,1) - ALGEBRAIC(:,21));
    ALGEBRAIC(:,43) = ALGEBRAIC(:,22)+ALGEBRAIC(:,25)+ALGEBRAIC(:,27)+ALGEBRAIC(:,32)+ALGEBRAIC(:,29)+ALGEBRAIC(:,37)+ALGEBRAIC(:,42)+ALGEBRAIC(:,41)+ALGEBRAIC(:,39)+ALGEBRAIC(:,38)+ALGEBRAIC(:,11);
    ALGEBRAIC(:,45) = piecewise({CONSTANTS(:,10)==1.00000&(VOI<=500.000||VOI>800.000), (CONSTANTS(:,11) - STATES(:,1))./1.00000 , CONSTANTS(:,10)==1.00000&VOI>500.000&VOI<=800.000, (CONSTANTS(:,12) - STATES(:,1))./1.00000 },   - 1.00000.*ALGEBRAIC(:,43));
    ALGEBRAIC(:,44) = piecewise({STATES(:,18)>CONSTANTS(:,30),  (( 1.00000.*CONSTANTS(:,27).*(STATES(:,18) - CONSTANTS(:,30)))./((CONSTANTS(:,29)+STATES(:,18)) - CONSTANTS(:,30))).*(1.00000 - STATES(:,16)).*STATES(:,16) , STATES(:,18)<=CONSTANTS(:,30)&STATES(:,20)>0.00000,  0.00000.*CONSTANTS(:,28).*(1.00000 - STATES(:,20)).*STATES(:,20) }, 0.00000);
    ALGEBRAIC(:,46) =  ALGEBRAIC(:,44).*(STATES(:,14) - STATES(:,6));
    ALGEBRAIC(:,47) = ( CONSTANTS(:,52).*STATES(:,6))./(STATES(:,6)+CONSTANTS(:,34));
    ALGEBRAIC(:,48) =  CONSTANTS(:,53).*STATES(:,22);
    ALGEBRAIC(:,49) = 1.00000./(1.00000+ CONSTANTS(:,40).*(( CONSTANTS(:,39).*CONSTANTS(:,37))./power(CONSTANTS(:,37)+STATES(:,6), 2.00000)+( CONSTANTS(:,38).*CONSTANTS(:,36))./power(CONSTANTS(:,36)+STATES(:,6), 2.00000)));
    ALGEBRAIC(:,50) = ( 1.00000.*(STATES(:,22) - STATES(:,14)))./CONSTANTS(:,35);
    ALGEBRAIC(:,51) = 1.00000./(1.00000+( CONSTANTS(:,41).*CONSTANTS(:,31))./power(CONSTANTS(:,31)+STATES(:,14), 2.00000));
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