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

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

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

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

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

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

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

function [LEGEND_STATES, LEGEND_ALGEBRAIC, LEGEND_VOI, LEGEND_CONSTANTS] = createLegends()
LEGEND_STATES = ''; LEGEND_ALGEBRAIC = ''; LEGEND_VOI = ''; LEGEND_CONSTANTS = '';
LEGEND_VOI = strpad('time in component environment (millisecond)');
LEGEND_STATES(:,1) = strpad('V in component membrane (millivolt)');
LEGEND_CONSTANTS(:,1) = strpad('R in component membrane (joule_per_mole_kelvin)');
LEGEND_CONSTANTS(:,2) = strpad('T in component membrane (kelvin)');
LEGEND_CONSTANTS(:,3) = strpad('F in component membrane (coulomb_per_millimole)');
LEGEND_CONSTANTS(:,4) = strpad('Cm in component membrane (microF)');
LEGEND_CONSTANTS(:,5) = strpad('V_c in component membrane (micrometre3)');
LEGEND_ALGEBRAIC(:,48) = strpad('i_K1 in component inward_rectifier_potassium_current (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,55) = strpad('i_to in component transient_outward_current (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,49) = strpad('i_Kr in component rapid_time_dependent_potassium_current (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,50) = strpad('i_Ks in component slow_time_dependent_potassium_current (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,53) = strpad('i_CaL in component L_type_Ca_current (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,56) = strpad('i_NaK in component sodium_potassium_pump_current (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,51) = strpad('i_Na in component fast_sodium_current (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,52) = strpad('i_b_Na in component sodium_background_current (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,57) = strpad('i_NaCa in component sodium_calcium_exchanger_current (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,54) = strpad('i_b_Ca in component calcium_background_current (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,59) = strpad('i_p_K in component potassium_pump_current (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,58) = strpad('i_p_Ca in component calcium_pump_current (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,13) = strpad('i_Stim in component membrane (picoA_per_picoF)');
LEGEND_CONSTANTS(:,6) = strpad('stim_start in component membrane (millisecond)');
LEGEND_CONSTANTS(:,7) = strpad('stim_period in component membrane (millisecond)');
LEGEND_CONSTANTS(:,8) = strpad('stim_duration in component membrane (millisecond)');
LEGEND_CONSTANTS(:,9) = strpad('stim_amplitude in component membrane (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,26) = strpad('E_Na in component reversal_potentials (millivolt)');
LEGEND_ALGEBRAIC(:,34) = strpad('E_K in component reversal_potentials (millivolt)');
LEGEND_ALGEBRAIC(:,42) = strpad('E_Ks in component reversal_potentials (millivolt)');
LEGEND_ALGEBRAIC(:,44) = strpad('E_Ca in component reversal_potentials (millivolt)');
LEGEND_CONSTANTS(:,10) = strpad('P_kna in component reversal_potentials (dimensionless)');
LEGEND_CONSTANTS(:,11) = strpad('K_o in component potassium_dynamics (millimolar)');
LEGEND_CONSTANTS(:,12) = strpad('Na_o in component sodium_dynamics (millimolar)');
LEGEND_STATES(:,2) = strpad('K_i in component potassium_dynamics (millimolar)');
LEGEND_STATES(:,3) = strpad('Na_i in component sodium_dynamics (millimolar)');
LEGEND_CONSTANTS(:,13) = strpad('Ca_o in component calcium_dynamics (millimolar)');
LEGEND_STATES(:,4) = strpad('Ca_i in component calcium_dynamics (millimolar)');
LEGEND_CONSTANTS(:,14) = strpad('g_K1 in component inward_rectifier_potassium_current (nanoS_per_picoF)');
LEGEND_ALGEBRAIC(:,47) = strpad('xK1_inf in component inward_rectifier_potassium_current (dimensionless)');
LEGEND_ALGEBRAIC(:,45) = strpad('alpha_K1 in component inward_rectifier_potassium_current (dimensionless)');
LEGEND_ALGEBRAIC(:,46) = strpad('beta_K1 in component inward_rectifier_potassium_current (dimensionless)');
LEGEND_CONSTANTS(:,15) = strpad('g_Kr in component rapid_time_dependent_potassium_current (nanoS_per_picoF)');
LEGEND_STATES(:,5) = strpad('Xr1 in component rapid_time_dependent_potassium_current_Xr1_gate (dimensionless)');
LEGEND_STATES(:,6) = strpad('Xr2 in component rapid_time_dependent_potassium_current_Xr2_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,1) = strpad('xr1_inf in component rapid_time_dependent_potassium_current_Xr1_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,14) = strpad('alpha_xr1 in component rapid_time_dependent_potassium_current_Xr1_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,27) = strpad('beta_xr1 in component rapid_time_dependent_potassium_current_Xr1_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,35) = strpad('tau_xr1 in component rapid_time_dependent_potassium_current_Xr1_gate (millisecond)');
LEGEND_ALGEBRAIC(:,2) = strpad('xr2_inf in component rapid_time_dependent_potassium_current_Xr2_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,15) = strpad('alpha_xr2 in component rapid_time_dependent_potassium_current_Xr2_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,28) = strpad('beta_xr2 in component rapid_time_dependent_potassium_current_Xr2_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,36) = strpad('tau_xr2 in component rapid_time_dependent_potassium_current_Xr2_gate (millisecond)');
LEGEND_CONSTANTS(:,16) = strpad('g_Ks in component slow_time_dependent_potassium_current (nanoS_per_picoF)');
LEGEND_STATES(:,7) = strpad('Xs in component slow_time_dependent_potassium_current_Xs_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,3) = strpad('xs_inf in component slow_time_dependent_potassium_current_Xs_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,16) = strpad('alpha_xs in component slow_time_dependent_potassium_current_Xs_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,29) = strpad('beta_xs in component slow_time_dependent_potassium_current_Xs_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,37) = strpad('tau_xs in component slow_time_dependent_potassium_current_Xs_gate (millisecond)');
LEGEND_CONSTANTS(:,17) = strpad('g_Na in component fast_sodium_current (nanoS_per_picoF)');
LEGEND_STATES(:,8) = strpad('m in component fast_sodium_current_m_gate (dimensionless)');
LEGEND_STATES(:,9) = strpad('h in component fast_sodium_current_h_gate (dimensionless)');
LEGEND_STATES(:,10) = strpad('j in component fast_sodium_current_j_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,4) = strpad('m_inf in component fast_sodium_current_m_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,17) = strpad('alpha_m in component fast_sodium_current_m_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,30) = strpad('beta_m in component fast_sodium_current_m_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,38) = strpad('tau_m in component fast_sodium_current_m_gate (millisecond)');
LEGEND_ALGEBRAIC(:,5) = strpad('h_inf in component fast_sodium_current_h_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,18) = strpad('alpha_h in component fast_sodium_current_h_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,31) = strpad('beta_h in component fast_sodium_current_h_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,39) = strpad('tau_h in component fast_sodium_current_h_gate (millisecond)');
LEGEND_ALGEBRAIC(:,6) = strpad('j_inf in component fast_sodium_current_j_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,19) = strpad('alpha_j in component fast_sodium_current_j_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,32) = strpad('beta_j in component fast_sodium_current_j_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,40) = strpad('tau_j in component fast_sodium_current_j_gate (millisecond)');
LEGEND_CONSTANTS(:,18) = strpad('g_bna in component sodium_background_current (nanoS_per_picoF)');
LEGEND_STATES(:,11) = strpad('Ca_ss in component calcium_dynamics (millimolar)');
LEGEND_STATES(:,12) = strpad('d in component L_type_Ca_current_d_gate (dimensionless)');
LEGEND_STATES(:,13) = strpad('f in component L_type_Ca_current_f_gate (dimensionless)');
LEGEND_STATES(:,14) = strpad('f2 in component L_type_Ca_current_f2_gate (dimensionless)');
LEGEND_STATES(:,15) = strpad('fCass in component L_type_Ca_current_fCass_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,7) = strpad('d_inf in component L_type_Ca_current_d_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,20) = strpad('alpha_d in component L_type_Ca_current_d_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,33) = strpad('beta_d in component L_type_Ca_current_d_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,41) = strpad('gamma_d in component L_type_Ca_current_d_gate (millisecond)');
LEGEND_ALGEBRAIC(:,43) = strpad('tau_d in component L_type_Ca_current_d_gate (millisecond)');
LEGEND_ALGEBRAIC(:,8) = strpad('f_inf in component L_type_Ca_current_f_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,21) = strpad('tau_f in component L_type_Ca_current_f_gate (millisecond)');
LEGEND_ALGEBRAIC(:,9) = strpad('f2_inf in component L_type_Ca_current_f2_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,22) = strpad('tau_f2 in component L_type_Ca_current_f2_gate (millisecond)');
LEGEND_ALGEBRAIC(:,10) = strpad('fCass_inf in component L_type_Ca_current_fCass_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,23) = strpad('tau_fCass in component L_type_Ca_current_fCass_gate (millisecond)');
LEGEND_CONSTANTS(:,20) = strpad('g_bca in component calcium_background_current (nanoS_per_picoF)');
LEGEND_CONSTANTS(:,21) = strpad('g_to in component transient_outward_current (nanoS_per_picoF)');
LEGEND_STATES(:,16) = strpad('s in component transient_outward_current_s_gate (dimensionless)');
LEGEND_STATES(:,17) = strpad('r in component transient_outward_current_r_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,11) = strpad('s_inf in component transient_outward_current_s_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,24) = strpad('tau_s in component transient_outward_current_s_gate (millisecond)');
LEGEND_ALGEBRAIC(:,12) = strpad('r_inf in component transient_outward_current_r_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,25) = strpad('tau_r in component transient_outward_current_r_gate (millisecond)');
LEGEND_CONSTANTS(:,22) = strpad('P_NaK in component sodium_potassium_pump_current (picoA_per_picoF)');
LEGEND_CONSTANTS(:,23) = strpad('K_mk in component sodium_potassium_pump_current (millimolar)');
LEGEND_CONSTANTS(:,24) = strpad('K_mNa in component sodium_potassium_pump_current (millimolar)');
LEGEND_CONSTANTS(:,25) = strpad('K_NaCa in component sodium_calcium_exchanger_current (picoA_per_picoF)');
LEGEND_CONSTANTS(:,26) = strpad('K_sat in component sodium_calcium_exchanger_current (dimensionless)');
LEGEND_CONSTANTS(:,27) = strpad('alpha in component sodium_calcium_exchanger_current (dimensionless)');
LEGEND_CONSTANTS(:,28) = strpad('gamma in component sodium_calcium_exchanger_current (dimensionless)');
LEGEND_CONSTANTS(:,29) = strpad('Km_Ca in component sodium_calcium_exchanger_current (millimolar)');
LEGEND_CONSTANTS(:,30) = strpad('Km_Nai in component sodium_calcium_exchanger_current (millimolar)');
LEGEND_CONSTANTS(:,31) = strpad('g_pCa in component calcium_pump_current (picoA_per_picoF)');
LEGEND_CONSTANTS(:,32) = strpad('K_pCa in component calcium_pump_current (millimolar)');
LEGEND_CONSTANTS(:,33) = strpad('g_pK in component potassium_pump_current (nanoS_per_picoF)');
LEGEND_STATES(:,18) = strpad('Ca_SR in component calcium_dynamics (millimolar)');
LEGEND_ALGEBRAIC(:,68) = strpad('i_rel in component calcium_dynamics (millimolar_per_millisecond)');
LEGEND_ALGEBRAIC(:,60) = strpad('i_up in component calcium_dynamics (millimolar_per_millisecond)');
LEGEND_ALGEBRAIC(:,61) = strpad('i_leak in component calcium_dynamics (millimolar_per_millisecond)');
LEGEND_ALGEBRAIC(:,62) = strpad('i_xfer in component calcium_dynamics (millimolar_per_millisecond)');
LEGEND_ALGEBRAIC(:,67) = strpad('O in component calcium_dynamics (dimensionless)');
LEGEND_STATES(:,19) = strpad('R_prime in component calcium_dynamics (dimensionless)');
LEGEND_ALGEBRAIC(:,65) = strpad('k1 in component calcium_dynamics (per_millimolar2_per_millisecond)');
LEGEND_ALGEBRAIC(:,66) = strpad('k2 in component calcium_dynamics (per_millimolar_per_millisecond)');
LEGEND_CONSTANTS(:,34) = strpad('k1_prime in component calcium_dynamics (per_millimolar2_per_millisecond)');
LEGEND_CONSTANTS(:,35) = strpad('k2_prime in component calcium_dynamics (per_millimolar_per_millisecond)');
LEGEND_CONSTANTS(:,36) = strpad('k3 in component calcium_dynamics (per_millisecond)');
LEGEND_CONSTANTS(:,37) = strpad('k4 in component calcium_dynamics (per_millisecond)');
LEGEND_CONSTANTS(:,38) = strpad('EC in component calcium_dynamics (millimolar)');
LEGEND_CONSTANTS(:,39) = strpad('max_sr in component calcium_dynamics (dimensionless)');
LEGEND_CONSTANTS(:,40) = strpad('min_sr in component calcium_dynamics (dimensionless)');
LEGEND_ALGEBRAIC(:,63) = strpad('kcasr in component calcium_dynamics (dimensionless)');
LEGEND_CONSTANTS(:,41) = strpad('V_rel in component calcium_dynamics (per_millisecond)');
LEGEND_CONSTANTS(:,42) = strpad('V_xfer in component calcium_dynamics (per_millisecond)');
LEGEND_CONSTANTS(:,43) = strpad('K_up in component calcium_dynamics (millimolar)');
LEGEND_CONSTANTS(:,44) = strpad('V_leak in component calcium_dynamics (per_millisecond)');
LEGEND_CONSTANTS(:,45) = strpad('Vmax_up in component calcium_dynamics (millimolar_per_millisecond)');
LEGEND_ALGEBRAIC(:,64) = strpad('Ca_i_bufc in component calcium_dynamics (dimensionless)');
LEGEND_ALGEBRAIC(:,69) = strpad('Ca_sr_bufsr in component calcium_dynamics (dimensionless)');
LEGEND_ALGEBRAIC(:,70) = strpad('Ca_ss_bufss in component calcium_dynamics (dimensionless)');
LEGEND_CONSTANTS(:,46) = strpad('Buf_c in component calcium_dynamics (millimolar)');
LEGEND_CONSTANTS(:,47) = strpad('K_buf_c in component calcium_dynamics (millimolar)');
LEGEND_CONSTANTS(:,48) = strpad('Buf_sr in component calcium_dynamics (millimolar)');
LEGEND_CONSTANTS(:,49) = strpad('K_buf_sr in component calcium_dynamics (millimolar)');
LEGEND_CONSTANTS(:,50) = strpad('Buf_ss in component calcium_dynamics (millimolar)');
LEGEND_CONSTANTS(:,51) = strpad('K_buf_ss in component calcium_dynamics (millimolar)');
LEGEND_CONSTANTS(:,52) = strpad('V_sr in component calcium_dynamics (micrometre3)');
LEGEND_CONSTANTS(:,53) = strpad('V_ss in component calcium_dynamics (micrometre3)');
LEGEND_RATES(:,1) = strpad('d/dt V in component membrane (millivolt)');
LEGEND_RATES(:,5) = strpad('d/dt Xr1 in component rapid_time_dependent_potassium_current_Xr1_gate (dimensionless)');
LEGEND_RATES(:,6) = strpad('d/dt Xr2 in component rapid_time_dependent_potassium_current_Xr2_gate (dimensionless)');
LEGEND_RATES(:,7) = strpad('d/dt Xs in component slow_time_dependent_potassium_current_Xs_gate (dimensionless)');
LEGEND_RATES(:,8) = strpad('d/dt m in component fast_sodium_current_m_gate (dimensionless)');
LEGEND_RATES(:,9) = strpad('d/dt h in component fast_sodium_current_h_gate (dimensionless)');
LEGEND_RATES(:,10) = strpad('d/dt j in component fast_sodium_current_j_gate (dimensionless)');
LEGEND_RATES(:,12) = strpad('d/dt d in component L_type_Ca_current_d_gate (dimensionless)');
LEGEND_RATES(:,13) = strpad('d/dt f in component L_type_Ca_current_f_gate (dimensionless)');
LEGEND_RATES(:,14) = strpad('d/dt f2 in component L_type_Ca_current_f2_gate (dimensionless)');
LEGEND_RATES(:,15) = strpad('d/dt fCass in component L_type_Ca_current_fCass_gate (dimensionless)');
LEGEND_RATES(:,16) = strpad('d/dt s in component transient_outward_current_s_gate (dimensionless)');
LEGEND_RATES(:,17) = strpad('d/dt r in component transient_outward_current_r_gate (dimensionless)');
LEGEND_RATES(:,19) = strpad('d/dt R_prime in component calcium_dynamics (dimensionless)');
LEGEND_RATES(:,4) = strpad('d/dt Ca_i in component calcium_dynamics (millimolar)');
LEGEND_RATES(:,18) = strpad('d/dt Ca_SR in component calcium_dynamics (millimolar)');
LEGEND_RATES(:,11) = strpad('d/dt Ca_ss in component calcium_dynamics (millimolar)');
LEGEND_RATES(:,3) = strpad('d/dt Na_i in component sodium_dynamics (millimolar)');
LEGEND_RATES(:,2) = strpad('d/dt K_i in component potassium_dynamics (millimolar)');
LEGEND_STATES  = LEGEND_STATES';
LEGEND_ALGEBRAIC = LEGEND_ALGEBRAIC';
LEGEND_RATES = LEGEND_RATES';
LEGEND_CONSTANTS = LEGEND_CONSTANTS';
end

function [STATES, CONSTANTS] = initConsts()
VOI = 0; CONSTANTS = []; STATES = []; ALGEBRAIC = [];
STATES(:,1) = -85.423;
CONSTANTS(:,1) = 8314.472;
CONSTANTS(:,2) = 310;
CONSTANTS(:,3) = 96485.3415;
CONSTANTS(:,4) = 0.185;
CONSTANTS(:,5) = 0.016404;
CONSTANTS(:,6) = 10;
CONSTANTS(:,7) = 1000;
CONSTANTS(:,8) = 1;
CONSTANTS(:,9) = 52;
CONSTANTS(:,10) = 0.03;
CONSTANTS(:,11) = 5.4;
CONSTANTS(:,12) = 140;
STATES(:,2) = 138.52;
STATES(:,3) = 10.132;
CONSTANTS(:,13) = 2;
STATES(:,4) = 0.000153;
CONSTANTS(:,14) = 5.405;
CONSTANTS(:,15) = 0.153;
STATES(:,5) = 0.0165;
STATES(:,6) = 0.473;
CONSTANTS(:,16) = 0.098;
STATES(:,7) = 0.0174;
CONSTANTS(:,17) = 14.838;
STATES(:,8) = 0.00165;
STATES(:,9) = 0.749;
STATES(:,10) = 0.6788;
CONSTANTS(:,18) = 0.00029;
CONSTANTS(:,19) = 0.0000398;
STATES(:,11) = 0.00042;
STATES(:,12) = 3.288e-5;
STATES(:,13) = 0.7026;
STATES(:,14) = 0.9526;
STATES(:,15) = 0.9942;
CONSTANTS(:,20) = 0.000592;
CONSTANTS(:,21) = 0.294;
STATES(:,16) = 0.999998;
STATES(:,17) = 2.347e-8;
CONSTANTS(:,22) = 2.724;
CONSTANTS(:,23) = 1;
CONSTANTS(:,24) = 40;
CONSTANTS(:,25) = 1000;
CONSTANTS(:,26) = 0.1;
CONSTANTS(:,27) = 2.5;
CONSTANTS(:,28) = 0.35;
CONSTANTS(:,29) = 1.38;
CONSTANTS(:,30) = 87.5;
CONSTANTS(:,31) = 0.1238;
CONSTANTS(:,32) = 0.0005;
CONSTANTS(:,33) = 0.0146;
STATES(:,18) = 4.272;
STATES(:,19) = 0.8978;
CONSTANTS(:,34) = 0.15;
CONSTANTS(:,35) = 0.045;
CONSTANTS(:,36) = 0.06;
CONSTANTS(:,37) = 0.005;
CONSTANTS(:,38) = 1.5;
CONSTANTS(:,39) = 2.5;
CONSTANTS(:,40) = 1;
CONSTANTS(:,41) = 0.102;
CONSTANTS(:,42) = 0.0038;
CONSTANTS(:,43) = 0.00025;
CONSTANTS(:,44) = 0.00036;
CONSTANTS(:,45) = 0.006375;
CONSTANTS(:,46) = 0.2;
CONSTANTS(:,47) = 0.001;
CONSTANTS(:,48) = 10;
CONSTANTS(:,49) = 0.3;
CONSTANTS(:,50) = 0.4;
CONSTANTS(:,51) = 0.00025;
CONSTANTS(:,52) = 0.001094;
CONSTANTS(:,53) = 0.00005468;
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(:,8) = 1.00000./(1.00000+exp((STATES(:,1)+20.0000)./7.00000));
ALGEBRAIC(:,21) =  1102.50.*exp( - power(STATES(:,1)+27.0000, 2.00000)./225.000)+200.000./(1.00000+exp((13.0000 - STATES(:,1))./10.0000))+180.000./(1.00000+exp((STATES(:,1)+30.0000)./10.0000))+20.0000;
RATES(:,13) = (ALGEBRAIC(:,8) - STATES(:,13))./ALGEBRAIC(:,21);
ALGEBRAIC(:,9) = 0.670000./(1.00000+exp((STATES(:,1)+35.0000)./7.00000))+0.330000;
ALGEBRAIC(:,22) =  562.000.*exp( - power(STATES(:,1)+27.0000, 2.00000)./240.000)+31.0000./(1.00000+exp((25.0000 - STATES(:,1))./10.0000))+80.0000./(1.00000+exp((STATES(:,1)+30.0000)./10.0000));
RATES(:,14) = (ALGEBRAIC(:,9) - STATES(:,14))./ALGEBRAIC(:,22);
ALGEBRAIC(:,10) = 0.600000./(1.00000+power(STATES(:,11)./0.0500000, 2.00000))+0.400000;
ALGEBRAIC(:,23) = 80.0000./(1.00000+power(STATES(:,11)./0.0500000, 2.00000))+2.00000;
RATES(:,15) = (ALGEBRAIC(:,10) - STATES(:,15))./ALGEBRAIC(:,23);
ALGEBRAIC(:,11) = 1.00000./(1.00000+exp((STATES(:,1)+20.0000)./5.00000));
ALGEBRAIC(:,24) =  85.0000.*exp( - power(STATES(:,1)+45.0000, 2.00000)./320.000)+5.00000./(1.00000+exp((STATES(:,1) - 20.0000)./5.00000))+3.00000;
RATES(:,16) = (ALGEBRAIC(:,11) - STATES(:,16))./ALGEBRAIC(:,24);
ALGEBRAIC(:,12) = 1.00000./(1.00000+exp((20.0000 - STATES(:,1))./6.00000));
ALGEBRAIC(:,25) =  9.50000.*exp( - power(STATES(:,1)+40.0000, 2.00000)./1800.00)+0.800000;
RATES(:,17) = (ALGEBRAIC(:,12) - STATES(:,17))./ALGEBRAIC(:,25);
ALGEBRAIC(:,1) = 1.00000./(1.00000+exp(( - 26.0000 - STATES(:,1))./7.00000));
ALGEBRAIC(:,14) = 450.000./(1.00000+exp(( - 45.0000 - STATES(:,1))./10.0000));
ALGEBRAIC(:,27) = 6.00000./(1.00000+exp((STATES(:,1)+30.0000)./11.5000));
ALGEBRAIC(:,35) =  1.00000.*ALGEBRAIC(:,14).*ALGEBRAIC(:,27);
RATES(:,5) = (ALGEBRAIC(:,1) - STATES(:,5))./ALGEBRAIC(:,35);
ALGEBRAIC(:,2) = 1.00000./(1.00000+exp((STATES(:,1)+88.0000)./24.0000));
ALGEBRAIC(:,15) = 3.00000./(1.00000+exp(( - 60.0000 - STATES(:,1))./20.0000));
ALGEBRAIC(:,28) = 1.12000./(1.00000+exp((STATES(:,1) - 60.0000)./20.0000));
ALGEBRAIC(:,36) =  1.00000.*ALGEBRAIC(:,15).*ALGEBRAIC(:,28);
RATES(:,6) = (ALGEBRAIC(:,2) - STATES(:,6))./ALGEBRAIC(:,36);
ALGEBRAIC(:,3) = 1.00000./(1.00000+exp(( - 5.00000 - STATES(:,1))./14.0000));
ALGEBRAIC(:,16) = 1400.00./power((1.00000+exp((5.00000 - STATES(:,1))./6.00000)), 1.0 ./ 2);
ALGEBRAIC(:,29) = 1.00000./(1.00000+exp((STATES(:,1) - 35.0000)./15.0000));
ALGEBRAIC(:,37) =  1.00000.*ALGEBRAIC(:,16).*ALGEBRAIC(:,29)+80.0000;
RATES(:,7) = (ALGEBRAIC(:,3) - STATES(:,7))./ALGEBRAIC(:,37);
ALGEBRAIC(:,4) = 1.00000./power(1.00000+exp(( - 56.8600 - STATES(:,1))./9.03000), 2.00000);
ALGEBRAIC(:,17) = 1.00000./(1.00000+exp(( - 60.0000 - STATES(:,1))./5.00000));
ALGEBRAIC(:,30) = 0.100000./(1.00000+exp((STATES(:,1)+35.0000)./5.00000))+0.100000./(1.00000+exp((STATES(:,1) - 50.0000)./200.000));
ALGEBRAIC(:,38) =  1.00000.*ALGEBRAIC(:,17).*ALGEBRAIC(:,30);
RATES(:,8) = (ALGEBRAIC(:,4) - STATES(:,8))./ALGEBRAIC(:,38);
ALGEBRAIC(:,5) = 1.00000./power(1.00000+exp((STATES(:,1)+71.5500)./7.43000), 2.00000);
ALGEBRAIC(:,18) = piecewise({STATES(:,1)< - 40.0000,  0.0570000.*exp( - (STATES(:,1)+80.0000)./6.80000) }, 0.00000);
ALGEBRAIC(:,31) = piecewise({STATES(:,1)< - 40.0000,  2.70000.*exp( 0.0790000.*STATES(:,1))+ 310000..*exp( 0.348500.*STATES(:,1)) }, 0.770000./( 0.130000.*(1.00000+exp((STATES(:,1)+10.6600)./ - 11.1000))));
ALGEBRAIC(:,39) = 1.00000./(ALGEBRAIC(:,18)+ALGEBRAIC(:,31));
RATES(:,9) = (ALGEBRAIC(:,5) - STATES(:,9))./ALGEBRAIC(:,39);
ALGEBRAIC(:,6) = 1.00000./power(1.00000+exp((STATES(:,1)+71.5500)./7.43000), 2.00000);
ALGEBRAIC(:,19) = piecewise({STATES(:,1)< - 40.0000, (( (  - 25428.0.*exp( 0.244400.*STATES(:,1)) -  6.94800e-06.*exp(  - 0.0439100.*STATES(:,1))).*(STATES(:,1)+37.7800))./1.00000)./(1.00000+exp( 0.311000.*(STATES(:,1)+79.2300))) }, 0.00000);
ALGEBRAIC(:,32) = piecewise({STATES(:,1)< - 40.0000, ( 0.0242400.*exp(  - 0.0105200.*STATES(:,1)))./(1.00000+exp(  - 0.137800.*(STATES(:,1)+40.1400))) }, ( 0.600000.*exp( 0.0570000.*STATES(:,1)))./(1.00000+exp(  - 0.100000.*(STATES(:,1)+32.0000))));
ALGEBRAIC(:,40) = 1.00000./(ALGEBRAIC(:,19)+ALGEBRAIC(:,32));
RATES(:,10) = (ALGEBRAIC(:,6) - STATES(:,10))./ALGEBRAIC(:,40);
ALGEBRAIC(:,7) = 1.00000./(1.00000+exp(( - 8.00000 - STATES(:,1))./7.50000));
ALGEBRAIC(:,20) = 1.40000./(1.00000+exp(( - 35.0000 - STATES(:,1))./13.0000))+0.250000;
ALGEBRAIC(:,33) = 1.40000./(1.00000+exp((STATES(:,1)+5.00000)./5.00000));
ALGEBRAIC(:,41) = 1.00000./(1.00000+exp((50.0000 - STATES(:,1))./20.0000));
ALGEBRAIC(:,43) =  1.00000.*ALGEBRAIC(:,20).*ALGEBRAIC(:,33)+ALGEBRAIC(:,41);
RATES(:,12) = (ALGEBRAIC(:,7) - STATES(:,12))./ALGEBRAIC(:,43);
ALGEBRAIC(:,56) = (( (( CONSTANTS(:,22).*CONSTANTS(:,11))./(CONSTANTS(:,11)+CONSTANTS(:,23))).*STATES(:,3))./(STATES(:,3)+CONSTANTS(:,24)))./(1.00000+ 0.124500.*exp((  - 0.100000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))+ 0.0353000.*exp((  - STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,26) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,12)./STATES(:,3));
ALGEBRAIC(:,51) =  CONSTANTS(:,17).*power(STATES(:,8), 3.00000).*STATES(:,9).*STATES(:,10).*(STATES(:,1) - ALGEBRAIC(:,26));
ALGEBRAIC(:,52) =  CONSTANTS(:,18).*(STATES(:,1) - ALGEBRAIC(:,26));
ALGEBRAIC(:,57) = ( CONSTANTS(:,25).*( exp(( CONSTANTS(:,28).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(STATES(:,3), 3.00000).*CONSTANTS(:,13) -  exp(( (CONSTANTS(:,28) - 1.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(CONSTANTS(:,12), 3.00000).*STATES(:,4).*CONSTANTS(:,27)))./( (power(CONSTANTS(:,30), 3.00000)+power(CONSTANTS(:,12), 3.00000)).*(CONSTANTS(:,29)+CONSTANTS(:,13)).*(1.00000+ CONSTANTS(:,26).*exp(( (CONSTANTS(:,28) - 1.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))));
RATES(:,3) =  ((  - 1.00000.*(ALGEBRAIC(:,51)+ALGEBRAIC(:,52)+ 3.00000.*ALGEBRAIC(:,56)+ 3.00000.*ALGEBRAIC(:,57)))./( 1.00000.*CONSTANTS(:,5).*CONSTANTS(:,3))).*CONSTANTS(:,4);
ALGEBRAIC(:,34) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,11)./STATES(:,2));
ALGEBRAIC(:,45) = 0.100000./(1.00000+exp( 0.0600000.*((STATES(:,1) - ALGEBRAIC(:,34)) - 200.000)));
ALGEBRAIC(:,46) = ( 3.00000.*exp( 0.000200000.*((STATES(:,1) - ALGEBRAIC(:,34))+100.000))+exp( 0.100000.*((STATES(:,1) - ALGEBRAIC(:,34)) - 10.0000)))./(1.00000+exp(  - 0.500000.*(STATES(:,1) - ALGEBRAIC(:,34))));
ALGEBRAIC(:,47) = ALGEBRAIC(:,45)./(ALGEBRAIC(:,45)+ALGEBRAIC(:,46));
ALGEBRAIC(:,48) =  CONSTANTS(:,14).*ALGEBRAIC(:,47).*power((CONSTANTS(:,11)./5.40000), 1.0 ./ 2).*(STATES(:,1) - ALGEBRAIC(:,34));
ALGEBRAIC(:,55) =  CONSTANTS(:,21).*STATES(:,17).*STATES(:,16).*(STATES(:,1) - ALGEBRAIC(:,34));
ALGEBRAIC(:,49) =  CONSTANTS(:,15).*power((CONSTANTS(:,11)./5.40000), 1.0 ./ 2).*STATES(:,5).*STATES(:,6).*(STATES(:,1) - ALGEBRAIC(:,34));
ALGEBRAIC(:,42) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log((CONSTANTS(:,11)+ CONSTANTS(:,10).*CONSTANTS(:,12))./(STATES(:,2)+ CONSTANTS(:,10).*STATES(:,3)));
ALGEBRAIC(:,50) =  CONSTANTS(:,16).*power(STATES(:,7), 2.00000).*(STATES(:,1) - ALGEBRAIC(:,42));
ALGEBRAIC(:,53) = ( (( CONSTANTS(:,19).*STATES(:,12).*STATES(:,13).*STATES(:,14).*STATES(:,15).*4.00000.*(STATES(:,1) - 15.0000).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( 0.250000.*STATES(:,11).*exp(( 2.00000.*(STATES(:,1) - 15.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - CONSTANTS(:,13)))./(exp(( 2.00000.*(STATES(:,1) - 15.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000);
ALGEBRAIC(:,44) =  (( 0.500000.*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,13)./STATES(:,4));
ALGEBRAIC(:,54) =  CONSTANTS(:,20).*(STATES(:,1) - ALGEBRAIC(:,44));
ALGEBRAIC(:,59) = ( CONSTANTS(:,33).*(STATES(:,1) - ALGEBRAIC(:,34)))./(1.00000+exp((25.0000 - STATES(:,1))./5.98000));
ALGEBRAIC(:,58) = ( CONSTANTS(:,31).*STATES(:,4))./(STATES(:,4)+CONSTANTS(:,32));
ALGEBRAIC(:,13) = piecewise({VOI -  floor(VOI./CONSTANTS(:,7)).*CONSTANTS(:,7)>=CONSTANTS(:,6)&VOI -  floor(VOI./CONSTANTS(:,7)).*CONSTANTS(:,7)<=CONSTANTS(:,6)+CONSTANTS(:,8),  - CONSTANTS(:,9) }, 0.00000);
RATES(:,1) =  - (ALGEBRAIC(:,48)+ALGEBRAIC(:,55)+ALGEBRAIC(:,49)+ALGEBRAIC(:,50)+ALGEBRAIC(:,53)+ALGEBRAIC(:,56)+ALGEBRAIC(:,51)+ALGEBRAIC(:,52)+ALGEBRAIC(:,57)+ALGEBRAIC(:,54)+ALGEBRAIC(:,59)+ALGEBRAIC(:,58)+ALGEBRAIC(:,13));
RATES(:,2) =  ((  - 1.00000.*((ALGEBRAIC(:,48)+ALGEBRAIC(:,55)+ALGEBRAIC(:,49)+ALGEBRAIC(:,50)+ALGEBRAIC(:,59)+ALGEBRAIC(:,13)) -  2.00000.*ALGEBRAIC(:,56)))./( 1.00000.*CONSTANTS(:,5).*CONSTANTS(:,3))).*CONSTANTS(:,4);
ALGEBRAIC(:,60) = CONSTANTS(:,45)./(1.00000+power(CONSTANTS(:,43), 2.00000)./power(STATES(:,4), 2.00000));
ALGEBRAIC(:,61) =  CONSTANTS(:,44).*(STATES(:,18) - STATES(:,4));
ALGEBRAIC(:,62) =  CONSTANTS(:,42).*(STATES(:,11) - STATES(:,4));
ALGEBRAIC(:,64) = 1.00000./(1.00000+( CONSTANTS(:,46).*CONSTANTS(:,47))./power(STATES(:,4)+CONSTANTS(:,47), 2.00000));
RATES(:,4) =  ALGEBRAIC(:,64).*((( (ALGEBRAIC(:,61) - ALGEBRAIC(:,60)).*CONSTANTS(:,52))./CONSTANTS(:,5)+ALGEBRAIC(:,62)) - ( 1.00000.*((ALGEBRAIC(:,54)+ALGEBRAIC(:,58)) -  2.00000.*ALGEBRAIC(:,57)).*CONSTANTS(:,4))./( 2.00000.*1.00000.*CONSTANTS(:,5).*CONSTANTS(:,3)));
ALGEBRAIC(:,63) = CONSTANTS(:,39) - (CONSTANTS(:,39) - CONSTANTS(:,40))./(1.00000+power(CONSTANTS(:,38)./STATES(:,18), 2.00000));
ALGEBRAIC(:,66) =  CONSTANTS(:,35).*ALGEBRAIC(:,63);
RATES(:,19) =   - ALGEBRAIC(:,66).*STATES(:,11).*STATES(:,19)+ CONSTANTS(:,37).*(1.00000 - STATES(:,19));
ALGEBRAIC(:,65) = CONSTANTS(:,34)./ALGEBRAIC(:,63);
ALGEBRAIC(:,67) = ( ALGEBRAIC(:,65).*power(STATES(:,11), 2.00000).*STATES(:,19))./(CONSTANTS(:,36)+ ALGEBRAIC(:,65).*power(STATES(:,11), 2.00000));
ALGEBRAIC(:,68) =  CONSTANTS(:,41).*ALGEBRAIC(:,67).*(STATES(:,18) - STATES(:,11));
ALGEBRAIC(:,69) = 1.00000./(1.00000+( CONSTANTS(:,48).*CONSTANTS(:,49))./power(STATES(:,18)+CONSTANTS(:,49), 2.00000));
RATES(:,18) =  ALGEBRAIC(:,69).*(ALGEBRAIC(:,60) - (ALGEBRAIC(:,68)+ALGEBRAIC(:,61)));
ALGEBRAIC(:,70) = 1.00000./(1.00000+( CONSTANTS(:,50).*CONSTANTS(:,51))./power(STATES(:,11)+CONSTANTS(:,51), 2.00000));
RATES(:,11) =  ALGEBRAIC(:,70).*(((  - 1.00000.*ALGEBRAIC(:,53).*CONSTANTS(:,4))./( 2.00000.*1.00000.*CONSTANTS(:,53).*CONSTANTS(:,3))+( ALGEBRAIC(:,68).*CONSTANTS(:,52))./CONSTANTS(:,53)) - ( ALGEBRAIC(:,62).*CONSTANTS(:,5))./CONSTANTS(:,53));
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(:,8) = 1.00000./(1.00000+exp((STATES(:,1)+20.0000)./7.00000));
ALGEBRAIC(:,21) =  1102.50.*exp( - power(STATES(:,1)+27.0000, 2.00000)./225.000)+200.000./(1.00000+exp((13.0000 - STATES(:,1))./10.0000))+180.000./(1.00000+exp((STATES(:,1)+30.0000)./10.0000))+20.0000;
ALGEBRAIC(:,9) = 0.670000./(1.00000+exp((STATES(:,1)+35.0000)./7.00000))+0.330000;
ALGEBRAIC(:,22) =  562.000.*exp( - power(STATES(:,1)+27.0000, 2.00000)./240.000)+31.0000./(1.00000+exp((25.0000 - STATES(:,1))./10.0000))+80.0000./(1.00000+exp((STATES(:,1)+30.0000)./10.0000));
ALGEBRAIC(:,10) = 0.600000./(1.00000+power(STATES(:,11)./0.0500000, 2.00000))+0.400000;
ALGEBRAIC(:,23) = 80.0000./(1.00000+power(STATES(:,11)./0.0500000, 2.00000))+2.00000;
ALGEBRAIC(:,11) = 1.00000./(1.00000+exp((STATES(:,1)+20.0000)./5.00000));
ALGEBRAIC(:,24) =  85.0000.*exp( - power(STATES(:,1)+45.0000, 2.00000)./320.000)+5.00000./(1.00000+exp((STATES(:,1) - 20.0000)./5.00000))+3.00000;
ALGEBRAIC(:,12) = 1.00000./(1.00000+exp((20.0000 - STATES(:,1))./6.00000));
ALGEBRAIC(:,25) =  9.50000.*exp( - power(STATES(:,1)+40.0000, 2.00000)./1800.00)+0.800000;
ALGEBRAIC(:,1) = 1.00000./(1.00000+exp(( - 26.0000 - STATES(:,1))./7.00000));
ALGEBRAIC(:,14) = 450.000./(1.00000+exp(( - 45.0000 - STATES(:,1))./10.0000));
ALGEBRAIC(:,27) = 6.00000./(1.00000+exp((STATES(:,1)+30.0000)./11.5000));
ALGEBRAIC(:,35) =  1.00000.*ALGEBRAIC(:,14).*ALGEBRAIC(:,27);
ALGEBRAIC(:,2) = 1.00000./(1.00000+exp((STATES(:,1)+88.0000)./24.0000));
ALGEBRAIC(:,15) = 3.00000./(1.00000+exp(( - 60.0000 - STATES(:,1))./20.0000));
ALGEBRAIC(:,28) = 1.12000./(1.00000+exp((STATES(:,1) - 60.0000)./20.0000));
ALGEBRAIC(:,36) =  1.00000.*ALGEBRAIC(:,15).*ALGEBRAIC(:,28);
ALGEBRAIC(:,3) = 1.00000./(1.00000+exp(( - 5.00000 - STATES(:,1))./14.0000));
ALGEBRAIC(:,16) = 1400.00./power((1.00000+exp((5.00000 - STATES(:,1))./6.00000)), 1.0 ./ 2);
ALGEBRAIC(:,29) = 1.00000./(1.00000+exp((STATES(:,1) - 35.0000)./15.0000));
ALGEBRAIC(:,37) =  1.00000.*ALGEBRAIC(:,16).*ALGEBRAIC(:,29)+80.0000;
ALGEBRAIC(:,4) = 1.00000./power(1.00000+exp(( - 56.8600 - STATES(:,1))./9.03000), 2.00000);
ALGEBRAIC(:,17) = 1.00000./(1.00000+exp(( - 60.0000 - STATES(:,1))./5.00000));
ALGEBRAIC(:,30) = 0.100000./(1.00000+exp((STATES(:,1)+35.0000)./5.00000))+0.100000./(1.00000+exp((STATES(:,1) - 50.0000)./200.000));
ALGEBRAIC(:,38) =  1.00000.*ALGEBRAIC(:,17).*ALGEBRAIC(:,30);
ALGEBRAIC(:,5) = 1.00000./power(1.00000+exp((STATES(:,1)+71.5500)./7.43000), 2.00000);
ALGEBRAIC(:,18) = piecewise({STATES(:,1)< - 40.0000,  0.0570000.*exp( - (STATES(:,1)+80.0000)./6.80000) }, 0.00000);
ALGEBRAIC(:,31) = piecewise({STATES(:,1)< - 40.0000,  2.70000.*exp( 0.0790000.*STATES(:,1))+ 310000..*exp( 0.348500.*STATES(:,1)) }, 0.770000./( 0.130000.*(1.00000+exp((STATES(:,1)+10.6600)./ - 11.1000))));
ALGEBRAIC(:,39) = 1.00000./(ALGEBRAIC(:,18)+ALGEBRAIC(:,31));
ALGEBRAIC(:,6) = 1.00000./power(1.00000+exp((STATES(:,1)+71.5500)./7.43000), 2.00000);
ALGEBRAIC(:,19) = piecewise({STATES(:,1)< - 40.0000, (( (  - 25428.0.*exp( 0.244400.*STATES(:,1)) -  6.94800e-06.*exp(  - 0.0439100.*STATES(:,1))).*(STATES(:,1)+37.7800))./1.00000)./(1.00000+exp( 0.311000.*(STATES(:,1)+79.2300))) }, 0.00000);
ALGEBRAIC(:,32) = piecewise({STATES(:,1)< - 40.0000, ( 0.0242400.*exp(  - 0.0105200.*STATES(:,1)))./(1.00000+exp(  - 0.137800.*(STATES(:,1)+40.1400))) }, ( 0.600000.*exp( 0.0570000.*STATES(:,1)))./(1.00000+exp(  - 0.100000.*(STATES(:,1)+32.0000))));
ALGEBRAIC(:,40) = 1.00000./(ALGEBRAIC(:,19)+ALGEBRAIC(:,32));
ALGEBRAIC(:,7) = 1.00000./(1.00000+exp(( - 8.00000 - STATES(:,1))./7.50000));
ALGEBRAIC(:,20) = 1.40000./(1.00000+exp(( - 35.0000 - STATES(:,1))./13.0000))+0.250000;
ALGEBRAIC(:,33) = 1.40000./(1.00000+exp((STATES(:,1)+5.00000)./5.00000));
ALGEBRAIC(:,41) = 1.00000./(1.00000+exp((50.0000 - STATES(:,1))./20.0000));
ALGEBRAIC(:,43) =  1.00000.*ALGEBRAIC(:,20).*ALGEBRAIC(:,33)+ALGEBRAIC(:,41);
ALGEBRAIC(:,56) = (( (( CONSTANTS(:,22).*CONSTANTS(:,11))./(CONSTANTS(:,11)+CONSTANTS(:,23))).*STATES(:,3))./(STATES(:,3)+CONSTANTS(:,24)))./(1.00000+ 0.124500.*exp((  - 0.100000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))+ 0.0353000.*exp((  - STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,26) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,12)./STATES(:,3));
ALGEBRAIC(:,51) =  CONSTANTS(:,17).*power(STATES(:,8), 3.00000).*STATES(:,9).*STATES(:,10).*(STATES(:,1) - ALGEBRAIC(:,26));
ALGEBRAIC(:,52) =  CONSTANTS(:,18).*(STATES(:,1) - ALGEBRAIC(:,26));
ALGEBRAIC(:,57) = ( CONSTANTS(:,25).*( exp(( CONSTANTS(:,28).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(STATES(:,3), 3.00000).*CONSTANTS(:,13) -  exp(( (CONSTANTS(:,28) - 1.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(CONSTANTS(:,12), 3.00000).*STATES(:,4).*CONSTANTS(:,27)))./( (power(CONSTANTS(:,30), 3.00000)+power(CONSTANTS(:,12), 3.00000)).*(CONSTANTS(:,29)+CONSTANTS(:,13)).*(1.00000+ CONSTANTS(:,26).*exp(( (CONSTANTS(:,28) - 1.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))));
ALGEBRAIC(:,34) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,11)./STATES(:,2));
ALGEBRAIC(:,45) = 0.100000./(1.00000+exp( 0.0600000.*((STATES(:,1) - ALGEBRAIC(:,34)) - 200.000)));
ALGEBRAIC(:,46) = ( 3.00000.*exp( 0.000200000.*((STATES(:,1) - ALGEBRAIC(:,34))+100.000))+exp( 0.100000.*((STATES(:,1) - ALGEBRAIC(:,34)) - 10.0000)))./(1.00000+exp(  - 0.500000.*(STATES(:,1) - ALGEBRAIC(:,34))));
ALGEBRAIC(:,47) = ALGEBRAIC(:,45)./(ALGEBRAIC(:,45)+ALGEBRAIC(:,46));
ALGEBRAIC(:,48) =  CONSTANTS(:,14).*ALGEBRAIC(:,47).*power((CONSTANTS(:,11)./5.40000), 1.0 ./ 2).*(STATES(:,1) - ALGEBRAIC(:,34));
ALGEBRAIC(:,55) =  CONSTANTS(:,21).*STATES(:,17).*STATES(:,16).*(STATES(:,1) - ALGEBRAIC(:,34));
ALGEBRAIC(:,49) =  CONSTANTS(:,15).*power((CONSTANTS(:,11)./5.40000), 1.0 ./ 2).*STATES(:,5).*STATES(:,6).*(STATES(:,1) - ALGEBRAIC(:,34));
ALGEBRAIC(:,42) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log((CONSTANTS(:,11)+ CONSTANTS(:,10).*CONSTANTS(:,12))./(STATES(:,2)+ CONSTANTS(:,10).*STATES(:,3)));
ALGEBRAIC(:,50) =  CONSTANTS(:,16).*power(STATES(:,7), 2.00000).*(STATES(:,1) - ALGEBRAIC(:,42));
ALGEBRAIC(:,53) = ( (( CONSTANTS(:,19).*STATES(:,12).*STATES(:,13).*STATES(:,14).*STATES(:,15).*4.00000.*(STATES(:,1) - 15.0000).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( 0.250000.*STATES(:,11).*exp(( 2.00000.*(STATES(:,1) - 15.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - CONSTANTS(:,13)))./(exp(( 2.00000.*(STATES(:,1) - 15.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000);
ALGEBRAIC(:,44) =  (( 0.500000.*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,13)./STATES(:,4));
ALGEBRAIC(:,54) =  CONSTANTS(:,20).*(STATES(:,1) - ALGEBRAIC(:,44));
ALGEBRAIC(:,59) = ( CONSTANTS(:,33).*(STATES(:,1) - ALGEBRAIC(:,34)))./(1.00000+exp((25.0000 - STATES(:,1))./5.98000));
ALGEBRAIC(:,58) = ( CONSTANTS(:,31).*STATES(:,4))./(STATES(:,4)+CONSTANTS(:,32));
ALGEBRAIC(:,13) = piecewise({VOI -  floor(VOI./CONSTANTS(:,7)).*CONSTANTS(:,7)>=CONSTANTS(:,6)&VOI -  floor(VOI./CONSTANTS(:,7)).*CONSTANTS(:,7)<=CONSTANTS(:,6)+CONSTANTS(:,8),  - CONSTANTS(:,9) }, 0.00000);
ALGEBRAIC(:,60) = CONSTANTS(:,45)./(1.00000+power(CONSTANTS(:,43), 2.00000)./power(STATES(:,4), 2.00000));
ALGEBRAIC(:,61) =  CONSTANTS(:,44).*(STATES(:,18) - STATES(:,4));
ALGEBRAIC(:,62) =  CONSTANTS(:,42).*(STATES(:,11) - STATES(:,4));
ALGEBRAIC(:,64) = 1.00000./(1.00000+( CONSTANTS(:,46).*CONSTANTS(:,47))./power(STATES(:,4)+CONSTANTS(:,47), 2.00000));
ALGEBRAIC(:,63) = CONSTANTS(:,39) - (CONSTANTS(:,39) - CONSTANTS(:,40))./(1.00000+power(CONSTANTS(:,38)./STATES(:,18), 2.00000));
ALGEBRAIC(:,66) =  CONSTANTS(:,35).*ALGEBRAIC(:,63);
ALGEBRAIC(:,65) = CONSTANTS(:,34)./ALGEBRAIC(:,63);
ALGEBRAIC(:,67) = ( ALGEBRAIC(:,65).*power(STATES(:,11), 2.00000).*STATES(:,19))./(CONSTANTS(:,36)+ ALGEBRAIC(:,65).*power(STATES(:,11), 2.00000));
ALGEBRAIC(:,68) =  CONSTANTS(:,41).*ALGEBRAIC(:,67).*(STATES(:,18) - STATES(:,11));
ALGEBRAIC(:,69) = 1.00000./(1.00000+( CONSTANTS(:,48).*CONSTANTS(:,49))./power(STATES(:,18)+CONSTANTS(:,49), 2.00000));
ALGEBRAIC(:,70) = 1.00000./(1.00000+( CONSTANTS(:,50).*CONSTANTS(:,51))./power(STATES(:,11)+CONSTANTS(:,51), 2.00000));
end

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

% Pad out or shorten strings to a set length
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 Tentusscher, Panfilov, 2006 at changeset 5dc42395eef6.
Collaboration
To begin collaborating on this work, please use your git client and issue this command: