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 =90;
end
% There are a total of 33 entries in each of the rate and state variable arrays.
% There are a total of 104 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 Membrane (joule_per_kilomole_kelvin)');
    LEGEND_CONSTANTS(:,2) = strpad('T in component Membrane (kelvin)');
    LEGEND_CONSTANTS(:,3) = strpad('F in component Membrane (coulomb_per_mole)');
    LEGEND_CONSTANTS(:,4) = strpad('C in component Membrane (microF)');
    LEGEND_CONSTANTS(:,86) = strpad('RTONF in component Membrane (millivolt)');
    LEGEND_ALGEBRAIC(:,52) = strpad('i_f in component i_f (nanoA)');
    LEGEND_ALGEBRAIC(:,53) = strpad('i_NaK in component i_NaK (nanoA)');
    LEGEND_ALGEBRAIC(:,67) = strpad('i_NaCa in component i_NaCa (nanoA)');
    LEGEND_ALGEBRAIC(:,69) = strpad('i_Na in component i_Na (nanoA)');
    LEGEND_ALGEBRAIC(:,77) = strpad('i_Kr in component i_Kr (nanoA)');
    LEGEND_ALGEBRAIC(:,81) = strpad('i_Ks in component i_Ks (nanoA)');
    LEGEND_ALGEBRAIC(:,75) = strpad('i_to in component i_to (nanoA)');
    LEGEND_ALGEBRAIC(:,73) = strpad('i_CaL in component i_CaL (nanoA)');
    LEGEND_ALGEBRAIC(:,74) = strpad('i_CaT in component i_CaT (nanoA)');
    LEGEND_ALGEBRAIC(:,84) = strpad('i_KACh in component i_KACh (nanoA)');
    LEGEND_ALGEBRAIC(:,8) = strpad('V in component Membrane (millivolt)');
    LEGEND_CONSTANTS(:,5) = strpad('clamp_mode in component Membrane (dimensionless)');
    LEGEND_ALGEBRAIC(:,4) = strpad('V_clamp in component Voltage_clamp (millivolt)');
    LEGEND_STATES(:,1) = strpad('V_ode in component Membrane (millivolt)');
    LEGEND_ALGEBRAIC(:,87) = strpad('i_tot in component Membrane (nanoA)');
    LEGEND_CONSTANTS(:,6) = strpad('t_holding in component Voltage_clamp (second)');
    LEGEND_CONSTANTS(:,7) = strpad('t_test in component Voltage_clamp (second)');
    LEGEND_CONSTANTS(:,8) = strpad('V_test in component Voltage_clamp (millivolt)');
    LEGEND_CONSTANTS(:,9) = strpad('V_holding in component Voltage_clamp (millivolt)');
    LEGEND_CONSTANTS(:,10) = strpad('Iva_3_uM in component Rate_modulation_experiments (dimensionless)');
    LEGEND_CONSTANTS(:,11) = strpad('Cs_5_mM in component Rate_modulation_experiments (dimensionless)');
    LEGEND_CONSTANTS(:,12) = strpad('ACh in component Rate_modulation_experiments (millimolar)');
    LEGEND_CONSTANTS(:,13) = strpad('Iso_1_uM in component Rate_modulation_experiments (dimensionless)');
    LEGEND_CONSTANTS(:,14) = strpad('BAPTA_10_mM in component Rate_modulation_experiments (dimensionless)');
    LEGEND_ALGEBRAIC(:,17) = strpad('Nai in component Nai_concentration (millimolar)');
    LEGEND_CONSTANTS(:,15) = strpad('Nao in component Ionic_values (millimolar)');
    LEGEND_CONSTANTS(:,16) = strpad('Ki in component Ionic_values (millimolar)');
    LEGEND_CONSTANTS(:,17) = strpad('Ko in component Ionic_values (millimolar)');
    LEGEND_STATES(:,2) = strpad('Ca_sub in component Ca_dynamics (millimolar)');
    LEGEND_CONSTANTS(:,18) = strpad('Cao in component Ionic_values (millimolar)');
    LEGEND_ALGEBRAIC(:,33) = strpad('E_Na in component Ionic_values (millivolt)');
    LEGEND_CONSTANTS(:,88) = strpad('E_K in component Ionic_values (millivolt)');
    LEGEND_ALGEBRAIC(:,1) = strpad('E_Ca in component Ionic_values (millivolt)');
    LEGEND_CONSTANTS(:,99) = strpad('V_sub in component Cell_parameters (millimetre3)');
    LEGEND_CONSTANTS(:,101) = strpad('V_i in component Cell_parameters (millimetre3)');
    LEGEND_ALGEBRAIC(:,47) = strpad('i_fNa in component i_f (nanoA)');
    LEGEND_ALGEBRAIC(:,72) = strpad('i_siNa in component i_CaL (nanoA)');
    LEGEND_STATES(:,3) = strpad('Nai_ in component Nai_concentration (millimolar)');
    LEGEND_ALGEBRAIC(:,43) = strpad('ICs_on_Icontrol in component i_f (dimensionless)');
    LEGEND_ALGEBRAIC(:,50) = strpad('i_fK in component i_f (nanoA)');
    LEGEND_CONSTANTS(:,83) = strpad('g_f_Na in component i_f (microS)');
    LEGEND_CONSTANTS(:,84) = strpad('g_f_K in component i_f (microS)');
    LEGEND_CONSTANTS(:,19) = strpad('Km_f in component i_f (millimolar)');
    LEGEND_STATES(:,4) = strpad('y in component i_f_y_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,9) = strpad('tau_y in component i_f_y_gate (second)');
    LEGEND_ALGEBRAIC(:,26) = strpad('y_infinity in component i_f_y_gate (dimensionless)');
    LEGEND_CONSTANTS(:,90) = strpad('ACh_shift in component i_f_y_gate (millivolt)');
    LEGEND_CONSTANTS(:,91) = strpad('Iso_shift in component i_f_y_gate (millivolt)');
    LEGEND_CONSTANTS(:,20) = strpad('Km_Kp in component i_NaK (millimolar)');
    LEGEND_CONSTANTS(:,21) = strpad('Km_Nap in component i_NaK (millimolar)');
    LEGEND_CONSTANTS(:,22) = strpad('i_NaK_max in component i_NaK (nanoA)');
    LEGEND_CONSTANTS(:,92) = strpad('Iso_increase in component i_NaK (dimensionless)');
    LEGEND_CONSTANTS(:,23) = strpad('K_NaCa in component i_NaCa (nanoA)');
    LEGEND_ALGEBRAIC(:,64) = strpad('x1 in component i_NaCa (dimensionless)');
    LEGEND_ALGEBRAIC(:,60) = strpad('x2 in component i_NaCa (dimensionless)');
    LEGEND_ALGEBRAIC(:,65) = strpad('x3 in component i_NaCa (dimensionless)');
    LEGEND_ALGEBRAIC(:,66) = strpad('x4 in component i_NaCa (dimensionless)');
    LEGEND_ALGEBRAIC(:,55) = strpad('k41 in component i_NaCa (dimensionless)');
    LEGEND_CONSTANTS(:,93) = strpad('k34 in component i_NaCa (dimensionless)');
    LEGEND_ALGEBRAIC(:,63) = strpad('k23 in component i_NaCa (dimensionless)');
    LEGEND_ALGEBRAIC(:,62) = strpad('k21 in component i_NaCa (dimensionless)');
    LEGEND_ALGEBRAIC(:,59) = strpad('k32 in component i_NaCa (dimensionless)');
    LEGEND_ALGEBRAIC(:,54) = strpad('k43 in component i_NaCa (dimensionless)');
    LEGEND_ALGEBRAIC(:,57) = strpad('k12 in component i_NaCa (dimensionless)');
    LEGEND_ALGEBRAIC(:,58) = strpad('k14 in component i_NaCa (dimensionless)');
    LEGEND_CONSTANTS(:,24) = strpad('Qci in component i_NaCa (dimensionless)');
    LEGEND_CONSTANTS(:,25) = strpad('Qn in component i_NaCa (dimensionless)');
    LEGEND_CONSTANTS(:,26) = strpad('Qco in component i_NaCa (dimensionless)');
    LEGEND_CONSTANTS(:,27) = strpad('K3ni in component i_NaCa (millimolar)');
    LEGEND_CONSTANTS(:,28) = strpad('Kci in component i_NaCa (millimolar)');
    LEGEND_CONSTANTS(:,29) = strpad('K1ni in component i_NaCa (millimolar)');
    LEGEND_CONSTANTS(:,30) = strpad('K2ni in component i_NaCa (millimolar)');
    LEGEND_CONSTANTS(:,31) = strpad('Kcni in component i_NaCa (millimolar)');
    LEGEND_CONSTANTS(:,32) = strpad('K3no in component i_NaCa (millimolar)');
    LEGEND_CONSTANTS(:,33) = strpad('K1no in component i_NaCa (millimolar)');
    LEGEND_CONSTANTS(:,34) = strpad('K2no in component i_NaCa (millimolar)');
    LEGEND_CONSTANTS(:,35) = strpad('Kco in component i_NaCa (millimolar)');
    LEGEND_ALGEBRAIC(:,61) = strpad('do in component i_NaCa (dimensionless)');
    LEGEND_ALGEBRAIC(:,56) = strpad('di in component i_NaCa (dimensionless)');
    LEGEND_CONSTANTS(:,36) = strpad('g_Na in component i_Na (microS)');
    LEGEND_ALGEBRAIC(:,68) = strpad('E_mh in component i_Na (millivolt)');
    LEGEND_STATES(:,5) = strpad('m in component i_Na_m_gate (dimensionless)');
    LEGEND_STATES(:,6) = strpad('h in component i_Na_h_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,27) = strpad('alpha_m in component i_Na_m_gate (per_second)');
    LEGEND_ALGEBRAIC(:,41) = strpad('beta_m in component i_Na_m_gate (per_second)');
    LEGEND_CONSTANTS(:,37) = strpad('delta_m in component i_Na_m_gate (millivolt)');
    LEGEND_ALGEBRAIC(:,10) = strpad('E0_m in component i_Na_m_gate (millivolt)');
    LEGEND_ALGEBRAIC(:,11) = strpad('alpha_h in component i_Na_h_gate (per_second)');
    LEGEND_ALGEBRAIC(:,28) = strpad('beta_h in component i_Na_h_gate (per_second)');
    LEGEND_ALGEBRAIC(:,70) = strpad('i_siCa in component i_CaL (nanoA)');
    LEGEND_ALGEBRAIC(:,71) = strpad('i_siK in component i_CaL (nanoA)');
    LEGEND_CONSTANTS(:,95) = strpad('ACh_block in component i_CaL (dimensionless)');
    LEGEND_CONSTANTS(:,38) = strpad('P_CaL in component i_CaL (nanoA_per_millimolar)');
    LEGEND_STATES(:,7) = strpad('dL in component i_CaL_dL_gate (dimensionless)');
    LEGEND_STATES(:,8) = strpad('fL in component i_CaL_fL_gate (dimensionless)');
    LEGEND_STATES(:,9) = strpad('fCa in component i_CaL_fCa_gate (dimensionless)');
    LEGEND_CONSTANTS(:,94) = strpad('Iso_increase in component i_CaL (dimensionless)');
    LEGEND_ALGEBRAIC(:,12) = strpad('dL_infinity in component i_CaL_dL_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,51) = strpad('tau_dL in component i_CaL_dL_gate (second)');
    LEGEND_ALGEBRAIC(:,42) = strpad('alpha_dL in component i_CaL_dL_gate (per_second)');
    LEGEND_ALGEBRAIC(:,49) = strpad('beta_dL in component i_CaL_dL_gate (per_second)');
    LEGEND_ALGEBRAIC(:,29) = strpad('adVm in component i_CaL_dL_gate (millivolt)');
    LEGEND_ALGEBRAIC(:,46) = strpad('bdVm in component i_CaL_dL_gate (millivolt)');
    LEGEND_CONSTANTS(:,96) = strpad('Iso_shift in component i_CaL_dL_gate (millivolt)');
    LEGEND_CONSTANTS(:,97) = strpad('Iso_slope in component i_CaL_dL_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,13) = strpad('fL_infinity in component i_CaL_fL_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,30) = strpad('tau_fL in component i_CaL_fL_gate (second)');
    LEGEND_CONSTANTS(:,39) = strpad('alpha_fCa in component i_CaL_fCa_gate (per_second)');
    LEGEND_ALGEBRAIC(:,2) = strpad('fCa_infinity in component i_CaL_fCa_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,6) = strpad('tau_fCa in component i_CaL_fCa_gate (second)');
    LEGEND_CONSTANTS(:,40) = strpad('Km_fCa in component i_CaL_fCa_gate (millimolar)');
    LEGEND_CONSTANTS(:,41) = strpad('P_CaT in component i_CaT (nanoA_per_millimolar)');
    LEGEND_STATES(:,10) = strpad('dT in component i_CaT_dT_gate (dimensionless)');
    LEGEND_STATES(:,11) = strpad('fT in component i_CaT_fT_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,14) = strpad('dT_infinity in component i_CaT_dT_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,31) = strpad('tau_dT in component i_CaT_dT_gate (second)');
    LEGEND_ALGEBRAIC(:,15) = strpad('fT_infinity in component i_CaT_fT_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,32) = strpad('tau_fT in component i_CaT_fT_gate (second)');
    LEGEND_ALGEBRAIC(:,76) = strpad('j_SRCarel in component Ca_SR_release (millimolar_per_second)');
    LEGEND_STATES(:,12) = strpad('R in component Ca_SR_release (dimensionless)');
    LEGEND_STATES(:,13) = strpad('O in component Ca_SR_release (dimensionless)');
    LEGEND_STATES(:,14) = strpad('I in component Ca_SR_release (dimensionless)');
    LEGEND_STATES(:,15) = strpad('RI in component Ca_SR_release (dimensionless)');
    LEGEND_CONSTANTS(:,42) = strpad('ks in component Ca_SR_release (per_second)');
    LEGEND_CONSTANTS(:,43) = strpad('MaxSR in component Ca_SR_release (dimensionless)');
    LEGEND_CONSTANTS(:,44) = strpad('MinSR in component Ca_SR_release (dimensionless)');
    LEGEND_CONSTANTS(:,45) = strpad('EC50_SR in component Ca_SR_release (millimolar)');
    LEGEND_CONSTANTS(:,46) = strpad('HSR in component Ca_SR_release (dimensionless)');
    LEGEND_ALGEBRAIC(:,7) = strpad('koSRCa in component Ca_SR_release (per_millimolar2_second)');
    LEGEND_ALGEBRAIC(:,16) = strpad('kiSRCa in component Ca_SR_release (per_millimolar_second)');
    LEGEND_CONSTANTS(:,47) = strpad('koCa in component Ca_SR_release (per_millimolar2_second)');
    LEGEND_CONSTANTS(:,48) = strpad('kiCa in component Ca_SR_release (per_millimolar_second)');
    LEGEND_ALGEBRAIC(:,3) = strpad('kCaSR in component Ca_SR_release (dimensionless)');
    LEGEND_CONSTANTS(:,49) = strpad('kim in component Ca_SR_release (per_second)');
    LEGEND_CONSTANTS(:,50) = strpad('kom in component Ca_SR_release (per_second)');
    LEGEND_STATES(:,16) = strpad('Ca_jsr in component Ca_dynamics (millimolar)');
    LEGEND_ALGEBRAIC(:,78) = strpad('j_Ca_dif in component Ca_intracellular_fluxes (millimolar_per_second)');
    LEGEND_ALGEBRAIC(:,80) = strpad('j_up in component Ca_intracellular_fluxes (millimolar_per_second)');
    LEGEND_ALGEBRAIC(:,83) = strpad('j_tr in component Ca_intracellular_fluxes (millimolar_per_second)');
    LEGEND_CONSTANTS(:,51) = strpad('tau_dif_Ca in component Ca_intracellular_fluxes (second)');
    LEGEND_CONSTANTS(:,52) = strpad('tau_tr in component Ca_intracellular_fluxes (second)');
    LEGEND_CONSTANTS(:,89) = strpad('P_up in component Ca_intracellular_fluxes (millimolar_per_second)');
    LEGEND_CONSTANTS(:,53) = strpad('P_up_basal in component Ca_intracellular_fluxes (millimolar_per_second)');
    LEGEND_CONSTANTS(:,85) = strpad('b_up in component Ca_intracellular_fluxes (dimensionless)');
    LEGEND_CONSTANTS(:,54) = strpad('K_up in component Ca_intracellular_fluxes (millimolar)');
    LEGEND_STATES(:,17) = strpad('Ca_nsr in component Ca_dynamics (millimolar)');
    LEGEND_STATES(:,18) = strpad('Cai in component Ca_dynamics (millimolar)');
    LEGEND_CONSTANTS(:,55) = strpad('TC_tot in component Ca_buffering (millimolar)');
    LEGEND_CONSTANTS(:,56) = strpad('TMC_tot in component Ca_buffering (millimolar)');
    LEGEND_CONSTANTS(:,57) = strpad('CM_tot in component Ca_buffering (millimolar)');
    LEGEND_CONSTANTS(:,58) = strpad('CQ_tot in component Ca_buffering (millimolar)');
    LEGEND_ALGEBRAIC(:,82) = strpad('delta_fTC in component Ca_buffering (per_second)');
    LEGEND_ALGEBRAIC(:,85) = strpad('delta_fTMC in component Ca_buffering (per_second)');
    LEGEND_ALGEBRAIC(:,89) = strpad('delta_fCMs in component Ca_buffering (per_second)');
    LEGEND_ALGEBRAIC(:,88) = strpad('delta_fCMi in component Ca_buffering (per_second)');
    LEGEND_ALGEBRAIC(:,86) = strpad('delta_fCQ in component Ca_buffering (per_second)');
    LEGEND_ALGEBRAIC(:,5) = strpad('delta_fTMM in component Ca_buffering (per_second)');
    LEGEND_STATES(:,19) = strpad('fTMM in component Ca_buffering (dimensionless)');
    LEGEND_STATES(:,20) = strpad('fCMi in component Ca_buffering (dimensionless)');
    LEGEND_STATES(:,21) = strpad('fCMs in component Ca_buffering (dimensionless)');
    LEGEND_STATES(:,22) = strpad('fTC in component Ca_buffering (dimensionless)');
    LEGEND_STATES(:,23) = strpad('fTMC in component Ca_buffering (dimensionless)');
    LEGEND_STATES(:,24) = strpad('fCQ in component Ca_buffering (dimensionless)');
    LEGEND_CONSTANTS(:,59) = strpad('kf_TC in component Ca_buffering (per_millimolar_second)');
    LEGEND_CONSTANTS(:,60) = strpad('kf_TMM in component Ca_buffering (per_millimolar_second)');
    LEGEND_CONSTANTS(:,61) = strpad('kf_TMC in component Ca_buffering (per_millimolar_second)');
    LEGEND_CONSTANTS(:,62) = strpad('kf_CM in component Ca_buffering (per_millimolar_second)');
    LEGEND_CONSTANTS(:,63) = strpad('kf_CQ in component Ca_buffering (per_millimolar_second)');
    LEGEND_CONSTANTS(:,64) = strpad('kb_TC in component Ca_buffering (per_second)');
    LEGEND_CONSTANTS(:,65) = strpad('kb_TMC in component Ca_buffering (per_second)');
    LEGEND_CONSTANTS(:,66) = strpad('kb_TMM in component Ca_buffering (per_second)');
    LEGEND_CONSTANTS(:,67) = strpad('kb_CM in component Ca_buffering (per_second)');
    LEGEND_CONSTANTS(:,68) = strpad('kb_CQ in component Ca_buffering (per_second)');
    LEGEND_CONSTANTS(:,69) = strpad('Mgi in component Ca_buffering (millimolar)');
    LEGEND_CONSTANTS(:,100) = strpad('V_jsr in component Cell_parameters (millimetre3)');
    LEGEND_CONSTANTS(:,102) = strpad('V_nsr in component Cell_parameters (millimetre3)');
    LEGEND_ALGEBRAIC(:,90) = strpad('BAPTA in component Ca_dynamics (millimolar)');
    LEGEND_CONSTANTS(:,70) = strpad('kfBAPTA in component Ca_dynamics (per_millimolar_second)');
    LEGEND_CONSTANTS(:,71) = strpad('kbBAPTA in component Ca_dynamics (per_second)');
    LEGEND_STATES(:,25) = strpad('fBAPTA in component Ca_dynamics (millimolar)');
    LEGEND_STATES(:,26) = strpad('fBAPTA_sub in component Ca_dynamics (millimolar)');
    LEGEND_CONSTANTS(:,72) = strpad('T in component Ca_dynamics (second)');
    LEGEND_CONSTANTS(:,98) = strpad('V_cell in component Cell_parameters (millimetre3)');
    LEGEND_CONSTANTS(:,73) = strpad('V_jsr_part in component Cell_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,74) = strpad('V_i_part in component Cell_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,75) = strpad('V_nsr_part in component Cell_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,76) = strpad('R_cell in component Cell_parameters (micrometre)');
    LEGEND_CONSTANTS(:,77) = strpad('L_cell in component Cell_parameters (micrometre)');
    LEGEND_CONSTANTS(:,78) = strpad('L_sub in component Cell_parameters (micrometre)');
    LEGEND_CONSTANTS(:,79) = strpad('g_to in component i_to (microS)');
    LEGEND_STATES(:,27) = strpad('q in component i_to_q_gate (dimensionless)');
    LEGEND_STATES(:,28) = strpad('r in component i_to_r_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,18) = strpad('q_infinity in component i_to_q_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,34) = strpad('tau_q in component i_to_q_gate (second)');
    LEGEND_ALGEBRAIC(:,19) = strpad('r_infinity in component i_to_r_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,35) = strpad('tau_r in component i_to_r_gate (second)');
    LEGEND_CONSTANTS(:,80) = strpad('g_Kr in component i_Kr (microS)');
    LEGEND_STATES(:,29) = strpad('paS in component i_Kr_pa_gate (dimensionless)');
    LEGEND_STATES(:,30) = strpad('paF in component i_Kr_pa_gate (dimensionless)');
    LEGEND_STATES(:,31) = strpad('piy in component i_Kr_pi_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,20) = strpad('pa_infinity in component i_Kr_pa_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,21) = strpad('alfapaF in component i_Kr_pa_gate (per_second)');
    LEGEND_ALGEBRAIC(:,22) = strpad('betapaF in component i_Kr_pa_gate (per_second)');
    LEGEND_ALGEBRAIC(:,36) = strpad('tau_paS in component i_Kr_pa_gate (second)');
    LEGEND_ALGEBRAIC(:,37) = strpad('tau_paF in component i_Kr_pa_gate (second)');
    LEGEND_ALGEBRAIC(:,38) = strpad('pi_infinity in component i_Kr_pi_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,23) = strpad('tau_pi in component i_Kr_pi_gate (second)');
    LEGEND_CONSTANTS(:,87) = strpad('g_Ks in component i_Ks (microS)');
    LEGEND_ALGEBRAIC(:,79) = strpad('E_Ks in component i_Ks (millivolt)');
    LEGEND_STATES(:,32) = strpad('n in component i_Ks_n_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,24) = strpad('n_infinity in component i_Ks_n_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,48) = strpad('tau_n in component i_Ks_n_gate (second)');
    LEGEND_CONSTANTS(:,103) = strpad('Iso_shift in component i_Ks_n_gate (millivolt)');
    LEGEND_CONSTANTS(:,81) = strpad('shift in component i_Ks_n_gate (millivolt)');
    LEGEND_ALGEBRAIC(:,39) = strpad('alpha_n in component i_Ks_n_gate (per_second)');
    LEGEND_ALGEBRAIC(:,44) = strpad('beta_n in component i_Ks_n_gate (per_second)');
    LEGEND_CONSTANTS(:,82) = strpad('g_KACh in component i_KACh (microS)');
    LEGEND_STATES(:,33) = strpad('a in component i_KACh_a_gate (dimensionless)');
    LEGEND_CONSTANTS(:,104) = strpad('alpha_a in component i_KACh_a_gate (per_second)');
    LEGEND_ALGEBRAIC(:,25) = strpad('beta_a in component i_KACh_a_gate (per_second)');
    LEGEND_ALGEBRAIC(:,40) = strpad('a_infinity in component i_KACh_a_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,45) = strpad('tau_a in component i_KACh_a_gate (second)');
    LEGEND_RATES(:,1) = strpad('d/dt V_ode in component Membrane (millivolt)');
    LEGEND_RATES(:,3) = strpad('d/dt Nai_ in component Nai_concentration (millimolar)');
    LEGEND_RATES(:,4) = strpad('d/dt y in component i_f_y_gate (dimensionless)');
    LEGEND_RATES(:,5) = strpad('d/dt m in component i_Na_m_gate (dimensionless)');
    LEGEND_RATES(:,6) = strpad('d/dt h in component i_Na_h_gate (dimensionless)');
    LEGEND_RATES(:,7) = strpad('d/dt dL in component i_CaL_dL_gate (dimensionless)');
    LEGEND_RATES(:,8) = strpad('d/dt fL in component i_CaL_fL_gate (dimensionless)');
    LEGEND_RATES(:,9) = strpad('d/dt fCa in component i_CaL_fCa_gate (dimensionless)');
    LEGEND_RATES(:,10) = strpad('d/dt dT in component i_CaT_dT_gate (dimensionless)');
    LEGEND_RATES(:,11) = strpad('d/dt fT in component i_CaT_fT_gate (dimensionless)');
    LEGEND_RATES(:,12) = strpad('d/dt R in component Ca_SR_release (dimensionless)');
    LEGEND_RATES(:,13) = strpad('d/dt O in component Ca_SR_release (dimensionless)');
    LEGEND_RATES(:,14) = strpad('d/dt I in component Ca_SR_release (dimensionless)');
    LEGEND_RATES(:,15) = strpad('d/dt RI in component Ca_SR_release (dimensionless)');
    LEGEND_RATES(:,22) = strpad('d/dt fTC in component Ca_buffering (dimensionless)');
    LEGEND_RATES(:,23) = strpad('d/dt fTMC in component Ca_buffering (dimensionless)');
    LEGEND_RATES(:,19) = strpad('d/dt fTMM in component Ca_buffering (dimensionless)');
    LEGEND_RATES(:,20) = strpad('d/dt fCMi in component Ca_buffering (dimensionless)');
    LEGEND_RATES(:,21) = strpad('d/dt fCMs in component Ca_buffering (dimensionless)');
    LEGEND_RATES(:,24) = strpad('d/dt fCQ in component Ca_buffering (dimensionless)');
    LEGEND_RATES(:,18) = strpad('d/dt Cai in component Ca_dynamics (millimolar)');
    LEGEND_RATES(:,25) = strpad('d/dt fBAPTA in component Ca_dynamics (millimolar)');
    LEGEND_RATES(:,2) = strpad('d/dt Ca_sub in component Ca_dynamics (millimolar)');
    LEGEND_RATES(:,26) = strpad('d/dt fBAPTA_sub in component Ca_dynamics (millimolar)');
    LEGEND_RATES(:,17) = strpad('d/dt Ca_nsr in component Ca_dynamics (millimolar)');
    LEGEND_RATES(:,16) = strpad('d/dt Ca_jsr in component Ca_dynamics (millimolar)');
    LEGEND_RATES(:,27) = strpad('d/dt q in component i_to_q_gate (dimensionless)');
    LEGEND_RATES(:,28) = strpad('d/dt r in component i_to_r_gate (dimensionless)');
    LEGEND_RATES(:,29) = strpad('d/dt paS in component i_Kr_pa_gate (dimensionless)');
    LEGEND_RATES(:,30) = strpad('d/dt paF in component i_Kr_pa_gate (dimensionless)');
    LEGEND_RATES(:,31) = strpad('d/dt piy in component i_Kr_pi_gate (dimensionless)');
    LEGEND_RATES(:,32) = strpad('d/dt n in component i_Ks_n_gate (dimensionless)');
    LEGEND_RATES(:,33) = strpad('d/dt a in component i_KACh_a_gate (dimensionless)');
    LEGEND_STATES  = LEGEND_STATES';
    LEGEND_ALGEBRAIC = LEGEND_ALGEBRAIC';
    LEGEND_RATES = LEGEND_RATES';
    LEGEND_CONSTANTS = LEGEND_CONSTANTS';
end

function [STATES, CONSTANTS] = initConsts()
    VOI = 0; CONSTANTS = []; STATES = []; ALGEBRAIC = [];
    CONSTANTS(:,1) = 8314.472;
    CONSTANTS(:,2) = 310;
    CONSTANTS(:,3) = 96485.3415;
    CONSTANTS(:,4) = 3.2e-5;
    CONSTANTS(:,5) = 0;
    STATES(:,1) = -52;
    CONSTANTS(:,6) = 0.5;
    CONSTANTS(:,7) = 0.5;
    CONSTANTS(:,8) = -35;
    CONSTANTS(:,9) = -45;
    CONSTANTS(:,10) = 0;
    CONSTANTS(:,11) = 0;
    CONSTANTS(:,12) = 0;
    CONSTANTS(:,13) = 0;
    CONSTANTS(:,14) = 0;
    CONSTANTS(:,15) = 140;
    CONSTANTS(:,16) = 140;
    CONSTANTS(:,17) = 5.4;
    STATES(:,2) = 1e-5;
    CONSTANTS(:,18) = 1.8;
    STATES(:,3) = 7.5;
    CONSTANTS(:,19) = 45;
    STATES(:,4) = 0.181334538702451;
    CONSTANTS(:,20) = 1.4;
    CONSTANTS(:,21) = 14;
    CONSTANTS(:,22) = 0.063;
    CONSTANTS(:,23) = 4;
    CONSTANTS(:,24) = 0.1369;
    CONSTANTS(:,25) = 0.4315;
    CONSTANTS(:,26) = 0;
    CONSTANTS(:,27) = 26.44;
    CONSTANTS(:,28) = 0.0207;
    CONSTANTS(:,29) = 395.3;
    CONSTANTS(:,30) = 2.289;
    CONSTANTS(:,31) = 26.44;
    CONSTANTS(:,32) = 4.663;
    CONSTANTS(:,33) = 1628;
    CONSTANTS(:,34) = 561.4;
    CONSTANTS(:,35) = 3.663;
    CONSTANTS(:,36) = 0.0125;
    STATES(:,5) = 0.440131579215766;
    STATES(:,6) = 1.3676940140066e-5;
    CONSTANTS(:,37) = 1e-5;
    CONSTANTS(:,38) = 0.2;
    STATES(:,7) = 0;
    STATES(:,8) = 0.497133507285601;
    STATES(:,9) = 0.697998543259722;
    CONSTANTS(:,39) = 0.01;
    CONSTANTS(:,40) = 0.00035;
    CONSTANTS(:,41) = 0.02;
    STATES(:,10) = 0;
    STATES(:,11) = 0;
    STATES(:,12) = 0.912317231017262;
    STATES(:,13) = 1.7340201253e-7;
    STATES(:,14) = 7.86181717518e-8;
    STATES(:,15) = 0.211148145512825;
    CONSTANTS(:,42) = 250000000;
    CONSTANTS(:,43) = 15;
    CONSTANTS(:,44) = 1;
    CONSTANTS(:,45) = 0.45;
    CONSTANTS(:,46) = 2.5;
    CONSTANTS(:,47) = 10000;
    CONSTANTS(:,48) = 500;
    CONSTANTS(:,49) = 5;
    CONSTANTS(:,50) = 60;
    STATES(:,16) = 0.316762674605;
    CONSTANTS(:,51) = 4e-5;
    CONSTANTS(:,52) = 0.04;
    CONSTANTS(:,53) = 12;
    CONSTANTS(:,54) = 0.0006;
    STATES(:,17) = 1.05386465080816;
    STATES(:,18) = 1e-5;
    CONSTANTS(:,55) = 0.031;
    CONSTANTS(:,56) = 0.062;
    CONSTANTS(:,57) = 0.045;
    CONSTANTS(:,58) = 10;
    STATES(:,19) = 0.501049376634;
    STATES(:,20) = 0.0373817991524254;
    STATES(:,21) = 0.054381370046;
    STATES(:,22) = 0.0180519400676086;
    STATES(:,23) = 0.281244308217086;
    STATES(:,24) = 0.299624275428735;
    CONSTANTS(:,59) = 88800;
    CONSTANTS(:,60) = 2277;
    CONSTANTS(:,61) = 227700;
    CONSTANTS(:,62) = 227700;
    CONSTANTS(:,63) = 534;
    CONSTANTS(:,64) = 446;
    CONSTANTS(:,65) = 7.51;
    CONSTANTS(:,66) = 751;
    CONSTANTS(:,67) = 542;
    CONSTANTS(:,68) = 445;
    CONSTANTS(:,69) = 2.5;
    CONSTANTS(:,70) = 940000;
    CONSTANTS(:,71) = 119.38;
    STATES(:,25) = 0;
    STATES(:,26) = 0;
    CONSTANTS(:,72) = 6.928;
    CONSTANTS(:,73) = 0.0012;
    CONSTANTS(:,74) = 0.46;
    CONSTANTS(:,75) = 0.0116;
    CONSTANTS(:,76) = 4;
    CONSTANTS(:,77) = 70;
    CONSTANTS(:,78) = 0.02;
    CONSTANTS(:,79) = 0.002;
    STATES(:,27) = 0.506139850982478;
    STATES(:,28) = 0.0144605370597924;
    CONSTANTS(:,80) = 0.0021637;
    STATES(:,29) = 0.322999177802891;
    STATES(:,30) = 0.0990510403258968;
    STATES(:,31) = 0.705410877258545;
    STATES(:,32) = 0;
    CONSTANTS(:,81) = 0;
    CONSTANTS(:,82) = 0.00864;
    STATES(:,33) = 0;
    CONSTANTS(:,83) = piecewise({CONSTANTS(:,10)>=1.00000,  0.0300000.*(1.00000 - 0.660000) }, 0.0300000);
    CONSTANTS(:,84) = piecewise({CONSTANTS(:,10)>=1.00000,  0.0300000.*(1.00000 - 0.660000) }, 0.0300000);
    CONSTANTS(:,85) = piecewise({CONSTANTS(:,13)>0.00000,  - 0.250000 , CONSTANTS(:,12)>0.00000, ( 0.700000.*CONSTANTS(:,12))./(9.00000e-05+CONSTANTS(:,12)) }, 0.00000);
    CONSTANTS(:,86) = ( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3);
    CONSTANTS(:,87) = piecewise({CONSTANTS(:,13)>0.00000,  1.20000.*0.00165760 }, 0.00165760);
    CONSTANTS(:,88) =  CONSTANTS(:,86).*log(CONSTANTS(:,17)./CONSTANTS(:,16));
    CONSTANTS(:,89) =  CONSTANTS(:,53).*(1.00000 - CONSTANTS(:,85));
    CONSTANTS(:,90) = piecewise({CONSTANTS(:,12)>0.00000,  - 1.00000 - ( 9.89800.*power( 1.00000.*CONSTANTS(:,12), 0.618000))./(power( 1.00000.*CONSTANTS(:,12), 0.618000)+0.00122423) }, 0.00000);
    CONSTANTS(:,91) = piecewise({CONSTANTS(:,13)>0.00000, 7.50000 }, 0.00000);
    CONSTANTS(:,92) = piecewise({CONSTANTS(:,13)>0.00000, 1.20000 }, 1.00000);
    CONSTANTS(:,93) = CONSTANTS(:,15)./(CONSTANTS(:,32)+CONSTANTS(:,15));
    CONSTANTS(:,94) = piecewise({CONSTANTS(:,13)>0.00000, 1.23000 }, 1.00000);
    CONSTANTS(:,95) = ( 0.310000.*CONSTANTS(:,12))./(CONSTANTS(:,12)+9.00000e-05);
    CONSTANTS(:,96) = piecewise({CONSTANTS(:,13)>0.00000,  - 8.00000 }, 0.00000);
    CONSTANTS(:,97) = piecewise({CONSTANTS(:,13)>0.00000, 0.690000 }, 1.00000);
    CONSTANTS(:,98) =  1.00000e-09.* pi.*power(CONSTANTS(:,76), 2.00000).*CONSTANTS(:,77);
    CONSTANTS(:,99) =  1.00000e-09.*2.00000.* pi.*CONSTANTS(:,78).*(CONSTANTS(:,76) - CONSTANTS(:,78)./2.00000).*CONSTANTS(:,77);
    CONSTANTS(:,100) =  CONSTANTS(:,73).*CONSTANTS(:,98);
    CONSTANTS(:,101) =  CONSTANTS(:,74).*CONSTANTS(:,98) - CONSTANTS(:,99);
    CONSTANTS(:,102) =  CONSTANTS(:,75).*CONSTANTS(:,98);
    CONSTANTS(:,103) = piecewise({CONSTANTS(:,13)>0.00000,  - 14.0000 }, 0.00000);
    CONSTANTS(:,104) = (3.59880 - 0.0256410)./(1.00000+1.21550e-06./power( 1.00000.*CONSTANTS(:,12), 1.69510))+0.0256410;
    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(:,5) =  CONSTANTS(:,60).*CONSTANTS(:,69).*(1.00000 - (STATES(:,23)+STATES(:,19))) -  CONSTANTS(:,66).*STATES(:,19);
    RATES(:,19) = ALGEBRAIC(:,5);
    ALGEBRAIC(:,2) = CONSTANTS(:,40)./(CONSTANTS(:,40)+STATES(:,2));
    ALGEBRAIC(:,6) = ( 0.00100000.*ALGEBRAIC(:,2))./CONSTANTS(:,39);
    RATES(:,9) = (ALGEBRAIC(:,2) - STATES(:,9))./ALGEBRAIC(:,6);
    ALGEBRAIC(:,3) = CONSTANTS(:,43) - (CONSTANTS(:,43) - CONSTANTS(:,44))./(1.00000+power(CONSTANTS(:,45)./STATES(:,16), CONSTANTS(:,46)));
    ALGEBRAIC(:,7) = CONSTANTS(:,47)./ALGEBRAIC(:,3);
    ALGEBRAIC(:,16) =  CONSTANTS(:,48).*ALGEBRAIC(:,3);
    RATES(:,12) = ( CONSTANTS(:,49).*STATES(:,15) -  ALGEBRAIC(:,16).*STATES(:,2).*STATES(:,12)) - ( ALGEBRAIC(:,7).*power(STATES(:,2), 2.00000).*STATES(:,12) -  CONSTANTS(:,50).*STATES(:,13));
    RATES(:,13) = ( ALGEBRAIC(:,7).*power(STATES(:,2), 2.00000).*STATES(:,12) -  CONSTANTS(:,50).*STATES(:,13)) - ( ALGEBRAIC(:,16).*STATES(:,2).*STATES(:,13) -  CONSTANTS(:,49).*STATES(:,14));
    RATES(:,14) = ( ALGEBRAIC(:,16).*STATES(:,2).*STATES(:,13) -  CONSTANTS(:,49).*STATES(:,14)) - ( CONSTANTS(:,50).*STATES(:,14) -  ALGEBRAIC(:,7).*power(STATES(:,2), 2.00000).*STATES(:,15));
    RATES(:,15) = ( CONSTANTS(:,50).*STATES(:,14) -  ALGEBRAIC(:,7).*power(STATES(:,2), 2.00000).*STATES(:,15)) - ( CONSTANTS(:,49).*STATES(:,15) -  ALGEBRAIC(:,16).*STATES(:,2).*STATES(:,12));
    ALGEBRAIC(:,4) = piecewise({VOI>CONSTANTS(:,6)&VOI<CONSTANTS(:,6)+CONSTANTS(:,7), CONSTANTS(:,8) }, CONSTANTS(:,9));
    ALGEBRAIC(:,8) = piecewise({CONSTANTS(:,5)>=1.00000, ALGEBRAIC(:,4) }, STATES(:,1));
    ALGEBRAIC(:,9) = 0.716653./( 0.0708000.*exp( - (((ALGEBRAIC(:,8)+5.00000) - CONSTANTS(:,90)) - CONSTANTS(:,91))./20.2791)+ 10.6000.*exp(((ALGEBRAIC(:,8) - CONSTANTS(:,90)) - CONSTANTS(:,91))./18.0000));
    ALGEBRAIC(:,26) = 1.00000./(1.00000+exp((((ALGEBRAIC(:,8)+52.5000) - CONSTANTS(:,90)) - CONSTANTS(:,91))./9.00000));
    RATES(:,4) = (ALGEBRAIC(:,26) - STATES(:,4))./ALGEBRAIC(:,9);
    ALGEBRAIC(:,11) =  20.0000.*exp(  - 0.125000.*(ALGEBRAIC(:,8)+75.0000));
    ALGEBRAIC(:,28) = 2000.00./( 320.000.*exp(  - 0.100000.*(ALGEBRAIC(:,8)+75.0000))+1.00000);
    RATES(:,6) =  ALGEBRAIC(:,11).*(1.00000 - STATES(:,6)) -  ALGEBRAIC(:,28).*STATES(:,6);
    ALGEBRAIC(:,13) = 1.00000./(1.00000+exp((ALGEBRAIC(:,8)+37.4000)./5.30000));
    ALGEBRAIC(:,30) =  0.00100000.*(44.3000+ 230.000.*exp( - power((ALGEBRAIC(:,8)+36.0000)./10.0000, 2.00000)));
    RATES(:,8) = (ALGEBRAIC(:,13) - STATES(:,8))./ALGEBRAIC(:,30);
    ALGEBRAIC(:,14) = 1.00000./(1.00000+exp( - (ALGEBRAIC(:,8)+38.3000)./5.50000));
    ALGEBRAIC(:,31) = 0.00100000./( 1.06800.*exp((ALGEBRAIC(:,8)+38.3000)./30.0000)+ 1.06800.*exp( - (ALGEBRAIC(:,8)+38.3000)./30.0000));
    RATES(:,10) = (ALGEBRAIC(:,14) - STATES(:,10))./ALGEBRAIC(:,31);
    ALGEBRAIC(:,15) = 1.00000./(1.00000+exp((ALGEBRAIC(:,8)+58.7000)./3.80000));
    ALGEBRAIC(:,32) = 1.00000./( 16.6700.*exp( - (ALGEBRAIC(:,8)+75.0000)./83.3000)+ 16.6700.*exp((ALGEBRAIC(:,8)+75.0000)./15.3800));
    RATES(:,11) = (ALGEBRAIC(:,15) - STATES(:,11))./ALGEBRAIC(:,32);
    ALGEBRAIC(:,18) = 1.00000./(1.00000+exp((ALGEBRAIC(:,8)+49.0000)./13.0000));
    ALGEBRAIC(:,34) =  0.00100000.*0.600000.*(65.1700./( 0.570000.*exp(  - 0.0800000.*(ALGEBRAIC(:,8)+44.0000))+ 0.0650000.*exp( 0.100000.*(ALGEBRAIC(:,8)+45.9300)))+10.1000);
    RATES(:,27) = (ALGEBRAIC(:,18) - STATES(:,27))./ALGEBRAIC(:,34);
    ALGEBRAIC(:,19) = 1.00000./(1.00000+exp( - (ALGEBRAIC(:,8) - 19.3000)./15.0000));
    ALGEBRAIC(:,35) =  0.00100000.*0.660000.*1.40000.*(15.5900./( 1.03700.*exp( 0.0900000.*(ALGEBRAIC(:,8)+30.6100))+ 0.369000.*exp(  - 0.120000.*(ALGEBRAIC(:,8)+23.8400)))+2.98000);
    RATES(:,28) = (ALGEBRAIC(:,19) - STATES(:,28))./ALGEBRAIC(:,35);
    ALGEBRAIC(:,20) = 1.00000./(1.00000+exp( - (ALGEBRAIC(:,8)+14.8000)./8.50000));
    ALGEBRAIC(:,36) = 0.846554./( 4.20000.*exp(ALGEBRAIC(:,8)./17.0000)+ 0.150000.*exp( - ALGEBRAIC(:,8)./21.6000));
    RATES(:,29) = (ALGEBRAIC(:,20) - STATES(:,29))./ALGEBRAIC(:,36);
    ALGEBRAIC(:,37) = 1.00000./( 30.0000.*exp(ALGEBRAIC(:,8)./10.0000)+exp( - ALGEBRAIC(:,8)./12.0000));
    RATES(:,30) = (ALGEBRAIC(:,20) - STATES(:,30))./ALGEBRAIC(:,37);
    ALGEBRAIC(:,38) = 1.00000./(1.00000+exp((ALGEBRAIC(:,8)+28.6000)./17.1000));
    ALGEBRAIC(:,23) = 1.00000./( 100.000.*exp( - ALGEBRAIC(:,8)./54.6450)+ 656.000.*exp(ALGEBRAIC(:,8)./106.157));
    RATES(:,31) = (ALGEBRAIC(:,38) - STATES(:,31))./ALGEBRAIC(:,23);
    ALGEBRAIC(:,10) = ALGEBRAIC(:,8)+41.0000;
    ALGEBRAIC(:,27) = piecewise({abs(ALGEBRAIC(:,10))<CONSTANTS(:,37), 2000.00 }, ( 200.000.*ALGEBRAIC(:,10))./(1.00000 - exp(  - 0.100000.*ALGEBRAIC(:,10))));
    ALGEBRAIC(:,41) =  8000.00.*exp(  - 0.0560000.*(ALGEBRAIC(:,8)+66.0000));
    RATES(:,5) =  ALGEBRAIC(:,27).*(1.00000 - STATES(:,5)) -  ALGEBRAIC(:,41).*STATES(:,5);
    ALGEBRAIC(:,25) =  10.0000.*exp( 0.0133000.*(ALGEBRAIC(:,8)+40.0000));
    ALGEBRAIC(:,40) = CONSTANTS(:,104)./(CONSTANTS(:,104)+ALGEBRAIC(:,25));
    ALGEBRAIC(:,45) = 1.00000./(CONSTANTS(:,104)+ALGEBRAIC(:,25));
    RATES(:,33) = (ALGEBRAIC(:,40) - STATES(:,33))./ALGEBRAIC(:,45);
    ALGEBRAIC(:,24) = (14.0000./(1.00000+exp( - ((ALGEBRAIC(:,8) - 40.0000) - CONSTANTS(:,103))./12.0000)))./(14.0000./(1.00000+exp( - ((ALGEBRAIC(:,8) - 40.0000) - CONSTANTS(:,103))./12.0000))+ 1.00000.*exp( - (ALGEBRAIC(:,8) - CONSTANTS(:,103))./45.0000));
    ALGEBRAIC(:,39) = 28.0000./(1.00000+exp( - ((ALGEBRAIC(:,8) - 40.0000) - CONSTANTS(:,103))./3.00000));
    ALGEBRAIC(:,44) =  1.00000.*exp( - (((ALGEBRAIC(:,8) - CONSTANTS(:,103)) - CONSTANTS(:,81)) - 5.00000)./25.0000);
    ALGEBRAIC(:,48) = 1.00000./(ALGEBRAIC(:,39)+ALGEBRAIC(:,44));
    RATES(:,32) = (ALGEBRAIC(:,24) - STATES(:,32))./ALGEBRAIC(:,48);
    ALGEBRAIC(:,12) = 1.00000./(1.00000+exp( - ((ALGEBRAIC(:,8)+20.3000) - CONSTANTS(:,96))./( CONSTANTS(:,97).*4.20000)));
    ALGEBRAIC(:,29) = piecewise({ALGEBRAIC(:,8)== - 41.8000,  - 41.8000 , ALGEBRAIC(:,8)==0.00000, 0.00000 , ALGEBRAIC(:,8)== - 6.80000,  - 6.80001 }, ALGEBRAIC(:,8));
    ALGEBRAIC(:,42) = (  - 0.0283900.*((ALGEBRAIC(:,29)+41.8000) - CONSTANTS(:,96)))./(exp( - ((ALGEBRAIC(:,29)+41.8000) - CONSTANTS(:,96))./2.50000) - 1.00000) - ( 0.0849000.*((ALGEBRAIC(:,29)+6.80000) - CONSTANTS(:,96)))./(exp( - ((ALGEBRAIC(:,29)+6.80000) - CONSTANTS(:,96))./4.80000) - 1.00000);
    ALGEBRAIC(:,46) = piecewise({ALGEBRAIC(:,8)== - 1.80000,  - 1.80001 }, ALGEBRAIC(:,8));
    ALGEBRAIC(:,49) = ( 0.0114300.*((ALGEBRAIC(:,46)+1.80000) - CONSTANTS(:,96)))./(exp(((ALGEBRAIC(:,46)+1.80000) - CONSTANTS(:,96))./2.50000) - 1.00000);
    ALGEBRAIC(:,51) = 0.00100000./(ALGEBRAIC(:,42)+ALGEBRAIC(:,49));
    RATES(:,7) = (ALGEBRAIC(:,12) - STATES(:,7))./ALGEBRAIC(:,51);
    ALGEBRAIC(:,17) = piecewise({CONSTANTS(:,14)>0.00000, 7.50000 }, STATES(:,3));
    ALGEBRAIC(:,33) =  CONSTANTS(:,86).*log(CONSTANTS(:,15)./ALGEBRAIC(:,17));
    ALGEBRAIC(:,53) =  CONSTANTS(:,92).*CONSTANTS(:,22).*power(1.00000+power(CONSTANTS(:,20)./CONSTANTS(:,17), 1.20000),  - 1.00000).*power(1.00000+power(CONSTANTS(:,21)./ALGEBRAIC(:,17), 1.30000),  - 1.00000).*power(1.00000+exp( - ((ALGEBRAIC(:,8) - ALGEBRAIC(:,33))+110.000)./20.0000),  - 1.00000);
    ALGEBRAIC(:,55) = exp((  - CONSTANTS(:,25).*ALGEBRAIC(:,8))./( 2.00000.*CONSTANTS(:,86)));
    ALGEBRAIC(:,61) = 1.00000+ (CONSTANTS(:,18)./CONSTANTS(:,35)).*(1.00000+exp(( CONSTANTS(:,26).*ALGEBRAIC(:,8))./CONSTANTS(:,86)))+ (CONSTANTS(:,15)./CONSTANTS(:,33)).*(1.00000+ (CONSTANTS(:,15)./CONSTANTS(:,34)).*(1.00000+CONSTANTS(:,15)./CONSTANTS(:,32)));
    ALGEBRAIC(:,63) = ( (( (CONSTANTS(:,15)./CONSTANTS(:,33)).*CONSTANTS(:,15))./CONSTANTS(:,34)).*(1.00000+CONSTANTS(:,15)./CONSTANTS(:,32)).*exp((  - CONSTANTS(:,25).*ALGEBRAIC(:,8))./( 2.00000.*CONSTANTS(:,86))))./ALGEBRAIC(:,61);
    ALGEBRAIC(:,62) = ( (CONSTANTS(:,18)./CONSTANTS(:,35)).*exp(( CONSTANTS(:,26).*ALGEBRAIC(:,8))./CONSTANTS(:,86)))./ALGEBRAIC(:,61);
    ALGEBRAIC(:,59) = exp(( CONSTANTS(:,25).*ALGEBRAIC(:,8))./( 2.00000.*CONSTANTS(:,86)));
    ALGEBRAIC(:,54) = ALGEBRAIC(:,17)./(CONSTANTS(:,27)+ALGEBRAIC(:,17));
    ALGEBRAIC(:,64) =  ALGEBRAIC(:,55).*CONSTANTS(:,93).*(ALGEBRAIC(:,63)+ALGEBRAIC(:,62))+ ALGEBRAIC(:,62).*ALGEBRAIC(:,59).*(ALGEBRAIC(:,54)+ALGEBRAIC(:,55));
    ALGEBRAIC(:,56) = 1.00000+ (STATES(:,2)./CONSTANTS(:,28)).*(1.00000+exp((  - CONSTANTS(:,24).*ALGEBRAIC(:,8))./CONSTANTS(:,86))+ALGEBRAIC(:,17)./CONSTANTS(:,31))+ (ALGEBRAIC(:,17)./CONSTANTS(:,29)).*(1.00000+ (ALGEBRAIC(:,17)./CONSTANTS(:,30)).*(1.00000+ALGEBRAIC(:,17)./CONSTANTS(:,27)));
    ALGEBRAIC(:,57) = ( (STATES(:,2)./CONSTANTS(:,28)).*exp((  - CONSTANTS(:,24).*ALGEBRAIC(:,8))./CONSTANTS(:,86)))./ALGEBRAIC(:,56);
    ALGEBRAIC(:,58) = ( (( (ALGEBRAIC(:,17)./CONSTANTS(:,29)).*ALGEBRAIC(:,17))./CONSTANTS(:,30)).*(1.00000+ALGEBRAIC(:,17)./CONSTANTS(:,27)).*exp(( CONSTANTS(:,25).*ALGEBRAIC(:,8))./( 2.00000.*CONSTANTS(:,86))))./ALGEBRAIC(:,56);
    ALGEBRAIC(:,60) =  ALGEBRAIC(:,59).*ALGEBRAIC(:,54).*(ALGEBRAIC(:,58)+ALGEBRAIC(:,57))+ ALGEBRAIC(:,55).*ALGEBRAIC(:,57).*(CONSTANTS(:,93)+ALGEBRAIC(:,59));
    ALGEBRAIC(:,65) =  ALGEBRAIC(:,58).*ALGEBRAIC(:,54).*(ALGEBRAIC(:,63)+ALGEBRAIC(:,62))+ ALGEBRAIC(:,57).*ALGEBRAIC(:,63).*(ALGEBRAIC(:,54)+ALGEBRAIC(:,55));
    ALGEBRAIC(:,66) =  ALGEBRAIC(:,63).*CONSTANTS(:,93).*(ALGEBRAIC(:,58)+ALGEBRAIC(:,57))+ ALGEBRAIC(:,58).*ALGEBRAIC(:,62).*(CONSTANTS(:,93)+ALGEBRAIC(:,59));
    ALGEBRAIC(:,67) = ( CONSTANTS(:,23).*( ALGEBRAIC(:,60).*ALGEBRAIC(:,62) -  ALGEBRAIC(:,64).*ALGEBRAIC(:,57)))./(ALGEBRAIC(:,64)+ALGEBRAIC(:,60)+ALGEBRAIC(:,65)+ALGEBRAIC(:,66));
    ALGEBRAIC(:,68) =  CONSTANTS(:,86).*log((CONSTANTS(:,15)+ 0.120000.*CONSTANTS(:,17))./(ALGEBRAIC(:,17)+ 0.120000.*CONSTANTS(:,16)));
    ALGEBRAIC(:,69) =  CONSTANTS(:,36).*power(STATES(:,5), 3.00000).*STATES(:,6).*(ALGEBRAIC(:,8) - ALGEBRAIC(:,68));
    ALGEBRAIC(:,43) = piecewise({CONSTANTS(:,11)>=1.00000, (10.6015./5.00000)./(10.6015./5.00000+exp((  - 0.710000.*ALGEBRAIC(:,8))./25.0000)) }, 1.00000);
    ALGEBRAIC(:,47) =  (( power(STATES(:,4), 2.00000).*CONSTANTS(:,17))./(CONSTANTS(:,17)+CONSTANTS(:,19))).*CONSTANTS(:,83).*(ALGEBRAIC(:,8) - ALGEBRAIC(:,33)).*ALGEBRAIC(:,43);
    ALGEBRAIC(:,72) =  (( 1.85000e-05.*CONSTANTS(:,38).*(ALGEBRAIC(:,8) - 0.00000))./( CONSTANTS(:,86).*(1.00000 - exp((  - 1.00000.*(ALGEBRAIC(:,8) - 0.00000))./CONSTANTS(:,86))))).*(ALGEBRAIC(:,17) -  CONSTANTS(:,15).*exp((  - 1.00000.*(ALGEBRAIC(:,8) - 0.00000))./CONSTANTS(:,86))).*STATES(:,7).*STATES(:,8).*STATES(:,9);
    RATES(:,3) = (  - 1.00000.*(ALGEBRAIC(:,69)+ALGEBRAIC(:,47)+ALGEBRAIC(:,72)+ 3.00000.*ALGEBRAIC(:,53)+ 3.00000.*ALGEBRAIC(:,67)))./( 1.00000.*(CONSTANTS(:,101)+CONSTANTS(:,99)).*CONSTANTS(:,3));
    ALGEBRAIC(:,82) =  CONSTANTS(:,59).*STATES(:,18).*(1.00000 - STATES(:,22)) -  CONSTANTS(:,64).*STATES(:,22);
    RATES(:,22) = ALGEBRAIC(:,82);
    ALGEBRAIC(:,80) = CONSTANTS(:,89)./(1.00000+CONSTANTS(:,54)./STATES(:,18));
    ALGEBRAIC(:,83) = (STATES(:,17) - STATES(:,16))./CONSTANTS(:,52);
    RATES(:,17) = ALGEBRAIC(:,80) - ( ALGEBRAIC(:,83).*CONSTANTS(:,100))./CONSTANTS(:,102);
    ALGEBRAIC(:,85) =  CONSTANTS(:,61).*STATES(:,18).*(1.00000 - (STATES(:,23)+STATES(:,19))) -  CONSTANTS(:,65).*STATES(:,23);
    RATES(:,23) = ALGEBRAIC(:,85);
    ALGEBRAIC(:,86) =  CONSTANTS(:,63).*STATES(:,16).*(1.00000 - STATES(:,24)) -  CONSTANTS(:,68).*STATES(:,24);
    RATES(:,24) = ALGEBRAIC(:,86);
    ALGEBRAIC(:,76) =  CONSTANTS(:,42).*STATES(:,13).*(STATES(:,16) - STATES(:,2));
    RATES(:,16) = ALGEBRAIC(:,83) - (ALGEBRAIC(:,76)+ CONSTANTS(:,58).*ALGEBRAIC(:,86));
    ALGEBRAIC(:,50) =  (( power(STATES(:,4), 2.00000).*CONSTANTS(:,17))./(CONSTANTS(:,17)+CONSTANTS(:,19))).*CONSTANTS(:,84).*(ALGEBRAIC(:,8) - CONSTANTS(:,88)).*ALGEBRAIC(:,43);
    ALGEBRAIC(:,52) = ALGEBRAIC(:,47)+ALGEBRAIC(:,50);
    ALGEBRAIC(:,77) =  CONSTANTS(:,80).*(ALGEBRAIC(:,8) - CONSTANTS(:,88)).*( 0.900000.*STATES(:,30)+ 0.100000.*STATES(:,29)).*STATES(:,31);
    ALGEBRAIC(:,79) =  CONSTANTS(:,86).*log((CONSTANTS(:,17)+ 0.00000.*CONSTANTS(:,15))./(CONSTANTS(:,16)+ 0.00000.*ALGEBRAIC(:,17)));
    ALGEBRAIC(:,81) =  CONSTANTS(:,87).*(ALGEBRAIC(:,8) - ALGEBRAIC(:,79)).*power(STATES(:,32), 2.00000);
    ALGEBRAIC(:,75) =  CONSTANTS(:,79).*(ALGEBRAIC(:,8) - CONSTANTS(:,88)).*STATES(:,27).*STATES(:,28);
    ALGEBRAIC(:,70) =  (( 2.00000.*CONSTANTS(:,38).*(ALGEBRAIC(:,8) - 0.00000))./( CONSTANTS(:,86).*(1.00000 - exp((  - 1.00000.*(ALGEBRAIC(:,8) - 0.00000).*2.00000)./CONSTANTS(:,86))))).*(STATES(:,2) -  CONSTANTS(:,18).*exp((  - 2.00000.*(ALGEBRAIC(:,8) - 0.00000))./CONSTANTS(:,86))).*STATES(:,7).*STATES(:,8).*STATES(:,9);
    ALGEBRAIC(:,71) =  (( 0.000365000.*CONSTANTS(:,38).*(ALGEBRAIC(:,8) - 0.00000))./( CONSTANTS(:,86).*(1.00000 - exp((  - 1.00000.*(ALGEBRAIC(:,8) - 0.00000))./CONSTANTS(:,86))))).*(CONSTANTS(:,16) -  CONSTANTS(:,17).*exp((  - 1.00000.*(ALGEBRAIC(:,8) - 0.00000))./CONSTANTS(:,86))).*STATES(:,7).*STATES(:,8).*STATES(:,9);
    ALGEBRAIC(:,73) =  (ALGEBRAIC(:,70)+ALGEBRAIC(:,71)+ALGEBRAIC(:,72)).*(1.00000 - CONSTANTS(:,95)).*1.00000.*CONSTANTS(:,94);
    ALGEBRAIC(:,74) =  (( 2.00000.*CONSTANTS(:,41).*ALGEBRAIC(:,8))./( CONSTANTS(:,86).*(1.00000 - exp((  - 1.00000.*ALGEBRAIC(:,8).*2.00000)./CONSTANTS(:,86))))).*(STATES(:,2) -  CONSTANTS(:,18).*exp((  - 2.00000.*ALGEBRAIC(:,8))./CONSTANTS(:,86))).*STATES(:,10).*STATES(:,11);
    ALGEBRAIC(:,84) = piecewise({CONSTANTS(:,12)>0.00000,  CONSTANTS(:,82).*(ALGEBRAIC(:,8) - CONSTANTS(:,88)).*(1.00000+exp((ALGEBRAIC(:,8)+20.0000)./20.0000)).*STATES(:,33) }, 0.00000);
    ALGEBRAIC(:,87) = ALGEBRAIC(:,52)+ALGEBRAIC(:,77)+ALGEBRAIC(:,81)+ALGEBRAIC(:,75)+ALGEBRAIC(:,53)+ALGEBRAIC(:,67)+ALGEBRAIC(:,69)+ALGEBRAIC(:,73)+ALGEBRAIC(:,74)+ALGEBRAIC(:,84);
    RATES(:,1) =  - ALGEBRAIC(:,87)./CONSTANTS(:,4);
    ALGEBRAIC(:,88) =  CONSTANTS(:,62).*STATES(:,18).*(1.00000 - STATES(:,20)) -  CONSTANTS(:,67).*STATES(:,20);
    RATES(:,20) = ALGEBRAIC(:,88);
    ALGEBRAIC(:,89) =  CONSTANTS(:,62).*STATES(:,2).*(1.00000 - STATES(:,21)) -  CONSTANTS(:,67).*STATES(:,21);
    RATES(:,21) = ALGEBRAIC(:,89);
    ALGEBRAIC(:,78) = (STATES(:,2) - STATES(:,18))./CONSTANTS(:,51);
    ALGEBRAIC(:,90) = piecewise({CONSTANTS(:,14)>0.00000&VOI>CONSTANTS(:,72), 10.0000 }, 0.00000);
    RATES(:,18) = (( 1.00000.*( ALGEBRAIC(:,78).*CONSTANTS(:,99) -  ALGEBRAIC(:,80).*CONSTANTS(:,102)))./CONSTANTS(:,101) - ( CONSTANTS(:,57).*ALGEBRAIC(:,88)+ CONSTANTS(:,55).*ALGEBRAIC(:,82)+ CONSTANTS(:,56).*ALGEBRAIC(:,85))) - ( CONSTANTS(:,70).*STATES(:,18).*(ALGEBRAIC(:,90) - STATES(:,25)) -  CONSTANTS(:,71).*STATES(:,25));
    RATES(:,25) =  CONSTANTS(:,70).*STATES(:,18).*(ALGEBRAIC(:,90) - STATES(:,25)) -  CONSTANTS(:,71).*STATES(:,25);
    RATES(:,2) = (( ALGEBRAIC(:,76).*CONSTANTS(:,100))./CONSTANTS(:,99) - (((ALGEBRAIC(:,70)+ALGEBRAIC(:,74)) -  2.00000.*ALGEBRAIC(:,67))./( 2.00000.*CONSTANTS(:,3).*CONSTANTS(:,99))+ALGEBRAIC(:,78)+ CONSTANTS(:,57).*ALGEBRAIC(:,89))) - ( CONSTANTS(:,70).*STATES(:,2).*(ALGEBRAIC(:,90) - STATES(:,26)) -  CONSTANTS(:,71).*STATES(:,26));
    RATES(:,26) =  CONSTANTS(:,70).*STATES(:,2).*(ALGEBRAIC(:,90) - STATES(:,26)) -  CONSTANTS(:,71).*STATES(:,26);
   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(:,5) =  CONSTANTS(:,60).*CONSTANTS(:,69).*(1.00000 - (STATES(:,23)+STATES(:,19))) -  CONSTANTS(:,66).*STATES(:,19);
    ALGEBRAIC(:,2) = CONSTANTS(:,40)./(CONSTANTS(:,40)+STATES(:,2));
    ALGEBRAIC(:,6) = ( 0.00100000.*ALGEBRAIC(:,2))./CONSTANTS(:,39);
    ALGEBRAIC(:,3) = CONSTANTS(:,43) - (CONSTANTS(:,43) - CONSTANTS(:,44))./(1.00000+power(CONSTANTS(:,45)./STATES(:,16), CONSTANTS(:,46)));
    ALGEBRAIC(:,7) = CONSTANTS(:,47)./ALGEBRAIC(:,3);
    ALGEBRAIC(:,16) =  CONSTANTS(:,48).*ALGEBRAIC(:,3);
    ALGEBRAIC(:,4) = piecewise({VOI>CONSTANTS(:,6)&VOI<CONSTANTS(:,6)+CONSTANTS(:,7), CONSTANTS(:,8) }, CONSTANTS(:,9));
    ALGEBRAIC(:,8) = piecewise({CONSTANTS(:,5)>=1.00000, ALGEBRAIC(:,4) }, STATES(:,1));
    ALGEBRAIC(:,9) = 0.716653./( 0.0708000.*exp( - (((ALGEBRAIC(:,8)+5.00000) - CONSTANTS(:,90)) - CONSTANTS(:,91))./20.2791)+ 10.6000.*exp(((ALGEBRAIC(:,8) - CONSTANTS(:,90)) - CONSTANTS(:,91))./18.0000));
    ALGEBRAIC(:,26) = 1.00000./(1.00000+exp((((ALGEBRAIC(:,8)+52.5000) - CONSTANTS(:,90)) - CONSTANTS(:,91))./9.00000));
    ALGEBRAIC(:,11) =  20.0000.*exp(  - 0.125000.*(ALGEBRAIC(:,8)+75.0000));
    ALGEBRAIC(:,28) = 2000.00./( 320.000.*exp(  - 0.100000.*(ALGEBRAIC(:,8)+75.0000))+1.00000);
    ALGEBRAIC(:,13) = 1.00000./(1.00000+exp((ALGEBRAIC(:,8)+37.4000)./5.30000));
    ALGEBRAIC(:,30) =  0.00100000.*(44.3000+ 230.000.*exp( - power((ALGEBRAIC(:,8)+36.0000)./10.0000, 2.00000)));
    ALGEBRAIC(:,14) = 1.00000./(1.00000+exp( - (ALGEBRAIC(:,8)+38.3000)./5.50000));
    ALGEBRAIC(:,31) = 0.00100000./( 1.06800.*exp((ALGEBRAIC(:,8)+38.3000)./30.0000)+ 1.06800.*exp( - (ALGEBRAIC(:,8)+38.3000)./30.0000));
    ALGEBRAIC(:,15) = 1.00000./(1.00000+exp((ALGEBRAIC(:,8)+58.7000)./3.80000));
    ALGEBRAIC(:,32) = 1.00000./( 16.6700.*exp( - (ALGEBRAIC(:,8)+75.0000)./83.3000)+ 16.6700.*exp((ALGEBRAIC(:,8)+75.0000)./15.3800));
    ALGEBRAIC(:,18) = 1.00000./(1.00000+exp((ALGEBRAIC(:,8)+49.0000)./13.0000));
    ALGEBRAIC(:,34) =  0.00100000.*0.600000.*(65.1700./( 0.570000.*exp(  - 0.0800000.*(ALGEBRAIC(:,8)+44.0000))+ 0.0650000.*exp( 0.100000.*(ALGEBRAIC(:,8)+45.9300)))+10.1000);
    ALGEBRAIC(:,19) = 1.00000./(1.00000+exp( - (ALGEBRAIC(:,8) - 19.3000)./15.0000));
    ALGEBRAIC(:,35) =  0.00100000.*0.660000.*1.40000.*(15.5900./( 1.03700.*exp( 0.0900000.*(ALGEBRAIC(:,8)+30.6100))+ 0.369000.*exp(  - 0.120000.*(ALGEBRAIC(:,8)+23.8400)))+2.98000);
    ALGEBRAIC(:,20) = 1.00000./(1.00000+exp( - (ALGEBRAIC(:,8)+14.8000)./8.50000));
    ALGEBRAIC(:,36) = 0.846554./( 4.20000.*exp(ALGEBRAIC(:,8)./17.0000)+ 0.150000.*exp( - ALGEBRAIC(:,8)./21.6000));
    ALGEBRAIC(:,37) = 1.00000./( 30.0000.*exp(ALGEBRAIC(:,8)./10.0000)+exp( - ALGEBRAIC(:,8)./12.0000));
    ALGEBRAIC(:,38) = 1.00000./(1.00000+exp((ALGEBRAIC(:,8)+28.6000)./17.1000));
    ALGEBRAIC(:,23) = 1.00000./( 100.000.*exp( - ALGEBRAIC(:,8)./54.6450)+ 656.000.*exp(ALGEBRAIC(:,8)./106.157));
    ALGEBRAIC(:,10) = ALGEBRAIC(:,8)+41.0000;
    ALGEBRAIC(:,27) = piecewise({abs(ALGEBRAIC(:,10))<CONSTANTS(:,37), 2000.00 }, ( 200.000.*ALGEBRAIC(:,10))./(1.00000 - exp(  - 0.100000.*ALGEBRAIC(:,10))));
    ALGEBRAIC(:,41) =  8000.00.*exp(  - 0.0560000.*(ALGEBRAIC(:,8)+66.0000));
    ALGEBRAIC(:,25) =  10.0000.*exp( 0.0133000.*(ALGEBRAIC(:,8)+40.0000));
    ALGEBRAIC(:,40) = CONSTANTS(:,104)./(CONSTANTS(:,104)+ALGEBRAIC(:,25));
    ALGEBRAIC(:,45) = 1.00000./(CONSTANTS(:,104)+ALGEBRAIC(:,25));
    ALGEBRAIC(:,24) = (14.0000./(1.00000+exp( - ((ALGEBRAIC(:,8) - 40.0000) - CONSTANTS(:,103))./12.0000)))./(14.0000./(1.00000+exp( - ((ALGEBRAIC(:,8) - 40.0000) - CONSTANTS(:,103))./12.0000))+ 1.00000.*exp( - (ALGEBRAIC(:,8) - CONSTANTS(:,103))./45.0000));
    ALGEBRAIC(:,39) = 28.0000./(1.00000+exp( - ((ALGEBRAIC(:,8) - 40.0000) - CONSTANTS(:,103))./3.00000));
    ALGEBRAIC(:,44) =  1.00000.*exp( - (((ALGEBRAIC(:,8) - CONSTANTS(:,103)) - CONSTANTS(:,81)) - 5.00000)./25.0000);
    ALGEBRAIC(:,48) = 1.00000./(ALGEBRAIC(:,39)+ALGEBRAIC(:,44));
    ALGEBRAIC(:,12) = 1.00000./(1.00000+exp( - ((ALGEBRAIC(:,8)+20.3000) - CONSTANTS(:,96))./( CONSTANTS(:,97).*4.20000)));
    ALGEBRAIC(:,29) = piecewise({ALGEBRAIC(:,8)== - 41.8000,  - 41.8000 , ALGEBRAIC(:,8)==0.00000, 0.00000 , ALGEBRAIC(:,8)== - 6.80000,  - 6.80001 }, ALGEBRAIC(:,8));
    ALGEBRAIC(:,42) = (  - 0.0283900.*((ALGEBRAIC(:,29)+41.8000) - CONSTANTS(:,96)))./(exp( - ((ALGEBRAIC(:,29)+41.8000) - CONSTANTS(:,96))./2.50000) - 1.00000) - ( 0.0849000.*((ALGEBRAIC(:,29)+6.80000) - CONSTANTS(:,96)))./(exp( - ((ALGEBRAIC(:,29)+6.80000) - CONSTANTS(:,96))./4.80000) - 1.00000);
    ALGEBRAIC(:,46) = piecewise({ALGEBRAIC(:,8)== - 1.80000,  - 1.80001 }, ALGEBRAIC(:,8));
    ALGEBRAIC(:,49) = ( 0.0114300.*((ALGEBRAIC(:,46)+1.80000) - CONSTANTS(:,96)))./(exp(((ALGEBRAIC(:,46)+1.80000) - CONSTANTS(:,96))./2.50000) - 1.00000);
    ALGEBRAIC(:,51) = 0.00100000./(ALGEBRAIC(:,42)+ALGEBRAIC(:,49));
    ALGEBRAIC(:,17) = piecewise({CONSTANTS(:,14)>0.00000, 7.50000 }, STATES(:,3));
    ALGEBRAIC(:,33) =  CONSTANTS(:,86).*log(CONSTANTS(:,15)./ALGEBRAIC(:,17));
    ALGEBRAIC(:,53) =  CONSTANTS(:,92).*CONSTANTS(:,22).*power(1.00000+power(CONSTANTS(:,20)./CONSTANTS(:,17), 1.20000),  - 1.00000).*power(1.00000+power(CONSTANTS(:,21)./ALGEBRAIC(:,17), 1.30000),  - 1.00000).*power(1.00000+exp( - ((ALGEBRAIC(:,8) - ALGEBRAIC(:,33))+110.000)./20.0000),  - 1.00000);
    ALGEBRAIC(:,55) = exp((  - CONSTANTS(:,25).*ALGEBRAIC(:,8))./( 2.00000.*CONSTANTS(:,86)));
    ALGEBRAIC(:,61) = 1.00000+ (CONSTANTS(:,18)./CONSTANTS(:,35)).*(1.00000+exp(( CONSTANTS(:,26).*ALGEBRAIC(:,8))./CONSTANTS(:,86)))+ (CONSTANTS(:,15)./CONSTANTS(:,33)).*(1.00000+ (CONSTANTS(:,15)./CONSTANTS(:,34)).*(1.00000+CONSTANTS(:,15)./CONSTANTS(:,32)));
    ALGEBRAIC(:,63) = ( (( (CONSTANTS(:,15)./CONSTANTS(:,33)).*CONSTANTS(:,15))./CONSTANTS(:,34)).*(1.00000+CONSTANTS(:,15)./CONSTANTS(:,32)).*exp((  - CONSTANTS(:,25).*ALGEBRAIC(:,8))./( 2.00000.*CONSTANTS(:,86))))./ALGEBRAIC(:,61);
    ALGEBRAIC(:,62) = ( (CONSTANTS(:,18)./CONSTANTS(:,35)).*exp(( CONSTANTS(:,26).*ALGEBRAIC(:,8))./CONSTANTS(:,86)))./ALGEBRAIC(:,61);
    ALGEBRAIC(:,59) = exp(( CONSTANTS(:,25).*ALGEBRAIC(:,8))./( 2.00000.*CONSTANTS(:,86)));
    ALGEBRAIC(:,54) = ALGEBRAIC(:,17)./(CONSTANTS(:,27)+ALGEBRAIC(:,17));
    ALGEBRAIC(:,64) =  ALGEBRAIC(:,55).*CONSTANTS(:,93).*(ALGEBRAIC(:,63)+ALGEBRAIC(:,62))+ ALGEBRAIC(:,62).*ALGEBRAIC(:,59).*(ALGEBRAIC(:,54)+ALGEBRAIC(:,55));
    ALGEBRAIC(:,56) = 1.00000+ (STATES(:,2)./CONSTANTS(:,28)).*(1.00000+exp((  - CONSTANTS(:,24).*ALGEBRAIC(:,8))./CONSTANTS(:,86))+ALGEBRAIC(:,17)./CONSTANTS(:,31))+ (ALGEBRAIC(:,17)./CONSTANTS(:,29)).*(1.00000+ (ALGEBRAIC(:,17)./CONSTANTS(:,30)).*(1.00000+ALGEBRAIC(:,17)./CONSTANTS(:,27)));
    ALGEBRAIC(:,57) = ( (STATES(:,2)./CONSTANTS(:,28)).*exp((  - CONSTANTS(:,24).*ALGEBRAIC(:,8))./CONSTANTS(:,86)))./ALGEBRAIC(:,56);
    ALGEBRAIC(:,58) = ( (( (ALGEBRAIC(:,17)./CONSTANTS(:,29)).*ALGEBRAIC(:,17))./CONSTANTS(:,30)).*(1.00000+ALGEBRAIC(:,17)./CONSTANTS(:,27)).*exp(( CONSTANTS(:,25).*ALGEBRAIC(:,8))./( 2.00000.*CONSTANTS(:,86))))./ALGEBRAIC(:,56);
    ALGEBRAIC(:,60) =  ALGEBRAIC(:,59).*ALGEBRAIC(:,54).*(ALGEBRAIC(:,58)+ALGEBRAIC(:,57))+ ALGEBRAIC(:,55).*ALGEBRAIC(:,57).*(CONSTANTS(:,93)+ALGEBRAIC(:,59));
    ALGEBRAIC(:,65) =  ALGEBRAIC(:,58).*ALGEBRAIC(:,54).*(ALGEBRAIC(:,63)+ALGEBRAIC(:,62))+ ALGEBRAIC(:,57).*ALGEBRAIC(:,63).*(ALGEBRAIC(:,54)+ALGEBRAIC(:,55));
    ALGEBRAIC(:,66) =  ALGEBRAIC(:,63).*CONSTANTS(:,93).*(ALGEBRAIC(:,58)+ALGEBRAIC(:,57))+ ALGEBRAIC(:,58).*ALGEBRAIC(:,62).*(CONSTANTS(:,93)+ALGEBRAIC(:,59));
    ALGEBRAIC(:,67) = ( CONSTANTS(:,23).*( ALGEBRAIC(:,60).*ALGEBRAIC(:,62) -  ALGEBRAIC(:,64).*ALGEBRAIC(:,57)))./(ALGEBRAIC(:,64)+ALGEBRAIC(:,60)+ALGEBRAIC(:,65)+ALGEBRAIC(:,66));
    ALGEBRAIC(:,68) =  CONSTANTS(:,86).*log((CONSTANTS(:,15)+ 0.120000.*CONSTANTS(:,17))./(ALGEBRAIC(:,17)+ 0.120000.*CONSTANTS(:,16)));
    ALGEBRAIC(:,69) =  CONSTANTS(:,36).*power(STATES(:,5), 3.00000).*STATES(:,6).*(ALGEBRAIC(:,8) - ALGEBRAIC(:,68));
    ALGEBRAIC(:,43) = piecewise({CONSTANTS(:,11)>=1.00000, (10.6015./5.00000)./(10.6015./5.00000+exp((  - 0.710000.*ALGEBRAIC(:,8))./25.0000)) }, 1.00000);
    ALGEBRAIC(:,47) =  (( power(STATES(:,4), 2.00000).*CONSTANTS(:,17))./(CONSTANTS(:,17)+CONSTANTS(:,19))).*CONSTANTS(:,83).*(ALGEBRAIC(:,8) - ALGEBRAIC(:,33)).*ALGEBRAIC(:,43);
    ALGEBRAIC(:,72) =  (( 1.85000e-05.*CONSTANTS(:,38).*(ALGEBRAIC(:,8) - 0.00000))./( CONSTANTS(:,86).*(1.00000 - exp((  - 1.00000.*(ALGEBRAIC(:,8) - 0.00000))./CONSTANTS(:,86))))).*(ALGEBRAIC(:,17) -  CONSTANTS(:,15).*exp((  - 1.00000.*(ALGEBRAIC(:,8) - 0.00000))./CONSTANTS(:,86))).*STATES(:,7).*STATES(:,8).*STATES(:,9);
    ALGEBRAIC(:,82) =  CONSTANTS(:,59).*STATES(:,18).*(1.00000 - STATES(:,22)) -  CONSTANTS(:,64).*STATES(:,22);
    ALGEBRAIC(:,80) = CONSTANTS(:,89)./(1.00000+CONSTANTS(:,54)./STATES(:,18));
    ALGEBRAIC(:,83) = (STATES(:,17) - STATES(:,16))./CONSTANTS(:,52);
    ALGEBRAIC(:,85) =  CONSTANTS(:,61).*STATES(:,18).*(1.00000 - (STATES(:,23)+STATES(:,19))) -  CONSTANTS(:,65).*STATES(:,23);
    ALGEBRAIC(:,86) =  CONSTANTS(:,63).*STATES(:,16).*(1.00000 - STATES(:,24)) -  CONSTANTS(:,68).*STATES(:,24);
    ALGEBRAIC(:,76) =  CONSTANTS(:,42).*STATES(:,13).*(STATES(:,16) - STATES(:,2));
    ALGEBRAIC(:,50) =  (( power(STATES(:,4), 2.00000).*CONSTANTS(:,17))./(CONSTANTS(:,17)+CONSTANTS(:,19))).*CONSTANTS(:,84).*(ALGEBRAIC(:,8) - CONSTANTS(:,88)).*ALGEBRAIC(:,43);
    ALGEBRAIC(:,52) = ALGEBRAIC(:,47)+ALGEBRAIC(:,50);
    ALGEBRAIC(:,77) =  CONSTANTS(:,80).*(ALGEBRAIC(:,8) - CONSTANTS(:,88)).*( 0.900000.*STATES(:,30)+ 0.100000.*STATES(:,29)).*STATES(:,31);
    ALGEBRAIC(:,79) =  CONSTANTS(:,86).*log((CONSTANTS(:,17)+ 0.00000.*CONSTANTS(:,15))./(CONSTANTS(:,16)+ 0.00000.*ALGEBRAIC(:,17)));
    ALGEBRAIC(:,81) =  CONSTANTS(:,87).*(ALGEBRAIC(:,8) - ALGEBRAIC(:,79)).*power(STATES(:,32), 2.00000);
    ALGEBRAIC(:,75) =  CONSTANTS(:,79).*(ALGEBRAIC(:,8) - CONSTANTS(:,88)).*STATES(:,27).*STATES(:,28);
    ALGEBRAIC(:,70) =  (( 2.00000.*CONSTANTS(:,38).*(ALGEBRAIC(:,8) - 0.00000))./( CONSTANTS(:,86).*(1.00000 - exp((  - 1.00000.*(ALGEBRAIC(:,8) - 0.00000).*2.00000)./CONSTANTS(:,86))))).*(STATES(:,2) -  CONSTANTS(:,18).*exp((  - 2.00000.*(ALGEBRAIC(:,8) - 0.00000))./CONSTANTS(:,86))).*STATES(:,7).*STATES(:,8).*STATES(:,9);
    ALGEBRAIC(:,71) =  (( 0.000365000.*CONSTANTS(:,38).*(ALGEBRAIC(:,8) - 0.00000))./( CONSTANTS(:,86).*(1.00000 - exp((  - 1.00000.*(ALGEBRAIC(:,8) - 0.00000))./CONSTANTS(:,86))))).*(CONSTANTS(:,16) -  CONSTANTS(:,17).*exp((  - 1.00000.*(ALGEBRAIC(:,8) - 0.00000))./CONSTANTS(:,86))).*STATES(:,7).*STATES(:,8).*STATES(:,9);
    ALGEBRAIC(:,73) =  (ALGEBRAIC(:,70)+ALGEBRAIC(:,71)+ALGEBRAIC(:,72)).*(1.00000 - CONSTANTS(:,95)).*1.00000.*CONSTANTS(:,94);
    ALGEBRAIC(:,74) =  (( 2.00000.*CONSTANTS(:,41).*ALGEBRAIC(:,8))./( CONSTANTS(:,86).*(1.00000 - exp((  - 1.00000.*ALGEBRAIC(:,8).*2.00000)./CONSTANTS(:,86))))).*(STATES(:,2) -  CONSTANTS(:,18).*exp((  - 2.00000.*ALGEBRAIC(:,8))./CONSTANTS(:,86))).*STATES(:,10).*STATES(:,11);
    ALGEBRAIC(:,84) = piecewise({CONSTANTS(:,12)>0.00000,  CONSTANTS(:,82).*(ALGEBRAIC(:,8) - CONSTANTS(:,88)).*(1.00000+exp((ALGEBRAIC(:,8)+20.0000)./20.0000)).*STATES(:,33) }, 0.00000);
    ALGEBRAIC(:,87) = ALGEBRAIC(:,52)+ALGEBRAIC(:,77)+ALGEBRAIC(:,81)+ALGEBRAIC(:,75)+ALGEBRAIC(:,53)+ALGEBRAIC(:,67)+ALGEBRAIC(:,69)+ALGEBRAIC(:,73)+ALGEBRAIC(:,74)+ALGEBRAIC(:,84);
    ALGEBRAIC(:,88) =  CONSTANTS(:,62).*STATES(:,18).*(1.00000 - STATES(:,20)) -  CONSTANTS(:,67).*STATES(:,20);
    ALGEBRAIC(:,89) =  CONSTANTS(:,62).*STATES(:,2).*(1.00000 - STATES(:,21)) -  CONSTANTS(:,67).*STATES(:,21);
    ALGEBRAIC(:,78) = (STATES(:,2) - STATES(:,18))./CONSTANTS(:,51);
    ALGEBRAIC(:,90) = piecewise({CONSTANTS(:,14)>0.00000&VOI>CONSTANTS(:,72), 10.0000 }, 0.00000);
    ALGEBRAIC(:,1) =  0.500000.*CONSTANTS(:,86).*log(CONSTANTS(:,18)./STATES(:,2));
    ALGEBRAIC(:,21) = (1.00000./(1.00000+exp( - (ALGEBRAIC(:,8)+23.2000)./6.60000)))./(0.846554./( 37.2000.*exp(ALGEBRAIC(:,8)./11.9000)+ 0.960000.*exp( - ALGEBRAIC(:,8)./18.5000)));
    ALGEBRAIC(:,22) =  4.00000.*(( 37.2000.*exp(ALGEBRAIC(:,8)./15.9000)+ 0.960000.*exp( - ALGEBRAIC(:,8)./22.5000))./0.846554 - (1.00000./(1.00000+exp( - (ALGEBRAIC(:,8)+23.2000)./10.6000)))./(0.846554./( 37.2000.*exp(ALGEBRAIC(:,8)./15.9000)+ 0.960000.*exp( - ALGEBRAIC(:,8)./22.5000))));
end

% Compute result of a piecewise function
function x = piecewise(cases, default)
    set = [0];
    for i = 1:2:length(cases)
        if (length(cases{i+1}) == 1)
            x(cases{i} & ~set,:) = cases{i+1};
        else
            x(cases{i} & ~set,:) = cases{i+1}(cases{i} & ~set);
        end
        set = set | cases{i};
        if(set), break, end
    end
    if (length(default) == 1)
        x(~set,:) = default;
    else
        x(~set,:) = default(~set);
    end
end

% Pad out or shorten strings to a set length
function strout = strpad(strin)
    req_length = 160;
    insize = size(strin,2);
    if insize > req_length
        strout = strin(1:req_length);
    else
        strout = [strin, blanks(req_length - insize)];
    end
end

Source
Derived from workspace severi_fantini_charawi_difrancesco_2012 at changeset 1acf719d8f4b.
This exposure was expired.
Collaboration
To begin collaborating on this work, please use your git client and issue this command:
License
The terms of use/license for this work is unspecified.