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 =86;
end
% There are a total of 41 entries in each of the rate and state variable arrays.
% There are a total of 90 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_CONSTANTS(:,1) = strpad('R in component model_parameters (joule_per_kilomole_kelvin)');
    LEGEND_CONSTANTS(:,2) = strpad('T in component model_parameters (kelvin)');
    LEGEND_CONSTANTS(:,3) = strpad('F in component model_parameters (coulomb_per_mole)');
    LEGEND_CONSTANTS(:,4) = strpad('Nae in component model_parameters (millimolar)');
    LEGEND_CONSTANTS(:,5) = strpad('Cae in component model_parameters (millimolar)');
    LEGEND_CONSTANTS(:,6) = strpad('Ke in component model_parameters (millimolar)');
    LEGEND_CONSTANTS(:,88) = strpad('Vt in component model_parameters (cm3)');
    LEGEND_CONSTANTS(:,55) = strpad('Vd in component model_parameters (cm3)');
    LEGEND_CONSTANTS(:,57) = strpad('Vmyo in component model_parameters (cm3)');
    LEGEND_CONSTANTS(:,59) = strpad('Sms in component model_parameters (cm2)');
    LEGEND_CONSTANTS(:,60) = strpad('Smt in component model_parameters (cm2)');
    LEGEND_CONSTANTS(:,90) = strpad('Cms in component model_parameters (microF)');
    LEGEND_CONSTANTS(:,89) = strpad('Cmt in component model_parameters (microF)');
    LEGEND_CONSTANTS(:,87) = strpad('Rst in component model_parameters (ohm)');
    LEGEND_CONSTANTS(:,56) = strpad('VSRrel in component model_parameters (cm3)');
    LEGEND_CONSTANTS(:,58) = strpad('VSRup in component model_parameters (cm3)');
    LEGEND_CONSTANTS(:,52) = strpad('Vc in component model_parameters (cm3)');
    LEGEND_CONSTANTS(:,85) = strpad('pt in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,86) = strpad('Lt in component model_parameters (cm)');
    LEGEND_CONSTANTS(:,7) = strpad('Rot in component model_parameters (ohm_cm)');
    LEGEND_CONSTANTS(:,8) = strpad('radiust in component model_parameters (cm)');
    LEGEND_CONSTANTS(:,9) = strpad('ptcm in component model_parameters (per_cm2)');
    LEGEND_CONSTANTS(:,10) = strpad('Smtot in component model_parameters (cm2)');
    LEGEND_ALGEBRAIC(:,23) = strpad('i_circ in component i_circ (microA)');
    LEGEND_STATES(:,1) = strpad('Vms in component Vms (millivolt)');
    LEGEND_STATES(:,2) = strpad('Vmt in component Vmt (millivolt)');
    LEGEND_ALGEBRAIC(:,47) = strpad('i_Stim in component i_Stim (microA)');
    LEGEND_CONSTANTS(:,11) = strpad('stim_offset in component i_Stim (second)');
    LEGEND_CONSTANTS(:,12) = strpad('stim_period in component i_Stim (second)');
    LEGEND_CONSTANTS(:,13) = strpad('stim_duration in component i_Stim (second)');
    LEGEND_CONSTANTS(:,14) = strpad('stim_amplitude in component i_Stim (microA)');
    LEGEND_ALGEBRAIC(:,44) = strpad('past in component i_Stim (second)');
    LEGEND_CONSTANTS(:,61) = strpad('gNas in component membrane_permeabilities (milliS)');
    LEGEND_CONSTANTS(:,62) = strpad('gCas in component membrane_permeabilities (cm3_per_second)');
    LEGEND_CONSTANTS(:,63) = strpad('gKfs in component membrane_permeabilities (milliS)');
    LEGEND_CONSTANTS(:,64) = strpad('gKsts in component membrane_permeabilities (milliS)');
    LEGEND_CONSTANTS(:,65) = strpad('gK1s in component membrane_permeabilities (milliS)');
    LEGEND_CONSTANTS(:,66) = strpad('gKbs in component membrane_permeabilities (milliS)');
    LEGEND_CONSTANTS(:,67) = strpad('gKtos in component membrane_permeabilities (milliS)');
    LEGEND_CONSTANTS(:,68) = strpad('gNabs in component membrane_permeabilities (milliS)');
    LEGEND_CONSTANTS(:,69) = strpad('gCabs in component membrane_permeabilities (milliS)');
    LEGEND_CONSTANTS(:,70) = strpad('i_pCa_maxs in component membrane_permeabilities (microA)');
    LEGEND_CONSTANTS(:,71) = strpad('i_NaK_maxs in component membrane_permeabilities (microA)');
    LEGEND_CONSTANTS(:,72) = strpad('i_NaCa_maxs in component membrane_permeabilities (microA)');
    LEGEND_CONSTANTS(:,73) = strpad('gNat in component membrane_permeabilities (milliS)');
    LEGEND_CONSTANTS(:,74) = strpad('gCat in component membrane_permeabilities (cm3_per_second)');
    LEGEND_CONSTANTS(:,75) = strpad('gKft in component membrane_permeabilities (milliS)');
    LEGEND_CONSTANTS(:,76) = strpad('gKstt in component membrane_permeabilities (milliS)');
    LEGEND_CONSTANTS(:,77) = strpad('gK1t in component membrane_permeabilities (milliS)');
    LEGEND_CONSTANTS(:,78) = strpad('gKbt in component membrane_permeabilities (milliS)');
    LEGEND_CONSTANTS(:,79) = strpad('gKtot in component membrane_permeabilities (milliS)');
    LEGEND_CONSTANTS(:,80) = strpad('gNabt in component membrane_permeabilities (milliS)');
    LEGEND_CONSTANTS(:,81) = strpad('gCabt in component membrane_permeabilities (milliS)');
    LEGEND_CONSTANTS(:,82) = strpad('i_pCa_maxt in component membrane_permeabilities (microA)');
    LEGEND_CONSTANTS(:,83) = strpad('i_NaK_maxt in component membrane_permeabilities (microA)');
    LEGEND_CONSTANTS(:,84) = strpad('i_NaCa_maxt in component membrane_permeabilities (microA)');
    LEGEND_CONSTANTS(:,15) = strpad('gNa in component membrane_permeabilities (milliS_per_cm2)');
    LEGEND_CONSTANTS(:,16) = strpad('fNat in component membrane_permeabilities (dimensionless)');
    LEGEND_CONSTANTS(:,17) = strpad('gKf in component membrane_permeabilities (milliS_per_cm2)');
    LEGEND_CONSTANTS(:,18) = strpad('fKft in component membrane_permeabilities (dimensionless)');
    LEGEND_CONSTANTS(:,19) = strpad('gKst in component membrane_permeabilities (milliS_per_cm2)');
    LEGEND_CONSTANTS(:,20) = strpad('fKstt in component membrane_permeabilities (dimensionless)');
    LEGEND_CONSTANTS(:,21) = strpad('gK1 in component membrane_permeabilities (milliS_per_cm2)');
    LEGEND_CONSTANTS(:,22) = strpad('fK1t in component membrane_permeabilities (dimensionless)');
    LEGEND_CONSTANTS(:,23) = strpad('gKb in component membrane_permeabilities (milliS_per_cm2)');
    LEGEND_CONSTANTS(:,24) = strpad('fKbt in component membrane_permeabilities (dimensionless)');
    LEGEND_CONSTANTS(:,25) = strpad('gKto in component membrane_permeabilities (milliS_per_cm2)');
    LEGEND_CONSTANTS(:,26) = strpad('fKtot in component membrane_permeabilities (dimensionless)');
    LEGEND_CONSTANTS(:,27) = strpad('gNab in component membrane_permeabilities (milliS_per_cm2)');
    LEGEND_CONSTANTS(:,28) = strpad('fNabt in component membrane_permeabilities (dimensionless)');
    LEGEND_CONSTANTS(:,29) = strpad('gCab in component membrane_permeabilities (milliS_per_cm2)');
    LEGEND_CONSTANTS(:,30) = strpad('fCabt in component membrane_permeabilities (dimensionless)');
    LEGEND_CONSTANTS(:,31) = strpad('gCa in component membrane_permeabilities (cm_per_second)');
    LEGEND_CONSTANTS(:,32) = strpad('fCat in component membrane_permeabilities (dimensionless)');
    LEGEND_CONSTANTS(:,33) = strpad('i_NaCa_max in component membrane_permeabilities (microA_per_cm2)');
    LEGEND_CONSTANTS(:,34) = strpad('fNaCat in component membrane_permeabilities (dimensionless)');
    LEGEND_CONSTANTS(:,35) = strpad('i_NaK_max in component membrane_permeabilities (microA_per_cm2)');
    LEGEND_CONSTANTS(:,36) = strpad('fNaKt in component membrane_permeabilities (dimensionless)');
    LEGEND_CONSTANTS(:,37) = strpad('i_pCa_max in component membrane_permeabilities (microA_per_cm2)');
    LEGEND_CONSTANTS(:,38) = strpad('fpCat in component membrane_permeabilities (dimensionless)');
    LEGEND_ALGEBRAIC(:,49) = strpad('i_Nas in component i_Nas (microA)');
    LEGEND_ALGEBRAIC(:,48) = strpad('E_Nas in component i_Nas (millivolt)');
    LEGEND_STATES(:,3) = strpad('Nai in component ion_concentrations (millimolar)');
    LEGEND_STATES(:,4) = strpad('Ki in component ion_concentrations (millimolar)');
    LEGEND_STATES(:,5) = strpad('m in component i_Nas_m_gate (dimensionless)');
    LEGEND_STATES(:,6) = strpad('h in component i_Nas_h_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,1) = strpad('alpha_m in component i_Nas_m_gate (per_second)');
    LEGEND_ALGEBRAIC(:,24) = strpad('beta_m in component i_Nas_m_gate (per_second)');
    LEGEND_ALGEBRAIC(:,2) = strpad('alpha_h in component i_Nas_h_gate (per_second)');
    LEGEND_ALGEBRAIC(:,25) = strpad('beta_h in component i_Nas_h_gate (per_second)');
    LEGEND_ALGEBRAIC(:,51) = strpad('i_Nat in component i_Nat (microA)');
    LEGEND_ALGEBRAIC(:,50) = strpad('E_Nat in component i_Nat (millivolt)');
    LEGEND_STATES(:,7) = strpad('Nat in component ion_concentrations (millimolar)');
    LEGEND_STATES(:,8) = strpad('Kt in component ion_concentrations (millimolar)');
    LEGEND_STATES(:,9) = strpad('m in component i_Nat_m_gate (dimensionless)');
    LEGEND_STATES(:,10) = strpad('h in component i_Nat_h_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,3) = strpad('alpha_m in component i_Nat_m_gate (per_second)');
    LEGEND_ALGEBRAIC(:,26) = strpad('beta_m in component i_Nat_m_gate (per_second)');
    LEGEND_ALGEBRAIC(:,4) = strpad('alpha_h in component i_Nat_h_gate (per_second)');
    LEGEND_ALGEBRAIC(:,27) = strpad('beta_h in component i_Nat_h_gate (per_second)');
    LEGEND_ALGEBRAIC(:,53) = strpad('i_Cas in component i_Cas (microA)');
    LEGEND_ALGEBRAIC(:,52) = strpad('E_Cas in component i_Cas (millivolt)');
    LEGEND_STATES(:,11) = strpad('Co in component i_Cas (dimensionless)');
    LEGEND_STATES(:,12) = strpad('C1 in component i_Cas (dimensionless)');
    LEGEND_STATES(:,13) = strpad('C2 in component i_Cas (dimensionless)');
    LEGEND_ALGEBRAIC(:,28) = strpad('tauCo in component i_Cas (second)');
    LEGEND_CONSTANTS(:,39) = strpad('tauCcast in component i_Cas (second)');
    LEGEND_ALGEBRAIC(:,29) = strpad('tauC1 in component i_Cas (second)');
    LEGEND_ALGEBRAIC(:,45) = strpad('tauC2 in component i_Cas (second)');
    LEGEND_STATES(:,14) = strpad('Ccast in component i_Cas (dimensionless)');
    LEGEND_ALGEBRAIC(:,5) = strpad('Coinf in component i_Cas (dimensionless)');
    LEGEND_ALGEBRAIC(:,6) = strpad('Ccastinf in component i_Cas (dimensionless)');
    LEGEND_ALGEBRAIC(:,7) = strpad('C1inf in component i_Cas (dimensionless)');
    LEGEND_ALGEBRAIC(:,30) = strpad('C2inf in component i_Cas (dimensionless)');
    LEGEND_STATES(:,15) = strpad('Cass in component ion_concentrations (millimolar)');
    LEGEND_STATES(:,16) = strpad('Cai in component ion_concentrations (millimolar)');
    LEGEND_ALGEBRAIC(:,55) = strpad('i_Cat in component i_Cat (microA)');
    LEGEND_ALGEBRAIC(:,54) = strpad('E_Cat in component i_Cat (millivolt)');
    LEGEND_STATES(:,17) = strpad('Co in component i_Cat (dimensionless)');
    LEGEND_STATES(:,18) = strpad('C1 in component i_Cat (dimensionless)');
    LEGEND_STATES(:,19) = strpad('C2 in component i_Cat (dimensionless)');
    LEGEND_ALGEBRAIC(:,31) = strpad('tauCo in component i_Cat (second)');
    LEGEND_CONSTANTS(:,40) = strpad('tauCcast in component i_Cat (second)');
    LEGEND_ALGEBRAIC(:,32) = strpad('tauC1 in component i_Cat (second)');
    LEGEND_ALGEBRAIC(:,46) = strpad('tauC2 in component i_Cat (second)');
    LEGEND_ALGEBRAIC(:,8) = strpad('Coinf in component i_Cat (dimensionless)');
    LEGEND_STATES(:,20) = strpad('Ccast in component i_Cat (dimensionless)');
    LEGEND_ALGEBRAIC(:,9) = strpad('Ccastinf in component i_Cat (dimensionless)');
    LEGEND_ALGEBRAIC(:,10) = strpad('C1inf in component i_Cat (dimensionless)');
    LEGEND_ALGEBRAIC(:,33) = strpad('C2inf in component i_Cat (dimensionless)');
    LEGEND_STATES(:,21) = strpad('Cat in component ion_concentrations (millimolar)');
    LEGEND_ALGEBRAIC(:,57) = strpad('i_Ktos in component i_Ktos (microA)');
    LEGEND_ALGEBRAIC(:,56) = strpad('E_Ks in component i_Ktos (millivolt)');
    LEGEND_STATES(:,22) = strpad('rs in component i_Ktos_rs_gate (dimensionless)');
    LEGEND_STATES(:,23) = strpad('ss in component i_Ktos_ss_gate (dimensionless)');
    LEGEND_STATES(:,24) = strpad('sss in component i_Ktos_sss_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,34) = strpad('taurs in component i_Ktos_rs_gate (second)');
    LEGEND_ALGEBRAIC(:,11) = strpad('rinfs in component i_Ktos_rs_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,35) = strpad('tauss in component i_Ktos_ss_gate (second)');
    LEGEND_ALGEBRAIC(:,12) = strpad('sinfs in component i_Ktos_ss_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,36) = strpad('tausss in component i_Ktos_sss_gate (second)');
    LEGEND_ALGEBRAIC(:,13) = strpad('ssinfs in component i_Ktos_sss_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,59) = strpad('i_Ktot in component i_Ktot (microA)');
    LEGEND_ALGEBRAIC(:,58) = strpad('E_Kt in component i_Ktot (millivolt)');
    LEGEND_STATES(:,25) = strpad('rt in component i_Ktot_rt_gate (dimensionless)');
    LEGEND_STATES(:,26) = strpad('st in component i_Ktot_st_gate (dimensionless)');
    LEGEND_STATES(:,27) = strpad('sst in component i_Ktot_sst_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,37) = strpad('taurt in component i_Ktot_rt_gate (second)');
    LEGEND_ALGEBRAIC(:,14) = strpad('rinft in component i_Ktot_rt_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,38) = strpad('taust in component i_Ktot_st_gate (second)');
    LEGEND_ALGEBRAIC(:,15) = strpad('sinft in component i_Ktot_st_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,39) = strpad('tausst in component i_Ktot_sst_gate (second)');
    LEGEND_ALGEBRAIC(:,16) = strpad('ssinft in component i_Ktot_sst_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,60) = strpad('i_Ksts in component i_Ksts (microA)');
    LEGEND_STATES(:,28) = strpad('rsts in component i_Ksts_rsts_gate (dimensionless)');
    LEGEND_STATES(:,29) = strpad('ssts in component i_Ksts_ssts_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,40) = strpad('taursts in component i_Ksts_rsts_gate (second)');
    LEGEND_ALGEBRAIC(:,17) = strpad('rstinfs in component i_Ksts_rsts_gate (dimensionless)');
    LEGEND_CONSTANTS(:,41) = strpad('taussts in component i_Ksts_ssts_gate (second)');
    LEGEND_ALGEBRAIC(:,18) = strpad('sstinfs in component i_Ksts_ssts_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,61) = strpad('i_Kstt in component i_Kstt (microA)');
    LEGEND_STATES(:,30) = strpad('rstt in component i_Kstt_rstt_gate (dimensionless)');
    LEGEND_STATES(:,31) = strpad('sstt in component i_Kstt_sstt_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,41) = strpad('taurstt in component i_Kstt_rstt_gate (second)');
    LEGEND_ALGEBRAIC(:,19) = strpad('rstinft in component i_Kstt_rstt_gate (dimensionless)');
    LEGEND_CONSTANTS(:,42) = strpad('tausstt in component i_Kstt_sstt_gate (second)');
    LEGEND_ALGEBRAIC(:,20) = strpad('sstinft in component i_Kstt_sstt_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,62) = strpad('i_Kfs in component i_Kfs (microA)');
    LEGEND_STATES(:,32) = strpad('qs in component i_Kfs_qs_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,42) = strpad('tauqs in component i_Kfs_qs_gate (second)');
    LEGEND_ALGEBRAIC(:,21) = strpad('qinfs in component i_Kfs_qs_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,63) = strpad('i_Kft in component i_Kft (microA)');
    LEGEND_STATES(:,33) = strpad('qt in component i_Kft_qt_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,43) = strpad('tauqt in component i_Kft_qt_gate (second)');
    LEGEND_ALGEBRAIC(:,22) = strpad('qinft in component i_Kft_qt_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,64) = strpad('i_K1s in component i_K1s (microA)');
    LEGEND_ALGEBRAIC(:,65) = strpad('i_K1t in component i_K1t (microA)');
    LEGEND_ALGEBRAIC(:,66) = strpad('i_Nabs in component i_Nabs (microA)');
    LEGEND_ALGEBRAIC(:,67) = strpad('i_Nabt in component i_Nabt (microA)');
    LEGEND_ALGEBRAIC(:,68) = strpad('i_Cabs in component i_Cabs (microA)');
    LEGEND_ALGEBRAIC(:,69) = strpad('i_Cabt in component i_Cabt (microA)');
    LEGEND_ALGEBRAIC(:,70) = strpad('i_Kbs in component i_Kbs (microA)');
    LEGEND_ALGEBRAIC(:,71) = strpad('i_Kbt in component i_Kbt (microA)');
    LEGEND_ALGEBRAIC(:,72) = strpad('i_NaCas in component i_NaCas (microA)');
    LEGEND_ALGEBRAIC(:,73) = strpad('i_NaCat in component i_NaCat (microA)');
    LEGEND_ALGEBRAIC(:,74) = strpad('i_NaKs in component i_NaKs (microA)');
    LEGEND_ALGEBRAIC(:,75) = strpad('i_NaKt in component i_NaKt (microA)');
    LEGEND_ALGEBRAIC(:,78) = strpad('i_pCas in component i_pCas (microA)');
    LEGEND_ALGEBRAIC(:,79) = strpad('i_pCat in component i_pCat (microA)');
    LEGEND_ALGEBRAIC(:,76) = strpad('JteNa in component t_tubular_ion_fluxes (millimolar_per_second)');
    LEGEND_ALGEBRAIC(:,80) = strpad('JteCa in component t_tubular_ion_fluxes (millimolar_per_second)');
    LEGEND_ALGEBRAIC(:,77) = strpad('JteK in component t_tubular_ion_fluxes (millimolar_per_second)');
    LEGEND_CONSTANTS(:,43) = strpad('tauNa in component t_tubular_ion_fluxes (second)');
    LEGEND_CONSTANTS(:,44) = strpad('tauCa in component t_tubular_ion_fluxes (second)');
    LEGEND_CONSTANTS(:,45) = strpad('tauK in component t_tubular_ion_fluxes (second)');
    LEGEND_ALGEBRAIC(:,81) = strpad('JCaSRup in component JCaSRup (millimolar_per_second)');
    LEGEND_STATES(:,34) = strpad('CaSRup in component CaSRup (millimolar)');
    LEGEND_ALGEBRAIC(:,82) = strpad('Jtr in component Jtr (millimolar_per_second)');
    LEGEND_CONSTANTS(:,46) = strpad('tautr in component Jtr (second)');
    LEGEND_STATES(:,35) = strpad('CaSRrel in component CaSRrel (millimolar)');
    LEGEND_ALGEBRAIC(:,83) = strpad('JCaSRrel in component JCaSRrel (millimolar_per_second)');
    LEGEND_CONSTANTS(:,53) = strpad('kap in component JCaSRrel (per_millimolar4_per_second)');
    LEGEND_CONSTANTS(:,47) = strpad('kam in component JCaSRrel (per_second)');
    LEGEND_CONSTANTS(:,54) = strpad('kbp in component JCaSRrel (per_millimolar3_per_second)');
    LEGEND_CONSTANTS(:,48) = strpad('kbm in component JCaSRrel (per_second)');
    LEGEND_CONSTANTS(:,49) = strpad('kcp in component JCaSRrel (per_second)');
    LEGEND_CONSTANTS(:,50) = strpad('kcm in component JCaSRrel (per_second)');
    LEGEND_STATES(:,36) = strpad('F1 in component JCaSRrel (dimensionless)');
    LEGEND_STATES(:,37) = strpad('F2 in component JCaSRrel (dimensionless)');
    LEGEND_STATES(:,38) = strpad('F3 in component JCaSRrel (dimensionless)');
    LEGEND_STATES(:,39) = strpad('F4 in component JCaSRrel (dimensionless)');
    LEGEND_ALGEBRAIC(:,84) = strpad('JCad in component JCad (millimolar_per_second)');
    LEGEND_CONSTANTS(:,51) = strpad('taud in component JCad (second)');
    LEGEND_STATES(:,40) = strpad('BTRH in component ion_concentrations (millimolar)');
    LEGEND_STATES(:,41) = strpad('BTRL in component ion_concentrations (millimolar)');
    LEGEND_ALGEBRAIC(:,85) = strpad('dBTRH in component ion_concentrations (millimolar_per_second)');
    LEGEND_ALGEBRAIC(:,86) = strpad('dBTRL in component ion_concentrations (millimolar_per_second)');
    LEGEND_RATES(:,5) = strpad('d/dt m in component i_Nas_m_gate (dimensionless)');
    LEGEND_RATES(:,6) = strpad('d/dt h in component i_Nas_h_gate (dimensionless)');
    LEGEND_RATES(:,9) = strpad('d/dt m in component i_Nat_m_gate (dimensionless)');
    LEGEND_RATES(:,10) = strpad('d/dt h in component i_Nat_h_gate (dimensionless)');
    LEGEND_RATES(:,12) = strpad('d/dt C1 in component i_Cas (dimensionless)');
    LEGEND_RATES(:,13) = strpad('d/dt C2 in component i_Cas (dimensionless)');
    LEGEND_RATES(:,11) = strpad('d/dt Co in component i_Cas (dimensionless)');
    LEGEND_RATES(:,14) = strpad('d/dt Ccast in component i_Cas (dimensionless)');
    LEGEND_RATES(:,18) = strpad('d/dt C1 in component i_Cat (dimensionless)');
    LEGEND_RATES(:,19) = strpad('d/dt C2 in component i_Cat (dimensionless)');
    LEGEND_RATES(:,17) = strpad('d/dt Co in component i_Cat (dimensionless)');
    LEGEND_RATES(:,20) = strpad('d/dt Ccast in component i_Cat (dimensionless)');
    LEGEND_RATES(:,22) = strpad('d/dt rs in component i_Ktos_rs_gate (dimensionless)');
    LEGEND_RATES(:,23) = strpad('d/dt ss in component i_Ktos_ss_gate (dimensionless)');
    LEGEND_RATES(:,24) = strpad('d/dt sss in component i_Ktos_sss_gate (dimensionless)');
    LEGEND_RATES(:,25) = strpad('d/dt rt in component i_Ktot_rt_gate (dimensionless)');
    LEGEND_RATES(:,26) = strpad('d/dt st in component i_Ktot_st_gate (dimensionless)');
    LEGEND_RATES(:,27) = strpad('d/dt sst in component i_Ktot_sst_gate (dimensionless)');
    LEGEND_RATES(:,28) = strpad('d/dt rsts in component i_Ksts_rsts_gate (dimensionless)');
    LEGEND_RATES(:,29) = strpad('d/dt ssts in component i_Ksts_ssts_gate (dimensionless)');
    LEGEND_RATES(:,30) = strpad('d/dt rstt in component i_Kstt_rstt_gate (dimensionless)');
    LEGEND_RATES(:,31) = strpad('d/dt sstt in component i_Kstt_sstt_gate (dimensionless)');
    LEGEND_RATES(:,32) = strpad('d/dt qs in component i_Kfs_qs_gate (dimensionless)');
    LEGEND_RATES(:,33) = strpad('d/dt qt in component i_Kft_qt_gate (dimensionless)');
    LEGEND_RATES(:,36) = strpad('d/dt F1 in component JCaSRrel (dimensionless)');
    LEGEND_RATES(:,37) = strpad('d/dt F2 in component JCaSRrel (dimensionless)');
    LEGEND_RATES(:,38) = strpad('d/dt F3 in component JCaSRrel (dimensionless)');
    LEGEND_RATES(:,39) = strpad('d/dt F4 in component JCaSRrel (dimensionless)');
    LEGEND_RATES(:,34) = strpad('d/dt CaSRup in component CaSRup (millimolar)');
    LEGEND_RATES(:,35) = strpad('d/dt CaSRrel in component CaSRrel (millimolar)');
    LEGEND_RATES(:,40) = strpad('d/dt BTRH in component ion_concentrations (millimolar)');
    LEGEND_RATES(:,41) = strpad('d/dt BTRL in component ion_concentrations (millimolar)');
    LEGEND_RATES(:,15) = strpad('d/dt Cass in component ion_concentrations (millimolar)');
    LEGEND_RATES(:,16) = strpad('d/dt Cai in component ion_concentrations (millimolar)');
    LEGEND_RATES(:,3) = strpad('d/dt Nai in component ion_concentrations (millimolar)');
    LEGEND_RATES(:,4) = strpad('d/dt Ki in component ion_concentrations (millimolar)');
    LEGEND_RATES(:,7) = strpad('d/dt Nat in component ion_concentrations (millimolar)');
    LEGEND_RATES(:,21) = strpad('d/dt Cat in component ion_concentrations (millimolar)');
    LEGEND_RATES(:,8) = strpad('d/dt Kt in component ion_concentrations (millimolar)');
    LEGEND_RATES(:,1) = strpad('d/dt Vms in component Vms (millivolt)');
    LEGEND_RATES(:,2) = strpad('d/dt Vmt in component Vmt (millivolt)');
    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) = 8310;
    CONSTANTS(:,2) = 295;
    CONSTANTS(:,3) = 96500;
    CONSTANTS(:,4) = 140;
    CONSTANTS(:,5) = 1.2;
    CONSTANTS(:,6) = 5.4;
    CONSTANTS(:,7) = 83.33;
    CONSTANTS(:,8) = 150e-7;
    CONSTANTS(:,9) = 30000000;
    CONSTANTS(:,10) = 0.0001;
    STATES(:,1) = -7.9709547e1;
    STATES(:,2) = -7.9709536e1;
    CONSTANTS(:,11) = 0;
    CONSTANTS(:,12) = 1;
    CONSTANTS(:,13) = 0.001;
    CONSTANTS(:,14) = 0.0052;
    CONSTANTS(:,15) = 10;
    CONSTANTS(:,16) = 0.56;
    CONSTANTS(:,17) = 0.0145;
    CONSTANTS(:,18) = 0.56;
    CONSTANTS(:,19) = 0.07;
    CONSTANTS(:,20) = 0.76;
    CONSTANTS(:,21) = 0.24;
    CONSTANTS(:,22) = 0.56;
    CONSTANTS(:,23) = 0.00138;
    CONSTANTS(:,24) = 0.56;
    CONSTANTS(:,25) = 0.35;
    CONSTANTS(:,26) = 0.56;
    CONSTANTS(:,27) = 0.0008015;
    CONSTANTS(:,28) = 0.56;
    CONSTANTS(:,29) = 0.000648;
    CONSTANTS(:,30) = 0.56;
    CONSTANTS(:,31) = 0.00021;
    CONSTANTS(:,32) = 0.87;
    CONSTANTS(:,33) = 0.00018;
    CONSTANTS(:,34) = 0.81;
    CONSTANTS(:,35) = 1;
    CONSTANTS(:,36) = 0.59;
    CONSTANTS(:,37) = 0.85;
    CONSTANTS(:,38) = 0.56;
    STATES(:,3) = 6.9435814e0;
    STATES(:,4) = 1.3753311e2;
    STATES(:,5) = 2.1832558e-6;
    STATES(:,6) = 5.8232781e-1;
    STATES(:,7) = 1.4001386e2;
    STATES(:,8) = 5.3627676e0;
    STATES(:,9) = 2.1832694e-6;
    STATES(:,10) = 5.8232717e-1;
    STATES(:,11) = 2.5436465e-6;
    STATES(:,12) = 9.9994546e-1;
    STATES(:,13) = 9.9994546e-1;
    CONSTANTS(:,39) = 0.009;
    STATES(:,14) = 9.9570063e-1;
    STATES(:,15) = 4.3112114e-5;
    STATES(:,16) = 3.5486498e-5;
    STATES(:,17) = 2.543652e-6;
    STATES(:,18) = 9.9994546e-1;
    STATES(:,19) = 9.9994546e-1;
    CONSTANTS(:,40) = 0.009;
    STATES(:,20) = 9.9570063e-1;
    STATES(:,21) = 1.2271399e0;
    STATES(:,22) = 2.3485072e-3;
    STATES(:,23) = 9.8315843e-1;
    STATES(:,24) = 6.748337e-1;
    STATES(:,25) = 2.3485094e-3;
    STATES(:,26) = 9.8315865e-1;
    STATES(:,27) = 6.7478532e-1;
    STATES(:,28) = 3.1079213e-3;
    STATES(:,29) = 3.0773393e-1;
    CONSTANTS(:,41) = 2.1;
    STATES(:,30) = 3.1079241e-3;
    STATES(:,31) = 3.0773368e-1;
    CONSTANTS(:,42) = 2.1;
    STATES(:,32) = 3.4357356e-3;
    STATES(:,33) = 3.4357175e-3;
    CONSTANTS(:,43) = 0.15;
    CONSTANTS(:,44) = 0.5;
    CONSTANTS(:,45) = 0.15;
    STATES(:,34) = 2.2755058e-1;
    CONSTANTS(:,46) = 0.03448;
    STATES(:,35) = 2.2638169e-1;
    CONSTANTS(:,47) = 576;
    CONSTANTS(:,48) = 1930;
    CONSTANTS(:,49) = 18;
    CONSTANTS(:,50) = 0.8;
    STATES(:,36) = 6.7606483e-1;
    STATES(:,37) = 3.8333331e-4;
    STATES(:,38) = 6.4516879e-11;
    STATES(:,39) = 3.2355462e-1;
    CONSTANTS(:,51) = 0.003125;
    STATES(:,40) = 9.2804169e-1;
    STATES(:,41) = 3.4317829e-2;
    CONSTANTS(:,52) = CONSTANTS(:,10)./7850.00;
    CONSTANTS(:,53) = 1.21500e+13;
    CONSTANTS(:,54) = 4.05000e+09;
    CONSTANTS(:,55) =  CONSTANTS(:,52).*7.50000e-05;
    CONSTANTS(:,56) =  CONSTANTS(:,52).*0.00350000;
    CONSTANTS(:,57) =  CONSTANTS(:,52).*0.585000;
    CONSTANTS(:,58) =  CONSTANTS(:,52).*0.0315000;
    CONSTANTS(:,59) = CONSTANTS(:,10) -  4400.00.*CONSTANTS(:,52);
    CONSTANTS(:,60) = CONSTANTS(:,10) - CONSTANTS(:,59);
    CONSTANTS(:,61) =  CONSTANTS(:,15).*(CONSTANTS(:,59)+CONSTANTS(:,60)).*(1.00000 - CONSTANTS(:,16));
    CONSTANTS(:,62) =  CONSTANTS(:,31).*(CONSTANTS(:,59)+CONSTANTS(:,60)).*(1.00000 - CONSTANTS(:,32));
    CONSTANTS(:,63) =  CONSTANTS(:,17).*(CONSTANTS(:,59)+CONSTANTS(:,60)).*(1.00000 - CONSTANTS(:,18));
    CONSTANTS(:,64) =  CONSTANTS(:,19).*(CONSTANTS(:,59)+CONSTANTS(:,60)).*(1.00000 - CONSTANTS(:,20));
    CONSTANTS(:,65) =  CONSTANTS(:,21).*(CONSTANTS(:,59)+CONSTANTS(:,60)).*(1.00000 - CONSTANTS(:,22));
    CONSTANTS(:,66) =  CONSTANTS(:,23).*(CONSTANTS(:,59)+CONSTANTS(:,60)).*(1.00000 - CONSTANTS(:,24));
    CONSTANTS(:,67) =  CONSTANTS(:,25).*(CONSTANTS(:,59)+CONSTANTS(:,60)).*(1.00000 - CONSTANTS(:,26));
    CONSTANTS(:,68) =  CONSTANTS(:,27).*(CONSTANTS(:,59)+CONSTANTS(:,60)).*(1.00000 - CONSTANTS(:,28));
    CONSTANTS(:,69) =  CONSTANTS(:,29).*(CONSTANTS(:,59)+CONSTANTS(:,60)).*(1.00000 - CONSTANTS(:,30));
    CONSTANTS(:,70) =  CONSTANTS(:,37).*(CONSTANTS(:,59)+CONSTANTS(:,60)).*(1.00000 - CONSTANTS(:,38));
    CONSTANTS(:,71) =  CONSTANTS(:,35).*(CONSTANTS(:,59)+CONSTANTS(:,60)).*(1.00000 - CONSTANTS(:,36));
    CONSTANTS(:,72) =  CONSTANTS(:,33).*(CONSTANTS(:,59)+CONSTANTS(:,60)).*(1.00000 - CONSTANTS(:,34));
    CONSTANTS(:,73) =  CONSTANTS(:,15).*(CONSTANTS(:,59)+CONSTANTS(:,60)).*CONSTANTS(:,16);
    CONSTANTS(:,74) =  CONSTANTS(:,31).*(CONSTANTS(:,59)+CONSTANTS(:,60)).*CONSTANTS(:,32);
    CONSTANTS(:,75) =  CONSTANTS(:,17).*(CONSTANTS(:,59)+CONSTANTS(:,60)).*CONSTANTS(:,18);
    CONSTANTS(:,76) =  CONSTANTS(:,19).*(CONSTANTS(:,59)+CONSTANTS(:,60)).*CONSTANTS(:,20);
    CONSTANTS(:,77) =  CONSTANTS(:,21).*(CONSTANTS(:,59)+CONSTANTS(:,60)).*CONSTANTS(:,22);
    CONSTANTS(:,78) =  CONSTANTS(:,23).*(CONSTANTS(:,59)+CONSTANTS(:,60)).*CONSTANTS(:,24);
    CONSTANTS(:,79) =  CONSTANTS(:,25).*(CONSTANTS(:,59)+CONSTANTS(:,60)).*CONSTANTS(:,26);
    CONSTANTS(:,80) =  CONSTANTS(:,27).*(CONSTANTS(:,59)+CONSTANTS(:,60)).*CONSTANTS(:,28);
    CONSTANTS(:,81) =  CONSTANTS(:,29).*(CONSTANTS(:,59)+CONSTANTS(:,60)).*CONSTANTS(:,30);
    CONSTANTS(:,82) =  CONSTANTS(:,37).*(CONSTANTS(:,59)+CONSTANTS(:,60)).*CONSTANTS(:,38);
    CONSTANTS(:,83) =  CONSTANTS(:,35).*(CONSTANTS(:,59)+CONSTANTS(:,60)).*CONSTANTS(:,36);
    CONSTANTS(:,84) =  CONSTANTS(:,33).*(CONSTANTS(:,59)+CONSTANTS(:,60)).*CONSTANTS(:,34);
    CONSTANTS(:,85) =  CONSTANTS(:,9).*CONSTANTS(:,59);
    CONSTANTS(:,86) = CONSTANTS(:,60)./( 2.00000.*3.14159.*CONSTANTS(:,8).*CONSTANTS(:,85));
    CONSTANTS(:,87) = (( CONSTANTS(:,7).*CONSTANTS(:,86))./2.00000)./( 3.14159.*power(CONSTANTS(:,8), 2.00000).*CONSTANTS(:,85));
    CONSTANTS(:,88) =  3.14159.*power(CONSTANTS(:,8), 2.00000).*CONSTANTS(:,86).*CONSTANTS(:,85);
    CONSTANTS(:,89) =  CONSTANTS(:,60).*1.00000;
    CONSTANTS(:,90) =  CONSTANTS(:,59).*1.00000;
    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(:,36) =  STATES(:,37).*CONSTANTS(:,47) -  STATES(:,36).*CONSTANTS(:,53).*power(STATES(:,15), 4.00000);
    RATES(:,37) = ( STATES(:,36).*CONSTANTS(:,53).*power(STATES(:,15), 4.00000)+ STATES(:,38).*CONSTANTS(:,48)+ STATES(:,39).*CONSTANTS(:,50)) -  STATES(:,37).*(CONSTANTS(:,47)+ CONSTANTS(:,54).*power(STATES(:,15), 3.00000)+CONSTANTS(:,49));
    RATES(:,38) =  STATES(:,37).*CONSTANTS(:,54).*power(STATES(:,15), 3.00000) -  STATES(:,38).*CONSTANTS(:,48);
    RATES(:,39) =  STATES(:,37).*CONSTANTS(:,49) -  STATES(:,39).*CONSTANTS(:,50);
    ALGEBRAIC(:,6) = 1.00000./(1.00000+STATES(:,15)./0.0100000);
    RATES(:,14) = (ALGEBRAIC(:,6) - STATES(:,14))./CONSTANTS(:,39);
    ALGEBRAIC(:,9) = 1.00000./(1.00000+STATES(:,15)./0.0100000);
    RATES(:,20) = (ALGEBRAIC(:,9) - STATES(:,20))./CONSTANTS(:,40);
    ALGEBRAIC(:,18) = 1.00000./(1.00000+exp((STATES(:,1)+87.5000)./10.3000));
    RATES(:,29) = (ALGEBRAIC(:,18) - STATES(:,29))./CONSTANTS(:,41);
    ALGEBRAIC(:,20) = 1.00000./(1.00000+exp((STATES(:,2)+87.5000)./10.3000));
    RATES(:,31) = (ALGEBRAIC(:,20) - STATES(:,31))./CONSTANTS(:,42);
    ALGEBRAIC(:,1) = ( 117.260.*(STATES(:,1)+59.3000))./(1.00000 - exp(  - 0.550000.*(STATES(:,1)+59.3000)));
    ALGEBRAIC(:,24) =  3800.00.*exp(  - 0.0720000.*(STATES(:,1)+61.0000));
    RATES(:,5) =  ALGEBRAIC(:,1).*(1.00000 - STATES(:,5)) -  ALGEBRAIC(:,24).*STATES(:,5);
    ALGEBRAIC(:,2) = 284.400./(1.00000+exp( 0.0812000.*(STATES(:,1)+115.900)));
    ALGEBRAIC(:,25) = ( 18.7700.*(STATES(:,1)+64.4000))./(1.00000 - exp(  - 0.220000.*(STATES(:,1)+64.4000)));
    RATES(:,6) =  ALGEBRAIC(:,2).*(1.00000 - STATES(:,6)) -  ALGEBRAIC(:,25).*STATES(:,6);
    ALGEBRAIC(:,3) = ( 117.260.*(STATES(:,2)+59.3000))./(1.00000 - exp(  - 0.550000.*(STATES(:,2)+59.3000)));
    ALGEBRAIC(:,26) =  3800.00.*exp(  - 0.0720000.*(STATES(:,2)+61.0000));
    RATES(:,9) =  ALGEBRAIC(:,3).*(1.00000 - STATES(:,9)) -  ALGEBRAIC(:,26).*STATES(:,9);
    ALGEBRAIC(:,4) = 284.400./(1.00000+exp( 0.0812000.*(STATES(:,2)+115.900)));
    ALGEBRAIC(:,27) = ( 18.7700.*(STATES(:,2)+64.4000))./(1.00000 - exp(  - 0.220000.*(STATES(:,2)+64.4000)));
    RATES(:,10) =  ALGEBRAIC(:,4).*(1.00000 - STATES(:,10)) -  ALGEBRAIC(:,27).*STATES(:,10);
    ALGEBRAIC(:,29) =  0.105000.*exp( - power((STATES(:,1)+45.0000)./12.0000, 2.00000))+0.0400000./(1.00000+exp(( - STATES(:,1)+25.0000)./25.0000))+0.0150000./(1.00000+exp((STATES(:,1)+75.0000)./25.0000));
    ALGEBRAIC(:,7) = 1.00000./(1.00000+exp((STATES(:,1)+26.7000)./5.40000));
    RATES(:,12) = (ALGEBRAIC(:,7) - STATES(:,12))./ALGEBRAIC(:,29);
    ALGEBRAIC(:,28) = 0.000250000+ 0.00305000.*exp(  - 0.00450000.*power(STATES(:,1)+7.00000, 2.00000))+ 0.00105000.*exp(  - 0.00200000.*power(STATES(:,1) - 18.0000, 2.00000));
    ALGEBRAIC(:,5) = 1.00000./(1.00000+exp( - (STATES(:,1)+15.3000)./5.00000));
    RATES(:,11) = (ALGEBRAIC(:,5) - STATES(:,11))./ALGEBRAIC(:,28);
    ALGEBRAIC(:,32) =  0.105000.*exp( - power((STATES(:,2)+45.0000)./12.0000, 2.00000))+0.0400000./(1.00000+exp(( - STATES(:,2)+25.0000)./25.0000))+0.0150000./(1.00000+exp((STATES(:,2)+75.0000)./25.0000));
    ALGEBRAIC(:,10) = 1.00000./(1.00000+exp((STATES(:,2)+26.7000)./5.40000));
    RATES(:,18) = (ALGEBRAIC(:,10) - STATES(:,18))./ALGEBRAIC(:,32);
    ALGEBRAIC(:,31) = 0.000250000+ 0.00305000.*exp(  - 0.00450000.*power(STATES(:,2)+7.00000, 2.00000))+ 0.00105000.*exp(  - 0.00200000.*power(STATES(:,2) - 18.0000, 2.00000));
    ALGEBRAIC(:,8) = 1.00000./(1.00000+exp( - (STATES(:,2)+15.3000)./5.00000));
    RATES(:,17) = (ALGEBRAIC(:,8) - STATES(:,17))./ALGEBRAIC(:,31);
    ALGEBRAIC(:,34) = 1.00000./( 45.1600.*exp( 0.0357700.*(STATES(:,1)+50.0000))+ 98.9000.*exp(  - 0.100000.*(STATES(:,1)+38.0000)));
    ALGEBRAIC(:,11) = 1.00000./(1.00000+exp((STATES(:,1)+10.6000)./ - 11.4200));
    RATES(:,22) = (ALGEBRAIC(:,11) - STATES(:,22))./ALGEBRAIC(:,34);
    ALGEBRAIC(:,35) =  0.350000.*exp( - power( 0.0666000.*(STATES(:,1)+70.0000), 2.00000))+0.0350000;
    ALGEBRAIC(:,12) = 1.00000./(1.00000+exp((STATES(:,1)+45.3000)./6.88410));
    RATES(:,23) = (ALGEBRAIC(:,12) - STATES(:,23))./ALGEBRAIC(:,35);
    ALGEBRAIC(:,36) =  3.70000.*exp( - power( 0.0333000.*(STATES(:,1)+70.0000), 2.00000))+0.0350000;
    ALGEBRAIC(:,13) = 1.00000./(1.00000+exp((STATES(:,1)+45.3000)./6.88410));
    RATES(:,24) = (ALGEBRAIC(:,13) - STATES(:,24))./ALGEBRAIC(:,36);
    ALGEBRAIC(:,37) = 1.00000./( 45.1600.*exp( 0.0357700.*(STATES(:,2)+50.0000))+ 98.9000.*exp(  - 0.100000.*(STATES(:,2)+38.0000)));
    ALGEBRAIC(:,14) = 1.00000./(1.00000+exp((STATES(:,2)+10.6000)./ - 11.4200));
    RATES(:,25) = (ALGEBRAIC(:,14) - STATES(:,25))./ALGEBRAIC(:,37);
    ALGEBRAIC(:,38) =  0.350000.*exp( - power( 0.0666000.*(STATES(:,2)+70.0000), 2.00000))+0.0350000;
    ALGEBRAIC(:,15) = 1.00000./(1.00000+exp((STATES(:,2)+45.3000)./6.88410));
    RATES(:,26) = (ALGEBRAIC(:,15) - STATES(:,26))./ALGEBRAIC(:,38);
    ALGEBRAIC(:,39) =  3.70000.*exp( - power( 0.0333000.*(STATES(:,2)+70.0000), 2.00000))+0.0350000;
    ALGEBRAIC(:,16) = 1.00000./(1.00000+exp((STATES(:,2)+45.3000)./6.88410));
    RATES(:,27) = (ALGEBRAIC(:,16) - STATES(:,27))./ALGEBRAIC(:,39);
    ALGEBRAIC(:,40) = 10.0000./( 45.1600.*exp( 0.0357700.*(STATES(:,1)+50.0000))+ 98.9000.*exp(  - 0.100000.*(STATES(:,1)+38.0000)));
    ALGEBRAIC(:,17) = 1.00000./(1.00000+exp( - (STATES(:,1)+11.5000)./11.8200));
    RATES(:,28) = (ALGEBRAIC(:,17) - STATES(:,28))./ALGEBRAIC(:,40);
    ALGEBRAIC(:,41) = 10.0000./( 45.1600.*exp( 0.0357700.*(STATES(:,2)+50.0000))+ 98.9000.*exp(  - 0.100000.*(STATES(:,2)+38.0000)));
    ALGEBRAIC(:,19) = 1.00000./(1.00000+exp( - (STATES(:,2)+11.5000)./11.8200));
    RATES(:,30) = (ALGEBRAIC(:,19) - STATES(:,30))./ALGEBRAIC(:,41);
    ALGEBRAIC(:,42) = 1.00000./( 0.118850.*exp((STATES(:,1)+80.0000)./28.3700)+ 0.562300.*exp( - (STATES(:,1)+80.0000)./14.1900));
    ALGEBRAIC(:,21) = 1.00000./(1.00000+exp((STATES(:,1)+138.600)./10.4800));
    RATES(:,32) = (ALGEBRAIC(:,21) - STATES(:,32))./ALGEBRAIC(:,42);
    ALGEBRAIC(:,43) = 1.00000./( 0.118850.*exp((STATES(:,2)+80.0000)./28.3700)+ 0.562300.*exp( - (STATES(:,2)+80.0000)./14.1900));
    ALGEBRAIC(:,22) = 1.00000./(1.00000+exp((STATES(:,2)+138.600)./10.4800));
    RATES(:,33) = (ALGEBRAIC(:,22) - STATES(:,33))./ALGEBRAIC(:,43);
    ALGEBRAIC(:,45) =  0.0410000.*exp( - power((STATES(:,1)+47.0000)./12.0000, 2.00000))+0.0800000./(1.00000+exp( - (STATES(:,1)+55.0000)./5.00000))+0.0150000./(1.00000+exp((STATES(:,1)+75.0000)./25.0000));
    ALGEBRAIC(:,30) = ALGEBRAIC(:,7);
    RATES(:,13) = (ALGEBRAIC(:,30) - STATES(:,13))./ALGEBRAIC(:,45);
    ALGEBRAIC(:,46) =  0.0410000.*exp( - power((STATES(:,2)+47.0000)./12.0000, 2.00000))+0.0800000./(1.00000+exp( - (STATES(:,2)+55.0000)./5.00000))+0.0150000./(1.00000+exp((STATES(:,2)+75.0000)./25.0000));
    ALGEBRAIC(:,33) = ALGEBRAIC(:,10);
    RATES(:,19) = (ALGEBRAIC(:,33) - STATES(:,19))./ALGEBRAIC(:,46);
    ALGEBRAIC(:,49) =  CONSTANTS(:,61).*power(STATES(:,5), 3.00000).*STATES(:,6).*(STATES(:,1) - ( log((CONSTANTS(:,4)+ 0.120000.*CONSTANTS(:,6))./(STATES(:,3)+ 0.120000.*STATES(:,4))).*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3));
    ALGEBRAIC(:,51) =  CONSTANTS(:,73).*power(STATES(:,9), 3.00000).*STATES(:,10).*(STATES(:,2) - ( log((STATES(:,7)+ 0.120000.*STATES(:,8))./(STATES(:,3)+ 0.120000.*STATES(:,4))).*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3));
    ALGEBRAIC(:,48) = ( log(CONSTANTS(:,4)./STATES(:,3)).*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3);
    ALGEBRAIC(:,66) =  CONSTANTS(:,68).*(STATES(:,1) - ALGEBRAIC(:,48));
    ALGEBRAIC(:,50) = ( log(STATES(:,7)./STATES(:,3)).*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3);
    ALGEBRAIC(:,67) =  CONSTANTS(:,80).*(STATES(:,2) - ALGEBRAIC(:,50));
    ALGEBRAIC(:,72) = ( CONSTANTS(:,72).*( exp( 0.0187000.*STATES(:,1)).*power(STATES(:,3), 3.00000).*CONSTANTS(:,5) -  exp(  - 0.0187000.*STATES(:,1)).*power(CONSTANTS(:,4), 3.00000).*STATES(:,16)))./(1.00000+ 0.000100000.*( power(CONSTANTS(:,4), 3.00000).*STATES(:,16)+ power(STATES(:,3), 3.00000).*CONSTANTS(:,5)));
    ALGEBRAIC(:,73) = ( CONSTANTS(:,84).*( exp( 0.0187000.*STATES(:,2)).*power(STATES(:,3), 3.00000).*STATES(:,21) -  exp(  - 0.0187000.*STATES(:,2)).*power(STATES(:,7), 3.00000).*STATES(:,16)))./(1.00000+ 0.000100000.*( power(STATES(:,7), 3.00000).*STATES(:,16)+ power(STATES(:,3), 3.00000).*STATES(:,21)));
    ALGEBRAIC(:,74) = ( (( (CONSTANTS(:,71)./(1.00000+ 0.124500.*exp((  - 0.100000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))+ (( 0.0365000.*1.00000)./7.00000).*(exp(CONSTANTS(:,4)./67.3000) - 1.00000).*exp((  - STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*1.00000)./(1.00000+power(10.0000./STATES(:,3), 1.50000))).*CONSTANTS(:,6))./(CONSTANTS(:,6)+1.50000);
    ALGEBRAIC(:,75) = ( (( (CONSTANTS(:,83)./(1.00000+ 0.124500.*exp((  - 0.100000.*STATES(:,2).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))+ (( 0.0365000.*1.00000)./7.00000).*(exp(STATES(:,7)./67.3000) - 1.00000).*exp((  - STATES(:,2).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*1.00000)./(1.00000+power(10.0000./STATES(:,3), 1.50000))).*STATES(:,8))./(STATES(:,8)+1.50000);
    RATES(:,3) =  - (ALGEBRAIC(:,49)+ALGEBRAIC(:,51)+ALGEBRAIC(:,66)+ALGEBRAIC(:,67)+ 3.00000.*ALGEBRAIC(:,72)+ 3.00000.*ALGEBRAIC(:,73)+ 3.00000.*ALGEBRAIC(:,74)+ 3.00000.*ALGEBRAIC(:,75))./( CONSTANTS(:,3).*CONSTANTS(:,57));
    ALGEBRAIC(:,44) =  floor(VOI./CONSTANTS(:,12)).*CONSTANTS(:,12);
    ALGEBRAIC(:,47) = piecewise({VOI - ALGEBRAIC(:,44)>=CONSTANTS(:,11)&VOI - ALGEBRAIC(:,44)<=CONSTANTS(:,11)+CONSTANTS(:,13), CONSTANTS(:,14) }, 0.00000);
    ALGEBRAIC(:,56) = ( log(CONSTANTS(:,6)./STATES(:,4)).*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3);
    ALGEBRAIC(:,57) =  CONSTANTS(:,67).*STATES(:,22).*( 0.886000.*STATES(:,23)+ 0.114000.*STATES(:,24)).*(STATES(:,1) - ALGEBRAIC(:,56));
    ALGEBRAIC(:,58) = ( log(STATES(:,8)./STATES(:,4)).*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3);
    ALGEBRAIC(:,59) =  CONSTANTS(:,79).*STATES(:,25).*( 0.886000.*STATES(:,26)+ 0.114000.*STATES(:,27)).*(STATES(:,2) - ALGEBRAIC(:,58));
    ALGEBRAIC(:,60) =  CONSTANTS(:,64).*STATES(:,28).*STATES(:,29).*(STATES(:,1) - ALGEBRAIC(:,56));
    ALGEBRAIC(:,61) =  CONSTANTS(:,76).*STATES(:,30).*STATES(:,31).*(STATES(:,2) - ALGEBRAIC(:,58));
    ALGEBRAIC(:,62) =  CONSTANTS(:,63).*STATES(:,32).*( 0.200000.*(STATES(:,1) - ALGEBRAIC(:,48))+ 0.800000.*(STATES(:,1) - ALGEBRAIC(:,56)));
    ALGEBRAIC(:,63) =  CONSTANTS(:,75).*STATES(:,33).*( 0.200000.*(STATES(:,2) - ALGEBRAIC(:,50))+ 0.800000.*(STATES(:,2) - ALGEBRAIC(:,58)));
    ALGEBRAIC(:,64) = ( CONSTANTS(:,65).*((STATES(:,1) - ALGEBRAIC(:,56)) - 1.73000))./(1.00000+ exp( (( 1.61300.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*((STATES(:,1) - ALGEBRAIC(:,56)) - 1.73000)).*(1.00000+exp((CONSTANTS(:,6) - 0.998800)./ - 0.124000)));
    ALGEBRAIC(:,65) = ( CONSTANTS(:,77).*((STATES(:,2) - ALGEBRAIC(:,58)) - 1.73000))./(1.00000+ exp( (( 1.61300.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*((STATES(:,2) - ALGEBRAIC(:,58)) - 1.73000)).*(1.00000+exp((STATES(:,8) - 0.998800)./ - 0.124000)));
    ALGEBRAIC(:,70) =  CONSTANTS(:,66).*(STATES(:,1) - ALGEBRAIC(:,56));
    ALGEBRAIC(:,71) =  CONSTANTS(:,78).*(STATES(:,2) - ALGEBRAIC(:,58));
    RATES(:,4) =  - (((( - ALGEBRAIC(:,47)+ALGEBRAIC(:,62)+ALGEBRAIC(:,63)+ALGEBRAIC(:,60)+ALGEBRAIC(:,61)+ALGEBRAIC(:,64)+ALGEBRAIC(:,65)+ALGEBRAIC(:,70)+ALGEBRAIC(:,71)) -  2.00000.*ALGEBRAIC(:,74)) -  2.00000.*ALGEBRAIC(:,75))+ALGEBRAIC(:,57)+ALGEBRAIC(:,59))./( CONSTANTS(:,3).*CONSTANTS(:,57));
    ALGEBRAIC(:,76) =  (( 1.00000.*CONSTANTS(:,88))./CONSTANTS(:,43)).*(STATES(:,7) - CONSTANTS(:,4));
    RATES(:,7) = ((ALGEBRAIC(:,51)+ALGEBRAIC(:,67)+ 3.00000.*ALGEBRAIC(:,73)+ 3.00000.*ALGEBRAIC(:,75))./CONSTANTS(:,3) -  1.00000.*ALGEBRAIC(:,76))./CONSTANTS(:,88);
    ALGEBRAIC(:,77) =  (( 1.00000.*CONSTANTS(:,88))./CONSTANTS(:,45)).*(STATES(:,8) - CONSTANTS(:,6));
    RATES(:,8) = ((((ALGEBRAIC(:,63)+ALGEBRAIC(:,61)+ALGEBRAIC(:,65)+ALGEBRAIC(:,71)) -  2.00000.*ALGEBRAIC(:,75))+ALGEBRAIC(:,59))./CONSTANTS(:,3) -  1.00000.*ALGEBRAIC(:,77))./CONSTANTS(:,88);
    ALGEBRAIC(:,23) =  1000.00.*(STATES(:,2)./CONSTANTS(:,87) - STATES(:,1)./CONSTANTS(:,87));
    ALGEBRAIC(:,53) =  (( (( CONSTANTS(:,62).*4.00000.*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( STATES(:,15).*exp(( 2.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  0.341000.*CONSTANTS(:,5)))./(exp(( 2.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000)).*STATES(:,11).*( (0.900000+STATES(:,14)./10.0000).*STATES(:,12)+ (0.100000 - STATES(:,14)./10.0000).*STATES(:,13));
    ALGEBRAIC(:,52) = ( log(CONSTANTS(:,5)./STATES(:,16)).*CONSTANTS(:,1).*CONSTANTS(:,2))./( 2.00000.*CONSTANTS(:,3));
    ALGEBRAIC(:,68) =  CONSTANTS(:,69).*(STATES(:,1) - ALGEBRAIC(:,52));
    ALGEBRAIC(:,78) = ( CONSTANTS(:,70).*STATES(:,16))./(0.000400000+STATES(:,16));
    RATES(:,1) = ( 1000.00.*((ALGEBRAIC(:,47)+ALGEBRAIC(:,23)) - (ALGEBRAIC(:,49)+ALGEBRAIC(:,53)+ALGEBRAIC(:,57)+ALGEBRAIC(:,60)+ALGEBRAIC(:,62)+ALGEBRAIC(:,64)+ALGEBRAIC(:,66)+ALGEBRAIC(:,68)+ALGEBRAIC(:,70)+ALGEBRAIC(:,74)+ALGEBRAIC(:,72)+ALGEBRAIC(:,78))))./CONSTANTS(:,90);
    ALGEBRAIC(:,55) =  (( (( CONSTANTS(:,74).*4.00000.*STATES(:,2).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( STATES(:,15).*exp(( 2.00000.*STATES(:,2).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  0.341000.*STATES(:,21)))./(exp(( 2.00000.*STATES(:,2).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000)).*STATES(:,17).*( (0.900000+STATES(:,20)./10.0000).*STATES(:,18)+ (0.100000 - STATES(:,20)./10.0000).*STATES(:,19));
    ALGEBRAIC(:,54) = ( log(STATES(:,21)./STATES(:,16)).*CONSTANTS(:,1).*CONSTANTS(:,2))./( 2.00000.*CONSTANTS(:,3));
    ALGEBRAIC(:,69) =  CONSTANTS(:,81).*(STATES(:,2) - ALGEBRAIC(:,54));
    ALGEBRAIC(:,79) = ( CONSTANTS(:,82).*STATES(:,16))./(0.000400000+STATES(:,16));
    RATES(:,2) = ( 1000.00.* - (ALGEBRAIC(:,23)+ALGEBRAIC(:,51)+ALGEBRAIC(:,55)+ALGEBRAIC(:,59)+ALGEBRAIC(:,61)+ALGEBRAIC(:,63)+ALGEBRAIC(:,65)+ALGEBRAIC(:,67)+ALGEBRAIC(:,69)+ALGEBRAIC(:,71)+ALGEBRAIC(:,75)+ALGEBRAIC(:,73)+ALGEBRAIC(:,79)))./CONSTANTS(:,89);
    ALGEBRAIC(:,80) =  (( 1.00000.*CONSTANTS(:,88))./CONSTANTS(:,44)).*(STATES(:,21) - CONSTANTS(:,5));
    RATES(:,21) = ((  - 2.00000.*ALGEBRAIC(:,73)+ALGEBRAIC(:,55)+ALGEBRAIC(:,69)+ALGEBRAIC(:,79))./( 2.00000.*CONSTANTS(:,3)) -  1.00000.*ALGEBRAIC(:,80))./CONSTANTS(:,88);
    ALGEBRAIC(:,81) = ( 1.00000.*CONSTANTS(:,57).*( 0.0400000.*10.0000.*power(STATES(:,16)./0.000168000, 1.20000) - ( 0.900000.*STATES(:,34))./3.29000))./(1.00000+power(STATES(:,16)./0.000168000, 1.20000)+STATES(:,34)./3.29000);
    ALGEBRAIC(:,82) =  (( 1.00000.*CONSTANTS(:,56))./CONSTANTS(:,46)).*(STATES(:,34) - STATES(:,35));
    RATES(:,34) = (ALGEBRAIC(:,81) - ALGEBRAIC(:,82))./( 1.00000.*CONSTANTS(:,58));
    ALGEBRAIC(:,83) =  1800.00.*CONSTANTS(:,56).*(STATES(:,37)+STATES(:,38)).*(STATES(:,35) - STATES(:,15));
    RATES(:,35) = ( (1.00000./(1.00000+( 15.0000.*0.800000)./power(0.800000+STATES(:,35), 2.00000))).*(ALGEBRAIC(:,82) - ALGEBRAIC(:,83)))./CONSTANTS(:,56);
    ALGEBRAIC(:,84) = ( 1.00000.*(STATES(:,15) - STATES(:,16)).*CONSTANTS(:,57))./CONSTANTS(:,51);
    RATES(:,15) =  (1.00000./(1.00000+( 0.0500000.*0.00238000)./power(0.00238000+STATES(:,15), 2.00000))).*(( - (ALGEBRAIC(:,53)+ALGEBRAIC(:,55))./( 2.00000.*CONSTANTS(:,3).*CONSTANTS(:,55))+( 1.00000.*ALGEBRAIC(:,83))./CONSTANTS(:,55)) - ( 1.00000.*ALGEBRAIC(:,84))./CONSTANTS(:,55));
    ALGEBRAIC(:,85) =  20000.0.*STATES(:,16).*(1.00000 - STATES(:,40)) -  0.0700000.*STATES(:,40);
    RATES(:,40) = ALGEBRAIC(:,85);
    ALGEBRAIC(:,86) =  40000.0.*STATES(:,16).*(1.00000 - STATES(:,41)) -  STATES(:,41).*40.0000;
    RATES(:,41) = ALGEBRAIC(:,86);
    RATES(:,16) =  (1.00000./(1.00000+( 0.0500000.*0.00238000)./power(0.00238000+STATES(:,16), 2.00000))).*((((  - 2.00000.*(ALGEBRAIC(:,72)+ALGEBRAIC(:,73))+ALGEBRAIC(:,68)+ALGEBRAIC(:,69)+ALGEBRAIC(:,78)+ALGEBRAIC(:,79))./(  - 2.00000.*CONSTANTS(:,3).*CONSTANTS(:,57))+( 1.00000.*(ALGEBRAIC(:,84) - ALGEBRAIC(:,81)))./CONSTANTS(:,57)) -  ALGEBRAIC(:,85).*0.140000) -  ALGEBRAIC(:,86).*0.0700000);
   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(:,6) = 1.00000./(1.00000+STATES(:,15)./0.0100000);
    ALGEBRAIC(:,9) = 1.00000./(1.00000+STATES(:,15)./0.0100000);
    ALGEBRAIC(:,18) = 1.00000./(1.00000+exp((STATES(:,1)+87.5000)./10.3000));
    ALGEBRAIC(:,20) = 1.00000./(1.00000+exp((STATES(:,2)+87.5000)./10.3000));
    ALGEBRAIC(:,1) = ( 117.260.*(STATES(:,1)+59.3000))./(1.00000 - exp(  - 0.550000.*(STATES(:,1)+59.3000)));
    ALGEBRAIC(:,24) =  3800.00.*exp(  - 0.0720000.*(STATES(:,1)+61.0000));
    ALGEBRAIC(:,2) = 284.400./(1.00000+exp( 0.0812000.*(STATES(:,1)+115.900)));
    ALGEBRAIC(:,25) = ( 18.7700.*(STATES(:,1)+64.4000))./(1.00000 - exp(  - 0.220000.*(STATES(:,1)+64.4000)));
    ALGEBRAIC(:,3) = ( 117.260.*(STATES(:,2)+59.3000))./(1.00000 - exp(  - 0.550000.*(STATES(:,2)+59.3000)));
    ALGEBRAIC(:,26) =  3800.00.*exp(  - 0.0720000.*(STATES(:,2)+61.0000));
    ALGEBRAIC(:,4) = 284.400./(1.00000+exp( 0.0812000.*(STATES(:,2)+115.900)));
    ALGEBRAIC(:,27) = ( 18.7700.*(STATES(:,2)+64.4000))./(1.00000 - exp(  - 0.220000.*(STATES(:,2)+64.4000)));
    ALGEBRAIC(:,29) =  0.105000.*exp( - power((STATES(:,1)+45.0000)./12.0000, 2.00000))+0.0400000./(1.00000+exp(( - STATES(:,1)+25.0000)./25.0000))+0.0150000./(1.00000+exp((STATES(:,1)+75.0000)./25.0000));
    ALGEBRAIC(:,7) = 1.00000./(1.00000+exp((STATES(:,1)+26.7000)./5.40000));
    ALGEBRAIC(:,28) = 0.000250000+ 0.00305000.*exp(  - 0.00450000.*power(STATES(:,1)+7.00000, 2.00000))+ 0.00105000.*exp(  - 0.00200000.*power(STATES(:,1) - 18.0000, 2.00000));
    ALGEBRAIC(:,5) = 1.00000./(1.00000+exp( - (STATES(:,1)+15.3000)./5.00000));
    ALGEBRAIC(:,32) =  0.105000.*exp( - power((STATES(:,2)+45.0000)./12.0000, 2.00000))+0.0400000./(1.00000+exp(( - STATES(:,2)+25.0000)./25.0000))+0.0150000./(1.00000+exp((STATES(:,2)+75.0000)./25.0000));
    ALGEBRAIC(:,10) = 1.00000./(1.00000+exp((STATES(:,2)+26.7000)./5.40000));
    ALGEBRAIC(:,31) = 0.000250000+ 0.00305000.*exp(  - 0.00450000.*power(STATES(:,2)+7.00000, 2.00000))+ 0.00105000.*exp(  - 0.00200000.*power(STATES(:,2) - 18.0000, 2.00000));
    ALGEBRAIC(:,8) = 1.00000./(1.00000+exp( - (STATES(:,2)+15.3000)./5.00000));
    ALGEBRAIC(:,34) = 1.00000./( 45.1600.*exp( 0.0357700.*(STATES(:,1)+50.0000))+ 98.9000.*exp(  - 0.100000.*(STATES(:,1)+38.0000)));
    ALGEBRAIC(:,11) = 1.00000./(1.00000+exp((STATES(:,1)+10.6000)./ - 11.4200));
    ALGEBRAIC(:,35) =  0.350000.*exp( - power( 0.0666000.*(STATES(:,1)+70.0000), 2.00000))+0.0350000;
    ALGEBRAIC(:,12) = 1.00000./(1.00000+exp((STATES(:,1)+45.3000)./6.88410));
    ALGEBRAIC(:,36) =  3.70000.*exp( - power( 0.0333000.*(STATES(:,1)+70.0000), 2.00000))+0.0350000;
    ALGEBRAIC(:,13) = 1.00000./(1.00000+exp((STATES(:,1)+45.3000)./6.88410));
    ALGEBRAIC(:,37) = 1.00000./( 45.1600.*exp( 0.0357700.*(STATES(:,2)+50.0000))+ 98.9000.*exp(  - 0.100000.*(STATES(:,2)+38.0000)));
    ALGEBRAIC(:,14) = 1.00000./(1.00000+exp((STATES(:,2)+10.6000)./ - 11.4200));
    ALGEBRAIC(:,38) =  0.350000.*exp( - power( 0.0666000.*(STATES(:,2)+70.0000), 2.00000))+0.0350000;
    ALGEBRAIC(:,15) = 1.00000./(1.00000+exp((STATES(:,2)+45.3000)./6.88410));
    ALGEBRAIC(:,39) =  3.70000.*exp( - power( 0.0333000.*(STATES(:,2)+70.0000), 2.00000))+0.0350000;
    ALGEBRAIC(:,16) = 1.00000./(1.00000+exp((STATES(:,2)+45.3000)./6.88410));
    ALGEBRAIC(:,40) = 10.0000./( 45.1600.*exp( 0.0357700.*(STATES(:,1)+50.0000))+ 98.9000.*exp(  - 0.100000.*(STATES(:,1)+38.0000)));
    ALGEBRAIC(:,17) = 1.00000./(1.00000+exp( - (STATES(:,1)+11.5000)./11.8200));
    ALGEBRAIC(:,41) = 10.0000./( 45.1600.*exp( 0.0357700.*(STATES(:,2)+50.0000))+ 98.9000.*exp(  - 0.100000.*(STATES(:,2)+38.0000)));
    ALGEBRAIC(:,19) = 1.00000./(1.00000+exp( - (STATES(:,2)+11.5000)./11.8200));
    ALGEBRAIC(:,42) = 1.00000./( 0.118850.*exp((STATES(:,1)+80.0000)./28.3700)+ 0.562300.*exp( - (STATES(:,1)+80.0000)./14.1900));
    ALGEBRAIC(:,21) = 1.00000./(1.00000+exp((STATES(:,1)+138.600)./10.4800));
    ALGEBRAIC(:,43) = 1.00000./( 0.118850.*exp((STATES(:,2)+80.0000)./28.3700)+ 0.562300.*exp( - (STATES(:,2)+80.0000)./14.1900));
    ALGEBRAIC(:,22) = 1.00000./(1.00000+exp((STATES(:,2)+138.600)./10.4800));
    ALGEBRAIC(:,45) =  0.0410000.*exp( - power((STATES(:,1)+47.0000)./12.0000, 2.00000))+0.0800000./(1.00000+exp( - (STATES(:,1)+55.0000)./5.00000))+0.0150000./(1.00000+exp((STATES(:,1)+75.0000)./25.0000));
    ALGEBRAIC(:,30) = ALGEBRAIC(:,7);
    ALGEBRAIC(:,46) =  0.0410000.*exp( - power((STATES(:,2)+47.0000)./12.0000, 2.00000))+0.0800000./(1.00000+exp( - (STATES(:,2)+55.0000)./5.00000))+0.0150000./(1.00000+exp((STATES(:,2)+75.0000)./25.0000));
    ALGEBRAIC(:,33) = ALGEBRAIC(:,10);
    ALGEBRAIC(:,49) =  CONSTANTS(:,61).*power(STATES(:,5), 3.00000).*STATES(:,6).*(STATES(:,1) - ( log((CONSTANTS(:,4)+ 0.120000.*CONSTANTS(:,6))./(STATES(:,3)+ 0.120000.*STATES(:,4))).*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3));
    ALGEBRAIC(:,51) =  CONSTANTS(:,73).*power(STATES(:,9), 3.00000).*STATES(:,10).*(STATES(:,2) - ( log((STATES(:,7)+ 0.120000.*STATES(:,8))./(STATES(:,3)+ 0.120000.*STATES(:,4))).*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3));
    ALGEBRAIC(:,48) = ( log(CONSTANTS(:,4)./STATES(:,3)).*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3);
    ALGEBRAIC(:,66) =  CONSTANTS(:,68).*(STATES(:,1) - ALGEBRAIC(:,48));
    ALGEBRAIC(:,50) = ( log(STATES(:,7)./STATES(:,3)).*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3);
    ALGEBRAIC(:,67) =  CONSTANTS(:,80).*(STATES(:,2) - ALGEBRAIC(:,50));
    ALGEBRAIC(:,72) = ( CONSTANTS(:,72).*( exp( 0.0187000.*STATES(:,1)).*power(STATES(:,3), 3.00000).*CONSTANTS(:,5) -  exp(  - 0.0187000.*STATES(:,1)).*power(CONSTANTS(:,4), 3.00000).*STATES(:,16)))./(1.00000+ 0.000100000.*( power(CONSTANTS(:,4), 3.00000).*STATES(:,16)+ power(STATES(:,3), 3.00000).*CONSTANTS(:,5)));
    ALGEBRAIC(:,73) = ( CONSTANTS(:,84).*( exp( 0.0187000.*STATES(:,2)).*power(STATES(:,3), 3.00000).*STATES(:,21) -  exp(  - 0.0187000.*STATES(:,2)).*power(STATES(:,7), 3.00000).*STATES(:,16)))./(1.00000+ 0.000100000.*( power(STATES(:,7), 3.00000).*STATES(:,16)+ power(STATES(:,3), 3.00000).*STATES(:,21)));
    ALGEBRAIC(:,74) = ( (( (CONSTANTS(:,71)./(1.00000+ 0.124500.*exp((  - 0.100000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))+ (( 0.0365000.*1.00000)./7.00000).*(exp(CONSTANTS(:,4)./67.3000) - 1.00000).*exp((  - STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*1.00000)./(1.00000+power(10.0000./STATES(:,3), 1.50000))).*CONSTANTS(:,6))./(CONSTANTS(:,6)+1.50000);
    ALGEBRAIC(:,75) = ( (( (CONSTANTS(:,83)./(1.00000+ 0.124500.*exp((  - 0.100000.*STATES(:,2).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))+ (( 0.0365000.*1.00000)./7.00000).*(exp(STATES(:,7)./67.3000) - 1.00000).*exp((  - STATES(:,2).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*1.00000)./(1.00000+power(10.0000./STATES(:,3), 1.50000))).*STATES(:,8))./(STATES(:,8)+1.50000);
    ALGEBRAIC(:,44) =  floor(VOI./CONSTANTS(:,12)).*CONSTANTS(:,12);
    ALGEBRAIC(:,47) = piecewise({VOI - ALGEBRAIC(:,44)>=CONSTANTS(:,11)&VOI - ALGEBRAIC(:,44)<=CONSTANTS(:,11)+CONSTANTS(:,13), CONSTANTS(:,14) }, 0.00000);
    ALGEBRAIC(:,56) = ( log(CONSTANTS(:,6)./STATES(:,4)).*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3);
    ALGEBRAIC(:,57) =  CONSTANTS(:,67).*STATES(:,22).*( 0.886000.*STATES(:,23)+ 0.114000.*STATES(:,24)).*(STATES(:,1) - ALGEBRAIC(:,56));
    ALGEBRAIC(:,58) = ( log(STATES(:,8)./STATES(:,4)).*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3);
    ALGEBRAIC(:,59) =  CONSTANTS(:,79).*STATES(:,25).*( 0.886000.*STATES(:,26)+ 0.114000.*STATES(:,27)).*(STATES(:,2) - ALGEBRAIC(:,58));
    ALGEBRAIC(:,60) =  CONSTANTS(:,64).*STATES(:,28).*STATES(:,29).*(STATES(:,1) - ALGEBRAIC(:,56));
    ALGEBRAIC(:,61) =  CONSTANTS(:,76).*STATES(:,30).*STATES(:,31).*(STATES(:,2) - ALGEBRAIC(:,58));
    ALGEBRAIC(:,62) =  CONSTANTS(:,63).*STATES(:,32).*( 0.200000.*(STATES(:,1) - ALGEBRAIC(:,48))+ 0.800000.*(STATES(:,1) - ALGEBRAIC(:,56)));
    ALGEBRAIC(:,63) =  CONSTANTS(:,75).*STATES(:,33).*( 0.200000.*(STATES(:,2) - ALGEBRAIC(:,50))+ 0.800000.*(STATES(:,2) - ALGEBRAIC(:,58)));
    ALGEBRAIC(:,64) = ( CONSTANTS(:,65).*((STATES(:,1) - ALGEBRAIC(:,56)) - 1.73000))./(1.00000+ exp( (( 1.61300.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*((STATES(:,1) - ALGEBRAIC(:,56)) - 1.73000)).*(1.00000+exp((CONSTANTS(:,6) - 0.998800)./ - 0.124000)));
    ALGEBRAIC(:,65) = ( CONSTANTS(:,77).*((STATES(:,2) - ALGEBRAIC(:,58)) - 1.73000))./(1.00000+ exp( (( 1.61300.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*((STATES(:,2) - ALGEBRAIC(:,58)) - 1.73000)).*(1.00000+exp((STATES(:,8) - 0.998800)./ - 0.124000)));
    ALGEBRAIC(:,70) =  CONSTANTS(:,66).*(STATES(:,1) - ALGEBRAIC(:,56));
    ALGEBRAIC(:,71) =  CONSTANTS(:,78).*(STATES(:,2) - ALGEBRAIC(:,58));
    ALGEBRAIC(:,76) =  (( 1.00000.*CONSTANTS(:,88))./CONSTANTS(:,43)).*(STATES(:,7) - CONSTANTS(:,4));
    ALGEBRAIC(:,77) =  (( 1.00000.*CONSTANTS(:,88))./CONSTANTS(:,45)).*(STATES(:,8) - CONSTANTS(:,6));
    ALGEBRAIC(:,23) =  1000.00.*(STATES(:,2)./CONSTANTS(:,87) - STATES(:,1)./CONSTANTS(:,87));
    ALGEBRAIC(:,53) =  (( (( CONSTANTS(:,62).*4.00000.*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( STATES(:,15).*exp(( 2.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  0.341000.*CONSTANTS(:,5)))./(exp(( 2.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000)).*STATES(:,11).*( (0.900000+STATES(:,14)./10.0000).*STATES(:,12)+ (0.100000 - STATES(:,14)./10.0000).*STATES(:,13));
    ALGEBRAIC(:,52) = ( log(CONSTANTS(:,5)./STATES(:,16)).*CONSTANTS(:,1).*CONSTANTS(:,2))./( 2.00000.*CONSTANTS(:,3));
    ALGEBRAIC(:,68) =  CONSTANTS(:,69).*(STATES(:,1) - ALGEBRAIC(:,52));
    ALGEBRAIC(:,78) = ( CONSTANTS(:,70).*STATES(:,16))./(0.000400000+STATES(:,16));
    ALGEBRAIC(:,55) =  (( (( CONSTANTS(:,74).*4.00000.*STATES(:,2).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( STATES(:,15).*exp(( 2.00000.*STATES(:,2).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  0.341000.*STATES(:,21)))./(exp(( 2.00000.*STATES(:,2).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000)).*STATES(:,17).*( (0.900000+STATES(:,20)./10.0000).*STATES(:,18)+ (0.100000 - STATES(:,20)./10.0000).*STATES(:,19));
    ALGEBRAIC(:,54) = ( log(STATES(:,21)./STATES(:,16)).*CONSTANTS(:,1).*CONSTANTS(:,2))./( 2.00000.*CONSTANTS(:,3));
    ALGEBRAIC(:,69) =  CONSTANTS(:,81).*(STATES(:,2) - ALGEBRAIC(:,54));
    ALGEBRAIC(:,79) = ( CONSTANTS(:,82).*STATES(:,16))./(0.000400000+STATES(:,16));
    ALGEBRAIC(:,80) =  (( 1.00000.*CONSTANTS(:,88))./CONSTANTS(:,44)).*(STATES(:,21) - CONSTANTS(:,5));
    ALGEBRAIC(:,81) = ( 1.00000.*CONSTANTS(:,57).*( 0.0400000.*10.0000.*power(STATES(:,16)./0.000168000, 1.20000) - ( 0.900000.*STATES(:,34))./3.29000))./(1.00000+power(STATES(:,16)./0.000168000, 1.20000)+STATES(:,34)./3.29000);
    ALGEBRAIC(:,82) =  (( 1.00000.*CONSTANTS(:,56))./CONSTANTS(:,46)).*(STATES(:,34) - STATES(:,35));
    ALGEBRAIC(:,83) =  1800.00.*CONSTANTS(:,56).*(STATES(:,37)+STATES(:,38)).*(STATES(:,35) - STATES(:,15));
    ALGEBRAIC(:,84) = ( 1.00000.*(STATES(:,15) - STATES(:,16)).*CONSTANTS(:,57))./CONSTANTS(:,51);
    ALGEBRAIC(:,85) =  20000.0.*STATES(:,16).*(1.00000 - STATES(:,40)) -  0.0700000.*STATES(:,40);
    ALGEBRAIC(:,86) =  40000.0.*STATES(:,16).*(1.00000 - STATES(:,41)) -  STATES(:,41).*40.0000;
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