Generated Code

The following is matlab code generated by the CellML API from this CellML file. (Back to language selection)

The raw code is available.

function [VOI, STATES, ALGEBRAIC, CONSTANTS] = mainFunction()
    % This is the "main function".  In Matlab, things work best if you rename this function to match the filename.
   [VOI, STATES, ALGEBRAIC, CONSTANTS] = solveModel();
end

function [algebraicVariableCount] = getAlgebraicVariableCount() 
    % Used later when setting a global variable with the number of algebraic variables.
    % Note: This is not the "main method".  
    algebraicVariableCount =78;
end
% There are a total of 27 entries in each of the rate and state variable arrays.
% There are a total of 61 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 (millisecond)');
    LEGEND_CONSTANTS(:,1) = strpad('R in component Environment (millijoule_per_mole_kelvin)');
    LEGEND_CONSTANTS(:,2) = strpad('T in component Environment (kelvin)');
    LEGEND_CONSTANTS(:,3) = strpad('F in component Environment (coulomb_per_mole)');
    LEGEND_CONSTANTS(:,4) = strpad('K_o in component Environment (millimolar)');
    LEGEND_CONSTANTS(:,5) = strpad('Ca_o in component Environment (millimolar)');
    LEGEND_CONSTANTS(:,6) = strpad('Na_o in component Environment (millimolar)');
    LEGEND_STATES(:,1) = strpad('V in component cell (millivolt)');
    LEGEND_CONSTANTS(:,7) = strpad('Cm in component cell (nanoF)');
    LEGEND_CONSTANTS(:,8) = strpad('Vol_c in component cell (nanolitre)');
    LEGEND_ALGEBRAIC(:,55) = strpad('i_K1 in component IK1 (nanoA_per_nanoF)');
    LEGEND_ALGEBRAIC(:,58) = strpad('i_to in component Ito (nanoA_per_nanoF)');
    LEGEND_ALGEBRAIC(:,56) = strpad('i_Kr in component IKr (nanoA_per_nanoF)');
    LEGEND_ALGEBRAIC(:,57) = strpad('i_Ks in component IKs (nanoA_per_nanoF)');
    LEGEND_ALGEBRAIC(:,61) = strpad('i_CaL in component ICaL (nanoA_per_nanoF)');
    LEGEND_ALGEBRAIC(:,65) = strpad('i_NaK in component INaK (nanoA_per_nanoF)');
    LEGEND_ALGEBRAIC(:,59) = strpad('i_Na in component INa (nanoA_per_nanoF)');
    LEGEND_ALGEBRAIC(:,60) = strpad('i_b_Na in component INab (nanoA_per_nanoF)');
    LEGEND_ALGEBRAIC(:,66) = strpad('i_NaCa in component INaCa (nanoA_per_nanoF)');
    LEGEND_ALGEBRAIC(:,62) = strpad('i_b_Ca in component ICab (nanoA_per_nanoF)');
    LEGEND_ALGEBRAIC(:,64) = strpad('i_p_K in component IpK (nanoA_per_nanoF)');
    LEGEND_ALGEBRAIC(:,63) = strpad('i_p_Ca in component IpCa (nanoA_per_nanoF)');
    LEGEND_ALGEBRAIC(:,1) = strpad('i_Stim in component cell (nanoA_per_nanoF)');
    LEGEND_ALGEBRAIC(:,67) = strpad('i_tot in component cell (nanoA_per_nanoF)');
    LEGEND_CONSTANTS(:,9) = strpad('stim_Period in component cell (millisecond)');
    LEGEND_ALGEBRAIC(:,13) = strpad('E_Na in component reversal_potentials (millivolt)');
    LEGEND_ALGEBRAIC(:,25) = strpad('E_K in component reversal_potentials (millivolt)');
    LEGEND_ALGEBRAIC(:,32) = strpad('E_Ks in component reversal_potentials (millivolt)');
    LEGEND_ALGEBRAIC(:,39) = strpad('E_Ca in component reversal_potentials (millivolt)');
    LEGEND_CONSTANTS(:,10) = strpad('P_kna in component reversal_potentials (dimensionless)');
    LEGEND_STATES(:,2) = strpad('K_i in component K (millimolar)');
    LEGEND_STATES(:,3) = strpad('Na_i in component Na (millimolar)');
    LEGEND_STATES(:,4) = strpad('Ca_i in component Ca (millimolar)');
    LEGEND_CONSTANTS(:,11) = strpad('g_K1_0 in component IK1 (microS_per_nanoF)');
    LEGEND_ALGEBRAIC(:,54) = strpad('xK1_inf in component iK1_rectification (dimensionless)');
    LEGEND_CONSTANTS(:,12) = strpad('Mg_Buf in component iK1_rectification (millimolar)');
    LEGEND_CONSTANTS(:,13) = strpad('SPM in component iK1_rectification (millimolar)');
    LEGEND_CONSTANTS(:,14) = strpad('fac in component iK1_rectification (dimensionless)');
    LEGEND_CONSTANTS(:,15) = strpad('phi in component iK1_rectification (dimensionless)');
    LEGEND_ALGEBRAIC(:,50) = strpad('temp in component iK1_rectification (dimensionless)');
    LEGEND_ALGEBRAIC(:,52) = strpad('rec1 in component iK1_rectification (dimensionless)');
    LEGEND_ALGEBRAIC(:,53) = strpad('rec2 in component iK1_rectification (dimensionless)');
    LEGEND_ALGEBRAIC(:,42) = strpad('KiMg in component iK1_rectification (millimolar)');
    LEGEND_ALGEBRAIC(:,44) = strpad('KbMg in component iK1_rectification (millimolar)');
    LEGEND_ALGEBRAIC(:,46) = strpad('Kd1SPM in component iK1_rectification (millimolar)');
    LEGEND_ALGEBRAIC(:,48) = strpad('Kd2SPM in component iK1_rectification (millimolar)');
    LEGEND_CONSTANTS(:,16) = strpad('g_Kr_0 in component IKr (microS_per_nanoF)');
    LEGEND_STATES(:,5) = strpad('Or4 in component iKr_Markov (dimensionless)');
    LEGEND_STATES(:,6) = strpad('Cr1 in component iKr_Markov (dimensionless)');
    LEGEND_STATES(:,7) = strpad('Cr2 in component iKr_Markov (dimensionless)');
    LEGEND_STATES(:,8) = strpad('Cr3 in component iKr_Markov (dimensionless)');
    LEGEND_STATES(:,9) = strpad('Ir5 in component iKr_Markov (dimensionless)');
    LEGEND_CONSTANTS(:,17) = strpad('T_Base in component iKr_Markov (kelvin)');
    LEGEND_ALGEBRAIC(:,2) = strpad('alpha_xr1 in component iKr_Markov (per_millisecond)');
    LEGEND_ALGEBRAIC(:,14) = strpad('beta_xr1 in component iKr_Markov (per_millisecond)');
    LEGEND_ALGEBRAIC(:,26) = strpad('alpha_xr2 in component iKr_Markov (per_millisecond)');
    LEGEND_ALGEBRAIC(:,33) = strpad('beta_xr2 in component iKr_Markov (per_millisecond)');
    LEGEND_ALGEBRAIC(:,40) = strpad('alpha_xr3 in component iKr_Markov (per_millisecond)');
    LEGEND_ALGEBRAIC(:,43) = strpad('beta_xr3 in component iKr_Markov (per_millisecond)');
    LEGEND_ALGEBRAIC(:,45) = strpad('alpha_xr4 in component iKr_Markov (per_millisecond)');
    LEGEND_ALGEBRAIC(:,47) = strpad('beta_xr4 in component iKr_Markov (per_millisecond)');
    LEGEND_ALGEBRAIC(:,49) = strpad('OtoB in component iKr_Markov_Sotalol_block (per_millisecond)');
    LEGEND_ALGEBRAIC(:,51) = strpad('BtoO in component iKr_Markov_Sotalol_block (per_millisecond)');
    LEGEND_CONSTANTS(:,18) = strpad('Sotalol_mM in component iKr_Markov_Sotalol_block (millimolar)');
    LEGEND_STATES(:,10) = strpad('BCr1 in component iKr_Markov_Sotalol_block (dimensionless)');
    LEGEND_STATES(:,11) = strpad('BCr2 in component iKr_Markov_Sotalol_block (dimensionless)');
    LEGEND_STATES(:,12) = strpad('BCr3 in component iKr_Markov_Sotalol_block (dimensionless)');
    LEGEND_STATES(:,13) = strpad('BOr4 in component iKr_Markov_Sotalol_block (dimensionless)');
    LEGEND_STATES(:,14) = strpad('BIr5 in component iKr_Markov_Sotalol_block (dimensionless)');
    LEGEND_CONSTANTS(:,19) = strpad('kBinding in component iKr_Markov_Sotalol_block (per_millimolar_per_millisecond)');
    LEGEND_CONSTANTS(:,20) = strpad('kDiss in component iKr_Markov_Sotalol_block (per_millisecond)');
    LEGEND_CONSTANTS(:,21) = strpad('g_Ks in component IKs (microS_per_nanoF)');
    LEGEND_STATES(:,15) = strpad('Xs in component iKs_Xs_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,3) = strpad('xs_inf in component iKs_Xs_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,15) = strpad('alpha_xs in component iKs_Xs_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,27) = strpad('beta_xs in component iKs_Xs_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,34) = strpad('tau_xs in component iKs_Xs_gate (millisecond)');
    LEGEND_CONSTANTS(:,22) = strpad('g_to in component Ito (microS_per_nanoF)');
    LEGEND_STATES(:,16) = strpad('s in component ito_s_gate (dimensionless)');
    LEGEND_STATES(:,17) = strpad('r in component ito_r_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,4) = strpad('s_inf in component ito_s_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,16) = strpad('tau_s in component ito_s_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,5) = strpad('r_inf in component ito_r_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,17) = strpad('tau_r in component ito_r_gate (millisecond)');
    LEGEND_CONSTANTS(:,23) = strpad('g_Na in component INa (microS_per_nanoF)');
    LEGEND_CONSTANTS(:,24) = strpad('shift_INa_inact in component INa (millivolt)');
    LEGEND_STATES(:,18) = strpad('m in component iNa_m_gate (dimensionless)');
    LEGEND_STATES(:,19) = strpad('h in component iNa_h_gate (dimensionless)');
    LEGEND_STATES(:,20) = strpad('j in component iNa_j_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,6) = strpad('m_inf in component iNa_m_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,18) = strpad('alpha_m in component iNa_m_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,28) = strpad('beta_m in component iNa_m_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,35) = strpad('tau_m in component iNa_m_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,7) = strpad('h_inf in component iNa_h_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,19) = strpad('alpha_h in component iNa_h_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,29) = strpad('beta_h in component iNa_h_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,36) = strpad('tau_h in component iNa_h_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,8) = strpad('j_inf in component iNa_j_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,20) = strpad('alpha_j in component iNa_j_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,30) = strpad('beta_j in component iNa_j_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,37) = strpad('tau_j in component iNa_j_gate (millisecond)');
    LEGEND_CONSTANTS(:,25) = strpad('g_bna in component INab (microS_per_nanoF)');
    LEGEND_CONSTANTS(:,26) = strpad('g_CaL in component ICaL (litre_per_farad_millisecond)');
    LEGEND_STATES(:,21) = strpad('Ca_ss in component Ca (millimolar)');
    LEGEND_STATES(:,22) = strpad('d in component iCaL_d_gate (dimensionless)');
    LEGEND_STATES(:,23) = strpad('f in component iCaL_f_gate (dimensionless)');
    LEGEND_STATES(:,24) = strpad('f2 in component iCaL_f2_gate (dimensionless)');
    LEGEND_STATES(:,25) = strpad('fCass in component iCaL_fCass_gate (dimensionless)');
    LEGEND_CONSTANTS(:,27) = strpad('z in component ICaL (dimensionless)');
    LEGEND_ALGEBRAIC(:,9) = strpad('d_inf in component iCaL_d_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,21) = strpad('alpha_d in component iCaL_d_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,31) = strpad('beta_d in component iCaL_d_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,38) = strpad('gamma_d in component iCaL_d_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,41) = strpad('tau_d in component iCaL_d_gate (millisecond)');
    LEGEND_CONSTANTS(:,28) = strpad('d_inf_shift in component iCaL_d_gate (millivolt)');
    LEGEND_ALGEBRAIC(:,10) = strpad('f_inf in component iCaL_f_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,22) = strpad('tau_f in component iCaL_f_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,11) = strpad('f2_inf in component iCaL_f2_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,23) = strpad('tau_f2 in component iCaL_f2_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,12) = strpad('fCass_inf in component iCaL_fCass_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,24) = strpad('tau_fCass in component iCaL_fCass_gate (millisecond)');
    LEGEND_CONSTANTS(:,29) = strpad('g_bca in component ICab (microS_per_nanoF)');
    LEGEND_CONSTANTS(:,30) = strpad('g_pCa in component IpCa (nanoA_per_nanoF)');
    LEGEND_CONSTANTS(:,31) = strpad('K_pCa in component IpCa (millimolar)');
    LEGEND_CONSTANTS(:,32) = strpad('g_pK in component IpK (microS_per_nanoF)');
    LEGEND_CONSTANTS(:,33) = strpad('P_NaK in component INaK (nanoA_per_nanoF)');
    LEGEND_CONSTANTS(:,34) = strpad('K_mk in component INaK (millimolar)');
    LEGEND_CONSTANTS(:,35) = strpad('K_mNa in component INaK (millimolar)');
    LEGEND_CONSTANTS(:,36) = strpad('K_NaCa in component INaCa (nanoA_per_nanoF)');
    LEGEND_CONSTANTS(:,37) = strpad('K_sat in component INaCa (dimensionless)');
    LEGEND_CONSTANTS(:,38) = strpad('alpha in component INaCa (dimensionless)');
    LEGEND_CONSTANTS(:,39) = strpad('gamma in component INaCa (dimensionless)');
    LEGEND_CONSTANTS(:,40) = strpad('Km_Ca in component INaCa (millimolar)');
    LEGEND_CONSTANTS(:,41) = strpad('Km_Nai in component INaCa (millimolar)');
    LEGEND_STATES(:,26) = strpad('Ca_SR in component Ca (millimolar)');
    LEGEND_ALGEBRAIC(:,71) = strpad('Ca_i_bufc in component Ca_buffer (dimensionless)');
    LEGEND_ALGEBRAIC(:,77) = strpad('Ca_sr_bufsr in component Ca_buffer (dimensionless)');
    LEGEND_ALGEBRAIC(:,78) = strpad('Ca_ss_bufss in component Ca_buffer (dimensionless)');
    LEGEND_CONSTANTS(:,42) = strpad('V_sr in component Ca (nanolitre)');
    LEGEND_CONSTANTS(:,43) = strpad('V_ss in component Ca (nanolitre)');
    LEGEND_ALGEBRAIC(:,76) = strpad('i_rel in component Irel (millimolar_per_millisecond)');
    LEGEND_ALGEBRAIC(:,68) = strpad('i_up in component Ileak_Iup_Ixfer (millimolar_per_millisecond)');
    LEGEND_ALGEBRAIC(:,69) = strpad('i_leak in component Ileak_Iup_Ixfer (millimolar_per_millisecond)');
    LEGEND_ALGEBRAIC(:,70) = strpad('i_xfer in component Ileak_Iup_Ixfer (millimolar_per_millisecond)');
    LEGEND_CONSTANTS(:,44) = strpad('Vol_xfer in component Ileak_Iup_Ixfer (per_millisecond)');
    LEGEND_CONSTANTS(:,45) = strpad('K_up in component Ileak_Iup_Ixfer (millimolar)');
    LEGEND_CONSTANTS(:,46) = strpad('Vol_leak in component Ileak_Iup_Ixfer (per_millisecond)');
    LEGEND_CONSTANTS(:,47) = strpad('Vmax_up in component Ileak_Iup_Ixfer (millimolar_per_millisecond)');
    LEGEND_STATES(:,27) = strpad('R_prime in component Irel (dimensionless)');
    LEGEND_CONSTANTS(:,48) = strpad('k1_prime in component Irel (per_millimolar2_per_millisecond)');
    LEGEND_CONSTANTS(:,49) = strpad('k2_prime in component Irel (per_millimolar_per_millisecond)');
    LEGEND_CONSTANTS(:,50) = strpad('EC in component Irel (millimolar)');
    LEGEND_CONSTANTS(:,51) = strpad('max_sr in component Irel (dimensionless)');
    LEGEND_CONSTANTS(:,52) = strpad('min_sr in component Irel (dimensionless)');
    LEGEND_CONSTANTS(:,53) = strpad('k3 in component Irel (per_millisecond)');
    LEGEND_CONSTANTS(:,54) = strpad('k4 in component Irel (per_millisecond)');
    LEGEND_CONSTANTS(:,55) = strpad('Vol_rel in component Irel (per_millisecond)');
    LEGEND_ALGEBRAIC(:,75) = strpad('O in component Irel (dimensionless)');
    LEGEND_ALGEBRAIC(:,72) = strpad('kcasr in component Irel (dimensionless)');
    LEGEND_ALGEBRAIC(:,73) = strpad('k1 in component Irel (per_millimolar2_per_millisecond)');
    LEGEND_ALGEBRAIC(:,74) = strpad('k2 in component Irel (per_millimolar_per_millisecond)');
    LEGEND_CONSTANTS(:,56) = strpad('Buf_c in component Ca_buffer (millimolar)');
    LEGEND_CONSTANTS(:,57) = strpad('K_buf_c in component Ca_buffer (millimolar)');
    LEGEND_CONSTANTS(:,58) = strpad('Buf_sr in component Ca_buffer (millimolar)');
    LEGEND_CONSTANTS(:,59) = strpad('K_buf_sr in component Ca_buffer (millimolar)');
    LEGEND_CONSTANTS(:,60) = strpad('Buf_ss in component Ca_buffer (millimolar)');
    LEGEND_CONSTANTS(:,61) = strpad('K_buf_ss in component Ca_buffer (millimolar)');
    LEGEND_RATES(:,1) = strpad('d/dt V in component cell (millivolt)');
    LEGEND_RATES(:,6) = strpad('d/dt Cr1 in component iKr_Markov (dimensionless)');
    LEGEND_RATES(:,7) = strpad('d/dt Cr2 in component iKr_Markov (dimensionless)');
    LEGEND_RATES(:,8) = strpad('d/dt Cr3 in component iKr_Markov (dimensionless)');
    LEGEND_RATES(:,5) = strpad('d/dt Or4 in component iKr_Markov (dimensionless)');
    LEGEND_RATES(:,9) = strpad('d/dt Ir5 in component iKr_Markov (dimensionless)');
    LEGEND_RATES(:,10) = strpad('d/dt BCr1 in component iKr_Markov_Sotalol_block (dimensionless)');
    LEGEND_RATES(:,11) = strpad('d/dt BCr2 in component iKr_Markov_Sotalol_block (dimensionless)');
    LEGEND_RATES(:,12) = strpad('d/dt BCr3 in component iKr_Markov_Sotalol_block (dimensionless)');
    LEGEND_RATES(:,13) = strpad('d/dt BOr4 in component iKr_Markov_Sotalol_block (dimensionless)');
    LEGEND_RATES(:,14) = strpad('d/dt BIr5 in component iKr_Markov_Sotalol_block (dimensionless)');
    LEGEND_RATES(:,15) = strpad('d/dt Xs in component iKs_Xs_gate (dimensionless)');
    LEGEND_RATES(:,16) = strpad('d/dt s in component ito_s_gate (dimensionless)');
    LEGEND_RATES(:,17) = strpad('d/dt r in component ito_r_gate (dimensionless)');
    LEGEND_RATES(:,18) = strpad('d/dt m in component iNa_m_gate (dimensionless)');
    LEGEND_RATES(:,19) = strpad('d/dt h in component iNa_h_gate (dimensionless)');
    LEGEND_RATES(:,20) = strpad('d/dt j in component iNa_j_gate (dimensionless)');
    LEGEND_RATES(:,22) = strpad('d/dt d in component iCaL_d_gate (dimensionless)');
    LEGEND_RATES(:,23) = strpad('d/dt f in component iCaL_f_gate (dimensionless)');
    LEGEND_RATES(:,24) = strpad('d/dt f2 in component iCaL_f2_gate (dimensionless)');
    LEGEND_RATES(:,25) = strpad('d/dt fCass in component iCaL_fCass_gate (dimensionless)');
    LEGEND_RATES(:,4) = strpad('d/dt Ca_i in component Ca (millimolar)');
    LEGEND_RATES(:,26) = strpad('d/dt Ca_SR in component Ca (millimolar)');
    LEGEND_RATES(:,21) = strpad('d/dt Ca_ss in component Ca (millimolar)');
    LEGEND_RATES(:,27) = strpad('d/dt R_prime in component Irel (dimensionless)');
    LEGEND_RATES(:,3) = strpad('d/dt Na_i in component Na (millimolar)');
    LEGEND_RATES(:,2) = strpad('d/dt K_i in component K (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 = [];
    CONSTANTS(:,1) = 8314.472;
    CONSTANTS(:,2) = 310;
    CONSTANTS(:,3) = 96485.3415;
    CONSTANTS(:,4) = 5.4;
    CONSTANTS(:,5) = 2;
    CONSTANTS(:,6) = 140;
    STATES(:,1) = -86.45;
    CONSTANTS(:,7) = 0.115;
    CONSTANTS(:,8) = 0.016404;
    CONSTANTS(:,9) = 1000;
    CONSTANTS(:,10) = 0.03;
    STATES(:,2) = 141.0167;
    STATES(:,3) = 7.940167;
    STATES(:,4) = 1.092e-4;
    CONSTANTS(:,11) = 0.6821;
    CONSTANTS(:,12) = 0.0356;
    CONSTANTS(:,13) = 1.4613e-3;
    CONSTANTS(:,14) = 1.0648;
    CONSTANTS(:,15) = 0.8838;
    CONSTANTS(:,16) = 0.024;
    STATES(:,5) = 0.014;
    STATES(:,6) = 0.9786;
    STATES(:,7) = 0.0031;
    STATES(:,8) = 0.0029;
    STATES(:,9) = 0.0014;
    CONSTANTS(:,17) = 310;
    CONSTANTS(:,18) = 0;
    STATES(:,10) = 0;
    STATES(:,11) = 0;
    STATES(:,12) = 0;
    STATES(:,13) = 0;
    STATES(:,14) = 0;
    CONSTANTS(:,19) = 5e-3;
    CONSTANTS(:,20) = 0.00125;
    CONSTANTS(:,21) = 0.0392;
    STATES(:,15) = 0.00303;
    CONSTANTS(:,22) = 0.2;
    STATES(:,16) = 1;
    STATES(:,17) = 2.11e-8;
    CONSTANTS(:,23) = 11;
    CONSTANTS(:,24) = 0;
    STATES(:,18) = 0.00132;
    STATES(:,19) = 0.7768;
    STATES(:,20) = 0.7766;
    CONSTANTS(:,25) = 0.00029;
    CONSTANTS(:,26) = 2e-5;
    STATES(:,21) = 1.893e-4;
    STATES(:,22) = 5.06e-6;
    STATES(:,23) = 0.9999;
    STATES(:,24) = 0.9995;
    STATES(:,25) = 1;
    CONSTANTS(:,27) = 2;
    CONSTANTS(:,28) = 5;
    CONSTANTS(:,29) = 0.0004736;
    CONSTANTS(:,30) = 0.0619;
    CONSTANTS(:,31) = 0.0005;
    CONSTANTS(:,32) = 0.00973;
    CONSTANTS(:,33) = 1.297;
    CONSTANTS(:,34) = 1;
    CONSTANTS(:,35) = 40;
    CONSTANTS(:,36) = 200;
    CONSTANTS(:,37) = 0.1;
    CONSTANTS(:,38) = 2.5;
    CONSTANTS(:,39) = 0.35;
    CONSTANTS(:,40) = 1.38;
    CONSTANTS(:,41) = 87.5;
    STATES(:,26) = 2.7656;
    CONSTANTS(:,42) = 0.001094;
    CONSTANTS(:,43) = 0.00005468;
    CONSTANTS(:,44) = 0.0038;
    CONSTANTS(:,45) = 0.00025;
    CONSTANTS(:,46) = 0.00036;
    CONSTANTS(:,47) = 0.006375;
    STATES(:,27) = 0.9864;
    CONSTANTS(:,48) = 0.15;
    CONSTANTS(:,49) = 0.045;
    CONSTANTS(:,50) = 1.5;
    CONSTANTS(:,51) = 2.5;
    CONSTANTS(:,52) = 1;
    CONSTANTS(:,53) = 0.06;
    CONSTANTS(:,54) = 0.005;
    CONSTANTS(:,55) = 0.306;
    CONSTANTS(:,56) = 0.2;
    CONSTANTS(:,57) = 0.001;
    CONSTANTS(:,58) = 10;
    CONSTANTS(:,59) = 0.3;
    CONSTANTS(:,60) = 0.4;
    CONSTANTS(:,61) = 0.00025;
    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
    ALGEBRAIC(:,2) =  (( 1.00000.*CONSTANTS(:,2))./CONSTANTS(:,17)).*exp(24.3350+ (CONSTANTS(:,17)./CONSTANTS(:,2)).*( 0.0112000.*STATES(:,1) - 25.9140));
    ALGEBRAIC(:,14) =  (( 1.00000.*CONSTANTS(:,2))./CONSTANTS(:,17)).*exp(13.6880+ (CONSTANTS(:,17)./CONSTANTS(:,2)).*(  - 0.0603000.*STATES(:,1) - 15.7070));
    RATES(:,6) =  ALGEBRAIC(:,14).*STATES(:,7) -  ALGEBRAIC(:,2).*STATES(:,6);
    RATES(:,10) =  ALGEBRAIC(:,14).*STATES(:,11) -  ALGEBRAIC(:,2).*STATES(:,10);
    ALGEBRAIC(:,4) = 1.00000./(1.00000+exp((STATES(:,1)+20.0000)./5.00000));
    ALGEBRAIC(:,16) =  85.0000.*exp( - power(STATES(:,1)+45.0000, 2.00000)./320.000)+5.00000./(1.00000+exp((STATES(:,1) - 20.0000)./5.00000))+3.00000;
    RATES(:,16) = (ALGEBRAIC(:,4) - STATES(:,16))./ALGEBRAIC(:,16);
    ALGEBRAIC(:,5) = 1.00000./(1.00000+exp((20.0000 - STATES(:,1))./6.00000));
    ALGEBRAIC(:,17) =  9.50000.*exp( - power(STATES(:,1)+40.0000, 2.00000)./1800.00)+0.800000;
    RATES(:,17) = (ALGEBRAIC(:,5) - STATES(:,17))./ALGEBRAIC(:,17);
    ALGEBRAIC(:,10) = 1.00000./(1.00000+exp((STATES(:,1)+20.0000)./7.00000));
    ALGEBRAIC(:,22) = ( 1102.50.*exp( - power(STATES(:,1)+27.0000, 2.00000)./225.000)+200.000./(1.00000+exp((13.0000 - STATES(:,1))./10.0000))+180.000./(1.00000+exp((STATES(:,1)+30.0000)./10.0000))+20.0000)./4.00000;
    RATES(:,23) = (ALGEBRAIC(:,10) - STATES(:,23))./ALGEBRAIC(:,22);
    ALGEBRAIC(:,11) = 0.750000./(1.00000+exp((STATES(:,1)+35.0000)./7.00000))+0.250000;
    ALGEBRAIC(:,23) = ( 562.000.*exp( - power(STATES(:,1)+27.0000, 2.00000)./240.000)+31.0000./(1.00000+exp((25.0000 - STATES(:,1))./10.0000))+80.0000./(1.00000+exp((STATES(:,1)+30.0000)./10.0000)))./2.00000;
    RATES(:,24) = (ALGEBRAIC(:,11) - STATES(:,24))./ALGEBRAIC(:,23);
    ALGEBRAIC(:,12) = 0.400000./(1.00000+power(STATES(:,21)./0.0500000, 2.00000))+0.600000;
    ALGEBRAIC(:,24) = 80.0000./(1.00000+power(STATES(:,21)./0.0500000, 2.00000))+2.00000;
    RATES(:,25) = (ALGEBRAIC(:,12) - STATES(:,25))./ALGEBRAIC(:,24);
    ALGEBRAIC(:,26) =  (( 1.00000.*CONSTANTS(:,2))./CONSTANTS(:,17)).*exp(22.7460+ (CONSTANTS(:,17)./CONSTANTS(:,2)).*( 0.00000.*STATES(:,1) - 25.9140));
    ALGEBRAIC(:,33) =  (( 1.00000.*CONSTANTS(:,2))./CONSTANTS(:,17)).*exp(13.1930+ (CONSTANTS(:,17)./CONSTANTS(:,2)).*( 0.00000.*STATES(:,1) - 15.7070));
    RATES(:,7) = ( ALGEBRAIC(:,2).*STATES(:,6)+ ALGEBRAIC(:,33).*STATES(:,8)) -  (ALGEBRAIC(:,26)+ALGEBRAIC(:,14)).*STATES(:,7);
    RATES(:,11) = ( ALGEBRAIC(:,2).*STATES(:,10)+ ALGEBRAIC(:,33).*STATES(:,12)) -  (ALGEBRAIC(:,26)+ALGEBRAIC(:,14)).*STATES(:,11);
    ALGEBRAIC(:,3) = 1.00000./(1.00000+exp(( - 5.00000 - STATES(:,1))./14.0000));
    ALGEBRAIC(:,15) = 1400.00./power((1.00000+exp((5.00000 - STATES(:,1))./6.00000)), 1.0 ./ 2);
    ALGEBRAIC(:,27) = 1.00000./(1.00000+exp((STATES(:,1) - 35.0000)./15.0000));
    ALGEBRAIC(:,34) =  1.00000.*ALGEBRAIC(:,15).*ALGEBRAIC(:,27)+80.0000;
    RATES(:,15) = (ALGEBRAIC(:,3) - STATES(:,15))./ALGEBRAIC(:,34);
    ALGEBRAIC(:,6) = 1.00000./power(1.00000+exp(( - 56.8600 - STATES(:,1))./9.03000), 2.00000);
    ALGEBRAIC(:,18) = 1.00000./(1.00000+exp(( - 60.0000 - STATES(:,1))./5.00000));
    ALGEBRAIC(:,28) = 0.100000./(1.00000+exp((STATES(:,1)+35.0000)./5.00000))+0.100000./(1.00000+exp((STATES(:,1) - 50.0000)./200.000));
    ALGEBRAIC(:,35) =  1.00000.*ALGEBRAIC(:,18).*ALGEBRAIC(:,28);
    RATES(:,18) = (ALGEBRAIC(:,6) - STATES(:,18))./ALGEBRAIC(:,35);
    ALGEBRAIC(:,7) = 1.00000./power(1.00000+exp(((STATES(:,1)+71.5500) - CONSTANTS(:,24))./7.43000), 2.00000);
    ALGEBRAIC(:,19) = piecewise({STATES(:,1)< - 40.0000+CONSTANTS(:,24),  0.0570000.*exp( - ((STATES(:,1)+80.0000) - CONSTANTS(:,24))./6.80000) }, 0.00000);
    ALGEBRAIC(:,29) = piecewise({STATES(:,1)< - 40.0000+CONSTANTS(:,24),  2.70000.*exp( 0.0790000.*(STATES(:,1) - CONSTANTS(:,24)))+ 310000..*exp( 0.348500.*(STATES(:,1) - CONSTANTS(:,24))) }, 0.770000./( 0.130000.*(1.00000+exp(((STATES(:,1)+10.6600) - CONSTANTS(:,24))./ - 11.1000))));
    ALGEBRAIC(:,36) = 1.00000./(ALGEBRAIC(:,19)+ALGEBRAIC(:,29));
    RATES(:,19) = (ALGEBRAIC(:,7) - STATES(:,19))./ALGEBRAIC(:,36);
    ALGEBRAIC(:,8) = 1.00000./power(1.00000+exp(((STATES(:,1)+71.5500) - CONSTANTS(:,24))./7.43000), 2.00000);
    ALGEBRAIC(:,20) = piecewise({STATES(:,1)< - 40.0000+CONSTANTS(:,24), (( (  - 25428.0.*exp( 0.244400.*(STATES(:,1) - CONSTANTS(:,24))) -  6.94800e-06.*exp(  - 0.0439100.*(STATES(:,1) - CONSTANTS(:,24)))).*(STATES(:,1)+37.7800))./1.00000)./(1.00000+exp( 0.311000.*((STATES(:,1)+79.2300) - CONSTANTS(:,24)))) }, 0.00000);
    ALGEBRAIC(:,30) = piecewise({STATES(:,1)< - 40.0000+CONSTANTS(:,24), ( 0.0242400.*exp(  - 0.0105200.*(STATES(:,1) - CONSTANTS(:,24))))./(1.00000+exp(  - 0.137800.*((STATES(:,1)+40.1400) - CONSTANTS(:,24)))) }, ( 0.600000.*exp( 0.0570000.*(STATES(:,1) - CONSTANTS(:,24))))./(1.00000+exp(  - 0.100000.*((STATES(:,1)+32.0000) - CONSTANTS(:,24)))));
    ALGEBRAIC(:,37) = 1.00000./(ALGEBRAIC(:,20)+ALGEBRAIC(:,30));
    RATES(:,20) = (ALGEBRAIC(:,8) - STATES(:,20))./ALGEBRAIC(:,37);
    ALGEBRAIC(:,9) = 1.00000./(1.00000+exp((CONSTANTS(:,28) - STATES(:,1))./7.50000));
    ALGEBRAIC(:,21) = 1.40000./(1.00000+exp(( - 35.0000 - STATES(:,1))./13.0000))+0.250000;
    ALGEBRAIC(:,31) = 1.40000./(1.00000+exp((STATES(:,1)+5.00000)./5.00000));
    ALGEBRAIC(:,38) = 1.00000./(1.00000+exp((50.0000 - STATES(:,1))./20.0000));
    ALGEBRAIC(:,41) =  1.00000.*ALGEBRAIC(:,21).*ALGEBRAIC(:,31)+ALGEBRAIC(:,38);
    RATES(:,22) = (ALGEBRAIC(:,9) - STATES(:,22))./ALGEBRAIC(:,41);
    ALGEBRAIC(:,40) =  (( 1.00000.*CONSTANTS(:,2))./CONSTANTS(:,17)).*exp(22.0980+ (CONSTANTS(:,17)./CONSTANTS(:,2)).*( 0.0365000.*STATES(:,1) - 25.9140));
    ALGEBRAIC(:,43) =  (( 1.00000.*CONSTANTS(:,2))./CONSTANTS(:,17)).*exp(7.31300+ (CONSTANTS(:,17)./CONSTANTS(:,2)).*(  - 0.0399000.*STATES(:,1) - 15.7070));
    RATES(:,8) = ( ALGEBRAIC(:,26).*STATES(:,7)+ ALGEBRAIC(:,43).*STATES(:,5)) -  (ALGEBRAIC(:,40)+ALGEBRAIC(:,33)).*STATES(:,8);
    RATES(:,12) = ( ALGEBRAIC(:,26).*STATES(:,11)+ ALGEBRAIC(:,43).*STATES(:,13)) -  (ALGEBRAIC(:,40)+ALGEBRAIC(:,33)).*STATES(:,12);
    ALGEBRAIC(:,45) =  (( 1.00000.*CONSTANTS(:,2))./CONSTANTS(:,17)).*exp(30.0160+ (CONSTANTS(:,17)./CONSTANTS(:,2)).*( 0.0223000.*STATES(:,1) - 30.8880)).*power(5.40000./CONSTANTS(:,4), 0.400000);
    ALGEBRAIC(:,47) =  (( 1.00000.*CONSTANTS(:,2))./CONSTANTS(:,17)).*exp(30.0610+ (CONSTANTS(:,17)./CONSTANTS(:,2)).*(  - 0.0312000.*STATES(:,1) - 33.2430));
    RATES(:,9) =  ALGEBRAIC(:,45).*STATES(:,5) -  ALGEBRAIC(:,47).*STATES(:,9);
    RATES(:,14) =  ALGEBRAIC(:,45).*STATES(:,13) -  ALGEBRAIC(:,47).*STATES(:,14);
    ALGEBRAIC(:,49) =  STATES(:,5).*CONSTANTS(:,18).*CONSTANTS(:,19);
    ALGEBRAIC(:,51) =  STATES(:,13).*CONSTANTS(:,20);
    RATES(:,5) = ((( ALGEBRAIC(:,40).*STATES(:,8)+ ALGEBRAIC(:,47).*STATES(:,9)) -  (ALGEBRAIC(:,45)+ALGEBRAIC(:,43)).*STATES(:,5)) - ALGEBRAIC(:,49))+ALGEBRAIC(:,51);
    RATES(:,13) = ((( ALGEBRAIC(:,40).*STATES(:,12)+ ALGEBRAIC(:,47).*STATES(:,14)) -  (ALGEBRAIC(:,45)+ALGEBRAIC(:,43)).*STATES(:,13))+ALGEBRAIC(:,49)) - ALGEBRAIC(:,51);
    ALGEBRAIC(:,25) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,4)./STATES(:,2));
    ALGEBRAIC(:,44) =  0.450000.*exp( - (STATES(:,1) -  CONSTANTS(:,14).*ALGEBRAIC(:,25))./20.0000);
    ALGEBRAIC(:,50) = 1.00000+CONSTANTS(:,12)./ALGEBRAIC(:,44);
    ALGEBRAIC(:,42) =  2.80000.*exp( - (STATES(:,1) -  CONSTANTS(:,14).*ALGEBRAIC(:,25))./180.000);
    ALGEBRAIC(:,46) =  0.000700000.*exp( - ((STATES(:,1) -  CONSTANTS(:,14).*ALGEBRAIC(:,25))+ 8.00000.*CONSTANTS(:,12))./4.80000);
    ALGEBRAIC(:,52) = ( ALGEBRAIC(:,50).*ALGEBRAIC(:,50))./(CONSTANTS(:,13)./ALGEBRAIC(:,46)+CONSTANTS(:,12)./ALGEBRAIC(:,42)+ ALGEBRAIC(:,50).*ALGEBRAIC(:,50).*ALGEBRAIC(:,50));
    ALGEBRAIC(:,48) =  0.0400000.*exp( - (STATES(:,1) -  CONSTANTS(:,14).*ALGEBRAIC(:,25))./9.10000);
    ALGEBRAIC(:,53) = 1.00000./(1.00000+CONSTANTS(:,13)./ALGEBRAIC(:,48));
    ALGEBRAIC(:,54) =  CONSTANTS(:,15).*ALGEBRAIC(:,52)+ (1.00000 - CONSTANTS(:,15)).*ALGEBRAIC(:,53);
    ALGEBRAIC(:,55) =  CONSTANTS(:,11).*(CONSTANTS(:,2)./35.0000 - 55.0000./7.00000).*power((CONSTANTS(:,4)./5.40000), 1.0 ./ 2).*ALGEBRAIC(:,54).*(STATES(:,1) - ALGEBRAIC(:,25));
    ALGEBRAIC(:,58) =  CONSTANTS(:,22).*STATES(:,17).*STATES(:,16).*(STATES(:,1) - ALGEBRAIC(:,25));
    ALGEBRAIC(:,56) =  CONSTANTS(:,16).*(CONSTANTS(:,2)./35.0000 - 55.0000./7.00000).*power((CONSTANTS(:,4)./5.40000), 1.0 ./ 2).*STATES(:,5).*(STATES(:,1) - ALGEBRAIC(:,25));
    ALGEBRAIC(:,32) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log((CONSTANTS(:,4)+ CONSTANTS(:,10).*CONSTANTS(:,6))./(STATES(:,2)+ CONSTANTS(:,10).*STATES(:,3)));
    ALGEBRAIC(:,57) =  CONSTANTS(:,21).*power(STATES(:,15), 2.00000).*(STATES(:,1) - ALGEBRAIC(:,32));
    ALGEBRAIC(:,65) = (( (( CONSTANTS(:,33).*CONSTANTS(:,4))./(CONSTANTS(:,4)+CONSTANTS(:,34))).*STATES(:,3))./(STATES(:,3)+CONSTANTS(:,35)))./(1.00000+ 0.124500.*exp((  - 0.100000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))+ 0.0353000.*exp((  - STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,64) = ( CONSTANTS(:,32).*(STATES(:,1) - ALGEBRAIC(:,25)))./(1.00000+exp((25.0000 - STATES(:,1))./5.98000));
    ALGEBRAIC(:,1) = piecewise({VOI -  floor(VOI./CONSTANTS(:,9)).*CONSTANTS(:,9)>=100.000&VOI -  floor(VOI./CONSTANTS(:,9)).*CONSTANTS(:,9)<=103.000,  - 12.0000 }, 0.00000);
    RATES(:,2) =  ( - ((ALGEBRAIC(:,55)+ALGEBRAIC(:,58)+ALGEBRAIC(:,56)+ALGEBRAIC(:,57)+ALGEBRAIC(:,64)+ALGEBRAIC(:,1)) -  2.00000.*ALGEBRAIC(:,65))./( CONSTANTS(:,8).*CONSTANTS(:,3))).*CONSTANTS(:,7);
    ALGEBRAIC(:,13) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,6)./STATES(:,3));
    ALGEBRAIC(:,59) =  CONSTANTS(:,23).*power(STATES(:,18), 3.00000).*STATES(:,19).*STATES(:,20).*(STATES(:,1) - ALGEBRAIC(:,13));
    ALGEBRAIC(:,60) =  CONSTANTS(:,25).*(STATES(:,1) - ALGEBRAIC(:,13));
    ALGEBRAIC(:,66) = ( CONSTANTS(:,36).*( exp(( CONSTANTS(:,39).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(STATES(:,3), 3.00000).*CONSTANTS(:,5) -  exp(( (CONSTANTS(:,39) - 1.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(CONSTANTS(:,6), 3.00000).*STATES(:,4).*CONSTANTS(:,38)))./( (power(CONSTANTS(:,41), 3.00000)+power(CONSTANTS(:,6), 3.00000)).*(CONSTANTS(:,40)+CONSTANTS(:,5)).*(1.00000+ CONSTANTS(:,37).*exp(( (CONSTANTS(:,39) - 1.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))));
    RATES(:,3) = (  - (ALGEBRAIC(:,59)+ALGEBRAIC(:,60)+ 3.00000.*ALGEBRAIC(:,65)+ 3.00000.*ALGEBRAIC(:,66)).*CONSTANTS(:,7))./( CONSTANTS(:,8).*CONSTANTS(:,3));
    ALGEBRAIC(:,61) = ( (( CONSTANTS(:,26).*STATES(:,22).*STATES(:,23).*STATES(:,24).*STATES(:,25).*power(CONSTANTS(:,27), 2.00000).*(STATES(:,1) - 15.0000).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( 0.250000.*STATES(:,21).*exp(( 2.00000.*(STATES(:,1) - 15.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - CONSTANTS(:,5)))./(exp(( 2.00000.*(STATES(:,1) - 15.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000);
    ALGEBRAIC(:,39) =  (( 0.500000.*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,5)./STATES(:,4));
    ALGEBRAIC(:,62) =  CONSTANTS(:,29).*(STATES(:,1) - ALGEBRAIC(:,39));
    ALGEBRAIC(:,63) = ( CONSTANTS(:,30).*STATES(:,4))./(STATES(:,4)+CONSTANTS(:,31));
    ALGEBRAIC(:,67) = ALGEBRAIC(:,55)+ALGEBRAIC(:,58)+ALGEBRAIC(:,56)+ALGEBRAIC(:,57)+ALGEBRAIC(:,61)+ALGEBRAIC(:,65)+ALGEBRAIC(:,59)+ALGEBRAIC(:,60)+ALGEBRAIC(:,66)+ALGEBRAIC(:,62)+ALGEBRAIC(:,64)+ALGEBRAIC(:,63)+ALGEBRAIC(:,1);
    RATES(:,1) =  - ALGEBRAIC(:,67);
    ALGEBRAIC(:,71) = 1.00000./(1.00000+( CONSTANTS(:,56).*CONSTANTS(:,57))./power(STATES(:,4)+CONSTANTS(:,57), 2.00000));
    ALGEBRAIC(:,68) = CONSTANTS(:,47)./(1.00000+power(CONSTANTS(:,45), 2.00000)./power(STATES(:,4), 2.00000));
    ALGEBRAIC(:,69) =  CONSTANTS(:,46).*(STATES(:,26) - STATES(:,4));
    ALGEBRAIC(:,70) =  CONSTANTS(:,44).*(STATES(:,21) - STATES(:,4));
    RATES(:,4) =  ALGEBRAIC(:,71).*((( (ALGEBRAIC(:,69) - ALGEBRAIC(:,68)).*CONSTANTS(:,42))./CONSTANTS(:,8)+ALGEBRAIC(:,70)) - ( ((ALGEBRAIC(:,62)+ALGEBRAIC(:,63)) -  2.00000.*ALGEBRAIC(:,66)).*CONSTANTS(:,7))./( 2.00000.*CONSTANTS(:,8).*CONSTANTS(:,3)));
    ALGEBRAIC(:,72) = CONSTANTS(:,51) - (CONSTANTS(:,51) - CONSTANTS(:,52))./(1.00000+power(CONSTANTS(:,50)./STATES(:,26), 2.00000));
    ALGEBRAIC(:,74) =  CONSTANTS(:,49).*ALGEBRAIC(:,72);
    RATES(:,27) =   - ALGEBRAIC(:,74).*STATES(:,21).*STATES(:,27)+ CONSTANTS(:,54).*(1.00000 - STATES(:,27));
    ALGEBRAIC(:,77) = 1.00000./(1.00000+( CONSTANTS(:,58).*CONSTANTS(:,59))./power(STATES(:,26)+CONSTANTS(:,59), 2.00000));
    ALGEBRAIC(:,73) = CONSTANTS(:,48)./ALGEBRAIC(:,72);
    ALGEBRAIC(:,75) = ( ALGEBRAIC(:,73).*power(STATES(:,21), 2.00000).*STATES(:,27))./(CONSTANTS(:,53)+ ALGEBRAIC(:,73).*power(STATES(:,21), 2.00000));
    ALGEBRAIC(:,76) =  CONSTANTS(:,55).*ALGEBRAIC(:,75).*(STATES(:,26) - STATES(:,21));
    RATES(:,26) =  ALGEBRAIC(:,77).*(ALGEBRAIC(:,68) - (ALGEBRAIC(:,76)+ALGEBRAIC(:,69)));
    ALGEBRAIC(:,78) = 1.00000./(1.00000+( CONSTANTS(:,60).*CONSTANTS(:,61))./power(STATES(:,21)+CONSTANTS(:,61), 2.00000));
    RATES(:,21) =  ALGEBRAIC(:,78).*(((  - ALGEBRAIC(:,61).*CONSTANTS(:,7))./( 2.00000.*CONSTANTS(:,43).*CONSTANTS(:,3))+( ALGEBRAIC(:,76).*CONSTANTS(:,42))./CONSTANTS(:,43)) - ( ALGEBRAIC(:,70).*CONSTANTS(:,8))./CONSTANTS(:,43));
   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) =  (( 1.00000.*CONSTANTS(:,2))./CONSTANTS(:,17)).*exp(24.3350+ (CONSTANTS(:,17)./CONSTANTS(:,2)).*( 0.0112000.*STATES(:,1) - 25.9140));
    ALGEBRAIC(:,14) =  (( 1.00000.*CONSTANTS(:,2))./CONSTANTS(:,17)).*exp(13.6880+ (CONSTANTS(:,17)./CONSTANTS(:,2)).*(  - 0.0603000.*STATES(:,1) - 15.7070));
    ALGEBRAIC(:,4) = 1.00000./(1.00000+exp((STATES(:,1)+20.0000)./5.00000));
    ALGEBRAIC(:,16) =  85.0000.*exp( - power(STATES(:,1)+45.0000, 2.00000)./320.000)+5.00000./(1.00000+exp((STATES(:,1) - 20.0000)./5.00000))+3.00000;
    ALGEBRAIC(:,5) = 1.00000./(1.00000+exp((20.0000 - STATES(:,1))./6.00000));
    ALGEBRAIC(:,17) =  9.50000.*exp( - power(STATES(:,1)+40.0000, 2.00000)./1800.00)+0.800000;
    ALGEBRAIC(:,10) = 1.00000./(1.00000+exp((STATES(:,1)+20.0000)./7.00000));
    ALGEBRAIC(:,22) = ( 1102.50.*exp( - power(STATES(:,1)+27.0000, 2.00000)./225.000)+200.000./(1.00000+exp((13.0000 - STATES(:,1))./10.0000))+180.000./(1.00000+exp((STATES(:,1)+30.0000)./10.0000))+20.0000)./4.00000;
    ALGEBRAIC(:,11) = 0.750000./(1.00000+exp((STATES(:,1)+35.0000)./7.00000))+0.250000;
    ALGEBRAIC(:,23) = ( 562.000.*exp( - power(STATES(:,1)+27.0000, 2.00000)./240.000)+31.0000./(1.00000+exp((25.0000 - STATES(:,1))./10.0000))+80.0000./(1.00000+exp((STATES(:,1)+30.0000)./10.0000)))./2.00000;
    ALGEBRAIC(:,12) = 0.400000./(1.00000+power(STATES(:,21)./0.0500000, 2.00000))+0.600000;
    ALGEBRAIC(:,24) = 80.0000./(1.00000+power(STATES(:,21)./0.0500000, 2.00000))+2.00000;
    ALGEBRAIC(:,26) =  (( 1.00000.*CONSTANTS(:,2))./CONSTANTS(:,17)).*exp(22.7460+ (CONSTANTS(:,17)./CONSTANTS(:,2)).*( 0.00000.*STATES(:,1) - 25.9140));
    ALGEBRAIC(:,33) =  (( 1.00000.*CONSTANTS(:,2))./CONSTANTS(:,17)).*exp(13.1930+ (CONSTANTS(:,17)./CONSTANTS(:,2)).*( 0.00000.*STATES(:,1) - 15.7070));
    ALGEBRAIC(:,3) = 1.00000./(1.00000+exp(( - 5.00000 - STATES(:,1))./14.0000));
    ALGEBRAIC(:,15) = 1400.00./power((1.00000+exp((5.00000 - STATES(:,1))./6.00000)), 1.0 ./ 2);
    ALGEBRAIC(:,27) = 1.00000./(1.00000+exp((STATES(:,1) - 35.0000)./15.0000));
    ALGEBRAIC(:,34) =  1.00000.*ALGEBRAIC(:,15).*ALGEBRAIC(:,27)+80.0000;
    ALGEBRAIC(:,6) = 1.00000./power(1.00000+exp(( - 56.8600 - STATES(:,1))./9.03000), 2.00000);
    ALGEBRAIC(:,18) = 1.00000./(1.00000+exp(( - 60.0000 - STATES(:,1))./5.00000));
    ALGEBRAIC(:,28) = 0.100000./(1.00000+exp((STATES(:,1)+35.0000)./5.00000))+0.100000./(1.00000+exp((STATES(:,1) - 50.0000)./200.000));
    ALGEBRAIC(:,35) =  1.00000.*ALGEBRAIC(:,18).*ALGEBRAIC(:,28);
    ALGEBRAIC(:,7) = 1.00000./power(1.00000+exp(((STATES(:,1)+71.5500) - CONSTANTS(:,24))./7.43000), 2.00000);
    ALGEBRAIC(:,19) = piecewise({STATES(:,1)< - 40.0000+CONSTANTS(:,24),  0.0570000.*exp( - ((STATES(:,1)+80.0000) - CONSTANTS(:,24))./6.80000) }, 0.00000);
    ALGEBRAIC(:,29) = piecewise({STATES(:,1)< - 40.0000+CONSTANTS(:,24),  2.70000.*exp( 0.0790000.*(STATES(:,1) - CONSTANTS(:,24)))+ 310000..*exp( 0.348500.*(STATES(:,1) - CONSTANTS(:,24))) }, 0.770000./( 0.130000.*(1.00000+exp(((STATES(:,1)+10.6600) - CONSTANTS(:,24))./ - 11.1000))));
    ALGEBRAIC(:,36) = 1.00000./(ALGEBRAIC(:,19)+ALGEBRAIC(:,29));
    ALGEBRAIC(:,8) = 1.00000./power(1.00000+exp(((STATES(:,1)+71.5500) - CONSTANTS(:,24))./7.43000), 2.00000);
    ALGEBRAIC(:,20) = piecewise({STATES(:,1)< - 40.0000+CONSTANTS(:,24), (( (  - 25428.0.*exp( 0.244400.*(STATES(:,1) - CONSTANTS(:,24))) -  6.94800e-06.*exp(  - 0.0439100.*(STATES(:,1) - CONSTANTS(:,24)))).*(STATES(:,1)+37.7800))./1.00000)./(1.00000+exp( 0.311000.*((STATES(:,1)+79.2300) - CONSTANTS(:,24)))) }, 0.00000);
    ALGEBRAIC(:,30) = piecewise({STATES(:,1)< - 40.0000+CONSTANTS(:,24), ( 0.0242400.*exp(  - 0.0105200.*(STATES(:,1) - CONSTANTS(:,24))))./(1.00000+exp(  - 0.137800.*((STATES(:,1)+40.1400) - CONSTANTS(:,24)))) }, ( 0.600000.*exp( 0.0570000.*(STATES(:,1) - CONSTANTS(:,24))))./(1.00000+exp(  - 0.100000.*((STATES(:,1)+32.0000) - CONSTANTS(:,24)))));
    ALGEBRAIC(:,37) = 1.00000./(ALGEBRAIC(:,20)+ALGEBRAIC(:,30));
    ALGEBRAIC(:,9) = 1.00000./(1.00000+exp((CONSTANTS(:,28) - STATES(:,1))./7.50000));
    ALGEBRAIC(:,21) = 1.40000./(1.00000+exp(( - 35.0000 - STATES(:,1))./13.0000))+0.250000;
    ALGEBRAIC(:,31) = 1.40000./(1.00000+exp((STATES(:,1)+5.00000)./5.00000));
    ALGEBRAIC(:,38) = 1.00000./(1.00000+exp((50.0000 - STATES(:,1))./20.0000));
    ALGEBRAIC(:,41) =  1.00000.*ALGEBRAIC(:,21).*ALGEBRAIC(:,31)+ALGEBRAIC(:,38);
    ALGEBRAIC(:,40) =  (( 1.00000.*CONSTANTS(:,2))./CONSTANTS(:,17)).*exp(22.0980+ (CONSTANTS(:,17)./CONSTANTS(:,2)).*( 0.0365000.*STATES(:,1) - 25.9140));
    ALGEBRAIC(:,43) =  (( 1.00000.*CONSTANTS(:,2))./CONSTANTS(:,17)).*exp(7.31300+ (CONSTANTS(:,17)./CONSTANTS(:,2)).*(  - 0.0399000.*STATES(:,1) - 15.7070));
    ALGEBRAIC(:,45) =  (( 1.00000.*CONSTANTS(:,2))./CONSTANTS(:,17)).*exp(30.0160+ (CONSTANTS(:,17)./CONSTANTS(:,2)).*( 0.0223000.*STATES(:,1) - 30.8880)).*power(5.40000./CONSTANTS(:,4), 0.400000);
    ALGEBRAIC(:,47) =  (( 1.00000.*CONSTANTS(:,2))./CONSTANTS(:,17)).*exp(30.0610+ (CONSTANTS(:,17)./CONSTANTS(:,2)).*(  - 0.0312000.*STATES(:,1) - 33.2430));
    ALGEBRAIC(:,49) =  STATES(:,5).*CONSTANTS(:,18).*CONSTANTS(:,19);
    ALGEBRAIC(:,51) =  STATES(:,13).*CONSTANTS(:,20);
    ALGEBRAIC(:,25) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,4)./STATES(:,2));
    ALGEBRAIC(:,44) =  0.450000.*exp( - (STATES(:,1) -  CONSTANTS(:,14).*ALGEBRAIC(:,25))./20.0000);
    ALGEBRAIC(:,50) = 1.00000+CONSTANTS(:,12)./ALGEBRAIC(:,44);
    ALGEBRAIC(:,42) =  2.80000.*exp( - (STATES(:,1) -  CONSTANTS(:,14).*ALGEBRAIC(:,25))./180.000);
    ALGEBRAIC(:,46) =  0.000700000.*exp( - ((STATES(:,1) -  CONSTANTS(:,14).*ALGEBRAIC(:,25))+ 8.00000.*CONSTANTS(:,12))./4.80000);
    ALGEBRAIC(:,52) = ( ALGEBRAIC(:,50).*ALGEBRAIC(:,50))./(CONSTANTS(:,13)./ALGEBRAIC(:,46)+CONSTANTS(:,12)./ALGEBRAIC(:,42)+ ALGEBRAIC(:,50).*ALGEBRAIC(:,50).*ALGEBRAIC(:,50));
    ALGEBRAIC(:,48) =  0.0400000.*exp( - (STATES(:,1) -  CONSTANTS(:,14).*ALGEBRAIC(:,25))./9.10000);
    ALGEBRAIC(:,53) = 1.00000./(1.00000+CONSTANTS(:,13)./ALGEBRAIC(:,48));
    ALGEBRAIC(:,54) =  CONSTANTS(:,15).*ALGEBRAIC(:,52)+ (1.00000 - CONSTANTS(:,15)).*ALGEBRAIC(:,53);
    ALGEBRAIC(:,55) =  CONSTANTS(:,11).*(CONSTANTS(:,2)./35.0000 - 55.0000./7.00000).*power((CONSTANTS(:,4)./5.40000), 1.0 ./ 2).*ALGEBRAIC(:,54).*(STATES(:,1) - ALGEBRAIC(:,25));
    ALGEBRAIC(:,58) =  CONSTANTS(:,22).*STATES(:,17).*STATES(:,16).*(STATES(:,1) - ALGEBRAIC(:,25));
    ALGEBRAIC(:,56) =  CONSTANTS(:,16).*(CONSTANTS(:,2)./35.0000 - 55.0000./7.00000).*power((CONSTANTS(:,4)./5.40000), 1.0 ./ 2).*STATES(:,5).*(STATES(:,1) - ALGEBRAIC(:,25));
    ALGEBRAIC(:,32) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log((CONSTANTS(:,4)+ CONSTANTS(:,10).*CONSTANTS(:,6))./(STATES(:,2)+ CONSTANTS(:,10).*STATES(:,3)));
    ALGEBRAIC(:,57) =  CONSTANTS(:,21).*power(STATES(:,15), 2.00000).*(STATES(:,1) - ALGEBRAIC(:,32));
    ALGEBRAIC(:,65) = (( (( CONSTANTS(:,33).*CONSTANTS(:,4))./(CONSTANTS(:,4)+CONSTANTS(:,34))).*STATES(:,3))./(STATES(:,3)+CONSTANTS(:,35)))./(1.00000+ 0.124500.*exp((  - 0.100000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))+ 0.0353000.*exp((  - STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,64) = ( CONSTANTS(:,32).*(STATES(:,1) - ALGEBRAIC(:,25)))./(1.00000+exp((25.0000 - STATES(:,1))./5.98000));
    ALGEBRAIC(:,1) = piecewise({VOI -  floor(VOI./CONSTANTS(:,9)).*CONSTANTS(:,9)>=100.000&VOI -  floor(VOI./CONSTANTS(:,9)).*CONSTANTS(:,9)<=103.000,  - 12.0000 }, 0.00000);
    ALGEBRAIC(:,13) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,6)./STATES(:,3));
    ALGEBRAIC(:,59) =  CONSTANTS(:,23).*power(STATES(:,18), 3.00000).*STATES(:,19).*STATES(:,20).*(STATES(:,1) - ALGEBRAIC(:,13));
    ALGEBRAIC(:,60) =  CONSTANTS(:,25).*(STATES(:,1) - ALGEBRAIC(:,13));
    ALGEBRAIC(:,66) = ( CONSTANTS(:,36).*( exp(( CONSTANTS(:,39).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(STATES(:,3), 3.00000).*CONSTANTS(:,5) -  exp(( (CONSTANTS(:,39) - 1.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(CONSTANTS(:,6), 3.00000).*STATES(:,4).*CONSTANTS(:,38)))./( (power(CONSTANTS(:,41), 3.00000)+power(CONSTANTS(:,6), 3.00000)).*(CONSTANTS(:,40)+CONSTANTS(:,5)).*(1.00000+ CONSTANTS(:,37).*exp(( (CONSTANTS(:,39) - 1.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))));
    ALGEBRAIC(:,61) = ( (( CONSTANTS(:,26).*STATES(:,22).*STATES(:,23).*STATES(:,24).*STATES(:,25).*power(CONSTANTS(:,27), 2.00000).*(STATES(:,1) - 15.0000).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( 0.250000.*STATES(:,21).*exp(( 2.00000.*(STATES(:,1) - 15.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - CONSTANTS(:,5)))./(exp(( 2.00000.*(STATES(:,1) - 15.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000);
    ALGEBRAIC(:,39) =  (( 0.500000.*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,5)./STATES(:,4));
    ALGEBRAIC(:,62) =  CONSTANTS(:,29).*(STATES(:,1) - ALGEBRAIC(:,39));
    ALGEBRAIC(:,63) = ( CONSTANTS(:,30).*STATES(:,4))./(STATES(:,4)+CONSTANTS(:,31));
    ALGEBRAIC(:,67) = ALGEBRAIC(:,55)+ALGEBRAIC(:,58)+ALGEBRAIC(:,56)+ALGEBRAIC(:,57)+ALGEBRAIC(:,61)+ALGEBRAIC(:,65)+ALGEBRAIC(:,59)+ALGEBRAIC(:,60)+ALGEBRAIC(:,66)+ALGEBRAIC(:,62)+ALGEBRAIC(:,64)+ALGEBRAIC(:,63)+ALGEBRAIC(:,1);
    ALGEBRAIC(:,71) = 1.00000./(1.00000+( CONSTANTS(:,56).*CONSTANTS(:,57))./power(STATES(:,4)+CONSTANTS(:,57), 2.00000));
    ALGEBRAIC(:,68) = CONSTANTS(:,47)./(1.00000+power(CONSTANTS(:,45), 2.00000)./power(STATES(:,4), 2.00000));
    ALGEBRAIC(:,69) =  CONSTANTS(:,46).*(STATES(:,26) - STATES(:,4));
    ALGEBRAIC(:,70) =  CONSTANTS(:,44).*(STATES(:,21) - STATES(:,4));
    ALGEBRAIC(:,72) = CONSTANTS(:,51) - (CONSTANTS(:,51) - CONSTANTS(:,52))./(1.00000+power(CONSTANTS(:,50)./STATES(:,26), 2.00000));
    ALGEBRAIC(:,74) =  CONSTANTS(:,49).*ALGEBRAIC(:,72);
    ALGEBRAIC(:,77) = 1.00000./(1.00000+( CONSTANTS(:,58).*CONSTANTS(:,59))./power(STATES(:,26)+CONSTANTS(:,59), 2.00000));
    ALGEBRAIC(:,73) = CONSTANTS(:,48)./ALGEBRAIC(:,72);
    ALGEBRAIC(:,75) = ( ALGEBRAIC(:,73).*power(STATES(:,21), 2.00000).*STATES(:,27))./(CONSTANTS(:,53)+ ALGEBRAIC(:,73).*power(STATES(:,21), 2.00000));
    ALGEBRAIC(:,76) =  CONSTANTS(:,55).*ALGEBRAIC(:,75).*(STATES(:,26) - STATES(:,21));
    ALGEBRAIC(:,78) = 1.00000./(1.00000+( CONSTANTS(:,60).*CONSTANTS(:,61))./power(STATES(:,21)+CONSTANTS(:,61), 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