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 =81;
end
% There are a total of 20 entries in each of the rate and state variable arrays.
% There are a total of 160 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_ALGEBRAIC(:,76) = strpad('sum_g_syn_e_s in component synaptic_coupling (nanoS)');
LEGEND_CONSTANTS(:,1) = strpad('g_syn_e_1_2 in component synaptic_coupling (nanoS)');
LEGEND_CONSTANTS(:,2) = strpad('g_syn_e_1_3 in component synaptic_coupling (nanoS)');
LEGEND_CONSTANTS(:,3) = strpad('g_syn_e_1_4 in component synaptic_coupling (nanoS)');
LEGEND_CONSTANTS(:,4) = strpad('g_syn_e_1_5 in component synaptic_coupling (nanoS)');
LEGEND_CONSTANTS(:,5) = strpad('g_syn_e_2_1 in component synaptic_coupling (nanoS)');
LEGEND_CONSTANTS(:,6) = strpad('g_syn_e_2_3 in component synaptic_coupling (nanoS)');
LEGEND_CONSTANTS(:,7) = strpad('g_syn_e_2_4 in component synaptic_coupling (nanoS)');
LEGEND_CONSTANTS(:,8) = strpad('g_syn_e_2_5 in component synaptic_coupling (nanoS)');
LEGEND_CONSTANTS(:,9) = strpad('g_syn_e_3_1 in component synaptic_coupling (nanoS)');
LEGEND_CONSTANTS(:,10) = strpad('g_syn_e_3_2 in component synaptic_coupling (nanoS)');
LEGEND_CONSTANTS(:,11) = strpad('g_syn_e_3_4 in component synaptic_coupling (nanoS)');
LEGEND_CONSTANTS(:,12) = strpad('g_syn_e_3_5 in component synaptic_coupling (nanoS)');
LEGEND_CONSTANTS(:,13) = strpad('g_syn_e_4_1 in component synaptic_coupling (nanoS)');
LEGEND_CONSTANTS(:,14) = strpad('g_syn_e_4_2 in component synaptic_coupling (nanoS)');
LEGEND_CONSTANTS(:,15) = strpad('g_syn_e_4_3 in component synaptic_coupling (nanoS)');
LEGEND_CONSTANTS(:,16) = strpad('g_syn_e_4_5 in component synaptic_coupling (nanoS)');
LEGEND_CONSTANTS(:,17) = strpad('g_syn_e_5_1 in component synaptic_coupling (nanoS)');
LEGEND_CONSTANTS(:,18) = strpad('g_syn_e_5_2 in component synaptic_coupling (nanoS)');
LEGEND_CONSTANTS(:,19) = strpad('g_syn_e_5_3 in component synaptic_coupling (nanoS)');
LEGEND_CONSTANTS(:,20) = strpad('g_syn_e_5_4 in component synaptic_coupling (nanoS)');
LEGEND_ALGEBRAIC(:,39) = strpad('s in component synaptic_input (dimensionless)');
LEGEND_ALGEBRAIC(:,48) = strpad('s in component synaptic_input (dimensionless)');
LEGEND_ALGEBRAIC(:,57) = strpad('s in component synaptic_input (dimensionless)');
LEGEND_ALGEBRAIC(:,66) = strpad('s in component synaptic_input (dimensionless)');
LEGEND_ALGEBRAIC(:,75) = strpad('s in component synaptic_input (dimensionless)');
LEGEND_VOI = strpad('time in component environment (millisecond)');
LEGEND_STATES(:,1) = strpad('V in component membrane (millivolt)');
LEGEND_CONSTANTS(:,21) = strpad('C in component membrane (picoF)');
LEGEND_CONSTANTS(:,22) = strpad('i_app in component membrane (picoA)');
LEGEND_ALGEBRAIC(:,35) = strpad('i_NaP in component persistent_sodium_current (picoA)');
LEGEND_ALGEBRAIC(:,17) = strpad('i_Na in component fast_sodium_current (picoA)');
LEGEND_ALGEBRAIC(:,33) = strpad('i_K in component potassium_current (picoA)');
LEGEND_ALGEBRAIC(:,36) = strpad('i_L in component leakage_current (picoA)');
LEGEND_ALGEBRAIC(:,37) = strpad('i_tonic_e in component tonic_current (picoA)');
LEGEND_ALGEBRAIC(:,77) = strpad('i_syn_e in component synaptic_input (picoA)');
LEGEND_CONSTANTS(:,23) = strpad('E_Na in component fast_sodium_current (millivolt)');
LEGEND_CONSTANTS(:,24) = strpad('g_Na in component fast_sodium_current (nanoS)');
LEGEND_ALGEBRAIC(:,1) = strpad('m_infinity in component fast_sodium_current_m_gate (dimensionless)');
LEGEND_STATES(:,2) = strpad('n in component fast_sodium_current_n_gate (dimensionless)');
LEGEND_CONSTANTS(:,25) = strpad('theta_m in component fast_sodium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,26) = strpad('sigma_m in component fast_sodium_current_m_gate (millivolt)');
LEGEND_ALGEBRAIC(:,2) = strpad('n_infinity in component fast_sodium_current_n_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,18) = strpad('tau_n in component fast_sodium_current_n_gate (millisecond)');
LEGEND_CONSTANTS(:,27) = strpad('tau_n_max in component fast_sodium_current_n_gate (millisecond)');
LEGEND_CONSTANTS(:,28) = strpad('theta_n in component fast_sodium_current_n_gate (millivolt)');
LEGEND_CONSTANTS(:,29) = strpad('sigma_n in component fast_sodium_current_n_gate (millivolt)');
LEGEND_CONSTANTS(:,30) = strpad('g_K in component potassium_current (nanoS)');
LEGEND_CONSTANTS(:,31) = strpad('E_K in component potassium_current (millivolt)');
LEGEND_STATES(:,3) = strpad('n in component potassium_current_n_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,3) = strpad('n_infinity in component potassium_current_n_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,19) = strpad('tau_n in component potassium_current_n_gate (millisecond)');
LEGEND_CONSTANTS(:,32) = strpad('tau_n_max in component potassium_current_n_gate (millisecond)');
LEGEND_CONSTANTS(:,33) = strpad('theta_n in component potassium_current_n_gate (millivolt)');
LEGEND_CONSTANTS(:,34) = strpad('sigma_n in component potassium_current_n_gate (millivolt)');
LEGEND_CONSTANTS(:,35) = strpad('g_NaP in component persistent_sodium_current (nanoS)');
LEGEND_ALGEBRAIC(:,34) = strpad('m_infinity in component persistent_sodium_current_m_gate (dimensionless)');
LEGEND_STATES(:,4) = strpad('h in component persistent_sodium_current_h_gate (dimensionless)');
LEGEND_CONSTANTS(:,36) = strpad('theta_m in component persistent_sodium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,37) = strpad('sigma_m in component persistent_sodium_current_m_gate (millivolt)');
LEGEND_ALGEBRAIC(:,4) = strpad('h_infinity in component persistent_sodium_current_h_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,20) = strpad('tau_h in component persistent_sodium_current_h_gate (millisecond)');
LEGEND_CONSTANTS(:,38) = strpad('tau_h_max in component persistent_sodium_current_h_gate (millisecond)');
LEGEND_CONSTANTS(:,39) = strpad('theta_h in component persistent_sodium_current_h_gate (millivolt)');
LEGEND_CONSTANTS(:,40) = strpad('sigma_h in component persistent_sodium_current_h_gate (millivolt)');
LEGEND_CONSTANTS(:,41) = strpad('g_L in component leakage_current (nanoS)');
LEGEND_CONSTANTS(:,42) = strpad('E_L in component leakage_current (millivolt)');
LEGEND_CONSTANTS(:,43) = strpad('E_syn_e in component tonic_current (millivolt)');
LEGEND_CONSTANTS(:,44) = strpad('g_tonic_e in component tonic_current (nanoS)');
LEGEND_ALGEBRAIC(:,38) = strpad('s_infinity in component synaptic_input (dimensionless)');
LEGEND_CONSTANTS(:,45) = strpad('kr in component synaptic_input (dimensionless)');
LEGEND_CONSTANTS(:,46) = strpad('tau_s in component synaptic_input (millisecond)');
LEGEND_CONSTANTS(:,47) = strpad('sigma_s in component synaptic_input (millivolt)');
LEGEND_CONSTANTS(:,48) = strpad('theta_s in component synaptic_input (millivolt)');
LEGEND_VOI = strpad('time in component environment (millisecond)');
LEGEND_STATES(:,5) = strpad('V in component membrane (millivolt)');
LEGEND_CONSTANTS(:,49) = strpad('C in component membrane (picoF)');
LEGEND_CONSTANTS(:,50) = strpad('i_app in component membrane (picoA)');
LEGEND_ALGEBRAIC(:,44) = strpad('i_NaP in component persistent_sodium_current (picoA)');
LEGEND_ALGEBRAIC(:,41) = strpad('i_Na in component fast_sodium_current (picoA)');
LEGEND_ALGEBRAIC(:,42) = strpad('i_K in component potassium_current (picoA)');
LEGEND_ALGEBRAIC(:,45) = strpad('i_L in component leakage_current (picoA)');
LEGEND_ALGEBRAIC(:,46) = strpad('i_tonic_e in component tonic_current (picoA)');
LEGEND_ALGEBRAIC(:,78) = strpad('i_syn_e in component synaptic_input (picoA)');
LEGEND_CONSTANTS(:,51) = strpad('E_Na in component fast_sodium_current (millivolt)');
LEGEND_CONSTANTS(:,52) = strpad('g_Na in component fast_sodium_current (nanoS)');
LEGEND_ALGEBRAIC(:,40) = strpad('m_infinity in component fast_sodium_current_m_gate (dimensionless)');
LEGEND_STATES(:,6) = strpad('n in component fast_sodium_current_n_gate (dimensionless)');
LEGEND_CONSTANTS(:,53) = strpad('theta_m in component fast_sodium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,54) = strpad('sigma_m in component fast_sodium_current_m_gate (millivolt)');
LEGEND_ALGEBRAIC(:,5) = strpad('n_infinity in component fast_sodium_current_n_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,21) = strpad('tau_n in component fast_sodium_current_n_gate (millisecond)');
LEGEND_CONSTANTS(:,55) = strpad('tau_n_max in component fast_sodium_current_n_gate (millisecond)');
LEGEND_CONSTANTS(:,56) = strpad('theta_n in component fast_sodium_current_n_gate (millivolt)');
LEGEND_CONSTANTS(:,57) = strpad('sigma_n in component fast_sodium_current_n_gate (millivolt)');
LEGEND_CONSTANTS(:,58) = strpad('g_K in component potassium_current (nanoS)');
LEGEND_CONSTANTS(:,59) = strpad('E_K in component potassium_current (millivolt)');
LEGEND_STATES(:,7) = strpad('n in component potassium_current_n_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,6) = strpad('n_infinity in component potassium_current_n_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,22) = strpad('tau_n in component potassium_current_n_gate (millisecond)');
LEGEND_CONSTANTS(:,60) = strpad('tau_n_max in component potassium_current_n_gate (millisecond)');
LEGEND_CONSTANTS(:,61) = strpad('theta_n in component potassium_current_n_gate (millivolt)');
LEGEND_CONSTANTS(:,62) = strpad('sigma_n in component potassium_current_n_gate (millivolt)');
LEGEND_CONSTANTS(:,63) = strpad('g_NaP in component persistent_sodium_current (nanoS)');
LEGEND_ALGEBRAIC(:,43) = strpad('m_infinity in component persistent_sodium_current_m_gate (dimensionless)');
LEGEND_STATES(:,8) = strpad('h in component persistent_sodium_current_h_gate (dimensionless)');
LEGEND_CONSTANTS(:,64) = strpad('theta_m in component persistent_sodium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,65) = strpad('sigma_m in component persistent_sodium_current_m_gate (millivolt)');
LEGEND_ALGEBRAIC(:,7) = strpad('h_infinity in component persistent_sodium_current_h_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,23) = strpad('tau_h in component persistent_sodium_current_h_gate (millisecond)');
LEGEND_CONSTANTS(:,66) = strpad('tau_h_max in component persistent_sodium_current_h_gate (millisecond)');
LEGEND_CONSTANTS(:,67) = strpad('theta_h in component persistent_sodium_current_h_gate (millivolt)');
LEGEND_CONSTANTS(:,68) = strpad('sigma_h in component persistent_sodium_current_h_gate (millivolt)');
LEGEND_CONSTANTS(:,69) = strpad('g_L in component leakage_current (nanoS)');
LEGEND_CONSTANTS(:,70) = strpad('E_L in component leakage_current (millivolt)');
LEGEND_CONSTANTS(:,71) = strpad('E_syn_e in component tonic_current (millivolt)');
LEGEND_CONSTANTS(:,72) = strpad('g_tonic_e in component tonic_current (nanoS)');
LEGEND_ALGEBRAIC(:,47) = strpad('s_infinity in component synaptic_input (dimensionless)');
LEGEND_CONSTANTS(:,73) = strpad('kr in component synaptic_input (dimensionless)');
LEGEND_CONSTANTS(:,74) = strpad('tau_s in component synaptic_input (millisecond)');
LEGEND_CONSTANTS(:,75) = strpad('sigma_s in component synaptic_input (millivolt)');
LEGEND_CONSTANTS(:,76) = strpad('theta_s in component synaptic_input (millivolt)');
LEGEND_VOI = strpad('time in component environment (millisecond)');
LEGEND_STATES(:,9) = strpad('V in component membrane (millivolt)');
LEGEND_CONSTANTS(:,77) = strpad('C in component membrane (picoF)');
LEGEND_CONSTANTS(:,78) = strpad('i_app in component membrane (picoA)');
LEGEND_ALGEBRAIC(:,53) = strpad('i_NaP in component persistent_sodium_current (picoA)');
LEGEND_ALGEBRAIC(:,50) = strpad('i_Na in component fast_sodium_current (picoA)');
LEGEND_ALGEBRAIC(:,51) = strpad('i_K in component potassium_current (picoA)');
LEGEND_ALGEBRAIC(:,54) = strpad('i_L in component leakage_current (picoA)');
LEGEND_ALGEBRAIC(:,55) = strpad('i_tonic_e in component tonic_current (picoA)');
LEGEND_ALGEBRAIC(:,79) = strpad('i_syn_e in component synaptic_input (picoA)');
LEGEND_CONSTANTS(:,79) = strpad('E_Na in component fast_sodium_current (millivolt)');
LEGEND_CONSTANTS(:,80) = strpad('g_Na in component fast_sodium_current (nanoS)');
LEGEND_ALGEBRAIC(:,49) = strpad('m_infinity in component fast_sodium_current_m_gate (dimensionless)');
LEGEND_STATES(:,10) = strpad('n in component fast_sodium_current_n_gate (dimensionless)');
LEGEND_CONSTANTS(:,81) = strpad('theta_m in component fast_sodium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,82) = strpad('sigma_m in component fast_sodium_current_m_gate (millivolt)');
LEGEND_ALGEBRAIC(:,8) = strpad('n_infinity in component fast_sodium_current_n_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,24) = strpad('tau_n in component fast_sodium_current_n_gate (millisecond)');
LEGEND_CONSTANTS(:,83) = strpad('tau_n_max in component fast_sodium_current_n_gate (millisecond)');
LEGEND_CONSTANTS(:,84) = strpad('theta_n in component fast_sodium_current_n_gate (millivolt)');
LEGEND_CONSTANTS(:,85) = strpad('sigma_n in component fast_sodium_current_n_gate (millivolt)');
LEGEND_CONSTANTS(:,86) = strpad('g_K in component potassium_current (nanoS)');
LEGEND_CONSTANTS(:,87) = strpad('E_K in component potassium_current (millivolt)');
LEGEND_STATES(:,11) = strpad('n in component potassium_current_n_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,9) = strpad('n_infinity in component potassium_current_n_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,25) = strpad('tau_n in component potassium_current_n_gate (millisecond)');
LEGEND_CONSTANTS(:,88) = strpad('tau_n_max in component potassium_current_n_gate (millisecond)');
LEGEND_CONSTANTS(:,89) = strpad('theta_n in component potassium_current_n_gate (millivolt)');
LEGEND_CONSTANTS(:,90) = strpad('sigma_n in component potassium_current_n_gate (millivolt)');
LEGEND_CONSTANTS(:,91) = strpad('g_NaP in component persistent_sodium_current (nanoS)');
LEGEND_ALGEBRAIC(:,52) = strpad('m_infinity in component persistent_sodium_current_m_gate (dimensionless)');
LEGEND_STATES(:,12) = strpad('h in component persistent_sodium_current_h_gate (dimensionless)');
LEGEND_CONSTANTS(:,92) = strpad('theta_m in component persistent_sodium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,93) = strpad('sigma_m in component persistent_sodium_current_m_gate (millivolt)');
LEGEND_ALGEBRAIC(:,10) = strpad('h_infinity in component persistent_sodium_current_h_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,26) = strpad('tau_h in component persistent_sodium_current_h_gate (millisecond)');
LEGEND_CONSTANTS(:,94) = strpad('tau_h_max in component persistent_sodium_current_h_gate (millisecond)');
LEGEND_CONSTANTS(:,95) = strpad('theta_h in component persistent_sodium_current_h_gate (millivolt)');
LEGEND_CONSTANTS(:,96) = strpad('sigma_h in component persistent_sodium_current_h_gate (millivolt)');
LEGEND_CONSTANTS(:,97) = strpad('g_L in component leakage_current (nanoS)');
LEGEND_CONSTANTS(:,98) = strpad('E_L in component leakage_current (millivolt)');
LEGEND_CONSTANTS(:,99) = strpad('E_syn_e in component tonic_current (millivolt)');
LEGEND_CONSTANTS(:,100) = strpad('g_tonic_e in component tonic_current (nanoS)');
LEGEND_ALGEBRAIC(:,56) = strpad('s_infinity in component synaptic_input (dimensionless)');
LEGEND_CONSTANTS(:,101) = strpad('kr in component synaptic_input (dimensionless)');
LEGEND_CONSTANTS(:,102) = strpad('tau_s in component synaptic_input (millisecond)');
LEGEND_CONSTANTS(:,103) = strpad('sigma_s in component synaptic_input (millivolt)');
LEGEND_CONSTANTS(:,104) = strpad('theta_s in component synaptic_input (millivolt)');
LEGEND_VOI = strpad('time in component environment (millisecond)');
LEGEND_STATES(:,13) = strpad('V in component membrane (millivolt)');
LEGEND_CONSTANTS(:,105) = strpad('C in component membrane (picoF)');
LEGEND_CONSTANTS(:,106) = strpad('i_app in component membrane (picoA)');
LEGEND_ALGEBRAIC(:,62) = strpad('i_NaP in component persistent_sodium_current (picoA)');
LEGEND_ALGEBRAIC(:,59) = strpad('i_Na in component fast_sodium_current (picoA)');
LEGEND_ALGEBRAIC(:,60) = strpad('i_K in component potassium_current (picoA)');
LEGEND_ALGEBRAIC(:,63) = strpad('i_L in component leakage_current (picoA)');
LEGEND_ALGEBRAIC(:,64) = strpad('i_tonic_e in component tonic_current (picoA)');
LEGEND_ALGEBRAIC(:,80) = strpad('i_syn_e in component synaptic_input (picoA)');
LEGEND_CONSTANTS(:,107) = strpad('E_Na in component fast_sodium_current (millivolt)');
LEGEND_CONSTANTS(:,108) = strpad('g_Na in component fast_sodium_current (nanoS)');
LEGEND_ALGEBRAIC(:,58) = strpad('m_infinity in component fast_sodium_current_m_gate (dimensionless)');
LEGEND_STATES(:,14) = strpad('n in component fast_sodium_current_n_gate (dimensionless)');
LEGEND_CONSTANTS(:,109) = strpad('theta_m in component fast_sodium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,110) = strpad('sigma_m in component fast_sodium_current_m_gate (millivolt)');
LEGEND_ALGEBRAIC(:,11) = strpad('n_infinity in component fast_sodium_current_n_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,27) = strpad('tau_n in component fast_sodium_current_n_gate (millisecond)');
LEGEND_CONSTANTS(:,111) = strpad('tau_n_max in component fast_sodium_current_n_gate (millisecond)');
LEGEND_CONSTANTS(:,112) = strpad('theta_n in component fast_sodium_current_n_gate (millivolt)');
LEGEND_CONSTANTS(:,113) = strpad('sigma_n in component fast_sodium_current_n_gate (millivolt)');
LEGEND_CONSTANTS(:,114) = strpad('g_K in component potassium_current (nanoS)');
LEGEND_CONSTANTS(:,115) = strpad('E_K in component potassium_current (millivolt)');
LEGEND_STATES(:,15) = strpad('n in component potassium_current_n_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,12) = strpad('n_infinity in component potassium_current_n_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,28) = strpad('tau_n in component potassium_current_n_gate (millisecond)');
LEGEND_CONSTANTS(:,116) = strpad('tau_n_max in component potassium_current_n_gate (millisecond)');
LEGEND_CONSTANTS(:,117) = strpad('theta_n in component potassium_current_n_gate (millivolt)');
LEGEND_CONSTANTS(:,118) = strpad('sigma_n in component potassium_current_n_gate (millivolt)');
LEGEND_CONSTANTS(:,119) = strpad('g_NaP in component persistent_sodium_current (nanoS)');
LEGEND_ALGEBRAIC(:,61) = strpad('m_infinity in component persistent_sodium_current_m_gate (dimensionless)');
LEGEND_STATES(:,16) = strpad('h in component persistent_sodium_current_h_gate (dimensionless)');
LEGEND_CONSTANTS(:,120) = strpad('theta_m in component persistent_sodium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,121) = strpad('sigma_m in component persistent_sodium_current_m_gate (millivolt)');
LEGEND_ALGEBRAIC(:,13) = strpad('h_infinity in component persistent_sodium_current_h_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,29) = strpad('tau_h in component persistent_sodium_current_h_gate (millisecond)');
LEGEND_CONSTANTS(:,122) = strpad('tau_h_max in component persistent_sodium_current_h_gate (millisecond)');
LEGEND_CONSTANTS(:,123) = strpad('theta_h in component persistent_sodium_current_h_gate (millivolt)');
LEGEND_CONSTANTS(:,124) = strpad('sigma_h in component persistent_sodium_current_h_gate (millivolt)');
LEGEND_CONSTANTS(:,125) = strpad('g_L in component leakage_current (nanoS)');
LEGEND_CONSTANTS(:,126) = strpad('E_L in component leakage_current (millivolt)');
LEGEND_CONSTANTS(:,127) = strpad('E_syn_e in component tonic_current (millivolt)');
LEGEND_CONSTANTS(:,128) = strpad('g_tonic_e in component tonic_current (nanoS)');
LEGEND_ALGEBRAIC(:,65) = strpad('s_infinity in component synaptic_input (dimensionless)');
LEGEND_CONSTANTS(:,129) = strpad('kr in component synaptic_input (dimensionless)');
LEGEND_CONSTANTS(:,130) = strpad('tau_s in component synaptic_input (millisecond)');
LEGEND_CONSTANTS(:,131) = strpad('sigma_s in component synaptic_input (millivolt)');
LEGEND_CONSTANTS(:,132) = strpad('theta_s in component synaptic_input (millivolt)');
LEGEND_VOI = strpad('time in component environment (millisecond)');
LEGEND_STATES(:,17) = strpad('V in component membrane (millivolt)');
LEGEND_CONSTANTS(:,133) = strpad('C in component membrane (picoF)');
LEGEND_CONSTANTS(:,134) = strpad('i_app in component membrane (picoA)');
LEGEND_ALGEBRAIC(:,71) = strpad('i_NaP in component persistent_sodium_current (picoA)');
LEGEND_ALGEBRAIC(:,68) = strpad('i_Na in component fast_sodium_current (picoA)');
LEGEND_ALGEBRAIC(:,69) = strpad('i_K in component potassium_current (picoA)');
LEGEND_ALGEBRAIC(:,72) = strpad('i_L in component leakage_current (picoA)');
LEGEND_ALGEBRAIC(:,73) = strpad('i_tonic_e in component tonic_current (picoA)');
LEGEND_ALGEBRAIC(:,81) = strpad('i_syn_e in component synaptic_input (picoA)');
LEGEND_CONSTANTS(:,135) = strpad('E_Na in component fast_sodium_current (millivolt)');
LEGEND_CONSTANTS(:,136) = strpad('g_Na in component fast_sodium_current (nanoS)');
LEGEND_ALGEBRAIC(:,67) = strpad('m_infinity in component fast_sodium_current_m_gate (dimensionless)');
LEGEND_STATES(:,18) = strpad('n in component fast_sodium_current_n_gate (dimensionless)');
LEGEND_CONSTANTS(:,137) = strpad('theta_m in component fast_sodium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,138) = strpad('sigma_m in component fast_sodium_current_m_gate (millivolt)');
LEGEND_ALGEBRAIC(:,14) = strpad('n_infinity in component fast_sodium_current_n_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,30) = strpad('tau_n in component fast_sodium_current_n_gate (millisecond)');
LEGEND_CONSTANTS(:,139) = strpad('tau_n_max in component fast_sodium_current_n_gate (millisecond)');
LEGEND_CONSTANTS(:,140) = strpad('theta_n in component fast_sodium_current_n_gate (millivolt)');
LEGEND_CONSTANTS(:,141) = strpad('sigma_n in component fast_sodium_current_n_gate (millivolt)');
LEGEND_CONSTANTS(:,142) = strpad('g_K in component potassium_current (nanoS)');
LEGEND_CONSTANTS(:,143) = strpad('E_K in component potassium_current (millivolt)');
LEGEND_STATES(:,19) = strpad('n in component potassium_current_n_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,15) = strpad('n_infinity in component potassium_current_n_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,31) = strpad('tau_n in component potassium_current_n_gate (millisecond)');
LEGEND_CONSTANTS(:,144) = strpad('tau_n_max in component potassium_current_n_gate (millisecond)');
LEGEND_CONSTANTS(:,145) = strpad('theta_n in component potassium_current_n_gate (millivolt)');
LEGEND_CONSTANTS(:,146) = strpad('sigma_n in component potassium_current_n_gate (millivolt)');
LEGEND_CONSTANTS(:,147) = strpad('g_NaP in component persistent_sodium_current (nanoS)');
LEGEND_ALGEBRAIC(:,70) = strpad('m_infinity in component persistent_sodium_current_m_gate (dimensionless)');
LEGEND_STATES(:,20) = strpad('h in component persistent_sodium_current_h_gate (dimensionless)');
LEGEND_CONSTANTS(:,148) = strpad('theta_m in component persistent_sodium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,149) = strpad('sigma_m in component persistent_sodium_current_m_gate (millivolt)');
LEGEND_ALGEBRAIC(:,16) = strpad('h_infinity in component persistent_sodium_current_h_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,32) = strpad('tau_h in component persistent_sodium_current_h_gate (millisecond)');
LEGEND_CONSTANTS(:,150) = strpad('tau_h_max in component persistent_sodium_current_h_gate (millisecond)');
LEGEND_CONSTANTS(:,151) = strpad('theta_h in component persistent_sodium_current_h_gate (millivolt)');
LEGEND_CONSTANTS(:,152) = strpad('sigma_h in component persistent_sodium_current_h_gate (millivolt)');
LEGEND_CONSTANTS(:,153) = strpad('g_L in component leakage_current (nanoS)');
LEGEND_CONSTANTS(:,154) = strpad('E_L in component leakage_current (millivolt)');
LEGEND_CONSTANTS(:,155) = strpad('E_syn_e in component tonic_current (millivolt)');
LEGEND_CONSTANTS(:,156) = strpad('g_tonic_e in component tonic_current (nanoS)');
LEGEND_ALGEBRAIC(:,74) = strpad('s_infinity in component synaptic_input (dimensionless)');
LEGEND_CONSTANTS(:,157) = strpad('kr in component synaptic_input (dimensionless)');
LEGEND_CONSTANTS(:,158) = strpad('tau_s in component synaptic_input (millisecond)');
LEGEND_CONSTANTS(:,159) = strpad('sigma_s in component synaptic_input (millivolt)');
LEGEND_CONSTANTS(:,160) = strpad('theta_s in component synaptic_input (millivolt)');
LEGEND_RATES(:,1) = strpad('d/dt V in component membrane (millivolt)');
LEGEND_RATES(:,2) = strpad('d/dt n in component fast_sodium_current_n_gate (dimensionless)');
LEGEND_RATES(:,3) = strpad('d/dt n in component potassium_current_n_gate (dimensionless)');
LEGEND_RATES(:,4) = strpad('d/dt h in component persistent_sodium_current_h_gate (dimensionless)');
LEGEND_RATES(:,5) = strpad('d/dt V in component membrane (millivolt)');
LEGEND_RATES(:,6) = strpad('d/dt n in component fast_sodium_current_n_gate (dimensionless)');
LEGEND_RATES(:,7) = strpad('d/dt n in component potassium_current_n_gate (dimensionless)');
LEGEND_RATES(:,8) = strpad('d/dt h in component persistent_sodium_current_h_gate (dimensionless)');
LEGEND_RATES(:,9) = strpad('d/dt V in component membrane (millivolt)');
LEGEND_RATES(:,10) = strpad('d/dt n in component fast_sodium_current_n_gate (dimensionless)');
LEGEND_RATES(:,11) = strpad('d/dt n in component potassium_current_n_gate (dimensionless)');
LEGEND_RATES(:,12) = strpad('d/dt h in component persistent_sodium_current_h_gate (dimensionless)');
LEGEND_RATES(:,13) = strpad('d/dt V in component membrane (millivolt)');
LEGEND_RATES(:,14) = strpad('d/dt n in component fast_sodium_current_n_gate (dimensionless)');
LEGEND_RATES(:,15) = strpad('d/dt n in component potassium_current_n_gate (dimensionless)');
LEGEND_RATES(:,16) = strpad('d/dt h in component persistent_sodium_current_h_gate (dimensionless)');
LEGEND_RATES(:,17) = strpad('d/dt V in component membrane (millivolt)');
LEGEND_RATES(:,18) = strpad('d/dt n in component fast_sodium_current_n_gate (dimensionless)');
LEGEND_RATES(:,19) = strpad('d/dt n in component potassium_current_n_gate (dimensionless)');
LEGEND_RATES(:,20) = strpad('d/dt h in component persistent_sodium_current_h_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) = 0.10;
CONSTANTS(:,2) = 0.10;
CONSTANTS(:,3) = 0.10;
CONSTANTS(:,4) = 0.10;
CONSTANTS(:,5) = 0.10;
CONSTANTS(:,6) = 0.10;
CONSTANTS(:,7) = 0.10;
CONSTANTS(:,8) = 0.10;
CONSTANTS(:,9) = 0.10;
CONSTANTS(:,10) = 0.10;
CONSTANTS(:,11) = 0.10;
CONSTANTS(:,12) = 0.10;
CONSTANTS(:,13) = 0.10;
CONSTANTS(:,14) = 0.10;
CONSTANTS(:,15) = 0.10;
CONSTANTS(:,16) = 0.10;
CONSTANTS(:,17) = 0.10;
CONSTANTS(:,18) = 0.10;
CONSTANTS(:,19) = 0.10;
CONSTANTS(:,20) = 0.10;
STATES(:,1) = -50.0;
CONSTANTS(:,21) = 21.0;
CONSTANTS(:,22) = 0.0;
CONSTANTS(:,23) = 50.0;
CONSTANTS(:,24) = 28.0;
STATES(:,2) = 0.01;
CONSTANTS(:,25) = -34.0;
CONSTANTS(:,26) = -5.0;
CONSTANTS(:,27) = 10.0;
CONSTANTS(:,28) = -29.0;
CONSTANTS(:,29) = -4.0;
CONSTANTS(:,30) = 11.2;
CONSTANTS(:,31) = -85.0;
STATES(:,3) = 0.01;
CONSTANTS(:,32) = 10.0;
CONSTANTS(:,33) = -29.0;
CONSTANTS(:,34) = -4.0;
CONSTANTS(:,35) = 2.8;
STATES(:,4) = 0.46;
CONSTANTS(:,36) = -40.0;
CONSTANTS(:,37) = -6.0;
CONSTANTS(:,38) = 10000.0;
CONSTANTS(:,39) = -48.0;
CONSTANTS(:,40) = 6.0;
CONSTANTS(:,41) = 2.8;
CONSTANTS(:,42) = -57.5;
CONSTANTS(:,43) = 0.0;
CONSTANTS(:,44) = 0.0;
CONSTANTS(:,45) = 1.0;
CONSTANTS(:,46) = 5.0;
CONSTANTS(:,47) = -5.0;
CONSTANTS(:,48) = -10.0;
STATES(:,5) = -50.0;
CONSTANTS(:,49) = 21.0;
CONSTANTS(:,50) = 0.0;
CONSTANTS(:,51) = 50.0;
CONSTANTS(:,52) = 28.0;
STATES(:,6) = 0.01;
CONSTANTS(:,53) = -34.0;
CONSTANTS(:,54) = -5.0;
CONSTANTS(:,55) = 10.0;
CONSTANTS(:,56) = -29.0;
CONSTANTS(:,57) = -4.0;
CONSTANTS(:,58) = 11.2;
CONSTANTS(:,59) = -85.0;
STATES(:,7) = 0.01;
CONSTANTS(:,60) = 10.0;
CONSTANTS(:,61) = -29.0;
CONSTANTS(:,62) = -4.0;
CONSTANTS(:,63) = 2.8;
STATES(:,8) = 0.46;
CONSTANTS(:,64) = -40.0;
CONSTANTS(:,65) = -6.0;
CONSTANTS(:,66) = 10000.0;
CONSTANTS(:,67) = -48.0;
CONSTANTS(:,68) = 6.0;
CONSTANTS(:,69) = 2.8;
CONSTANTS(:,70) = -57.5;
CONSTANTS(:,71) = 0.0;
CONSTANTS(:,72) = 0.0;
CONSTANTS(:,73) = 1.0;
CONSTANTS(:,74) = 5.0;
CONSTANTS(:,75) = -5.0;
CONSTANTS(:,76) = -10.0;
STATES(:,9) = -50.0;
CONSTANTS(:,77) = 21.0;
CONSTANTS(:,78) = 0.0;
CONSTANTS(:,79) = 50.0;
CONSTANTS(:,80) = 28.0;
STATES(:,10) = 0.01;
CONSTANTS(:,81) = -34.0;
CONSTANTS(:,82) = -5.0;
CONSTANTS(:,83) = 10.0;
CONSTANTS(:,84) = -29.0;
CONSTANTS(:,85) = -4.0;
CONSTANTS(:,86) = 11.2;
CONSTANTS(:,87) = -85.0;
STATES(:,11) = 0.01;
CONSTANTS(:,88) = 10.0;
CONSTANTS(:,89) = -29.0;
CONSTANTS(:,90) = -4.0;
CONSTANTS(:,91) = 2.8;
STATES(:,12) = 0.46;
CONSTANTS(:,92) = -40.0;
CONSTANTS(:,93) = -6.0;
CONSTANTS(:,94) = 10000.0;
CONSTANTS(:,95) = -48.0;
CONSTANTS(:,96) = 6.0;
CONSTANTS(:,97) = 2.8;
CONSTANTS(:,98) = -57.5;
CONSTANTS(:,99) = 0.0;
CONSTANTS(:,100) = 0.0;
CONSTANTS(:,101) = 1.0;
CONSTANTS(:,102) = 5.0;
CONSTANTS(:,103) = -5.0;
CONSTANTS(:,104) = -10.0;
STATES(:,13) = -50.0;
CONSTANTS(:,105) = 21.0;
CONSTANTS(:,106) = 0.0;
CONSTANTS(:,107) = 50.0;
CONSTANTS(:,108) = 28.0;
STATES(:,14) = 0.01;
CONSTANTS(:,109) = -34.0;
CONSTANTS(:,110) = -5.0;
CONSTANTS(:,111) = 10.0;
CONSTANTS(:,112) = -29.0;
CONSTANTS(:,113) = -4.0;
CONSTANTS(:,114) = 11.2;
CONSTANTS(:,115) = -85.0;
STATES(:,15) = 0.01;
CONSTANTS(:,116) = 10.0;
CONSTANTS(:,117) = -29.0;
CONSTANTS(:,118) = -4.0;
CONSTANTS(:,119) = 2.8;
STATES(:,16) = 0.46;
CONSTANTS(:,120) = -40.0;
CONSTANTS(:,121) = -6.0;
CONSTANTS(:,122) = 10000.0;
CONSTANTS(:,123) = -48.0;
CONSTANTS(:,124) = 6.0;
CONSTANTS(:,125) = 2.8;
CONSTANTS(:,126) = -57.5;
CONSTANTS(:,127) = 0.0;
CONSTANTS(:,128) = 0.0;
CONSTANTS(:,129) = 1.0;
CONSTANTS(:,130) = 5.0;
CONSTANTS(:,131) = -5.0;
CONSTANTS(:,132) = -10.0;
STATES(:,17) = -50.0;
CONSTANTS(:,133) = 21.0;
CONSTANTS(:,134) = 0.0;
CONSTANTS(:,135) = 50.0;
CONSTANTS(:,136) = 28.0;
STATES(:,18) = 0.01;
CONSTANTS(:,137) = -34.0;
CONSTANTS(:,138) = -5.0;
CONSTANTS(:,139) = 10.0;
CONSTANTS(:,140) = -29.0;
CONSTANTS(:,141) = -4.0;
CONSTANTS(:,142) = 11.2;
CONSTANTS(:,143) = -85.0;
STATES(:,19) = 0.01;
CONSTANTS(:,144) = 10.0;
CONSTANTS(:,145) = -29.0;
CONSTANTS(:,146) = -4.0;
CONSTANTS(:,147) = 2.8;
STATES(:,20) = 0.46;
CONSTANTS(:,148) = -40.0;
CONSTANTS(:,149) = -6.0;
CONSTANTS(:,150) = 10000.0;
CONSTANTS(:,151) = -48.0;
CONSTANTS(:,152) = 6.0;
CONSTANTS(:,153) = 2.8;
CONSTANTS(:,154) = -57.5;
CONSTANTS(:,155) = 0.0;
CONSTANTS(:,156) = 0.0;
CONSTANTS(:,157) = 1.0;
CONSTANTS(:,158) = 5.0;
CONSTANTS(:,159) = -5.0;
CONSTANTS(:,160) = -10.0;
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);
else
statesRowCount = statesSize(1);
ALGEBRAIC = zeros(statesRowCount, algebraicVariableCount);
RATES = zeros(statesRowCount, statesColumnCount);
end
ALGEBRAIC(:,2) = 1.00000./(1.00000+exp((STATES(:,1) - CONSTANTS(:,28))./CONSTANTS(:,29)));
ALGEBRAIC(:,18) = CONSTANTS(:,27)./cosh((STATES(:,1) - CONSTANTS(:,28))./( 2.00000.*CONSTANTS(:,29)));
RATES(:,2) = (ALGEBRAIC(:,2) - STATES(:,2))./ALGEBRAIC(:,18);
ALGEBRAIC(:,3) = 1.00000./(1.00000+exp((STATES(:,1) - CONSTANTS(:,33))./CONSTANTS(:,34)));
ALGEBRAIC(:,19) = CONSTANTS(:,32)./cosh((STATES(:,1) - CONSTANTS(:,33))./( 2.00000.*CONSTANTS(:,34)));
RATES(:,3) = (ALGEBRAIC(:,3) - STATES(:,3))./ALGEBRAIC(:,19);
ALGEBRAIC(:,4) = 1.00000./(1.00000+exp((STATES(:,1) - CONSTANTS(:,39))./CONSTANTS(:,40)));
ALGEBRAIC(:,20) = CONSTANTS(:,38)./cosh((STATES(:,1) - CONSTANTS(:,39))./( 2.00000.*CONSTANTS(:,40)));
RATES(:,4) = (ALGEBRAIC(:,4) - STATES(:,4))./ALGEBRAIC(:,20);
ALGEBRAIC(:,5) = 1.00000./(1.00000+exp((STATES(:,5) - CONSTANTS(:,56))./CONSTANTS(:,57)));
ALGEBRAIC(:,21) = CONSTANTS(:,55)./cosh((STATES(:,5) - CONSTANTS(:,56))./( 2.00000.*CONSTANTS(:,57)));
RATES(:,6) = (ALGEBRAIC(:,5) - STATES(:,6))./ALGEBRAIC(:,21);
ALGEBRAIC(:,6) = 1.00000./(1.00000+exp((STATES(:,5) - CONSTANTS(:,61))./CONSTANTS(:,62)));
ALGEBRAIC(:,22) = CONSTANTS(:,60)./cosh((STATES(:,5) - CONSTANTS(:,61))./( 2.00000.*CONSTANTS(:,62)));
RATES(:,7) = (ALGEBRAIC(:,6) - STATES(:,7))./ALGEBRAIC(:,22);
ALGEBRAIC(:,7) = 1.00000./(1.00000+exp((STATES(:,5) - CONSTANTS(:,67))./CONSTANTS(:,68)));
ALGEBRAIC(:,23) = CONSTANTS(:,66)./cosh((STATES(:,5) - CONSTANTS(:,67))./( 2.00000.*CONSTANTS(:,68)));
RATES(:,8) = (ALGEBRAIC(:,7) - STATES(:,8))./ALGEBRAIC(:,23);
ALGEBRAIC(:,8) = 1.00000./(1.00000+exp((STATES(:,9) - CONSTANTS(:,84))./CONSTANTS(:,85)));
ALGEBRAIC(:,24) = CONSTANTS(:,83)./cosh((STATES(:,9) - CONSTANTS(:,84))./( 2.00000.*CONSTANTS(:,85)));
RATES(:,10) = (ALGEBRAIC(:,8) - STATES(:,10))./ALGEBRAIC(:,24);
ALGEBRAIC(:,9) = 1.00000./(1.00000+exp((STATES(:,9) - CONSTANTS(:,89))./CONSTANTS(:,90)));
ALGEBRAIC(:,25) = CONSTANTS(:,88)./cosh((STATES(:,9) - CONSTANTS(:,89))./( 2.00000.*CONSTANTS(:,90)));
RATES(:,11) = (ALGEBRAIC(:,9) - STATES(:,11))./ALGEBRAIC(:,25);
ALGEBRAIC(:,10) = 1.00000./(1.00000+exp((STATES(:,9) - CONSTANTS(:,95))./CONSTANTS(:,96)));
ALGEBRAIC(:,26) = CONSTANTS(:,94)./cosh((STATES(:,9) - CONSTANTS(:,95))./( 2.00000.*CONSTANTS(:,96)));
RATES(:,12) = (ALGEBRAIC(:,10) - STATES(:,12))./ALGEBRAIC(:,26);
ALGEBRAIC(:,11) = 1.00000./(1.00000+exp((STATES(:,13) - CONSTANTS(:,112))./CONSTANTS(:,113)));
ALGEBRAIC(:,27) = CONSTANTS(:,111)./cosh((STATES(:,13) - CONSTANTS(:,112))./( 2.00000.*CONSTANTS(:,113)));
RATES(:,14) = (ALGEBRAIC(:,11) - STATES(:,14))./ALGEBRAIC(:,27);
ALGEBRAIC(:,12) = 1.00000./(1.00000+exp((STATES(:,13) - CONSTANTS(:,117))./CONSTANTS(:,118)));
ALGEBRAIC(:,28) = CONSTANTS(:,116)./cosh((STATES(:,13) - CONSTANTS(:,117))./( 2.00000.*CONSTANTS(:,118)));
RATES(:,15) = (ALGEBRAIC(:,12) - STATES(:,15))./ALGEBRAIC(:,28);
ALGEBRAIC(:,13) = 1.00000./(1.00000+exp((STATES(:,13) - CONSTANTS(:,123))./CONSTANTS(:,124)));
ALGEBRAIC(:,29) = CONSTANTS(:,122)./cosh((STATES(:,13) - CONSTANTS(:,123))./( 2.00000.*CONSTANTS(:,124)));
RATES(:,16) = (ALGEBRAIC(:,13) - STATES(:,16))./ALGEBRAIC(:,29);
ALGEBRAIC(:,14) = 1.00000./(1.00000+exp((STATES(:,17) - CONSTANTS(:,140))./CONSTANTS(:,141)));
ALGEBRAIC(:,30) = CONSTANTS(:,139)./cosh((STATES(:,17) - CONSTANTS(:,140))./( 2.00000.*CONSTANTS(:,141)));
RATES(:,18) = (ALGEBRAIC(:,14) - STATES(:,18))./ALGEBRAIC(:,30);
ALGEBRAIC(:,15) = 1.00000./(1.00000+exp((STATES(:,17) - CONSTANTS(:,145))./CONSTANTS(:,146)));
ALGEBRAIC(:,31) = CONSTANTS(:,144)./cosh((STATES(:,17) - CONSTANTS(:,145))./( 2.00000.*CONSTANTS(:,146)));
RATES(:,19) = (ALGEBRAIC(:,15) - STATES(:,19))./ALGEBRAIC(:,31);
ALGEBRAIC(:,16) = 1.00000./(1.00000+exp((STATES(:,17) - CONSTANTS(:,151))./CONSTANTS(:,152)));
ALGEBRAIC(:,32) = CONSTANTS(:,150)./cosh((STATES(:,17) - CONSTANTS(:,151))./( 2.00000.*CONSTANTS(:,152)));
RATES(:,20) = (ALGEBRAIC(:,16) - STATES(:,20))./ALGEBRAIC(:,32);
ALGEBRAIC(:,34) = 1.00000./(1.00000+exp((STATES(:,1) - CONSTANTS(:,36))./CONSTANTS(:,37)));
ALGEBRAIC(:,35) =  CONSTANTS(:,35).*ALGEBRAIC(:,34).*STATES(:,4).*(STATES(:,1) - CONSTANTS(:,23));
ALGEBRAIC(:,1) = 1.00000./(1.00000+exp((STATES(:,1) - CONSTANTS(:,25))./CONSTANTS(:,26)));
ALGEBRAIC(:,17) =  CONSTANTS(:,24).*ALGEBRAIC(:,1) .^ 3.00000.*(1.00000 - STATES(:,2)).*(STATES(:,1) - CONSTANTS(:,23));
ALGEBRAIC(:,33) =  CONSTANTS(:,30).*STATES(:,3) .^ 4.00000.*(STATES(:,1) - CONSTANTS(:,31));
ALGEBRAIC(:,36) =  CONSTANTS(:,41).*(STATES(:,1) - CONSTANTS(:,42));
ALGEBRAIC(:,37) =  CONSTANTS(:,44).*(STATES(:,1) - CONSTANTS(:,43));
ALGEBRAIC(:,38) = 1.00000./(1.00000+exp((STATES(:,1) - CONSTANTS(:,48))./CONSTANTS(:,47)));
[CONSTANTS, STATES, ALGEBRAIC] = rootfind_0(VOI, CONSTANTS, STATES, ALGEBRAIC);
ALGEBRAIC(:,47) = 1.00000./(1.00000+exp((STATES(:,5) - CONSTANTS(:,76))./CONSTANTS(:,75)));
[CONSTANTS, STATES, ALGEBRAIC] = rootfind_1(VOI, CONSTANTS, STATES, ALGEBRAIC);
ALGEBRAIC(:,56) = 1.00000./(1.00000+exp((STATES(:,9) - CONSTANTS(:,104))./CONSTANTS(:,103)));
[CONSTANTS, STATES, ALGEBRAIC] = rootfind_2(VOI, CONSTANTS, STATES, ALGEBRAIC);
ALGEBRAIC(:,65) = 1.00000./(1.00000+exp((STATES(:,13) - CONSTANTS(:,132))./CONSTANTS(:,131)));
[CONSTANTS, STATES, ALGEBRAIC] = rootfind_3(VOI, CONSTANTS, STATES, ALGEBRAIC);
ALGEBRAIC(:,74) = 1.00000./(1.00000+exp((STATES(:,17) - CONSTANTS(:,160))./CONSTANTS(:,159)));
[CONSTANTS, STATES, ALGEBRAIC] = rootfind_4(VOI, CONSTANTS, STATES, ALGEBRAIC);
ALGEBRAIC(:,76) =  CONSTANTS(:,1).*ALGEBRAIC(:,39)+ CONSTANTS(:,2).*ALGEBRAIC(:,39)+ CONSTANTS(:,3).*ALGEBRAIC(:,39)+ CONSTANTS(:,4).*ALGEBRAIC(:,39)+ CONSTANTS(:,5).*ALGEBRAIC(:,48)+ CONSTANTS(:,6).*ALGEBRAIC(:,48)+ CONSTANTS(:,7).*ALGEBRAIC(:,48)+ CONSTANTS(:,8).*ALGEBRAIC(:,48)+ CONSTANTS(:,9).*ALGEBRAIC(:,57)+ CONSTANTS(:,10).*ALGEBRAIC(:,57)+ CONSTANTS(:,11).*ALGEBRAIC(:,57)+ CONSTANTS(:,12).*ALGEBRAIC(:,57)+ CONSTANTS(:,13).*ALGEBRAIC(:,66)+ CONSTANTS(:,14).*ALGEBRAIC(:,66)+ CONSTANTS(:,15).*ALGEBRAIC(:,66)+ CONSTANTS(:,16).*ALGEBRAIC(:,66)+ CONSTANTS(:,17).*ALGEBRAIC(:,75)+ CONSTANTS(:,18).*ALGEBRAIC(:,75)+ CONSTANTS(:,19).*ALGEBRAIC(:,75)+ CONSTANTS(:,20).*ALGEBRAIC(:,75);
ALGEBRAIC(:,77) =  ALGEBRAIC(:,76).*(STATES(:,1) - CONSTANTS(:,43));
RATES(:,1) = ( - (ALGEBRAIC(:,35)+ALGEBRAIC(:,17)+ALGEBRAIC(:,33)+ALGEBRAIC(:,36)+ALGEBRAIC(:,37)+ALGEBRAIC(:,77))+CONSTANTS(:,22))./CONSTANTS(:,21);
ALGEBRAIC(:,43) = 1.00000./(1.00000+exp((STATES(:,5) - CONSTANTS(:,64))./CONSTANTS(:,65)));
ALGEBRAIC(:,44) =  CONSTANTS(:,63).*ALGEBRAIC(:,43).*STATES(:,8).*(STATES(:,5) - CONSTANTS(:,51));
ALGEBRAIC(:,40) = 1.00000./(1.00000+exp((STATES(:,5) - CONSTANTS(:,53))./CONSTANTS(:,54)));
ALGEBRAIC(:,41) =  CONSTANTS(:,52).*ALGEBRAIC(:,40) .^ 3.00000.*(1.00000 - STATES(:,6)).*(STATES(:,5) - CONSTANTS(:,51));
ALGEBRAIC(:,42) =  CONSTANTS(:,58).*STATES(:,7) .^ 4.00000.*(STATES(:,5) - CONSTANTS(:,59));
ALGEBRAIC(:,45) =  CONSTANTS(:,69).*(STATES(:,5) - CONSTANTS(:,70));
ALGEBRAIC(:,46) =  CONSTANTS(:,72).*(STATES(:,5) - CONSTANTS(:,71));
ALGEBRAIC(:,78) =  ALGEBRAIC(:,76).*(STATES(:,5) - CONSTANTS(:,71));
RATES(:,5) = ( - (ALGEBRAIC(:,44)+ALGEBRAIC(:,41)+ALGEBRAIC(:,42)+ALGEBRAIC(:,45)+ALGEBRAIC(:,46)+ALGEBRAIC(:,78))+CONSTANTS(:,50))./CONSTANTS(:,49);
ALGEBRAIC(:,52) = 1.00000./(1.00000+exp((STATES(:,9) - CONSTANTS(:,92))./CONSTANTS(:,93)));
ALGEBRAIC(:,53) =  CONSTANTS(:,91).*ALGEBRAIC(:,52).*STATES(:,12).*(STATES(:,9) - CONSTANTS(:,79));
ALGEBRAIC(:,49) = 1.00000./(1.00000+exp((STATES(:,9) - CONSTANTS(:,81))./CONSTANTS(:,82)));
ALGEBRAIC(:,50) =  CONSTANTS(:,80).*ALGEBRAIC(:,49) .^ 3.00000.*(1.00000 - STATES(:,10)).*(STATES(:,9) - CONSTANTS(:,79));
ALGEBRAIC(:,51) =  CONSTANTS(:,86).*STATES(:,11) .^ 4.00000.*(STATES(:,9) - CONSTANTS(:,87));
ALGEBRAIC(:,54) =  CONSTANTS(:,97).*(STATES(:,9) - CONSTANTS(:,98));
ALGEBRAIC(:,55) =  CONSTANTS(:,100).*(STATES(:,9) - CONSTANTS(:,99));
ALGEBRAIC(:,79) =  ALGEBRAIC(:,76).*(STATES(:,9) - CONSTANTS(:,99));
RATES(:,9) = ( - (ALGEBRAIC(:,53)+ALGEBRAIC(:,50)+ALGEBRAIC(:,51)+ALGEBRAIC(:,54)+ALGEBRAIC(:,55)+ALGEBRAIC(:,79))+CONSTANTS(:,78))./CONSTANTS(:,77);
ALGEBRAIC(:,61) = 1.00000./(1.00000+exp((STATES(:,13) - CONSTANTS(:,120))./CONSTANTS(:,121)));
ALGEBRAIC(:,62) =  CONSTANTS(:,119).*ALGEBRAIC(:,61).*STATES(:,16).*(STATES(:,13) - CONSTANTS(:,107));
ALGEBRAIC(:,58) = 1.00000./(1.00000+exp((STATES(:,13) - CONSTANTS(:,109))./CONSTANTS(:,110)));
ALGEBRAIC(:,59) =  CONSTANTS(:,108).*ALGEBRAIC(:,58) .^ 3.00000.*(1.00000 - STATES(:,14)).*(STATES(:,13) - CONSTANTS(:,107));
ALGEBRAIC(:,60) =  CONSTANTS(:,114).*STATES(:,15) .^ 4.00000.*(STATES(:,13) - CONSTANTS(:,115));
ALGEBRAIC(:,63) =  CONSTANTS(:,125).*(STATES(:,13) - CONSTANTS(:,126));
ALGEBRAIC(:,64) =  CONSTANTS(:,128).*(STATES(:,13) - CONSTANTS(:,127));
ALGEBRAIC(:,80) =  ALGEBRAIC(:,76).*(STATES(:,13) - CONSTANTS(:,127));
RATES(:,13) = ( - (ALGEBRAIC(:,62)+ALGEBRAIC(:,59)+ALGEBRAIC(:,60)+ALGEBRAIC(:,63)+ALGEBRAIC(:,64)+ALGEBRAIC(:,80))+CONSTANTS(:,106))./CONSTANTS(:,105);
ALGEBRAIC(:,70) = 1.00000./(1.00000+exp((STATES(:,17) - CONSTANTS(:,148))./CONSTANTS(:,149)));
ALGEBRAIC(:,71) =  CONSTANTS(:,147).*ALGEBRAIC(:,70).*STATES(:,20).*(STATES(:,17) - CONSTANTS(:,135));
ALGEBRAIC(:,67) = 1.00000./(1.00000+exp((STATES(:,17) - CONSTANTS(:,137))./CONSTANTS(:,138)));
ALGEBRAIC(:,68) =  CONSTANTS(:,136).*ALGEBRAIC(:,67) .^ 3.00000.*(1.00000 - STATES(:,18)).*(STATES(:,17) - CONSTANTS(:,135));
ALGEBRAIC(:,69) =  CONSTANTS(:,142).*STATES(:,19) .^ 4.00000.*(STATES(:,17) - CONSTANTS(:,143));
ALGEBRAIC(:,72) =  CONSTANTS(:,153).*(STATES(:,17) - CONSTANTS(:,154));
ALGEBRAIC(:,73) =  CONSTANTS(:,156).*(STATES(:,17) - CONSTANTS(:,155));
ALGEBRAIC(:,81) =  ALGEBRAIC(:,76).*(STATES(:,17) - CONSTANTS(:,155));
RATES(:,17) = ( - (ALGEBRAIC(:,71)+ALGEBRAIC(:,68)+ALGEBRAIC(:,69)+ALGEBRAIC(:,72)+ALGEBRAIC(:,73)+ALGEBRAIC(:,81))+CONSTANTS(:,134))./CONSTANTS(:,133);
RATES = RATES';
end

% Calculate algebraic variables
function ALGEBRAIC = computeAlgebraic(ALGEBRAIC, CONSTANTS, STATES, VOI)
ALGEBRAIC(:,2) = 1.00000./(1.00000+exp((STATES(:,1) - CONSTANTS(:,28))./CONSTANTS(:,29)));
ALGEBRAIC(:,18) = CONSTANTS(:,27)./cosh((STATES(:,1) - CONSTANTS(:,28))./( 2.00000.*CONSTANTS(:,29)));
ALGEBRAIC(:,3) = 1.00000./(1.00000+exp((STATES(:,1) - CONSTANTS(:,33))./CONSTANTS(:,34)));
ALGEBRAIC(:,19) = CONSTANTS(:,32)./cosh((STATES(:,1) - CONSTANTS(:,33))./( 2.00000.*CONSTANTS(:,34)));
ALGEBRAIC(:,4) = 1.00000./(1.00000+exp((STATES(:,1) - CONSTANTS(:,39))./CONSTANTS(:,40)));
ALGEBRAIC(:,20) = CONSTANTS(:,38)./cosh((STATES(:,1) - CONSTANTS(:,39))./( 2.00000.*CONSTANTS(:,40)));
ALGEBRAIC(:,5) = 1.00000./(1.00000+exp((STATES(:,5) - CONSTANTS(:,56))./CONSTANTS(:,57)));
ALGEBRAIC(:,21) = CONSTANTS(:,55)./cosh((STATES(:,5) - CONSTANTS(:,56))./( 2.00000.*CONSTANTS(:,57)));
ALGEBRAIC(:,6) = 1.00000./(1.00000+exp((STATES(:,5) - CONSTANTS(:,61))./CONSTANTS(:,62)));
ALGEBRAIC(:,22) = CONSTANTS(:,60)./cosh((STATES(:,5) - CONSTANTS(:,61))./( 2.00000.*CONSTANTS(:,62)));
ALGEBRAIC(:,7) = 1.00000./(1.00000+exp((STATES(:,5) - CONSTANTS(:,67))./CONSTANTS(:,68)));
ALGEBRAIC(:,23) = CONSTANTS(:,66)./cosh((STATES(:,5) - CONSTANTS(:,67))./( 2.00000.*CONSTANTS(:,68)));
ALGEBRAIC(:,8) = 1.00000./(1.00000+exp((STATES(:,9) - CONSTANTS(:,84))./CONSTANTS(:,85)));
ALGEBRAIC(:,24) = CONSTANTS(:,83)./cosh((STATES(:,9) - CONSTANTS(:,84))./( 2.00000.*CONSTANTS(:,85)));
ALGEBRAIC(:,9) = 1.00000./(1.00000+exp((STATES(:,9) - CONSTANTS(:,89))./CONSTANTS(:,90)));
ALGEBRAIC(:,25) = CONSTANTS(:,88)./cosh((STATES(:,9) - CONSTANTS(:,89))./( 2.00000.*CONSTANTS(:,90)));
ALGEBRAIC(:,10) = 1.00000./(1.00000+exp((STATES(:,9) - CONSTANTS(:,95))./CONSTANTS(:,96)));
ALGEBRAIC(:,26) = CONSTANTS(:,94)./cosh((STATES(:,9) - CONSTANTS(:,95))./( 2.00000.*CONSTANTS(:,96)));
ALGEBRAIC(:,11) = 1.00000./(1.00000+exp((STATES(:,13) - CONSTANTS(:,112))./CONSTANTS(:,113)));
ALGEBRAIC(:,27) = CONSTANTS(:,111)./cosh((STATES(:,13) - CONSTANTS(:,112))./( 2.00000.*CONSTANTS(:,113)));
ALGEBRAIC(:,12) = 1.00000./(1.00000+exp((STATES(:,13) - CONSTANTS(:,117))./CONSTANTS(:,118)));
ALGEBRAIC(:,28) = CONSTANTS(:,116)./cosh((STATES(:,13) - CONSTANTS(:,117))./( 2.00000.*CONSTANTS(:,118)));
ALGEBRAIC(:,13) = 1.00000./(1.00000+exp((STATES(:,13) - CONSTANTS(:,123))./CONSTANTS(:,124)));
ALGEBRAIC(:,29) = CONSTANTS(:,122)./cosh((STATES(:,13) - CONSTANTS(:,123))./( 2.00000.*CONSTANTS(:,124)));
ALGEBRAIC(:,14) = 1.00000./(1.00000+exp((STATES(:,17) - CONSTANTS(:,140))./CONSTANTS(:,141)));
ALGEBRAIC(:,30) = CONSTANTS(:,139)./cosh((STATES(:,17) - CONSTANTS(:,140))./( 2.00000.*CONSTANTS(:,141)));
ALGEBRAIC(:,15) = 1.00000./(1.00000+exp((STATES(:,17) - CONSTANTS(:,145))./CONSTANTS(:,146)));
ALGEBRAIC(:,31) = CONSTANTS(:,144)./cosh((STATES(:,17) - CONSTANTS(:,145))./( 2.00000.*CONSTANTS(:,146)));
ALGEBRAIC(:,16) = 1.00000./(1.00000+exp((STATES(:,17) - CONSTANTS(:,151))./CONSTANTS(:,152)));
ALGEBRAIC(:,32) = CONSTANTS(:,150)./cosh((STATES(:,17) - CONSTANTS(:,151))./( 2.00000.*CONSTANTS(:,152)));
ALGEBRAIC(:,34) = 1.00000./(1.00000+exp((STATES(:,1) - CONSTANTS(:,36))./CONSTANTS(:,37)));
ALGEBRAIC(:,35) =  CONSTANTS(:,35).*ALGEBRAIC(:,34).*STATES(:,4).*(STATES(:,1) - CONSTANTS(:,23));
ALGEBRAIC(:,1) = 1.00000./(1.00000+exp((STATES(:,1) - CONSTANTS(:,25))./CONSTANTS(:,26)));
ALGEBRAIC(:,17) =  CONSTANTS(:,24).*ALGEBRAIC(:,1) .^ 3.00000.*(1.00000 - STATES(:,2)).*(STATES(:,1) - CONSTANTS(:,23));
ALGEBRAIC(:,33) =  CONSTANTS(:,30).*STATES(:,3) .^ 4.00000.*(STATES(:,1) - CONSTANTS(:,31));
ALGEBRAIC(:,36) =  CONSTANTS(:,41).*(STATES(:,1) - CONSTANTS(:,42));
ALGEBRAIC(:,37) =  CONSTANTS(:,44).*(STATES(:,1) - CONSTANTS(:,43));
ALGEBRAIC(:,38) = 1.00000./(1.00000+exp((STATES(:,1) - CONSTANTS(:,48))./CONSTANTS(:,47)));
ALGEBRAIC(:,47) = 1.00000./(1.00000+exp((STATES(:,5) - CONSTANTS(:,76))./CONSTANTS(:,75)));
ALGEBRAIC(:,56) = 1.00000./(1.00000+exp((STATES(:,9) - CONSTANTS(:,104))./CONSTANTS(:,103)));
ALGEBRAIC(:,65) = 1.00000./(1.00000+exp((STATES(:,13) - CONSTANTS(:,132))./CONSTANTS(:,131)));
ALGEBRAIC(:,74) = 1.00000./(1.00000+exp((STATES(:,17) - CONSTANTS(:,160))./CONSTANTS(:,159)));
ALGEBRAIC(:,76) =  CONSTANTS(:,1).*ALGEBRAIC(:,39)+ CONSTANTS(:,2).*ALGEBRAIC(:,39)+ CONSTANTS(:,3).*ALGEBRAIC(:,39)+ CONSTANTS(:,4).*ALGEBRAIC(:,39)+ CONSTANTS(:,5).*ALGEBRAIC(:,48)+ CONSTANTS(:,6).*ALGEBRAIC(:,48)+ CONSTANTS(:,7).*ALGEBRAIC(:,48)+ CONSTANTS(:,8).*ALGEBRAIC(:,48)+ CONSTANTS(:,9).*ALGEBRAIC(:,57)+ CONSTANTS(:,10).*ALGEBRAIC(:,57)+ CONSTANTS(:,11).*ALGEBRAIC(:,57)+ CONSTANTS(:,12).*ALGEBRAIC(:,57)+ CONSTANTS(:,13).*ALGEBRAIC(:,66)+ CONSTANTS(:,14).*ALGEBRAIC(:,66)+ CONSTANTS(:,15).*ALGEBRAIC(:,66)+ CONSTANTS(:,16).*ALGEBRAIC(:,66)+ CONSTANTS(:,17).*ALGEBRAIC(:,75)+ CONSTANTS(:,18).*ALGEBRAIC(:,75)+ CONSTANTS(:,19).*ALGEBRAIC(:,75)+ CONSTANTS(:,20).*ALGEBRAIC(:,75);
ALGEBRAIC(:,77) =  ALGEBRAIC(:,76).*(STATES(:,1) - CONSTANTS(:,43));
ALGEBRAIC(:,43) = 1.00000./(1.00000+exp((STATES(:,5) - CONSTANTS(:,64))./CONSTANTS(:,65)));
ALGEBRAIC(:,44) =  CONSTANTS(:,63).*ALGEBRAIC(:,43).*STATES(:,8).*(STATES(:,5) - CONSTANTS(:,51));
ALGEBRAIC(:,40) = 1.00000./(1.00000+exp((STATES(:,5) - CONSTANTS(:,53))./CONSTANTS(:,54)));
ALGEBRAIC(:,41) =  CONSTANTS(:,52).*ALGEBRAIC(:,40) .^ 3.00000.*(1.00000 - STATES(:,6)).*(STATES(:,5) - CONSTANTS(:,51));
ALGEBRAIC(:,42) =  CONSTANTS(:,58).*STATES(:,7) .^ 4.00000.*(STATES(:,5) - CONSTANTS(:,59));
ALGEBRAIC(:,45) =  CONSTANTS(:,69).*(STATES(:,5) - CONSTANTS(:,70));
ALGEBRAIC(:,46) =  CONSTANTS(:,72).*(STATES(:,5) - CONSTANTS(:,71));
ALGEBRAIC(:,78) =  ALGEBRAIC(:,76).*(STATES(:,5) - CONSTANTS(:,71));
ALGEBRAIC(:,52) = 1.00000./(1.00000+exp((STATES(:,9) - CONSTANTS(:,92))./CONSTANTS(:,93)));
ALGEBRAIC(:,53) =  CONSTANTS(:,91).*ALGEBRAIC(:,52).*STATES(:,12).*(STATES(:,9) - CONSTANTS(:,79));
ALGEBRAIC(:,49) = 1.00000./(1.00000+exp((STATES(:,9) - CONSTANTS(:,81))./CONSTANTS(:,82)));
ALGEBRAIC(:,50) =  CONSTANTS(:,80).*ALGEBRAIC(:,49) .^ 3.00000.*(1.00000 - STATES(:,10)).*(STATES(:,9) - CONSTANTS(:,79));
ALGEBRAIC(:,51) =  CONSTANTS(:,86).*STATES(:,11) .^ 4.00000.*(STATES(:,9) - CONSTANTS(:,87));
ALGEBRAIC(:,54) =  CONSTANTS(:,97).*(STATES(:,9) - CONSTANTS(:,98));
ALGEBRAIC(:,55) =  CONSTANTS(:,100).*(STATES(:,9) - CONSTANTS(:,99));
ALGEBRAIC(:,79) =  ALGEBRAIC(:,76).*(STATES(:,9) - CONSTANTS(:,99));
ALGEBRAIC(:,61) = 1.00000./(1.00000+exp((STATES(:,13) - CONSTANTS(:,120))./CONSTANTS(:,121)));
ALGEBRAIC(:,62) =  CONSTANTS(:,119).*ALGEBRAIC(:,61).*STATES(:,16).*(STATES(:,13) - CONSTANTS(:,107));
ALGEBRAIC(:,58) = 1.00000./(1.00000+exp((STATES(:,13) - CONSTANTS(:,109))./CONSTANTS(:,110)));
ALGEBRAIC(:,59) =  CONSTANTS(:,108).*ALGEBRAIC(:,58) .^ 3.00000.*(1.00000 - STATES(:,14)).*(STATES(:,13) - CONSTANTS(:,107));
ALGEBRAIC(:,60) =  CONSTANTS(:,114).*STATES(:,15) .^ 4.00000.*(STATES(:,13) - CONSTANTS(:,115));
ALGEBRAIC(:,63) =  CONSTANTS(:,125).*(STATES(:,13) - CONSTANTS(:,126));
ALGEBRAIC(:,64) =  CONSTANTS(:,128).*(STATES(:,13) - CONSTANTS(:,127));
ALGEBRAIC(:,80) =  ALGEBRAIC(:,76).*(STATES(:,13) - CONSTANTS(:,127));
ALGEBRAIC(:,70) = 1.00000./(1.00000+exp((STATES(:,17) - CONSTANTS(:,148))./CONSTANTS(:,149)));
ALGEBRAIC(:,71) =  CONSTANTS(:,147).*ALGEBRAIC(:,70).*STATES(:,20).*(STATES(:,17) - CONSTANTS(:,135));
ALGEBRAIC(:,67) = 1.00000./(1.00000+exp((STATES(:,17) - CONSTANTS(:,137))./CONSTANTS(:,138)));
ALGEBRAIC(:,68) =  CONSTANTS(:,136).*ALGEBRAIC(:,67) .^ 3.00000.*(1.00000 - STATES(:,18)).*(STATES(:,17) - CONSTANTS(:,135));
ALGEBRAIC(:,69) =  CONSTANTS(:,142).*STATES(:,19) .^ 4.00000.*(STATES(:,17) - CONSTANTS(:,143));
ALGEBRAIC(:,72) =  CONSTANTS(:,153).*(STATES(:,17) - CONSTANTS(:,154));
ALGEBRAIC(:,73) =  CONSTANTS(:,156).*(STATES(:,17) - CONSTANTS(:,155));
ALGEBRAIC(:,81) =  ALGEBRAIC(:,76).*(STATES(:,17) - CONSTANTS(:,155));
end

% Functions required for solving differential algebraic equation
function [CONSTANTS, STATES, ALGEBRAIC] = rootfind_0(VOI, CONSTANTS_IN, STATES_IN, ALGEBRAIC_IN)
CONSTANTS = CONSTANTS_IN;
STATES = STATES_IN;
ALGEBRAIC = ALGEBRAIC_IN;
global initialGuess_0;
if (length(initialGuess_0) ~= 1), initialGuess_0 = 0.1;, end
options = optimset('Display', 'off', 'TolX', 1E-6);
if length(VOI) == 1
residualfn = @(algebraicCandidate)residualSN_0(algebraicCandidate, ALGEBRAIC, VOI, CONSTANTS, STATES);
ALGEBRAIC(:,39) = fsolve(residualfn, initialGuess_0, options);
initialGuess_0 = ALGEBRAIC(:,39);
else
SET_ALGEBRAIC(:,39) = logical(1);
for i=1:length(VOI)
residualfn = @(algebraicCandidate)residualSN_0(algebraicCandidate, ALGEBRAIC(i,:), VOI(i), CONSTANTS, STATES(i,:));
TEMP_ALGEBRAIC(:,39) = fsolve(residualfn, initialGuess_0, options);
ALGEBRAIC(i,SET_ALGEBRAIC) = TEMP_ALGEBRAIC(SET_ALGEBRAIC);
initialGuess_0 = TEMP_ALGEBRAIC(:,39);
end
end
end

function resid = residualSN_0(algebraicCandidate, ALGEBRAIC, VOI, CONSTANTS, STATES)
ALGEBRAIC(:,39) = algebraicCandidate;
resid = (ALGEBRAIC(:,39)) - (( (1.00000 - ALGEBRAIC(:,39)).*ALGEBRAIC(:,38) -  - ( CONSTANTS(:,45).*ALGEBRAIC(:,39)))./CONSTANTS(:,46));
end

% Functions required for solving differential algebraic equation
function [CONSTANTS, STATES, ALGEBRAIC] = rootfind_1(VOI, CONSTANTS_IN, STATES_IN, ALGEBRAIC_IN)
CONSTANTS = CONSTANTS_IN;
STATES = STATES_IN;
ALGEBRAIC = ALGEBRAIC_IN;
global initialGuess_1;
if (length(initialGuess_1) ~= 1), initialGuess_1 = 0.1;, end
options = optimset('Display', 'off', 'TolX', 1E-6);
if length(VOI) == 1
residualfn = @(algebraicCandidate)residualSN_1(algebraicCandidate, ALGEBRAIC, VOI, CONSTANTS, STATES);
ALGEBRAIC(:,48) = fsolve(residualfn, initialGuess_1, options);
initialGuess_1 = ALGEBRAIC(:,48);
else
SET_ALGEBRAIC(:,48) = logical(1);
for i=1:length(VOI)
residualfn = @(algebraicCandidate)residualSN_1(algebraicCandidate, ALGEBRAIC(i,:), VOI(i), CONSTANTS, STATES(i,:));
TEMP_ALGEBRAIC(:,48) = fsolve(residualfn, initialGuess_1, options);
ALGEBRAIC(i,SET_ALGEBRAIC) = TEMP_ALGEBRAIC(SET_ALGEBRAIC);
initialGuess_1 = TEMP_ALGEBRAIC(:,48);
end
end
end

function resid = residualSN_1(algebraicCandidate, ALGEBRAIC, VOI, CONSTANTS, STATES)
ALGEBRAIC(:,48) = algebraicCandidate;
resid = (ALGEBRAIC(:,48)) - (( (1.00000 - ALGEBRAIC(:,48)).*ALGEBRAIC(:,47) -  - ( CONSTANTS(:,73).*ALGEBRAIC(:,48)))./CONSTANTS(:,74));
end

% Functions required for solving differential algebraic equation
function [CONSTANTS, STATES, ALGEBRAIC] = rootfind_2(VOI, CONSTANTS_IN, STATES_IN, ALGEBRAIC_IN)
CONSTANTS = CONSTANTS_IN;
STATES = STATES_IN;
ALGEBRAIC = ALGEBRAIC_IN;
global initialGuess_2;
if (length(initialGuess_2) ~= 1), initialGuess_2 = 0.1;, end
options = optimset('Display', 'off', 'TolX', 1E-6);
if length(VOI) == 1
residualfn = @(algebraicCandidate)residualSN_2(algebraicCandidate, ALGEBRAIC, VOI, CONSTANTS, STATES);
ALGEBRAIC(:,57) = fsolve(residualfn, initialGuess_2, options);
initialGuess_2 = ALGEBRAIC(:,57);
else
SET_ALGEBRAIC(:,57) = logical(1);
for i=1:length(VOI)
residualfn = @(algebraicCandidate)residualSN_2(algebraicCandidate, ALGEBRAIC(i,:), VOI(i), CONSTANTS, STATES(i,:));
TEMP_ALGEBRAIC(:,57) = fsolve(residualfn, initialGuess_2, options);
ALGEBRAIC(i,SET_ALGEBRAIC) = TEMP_ALGEBRAIC(SET_ALGEBRAIC);
initialGuess_2 = TEMP_ALGEBRAIC(:,57);
end
end
end

function resid = residualSN_2(algebraicCandidate, ALGEBRAIC, VOI, CONSTANTS, STATES)
ALGEBRAIC(:,57) = algebraicCandidate;
resid = (ALGEBRAIC(:,57)) - (( (1.00000 - ALGEBRAIC(:,57)).*ALGEBRAIC(:,56) -  - ( CONSTANTS(:,101).*ALGEBRAIC(:,57)))./CONSTANTS(:,102));
end

% Functions required for solving differential algebraic equation
function [CONSTANTS, STATES, ALGEBRAIC] = rootfind_3(VOI, CONSTANTS_IN, STATES_IN, ALGEBRAIC_IN)
CONSTANTS = CONSTANTS_IN;
STATES = STATES_IN;
ALGEBRAIC = ALGEBRAIC_IN;
global initialGuess_3;
if (length(initialGuess_3) ~= 1), initialGuess_3 = 0.1;, end
options = optimset('Display', 'off', 'TolX', 1E-6);
if length(VOI) == 1
residualfn = @(algebraicCandidate)residualSN_3(algebraicCandidate, ALGEBRAIC, VOI, CONSTANTS, STATES);
ALGEBRAIC(:,66) = fsolve(residualfn, initialGuess_3, options);
initialGuess_3 = ALGEBRAIC(:,66);
else
SET_ALGEBRAIC(:,66) = logical(1);
for i=1:length(VOI)
residualfn = @(algebraicCandidate)residualSN_3(algebraicCandidate, ALGEBRAIC(i,:), VOI(i), CONSTANTS, STATES(i,:));
TEMP_ALGEBRAIC(:,66) = fsolve(residualfn, initialGuess_3, options);
ALGEBRAIC(i,SET_ALGEBRAIC) = TEMP_ALGEBRAIC(SET_ALGEBRAIC);
initialGuess_3 = TEMP_ALGEBRAIC(:,66);
end
end
end

function resid = residualSN_3(algebraicCandidate, ALGEBRAIC, VOI, CONSTANTS, STATES)
ALGEBRAIC(:,66) = algebraicCandidate;
resid = (ALGEBRAIC(:,66)) - (( (1.00000 - ALGEBRAIC(:,66)).*ALGEBRAIC(:,65) -  - ( CONSTANTS(:,129).*ALGEBRAIC(:,66)))./CONSTANTS(:,130));
end

% Functions required for solving differential algebraic equation
function [CONSTANTS, STATES, ALGEBRAIC] = rootfind_4(VOI, CONSTANTS_IN, STATES_IN, ALGEBRAIC_IN)
CONSTANTS = CONSTANTS_IN;
STATES = STATES_IN;
ALGEBRAIC = ALGEBRAIC_IN;
global initialGuess_4;
if (length(initialGuess_4) ~= 1), initialGuess_4 = 0.1;, end
options = optimset('Display', 'off', 'TolX', 1E-6);
if length(VOI) == 1
residualfn = @(algebraicCandidate)residualSN_4(algebraicCandidate, ALGEBRAIC, VOI, CONSTANTS, STATES);
ALGEBRAIC(:,75) = fsolve(residualfn, initialGuess_4, options);
initialGuess_4 = ALGEBRAIC(:,75);
else
SET_ALGEBRAIC(:,75) = logical(1);
for i=1:length(VOI)
residualfn = @(algebraicCandidate)residualSN_4(algebraicCandidate, ALGEBRAIC(i,:), VOI(i), CONSTANTS, STATES(i,:));
TEMP_ALGEBRAIC(:,75) = fsolve(residualfn, initialGuess_4, options);
ALGEBRAIC(i,SET_ALGEBRAIC) = TEMP_ALGEBRAIC(SET_ALGEBRAIC);
initialGuess_4 = TEMP_ALGEBRAIC(:,75);
end
end
end

function resid = residualSN_4(algebraicCandidate, ALGEBRAIC, VOI, CONSTANTS, STATES)
ALGEBRAIC(:,75) = algebraicCandidate;
resid = (ALGEBRAIC(:,75)) - (( (1.00000 - ALGEBRAIC(:,75)).*ALGEBRAIC(:,74) -  - ( CONSTANTS(:,157).*ALGEBRAIC(:,75)))./CONSTANTS(:,158));
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 Butera, Rinzel, Smith II 1999 at changeset 263f827f246b.
This exposure was expired.
Collaboration
To begin collaborating on this work, please use your git client and issue this command: