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 =31;
end
% There are a total of 16 entries in each of the rate and state variable arrays.
% There are a total of 72 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('C in component membrane (uF)');
LEGEND_ALGEBRAIC(:,1) = strpad('i_Na in component sodium_current (nanoA)');
LEGEND_ALGEBRAIC(:,16) = strpad('i_NaP in component persistent_sodium_current (nanoA)');
LEGEND_ALGEBRAIC(:,23) = strpad('i_K in component delayed_rectifier_current (nanoA)');
LEGEND_ALGEBRAIC(:,24) = strpad('i_leak in component leak_current (nanoA)');
LEGEND_ALGEBRAIC(:,25) = strpad('i_T in component LVA_calcium_current (nanoA)');
LEGEND_ALGEBRAIC(:,26) = strpad('i_N in component N_HVA_calcium_current (nanoA)');
LEGEND_ALGEBRAIC(:,27) = strpad('i_P in component P_HVA_calcium_current (nanoA)');
LEGEND_ALGEBRAIC(:,28) = strpad('i_SK in component calcium_dependent_potassium_current (nanoA)');
LEGEND_ALGEBRAIC(:,29) = strpad('i_A in component fast_transient_potassium_current (nanoA)');
LEGEND_ALGEBRAIC(:,30) = strpad('i_H in component hyperpolarization_activated_current (nanoA)');
LEGEND_ALGEBRAIC(:,31) = strpad('i_app in component stimulus_protocol (nanoA)');
LEGEND_CONSTANTS(:,2) = strpad('g_Na in component sodium_current (uS)');
LEGEND_CONSTANTS(:,3) = strpad('E_Na in component sodium_current (millivolt)');
LEGEND_STATES(:,2) = strpad('m in component sodium_current_m_gate (dimensionless)');
LEGEND_STATES(:,3) = strpad('h in component sodium_current_h_gate (dimensionless)');
LEGEND_CONSTANTS(:,4) = strpad('theta_h in component sodium_current_h_gate (millivolt)');
LEGEND_CONSTANTS(:,5) = strpad('sigma_h in component sodium_current_h_gate (millivolt)');
LEGEND_CONSTANTS(:,6) = strpad('theta_1 in component sodium_current_h_gate (millivolt)');
LEGEND_CONSTANTS(:,7) = strpad('sigma_1 in component sodium_current_h_gate (millivolt)');
LEGEND_CONSTANTS(:,8) = strpad('sigma_2 in component sodium_current_h_gate (millivolt)');
LEGEND_ALGEBRAIC(:,2) = strpad('tau_h in component sodium_current_h_gate (millisecond)');
LEGEND_ALGEBRAIC(:,17) = strpad('h_infinity in component sodium_current_h_gate (dimensionless)');
LEGEND_CONSTANTS(:,9) = strpad('theta_m in component sodium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,10) = strpad('sigma_m in component sodium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,11) = strpad('tau_m in component sodium_current_m_gate (millisecond)');
LEGEND_ALGEBRAIC(:,3) = strpad('m_infinity in component sodium_current_m_gate (dimensionless)');
LEGEND_CONSTANTS(:,12) = strpad('g_NaP in component persistent_sodium_current (uS)');
LEGEND_STATES(:,4) = strpad('m in component persistent_sodium_current_m_gate (dimensionless)');
LEGEND_STATES(:,5) = strpad('h in component persistent_sodium_current_h_gate (dimensionless)');
LEGEND_CONSTANTS(:,13) = strpad('theta_h in component persistent_sodium_current_h_gate (millivolt)');
LEGEND_CONSTANTS(:,14) = strpad('sigma_h in component persistent_sodium_current_h_gate (millivolt)');
LEGEND_CONSTANTS(:,15) = strpad('tau_h in component persistent_sodium_current_h_gate (millisecond)');
LEGEND_ALGEBRAIC(:,4) = strpad('h_infinity in component persistent_sodium_current_h_gate (dimensionless)');
LEGEND_CONSTANTS(:,16) = strpad('theta_m in component persistent_sodium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,17) = strpad('sigma_m in component persistent_sodium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,18) = strpad('tau_m in component persistent_sodium_current_m_gate (millisecond)');
LEGEND_ALGEBRAIC(:,5) = strpad('m_infinity in component persistent_sodium_current_m_gate (dimensionless)');
LEGEND_CONSTANTS(:,19) = strpad('g_K in component delayed_rectifier_current (uS)');
LEGEND_CONSTANTS(:,20) = strpad('E_K in component delayed_rectifier_current (millivolt)');
LEGEND_STATES(:,6) = strpad('n in component delayed_rectifier_current_n_gate (dimensionless)');
LEGEND_CONSTANTS(:,21) = strpad('theta_n in component delayed_rectifier_current_n_gate (millivolt)');
LEGEND_CONSTANTS(:,22) = strpad('sigma_n in component delayed_rectifier_current_n_gate (millivolt)');
LEGEND_CONSTANTS(:,23) = strpad('theta_1 in component delayed_rectifier_current_n_gate (millivolt)');
LEGEND_CONSTANTS(:,24) = strpad('sigma_1 in component delayed_rectifier_current_n_gate (millivolt)');
LEGEND_CONSTANTS(:,25) = strpad('sigma_2 in component delayed_rectifier_current_n_gate (millivolt)');
LEGEND_ALGEBRAIC(:,6) = strpad('tau_n in component delayed_rectifier_current_n_gate (millisecond)');
LEGEND_ALGEBRAIC(:,18) = strpad('n_infinity in component delayed_rectifier_current_n_gate (dimensionless)');
LEGEND_CONSTANTS(:,26) = strpad('g_leak in component leak_current (uS)');
LEGEND_CONSTANTS(:,27) = strpad('E_leak in component leak_current (millivolt)');
LEGEND_CONSTANTS(:,28) = strpad('g_T in component LVA_calcium_current (uS)');
LEGEND_CONSTANTS(:,29) = strpad('E_Ca in component LVA_calcium_current (millivolt)');
LEGEND_STATES(:,7) = strpad('m in component LVA_calcium_current_m_gate (dimensionless)');
LEGEND_STATES(:,8) = strpad('h in component LVA_calcium_current_h_gate (dimensionless)');
LEGEND_CONSTANTS(:,30) = strpad('theta_m in component LVA_calcium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,31) = strpad('sigma_m in component LVA_calcium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,32) = strpad('theta_1 in component LVA_calcium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,33) = strpad('sigma_1 in component LVA_calcium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,34) = strpad('sigma_2 in component LVA_calcium_current_m_gate (millivolt)');
LEGEND_ALGEBRAIC(:,7) = strpad('tau_m in component LVA_calcium_current_m_gate (millisecond)');
LEGEND_ALGEBRAIC(:,19) = strpad('m_infinity in component LVA_calcium_current_m_gate (dimensionless)');
LEGEND_CONSTANTS(:,35) = strpad('theta_h in component LVA_calcium_current_h_gate (millivolt)');
LEGEND_CONSTANTS(:,36) = strpad('sigma_h in component LVA_calcium_current_h_gate (millivolt)');
LEGEND_CONSTANTS(:,37) = strpad('theta_1 in component LVA_calcium_current_h_gate (millivolt)');
LEGEND_CONSTANTS(:,38) = strpad('sigma_1 in component LVA_calcium_current_h_gate (millivolt)');
LEGEND_ALGEBRAIC(:,8) = strpad('tau_h in component LVA_calcium_current_h_gate (millisecond)');
LEGEND_ALGEBRAIC(:,20) = strpad('h_infinity in component LVA_calcium_current_h_gate (dimensionless)');
LEGEND_CONSTANTS(:,39) = strpad('g_N in component N_HVA_calcium_current (uS)');
LEGEND_STATES(:,9) = strpad('m in component N_HVA_calcium_current_m_gate (dimensionless)');
LEGEND_STATES(:,10) = strpad('h in component N_HVA_calcium_current_h_gate (dimensionless)');
LEGEND_CONSTANTS(:,40) = strpad('theta_m in component N_HVA_calcium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,41) = strpad('sigma_m in component N_HVA_calcium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,42) = strpad('tau_m in component N_HVA_calcium_current_m_gate (millisecond)');
LEGEND_ALGEBRAIC(:,9) = strpad('m_infinity in component N_HVA_calcium_current_m_gate (dimensionless)');
LEGEND_CONSTANTS(:,43) = strpad('theta_h in component N_HVA_calcium_current_h_gate (millivolt)');
LEGEND_CONSTANTS(:,44) = strpad('sigma_h in component N_HVA_calcium_current_h_gate (millivolt)');
LEGEND_CONSTANTS(:,45) = strpad('tau_h in component N_HVA_calcium_current_h_gate (millisecond)');
LEGEND_ALGEBRAIC(:,10) = strpad('h_infinity in component N_HVA_calcium_current_h_gate (dimensionless)');
LEGEND_CONSTANTS(:,46) = strpad('g_P in component P_HVA_calcium_current (uS)');
LEGEND_STATES(:,11) = strpad('m in component P_HVA_calcium_current_m_gate (dimensionless)');
LEGEND_CONSTANTS(:,47) = strpad('theta_m in component P_HVA_calcium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,48) = strpad('sigma_m in component P_HVA_calcium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,49) = strpad('tau_m in component P_HVA_calcium_current_m_gate (millisecond)');
LEGEND_ALGEBRAIC(:,11) = strpad('m_infinity in component P_HVA_calcium_current_m_gate (dimensionless)');
LEGEND_CONSTANTS(:,50) = strpad('g_SK in component calcium_dependent_potassium_current (uS)');
LEGEND_STATES(:,12) = strpad('z in component calcium_dependent_potassium_current_z_gate (dimensionless)');
LEGEND_CONSTANTS(:,51) = strpad('K1 in component calcium_dependent_potassium_current_z_gate (uM_per_nanocoulomb)');
LEGEND_CONSTANTS(:,52) = strpad('K2 in component calcium_dependent_potassium_current_z_gate (per_ms)');
LEGEND_STATES(:,13) = strpad('Ca_conc in component calcium_dependent_potassium_current_z_gate (uM)');
LEGEND_CONSTANTS(:,53) = strpad('tau_z in component calcium_dependent_potassium_current_z_gate (millisecond)');
LEGEND_ALGEBRAIC(:,12) = strpad('z_infinity in component calcium_dependent_potassium_current_z_gate (dimensionless)');
LEGEND_CONSTANTS(:,54) = strpad('g_A in component fast_transient_potassium_current (uS)');
LEGEND_STATES(:,14) = strpad('m in component fast_transient_potassium_current_m_gate (dimensionless)');
LEGEND_STATES(:,15) = strpad('h in component fast_transient_potassium_current_h_gate (dimensionless)');
LEGEND_CONSTANTS(:,55) = strpad('theta_m in component fast_transient_potassium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,56) = strpad('sigma_m in component fast_transient_potassium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,57) = strpad('theta_1 in component fast_transient_potassium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,58) = strpad('theta_2 in component fast_transient_potassium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,59) = strpad('sigma_1 in component fast_transient_potassium_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,60) = strpad('sigma_2 in component fast_transient_potassium_current_m_gate (millivolt)');
LEGEND_ALGEBRAIC(:,13) = strpad('tau_m in component fast_transient_potassium_current_m_gate (millisecond)');
LEGEND_ALGEBRAIC(:,21) = strpad('m_infinity in component fast_transient_potassium_current_m_gate (dimensionless)');
LEGEND_CONSTANTS(:,61) = strpad('theta_h in component fast_transient_potassium_current_h_gate (millivolt)');
LEGEND_CONSTANTS(:,62) = strpad('sigma_h in component fast_transient_potassium_current_h_gate (millivolt)');
LEGEND_CONSTANTS(:,63) = strpad('tau_h in component fast_transient_potassium_current_h_gate (millisecond)');
LEGEND_ALGEBRAIC(:,14) = strpad('h_infinity in component fast_transient_potassium_current_h_gate (dimensionless)');
LEGEND_CONSTANTS(:,64) = strpad('g_H in component hyperpolarization_activated_current (uS)');
LEGEND_CONSTANTS(:,65) = strpad('E_H in component hyperpolarization_activated_current (millivolt)');
LEGEND_STATES(:,16) = strpad('m in component hyperpolarization_activated_current_m_gate (dimensionless)');
LEGEND_CONSTANTS(:,66) = strpad('theta_m in component hyperpolarization_activated_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,67) = strpad('sigma_m in component hyperpolarization_activated_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,68) = strpad('theta_1 in component hyperpolarization_activated_current_m_gate (millivolt)');
LEGEND_CONSTANTS(:,69) = strpad('sigma_1 in component hyperpolarization_activated_current_m_gate (millivolt)');
LEGEND_ALGEBRAIC(:,15) = strpad('tau_m in component hyperpolarization_activated_current_m_gate (millisecond)');
LEGEND_ALGEBRAIC(:,22) = strpad('m_infinity in component hyperpolarization_activated_current_m_gate (dimensionless)');
LEGEND_CONSTANTS(:,70) = strpad('i_stimStart in component stimulus_protocol (millisecond)');
LEGEND_CONSTANTS(:,71) = strpad('i_stimEnd in component stimulus_protocol (millisecond)');
LEGEND_CONSTANTS(:,72) = strpad('i_stimAmplitude in component stimulus_protocol (nanoA)');
LEGEND_RATES(:,1) = strpad('d/dt V in component membrane (millivolt)');
LEGEND_RATES(:,3) = strpad('d/dt h in component sodium_current_h_gate (dimensionless)');
LEGEND_RATES(:,2) = strpad('d/dt m in component sodium_current_m_gate (dimensionless)');
LEGEND_RATES(:,5) = strpad('d/dt h in component persistent_sodium_current_h_gate (dimensionless)');
LEGEND_RATES(:,4) = strpad('d/dt m in component persistent_sodium_current_m_gate (dimensionless)');
LEGEND_RATES(:,6) = strpad('d/dt n in component delayed_rectifier_current_n_gate (dimensionless)');
LEGEND_RATES(:,7) = strpad('d/dt m in component LVA_calcium_current_m_gate (dimensionless)');
LEGEND_RATES(:,8) = strpad('d/dt h in component LVA_calcium_current_h_gate (dimensionless)');
LEGEND_RATES(:,9) = strpad('d/dt m in component N_HVA_calcium_current_m_gate (dimensionless)');
LEGEND_RATES(:,10) = strpad('d/dt h in component N_HVA_calcium_current_h_gate (dimensionless)');
LEGEND_RATES(:,11) = strpad('d/dt m in component P_HVA_calcium_current_m_gate (dimensionless)');
LEGEND_RATES(:,13) = strpad('d/dt Ca_conc in component calcium_dependent_potassium_current_z_gate (uM)');
LEGEND_RATES(:,12) = strpad('d/dt z in component calcium_dependent_potassium_current_z_gate (dimensionless)');
LEGEND_RATES(:,14) = strpad('d/dt m in component fast_transient_potassium_current_m_gate (dimensionless)');
LEGEND_RATES(:,15) = strpad('d/dt h in component fast_transient_potassium_current_h_gate (dimensionless)');
LEGEND_RATES(:,16) = strpad('d/dt m in component hyperpolarization_activated_current_m_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 = [];
STATES(:,1) = -71.847;
CONSTANTS(:,1) = 0.04;
CONSTANTS(:,2) = 0.7;
CONSTANTS(:,3) = 60;
STATES(:,2) = 0.015;
STATES(:,3) = 0.981;
CONSTANTS(:,4) = 44.1;
CONSTANTS(:,5) = 7;
CONSTANTS(:,6) = 35;
CONSTANTS(:,7) = 4;
CONSTANTS(:,8) = 25;
CONSTANTS(:,9) = 36;
CONSTANTS(:,10) = 8.5;
CONSTANTS(:,11) = 0.1;
CONSTANTS(:,12) = 0.05;
STATES(:,4) = 0.002;
STATES(:,5) = 0.797;
CONSTANTS(:,13) = 65;
CONSTANTS(:,14) = 5;
CONSTANTS(:,15) = 150;
CONSTANTS(:,16) = 47.1;
CONSTANTS(:,17) = 4.1;
CONSTANTS(:,18) = 0.1;
CONSTANTS(:,19) = 1.3;
CONSTANTS(:,20) = -80;
STATES(:,6) = 0.158;
CONSTANTS(:,21) = 30;
CONSTANTS(:,22) = 25;
CONSTANTS(:,23) = 30;
CONSTANTS(:,24) = 40;
CONSTANTS(:,25) = 50;
CONSTANTS(:,26) = 0.005;
CONSTANTS(:,27) = -50;
CONSTANTS(:,28) = 0.1;
CONSTANTS(:,29) = 40;
STATES(:,7) = 0.001;
STATES(:,8) = 0.562;
CONSTANTS(:,30) = 38;
CONSTANTS(:,31) = 5;
CONSTANTS(:,32) = 28;
CONSTANTS(:,33) = 25;
CONSTANTS(:,34) = 70;
CONSTANTS(:,35) = 70.1;
CONSTANTS(:,36) = 7;
CONSTANTS(:,37) = 70;
CONSTANTS(:,38) = 65;
CONSTANTS(:,39) = 0.05;
STATES(:,9) = 0.001;
STATES(:,10) = 0.649;
CONSTANTS(:,40) = 30;
CONSTANTS(:,41) = 6;
CONSTANTS(:,42) = 5;
CONSTANTS(:,43) = 70;
CONSTANTS(:,44) = 3;
CONSTANTS(:,45) = 25;
CONSTANTS(:,46) = 0.05;
STATES(:,11) = 0;
CONSTANTS(:,47) = 17;
CONSTANTS(:,48) = 3;
CONSTANTS(:,49) = 10;
CONSTANTS(:,50) = 0.3;
STATES(:,12) = 0;
CONSTANTS(:,51) = -500;
CONSTANTS(:,52) = 0.04;
STATES(:,13) = 0.0604;
CONSTANTS(:,53) = 1;
CONSTANTS(:,54) = 1;
STATES(:,14) = 0.057;
STATES(:,15) = 0.287;
CONSTANTS(:,55) = 27;
CONSTANTS(:,56) = 16;
CONSTANTS(:,57) = 40;
CONSTANTS(:,58) = 74;
CONSTANTS(:,59) = 5;
CONSTANTS(:,60) = 7.5;
CONSTANTS(:,61) = 80;
CONSTANTS(:,62) = 11;
CONSTANTS(:,63) = 20;
CONSTANTS(:,64) = 0.005;
CONSTANTS(:,65) = -38.8;
STATES(:,16) = 0.182;
CONSTANTS(:,66) = 79.8;
CONSTANTS(:,67) = 5.3;
CONSTANTS(:,68) = 70;
CONSTANTS(:,69) = 11;
CONSTANTS(:,70) = 10;
CONSTANTS(:,71) = 11;
CONSTANTS(:,72) = 10;
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(:,3) = 1.00000./(1.00000+exp((STATES(:,1)+CONSTANTS(:,9))./ - CONSTANTS(:,10)));
RATES(:,2) = (ALGEBRAIC(:,3) - STATES(:,2))./CONSTANTS(:,11);
ALGEBRAIC(:,4) = 1.00000./(1.00000+exp((STATES(:,1)+CONSTANTS(:,13))./CONSTANTS(:,14)));
RATES(:,5) = (ALGEBRAIC(:,4) - STATES(:,5))./CONSTANTS(:,15);
ALGEBRAIC(:,5) = 1.00000./(1.00000+exp( - (STATES(:,1)+CONSTANTS(:,16))./CONSTANTS(:,17)));
RATES(:,4) = (ALGEBRAIC(:,5) - STATES(:,4))./CONSTANTS(:,18);
ALGEBRAIC(:,9) = 1.00000./(1.00000+exp( - (STATES(:,1)+CONSTANTS(:,40))./CONSTANTS(:,41)));
RATES(:,9) = (ALGEBRAIC(:,9) - STATES(:,9))./CONSTANTS(:,42);
ALGEBRAIC(:,10) = 1.00000./(1.00000+exp((STATES(:,1)+CONSTANTS(:,43))./CONSTANTS(:,44)));
RATES(:,10) = (ALGEBRAIC(:,10) - STATES(:,10))./CONSTANTS(:,45);
ALGEBRAIC(:,11) = 1.00000./(1.00000+exp( - (STATES(:,1)+CONSTANTS(:,47))./CONSTANTS(:,48)));
RATES(:,11) = (ALGEBRAIC(:,11) - STATES(:,11))./CONSTANTS(:,49);
ALGEBRAIC(:,12) = 1.00000./(1.00000+power(0.00300000./STATES(:,13), 2.00000));
RATES(:,12) = (ALGEBRAIC(:,12) - STATES(:,12))./CONSTANTS(:,53);
ALGEBRAIC(:,14) = 1.00000./(1.00000+exp((STATES(:,1)+CONSTANTS(:,61))./CONSTANTS(:,62)));
RATES(:,15) = (ALGEBRAIC(:,14) - STATES(:,15))./CONSTANTS(:,63);
ALGEBRAIC(:,2) = 3.50000./(exp((STATES(:,1)+CONSTANTS(:,6))./CONSTANTS(:,7))+exp( - (STATES(:,1)+CONSTANTS(:,6))./CONSTANTS(:,8)))+1.00000;
ALGEBRAIC(:,17) = 1.00000./(1.00000+exp((STATES(:,1)+CONSTANTS(:,4))./CONSTANTS(:,5)));
RATES(:,3) = (ALGEBRAIC(:,17) - STATES(:,3))./ALGEBRAIC(:,2);
ALGEBRAIC(:,6) = 2.50000./(exp((STATES(:,1)+CONSTANTS(:,23))./CONSTANTS(:,24))+exp( - (STATES(:,1)+CONSTANTS(:,23))./CONSTANTS(:,25)))+0.0100000;
ALGEBRAIC(:,18) = 1.00000./(1.00000+exp( - (STATES(:,1)+CONSTANTS(:,21))./CONSTANTS(:,22)));
RATES(:,6) = (ALGEBRAIC(:,18) - STATES(:,6))./ALGEBRAIC(:,6);
ALGEBRAIC(:,7) = 5.00000./(exp((STATES(:,1)+CONSTANTS(:,32))./CONSTANTS(:,33))+exp( - (STATES(:,1)+CONSTANTS(:,32))./CONSTANTS(:,34)))+2.00000;
ALGEBRAIC(:,19) = 1.00000./(1.00000+exp( - (STATES(:,1)+CONSTANTS(:,30))./CONSTANTS(:,31)));
RATES(:,7) = (ALGEBRAIC(:,19) - STATES(:,7))./ALGEBRAIC(:,7);
ALGEBRAIC(:,8) = 20.0000./(exp((STATES(:,1)+CONSTANTS(:,37))./CONSTANTS(:,38))+exp( - (STATES(:,1)+CONSTANTS(:,37))./CONSTANTS(:,38)))+1.00000;
ALGEBRAIC(:,20) = 1.00000./(1.00000+exp((STATES(:,1)+CONSTANTS(:,35))./CONSTANTS(:,36)));
RATES(:,8) = (ALGEBRAIC(:,20) - STATES(:,8))./ALGEBRAIC(:,8);
ALGEBRAIC(:,13) = 1.00000./(exp((STATES(:,1)+CONSTANTS(:,57))./CONSTANTS(:,59))+exp( - (STATES(:,1)+CONSTANTS(:,58))./CONSTANTS(:,60)))+0.370000;
ALGEBRAIC(:,21) = 1.00000./(1.00000+exp( - (STATES(:,1)+CONSTANTS(:,55))./CONSTANTS(:,56)));
RATES(:,14) = (ALGEBRAIC(:,21) - STATES(:,14))./ALGEBRAIC(:,13);
ALGEBRAIC(:,15) = 1.00000./(exp((STATES(:,1)+CONSTANTS(:,68))./CONSTANTS(:,69))+exp( - (STATES(:,1)+CONSTANTS(:,68))./CONSTANTS(:,69)))+50.0000;
ALGEBRAIC(:,22) = 1.00000./(1.00000+exp((STATES(:,1)+CONSTANTS(:,66))./CONSTANTS(:,67)));
RATES(:,16) = (ALGEBRAIC(:,22) - STATES(:,16))./ALGEBRAIC(:,15);
ALGEBRAIC(:,25) = CONSTANTS(:,28).*STATES(:,7).*STATES(:,8).*(STATES(:,1) - CONSTANTS(:,29));
ALGEBRAIC(:,26) = CONSTANTS(:,39).*STATES(:,9).*STATES(:,10).*(STATES(:,1) - CONSTANTS(:,29));
ALGEBRAIC(:,27) = CONSTANTS(:,46).*STATES(:,11).*(STATES(:,1) - CONSTANTS(:,29));
RATES(:,13) = (1.00000./1000.00).*CONSTANTS(:,51).*(ALGEBRAIC(:,25)+ALGEBRAIC(:,26)+ALGEBRAIC(:,27)) - CONSTANTS(:,52).*STATES(:,13);
ALGEBRAIC(:,1) = CONSTANTS(:,2).*power(STATES(:,2), 3.00000).*STATES(:,3).*(STATES(:,1) - CONSTANTS(:,3));
ALGEBRAIC(:,16) = CONSTANTS(:,12).*STATES(:,4).*STATES(:,5).*(STATES(:,1) - CONSTANTS(:,3));
ALGEBRAIC(:,23) = CONSTANTS(:,19).*power(STATES(:,6), 4.00000).*(STATES(:,1) - CONSTANTS(:,20));
ALGEBRAIC(:,24) = CONSTANTS(:,26).*(STATES(:,1) - CONSTANTS(:,27));
ALGEBRAIC(:,28) = CONSTANTS(:,50).*power(STATES(:,12), 2.00000).*(STATES(:,1) - CONSTANTS(:,20));
ALGEBRAIC(:,29) = CONSTANTS(:,54).*STATES(:,14).*STATES(:,15).*(STATES(:,1) - CONSTANTS(:,20));
ALGEBRAIC(:,30) = CONSTANTS(:,64).*STATES(:,16).*(STATES(:,1) - CONSTANTS(:,65));
ALGEBRAIC(:,31) = piecewise({VOI>=CONSTANTS(:,70)&VOI<=CONSTANTS(:,71), CONSTANTS(:,72) }, 0.00000);
RATES(:,1) = ( - (ALGEBRAIC(:,1)+ALGEBRAIC(:,16)+ALGEBRAIC(:,23)+ALGEBRAIC(:,24)+ALGEBRAIC(:,25)+ALGEBRAIC(:,26)+ALGEBRAIC(:,27)+ALGEBRAIC(:,28)+ALGEBRAIC(:,29)+ALGEBRAIC(:,30))+ALGEBRAIC(:,31))./CONSTANTS(:,1);
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(:,3) = 1.00000./(1.00000+exp((STATES(:,1)+CONSTANTS(:,9))./ - CONSTANTS(:,10)));
ALGEBRAIC(:,4) = 1.00000./(1.00000+exp((STATES(:,1)+CONSTANTS(:,13))./CONSTANTS(:,14)));
ALGEBRAIC(:,5) = 1.00000./(1.00000+exp( - (STATES(:,1)+CONSTANTS(:,16))./CONSTANTS(:,17)));
ALGEBRAIC(:,9) = 1.00000./(1.00000+exp( - (STATES(:,1)+CONSTANTS(:,40))./CONSTANTS(:,41)));
ALGEBRAIC(:,10) = 1.00000./(1.00000+exp((STATES(:,1)+CONSTANTS(:,43))./CONSTANTS(:,44)));
ALGEBRAIC(:,11) = 1.00000./(1.00000+exp( - (STATES(:,1)+CONSTANTS(:,47))./CONSTANTS(:,48)));
ALGEBRAIC(:,12) = 1.00000./(1.00000+power(0.00300000./STATES(:,13), 2.00000));
ALGEBRAIC(:,14) = 1.00000./(1.00000+exp((STATES(:,1)+CONSTANTS(:,61))./CONSTANTS(:,62)));
ALGEBRAIC(:,2) = 3.50000./(exp((STATES(:,1)+CONSTANTS(:,6))./CONSTANTS(:,7))+exp( - (STATES(:,1)+CONSTANTS(:,6))./CONSTANTS(:,8)))+1.00000;
ALGEBRAIC(:,17) = 1.00000./(1.00000+exp((STATES(:,1)+CONSTANTS(:,4))./CONSTANTS(:,5)));
ALGEBRAIC(:,6) = 2.50000./(exp((STATES(:,1)+CONSTANTS(:,23))./CONSTANTS(:,24))+exp( - (STATES(:,1)+CONSTANTS(:,23))./CONSTANTS(:,25)))+0.0100000;
ALGEBRAIC(:,18) = 1.00000./(1.00000+exp( - (STATES(:,1)+CONSTANTS(:,21))./CONSTANTS(:,22)));
ALGEBRAIC(:,7) = 5.00000./(exp((STATES(:,1)+CONSTANTS(:,32))./CONSTANTS(:,33))+exp( - (STATES(:,1)+CONSTANTS(:,32))./CONSTANTS(:,34)))+2.00000;
ALGEBRAIC(:,19) = 1.00000./(1.00000+exp( - (STATES(:,1)+CONSTANTS(:,30))./CONSTANTS(:,31)));
ALGEBRAIC(:,8) = 20.0000./(exp((STATES(:,1)+CONSTANTS(:,37))./CONSTANTS(:,38))+exp( - (STATES(:,1)+CONSTANTS(:,37))./CONSTANTS(:,38)))+1.00000;
ALGEBRAIC(:,20) = 1.00000./(1.00000+exp((STATES(:,1)+CONSTANTS(:,35))./CONSTANTS(:,36)));
ALGEBRAIC(:,13) = 1.00000./(exp((STATES(:,1)+CONSTANTS(:,57))./CONSTANTS(:,59))+exp( - (STATES(:,1)+CONSTANTS(:,58))./CONSTANTS(:,60)))+0.370000;
ALGEBRAIC(:,21) = 1.00000./(1.00000+exp( - (STATES(:,1)+CONSTANTS(:,55))./CONSTANTS(:,56)));
ALGEBRAIC(:,15) = 1.00000./(exp((STATES(:,1)+CONSTANTS(:,68))./CONSTANTS(:,69))+exp( - (STATES(:,1)+CONSTANTS(:,68))./CONSTANTS(:,69)))+50.0000;
ALGEBRAIC(:,22) = 1.00000./(1.00000+exp((STATES(:,1)+CONSTANTS(:,66))./CONSTANTS(:,67)));
ALGEBRAIC(:,25) = CONSTANTS(:,28).*STATES(:,7).*STATES(:,8).*(STATES(:,1) - CONSTANTS(:,29));
ALGEBRAIC(:,26) = CONSTANTS(:,39).*STATES(:,9).*STATES(:,10).*(STATES(:,1) - CONSTANTS(:,29));
ALGEBRAIC(:,27) = CONSTANTS(:,46).*STATES(:,11).*(STATES(:,1) - CONSTANTS(:,29));
ALGEBRAIC(:,1) = CONSTANTS(:,2).*power(STATES(:,2), 3.00000).*STATES(:,3).*(STATES(:,1) - CONSTANTS(:,3));
ALGEBRAIC(:,16) = CONSTANTS(:,12).*STATES(:,4).*STATES(:,5).*(STATES(:,1) - CONSTANTS(:,3));
ALGEBRAIC(:,23) = CONSTANTS(:,19).*power(STATES(:,6), 4.00000).*(STATES(:,1) - CONSTANTS(:,20));
ALGEBRAIC(:,24) = CONSTANTS(:,26).*(STATES(:,1) - CONSTANTS(:,27));
ALGEBRAIC(:,28) = CONSTANTS(:,50).*power(STATES(:,12), 2.00000).*(STATES(:,1) - CONSTANTS(:,20));
ALGEBRAIC(:,29) = CONSTANTS(:,54).*STATES(:,14).*STATES(:,15).*(STATES(:,1) - CONSTANTS(:,20));
ALGEBRAIC(:,30) = CONSTANTS(:,64).*STATES(:,16).*(STATES(:,1) - CONSTANTS(:,65));
ALGEBRAIC(:,31) = piecewise({VOI>=CONSTANTS(:,70)&VOI<=CONSTANTS(:,71), CONSTANTS(:,72) }, 0.00000);
end
% Compute result of a piecewise function
function x = piecewise(cases, default)
set = [0];
for i = 1:2:length(cases)
if (length(cases{i+1}) == 1)
x(cases{i} & ~set,:) = cases{i+1};
else
x(cases{i} & ~set,:) = cases{i+1}(cases{i} & ~set);
end
set = set | cases{i};
if(set), break, end
end
if (length(default) == 1)
x(~set,:) = default;
else
x(~set,:) = default(~set);
end
end
% Pad out or shorten strings to a set length
function strout = strpad(strin)
req_length = 160;
insize = size(strin,2);
if insize > req_length
strout = strin(1:req_length);
else
strout = [strin, blanks(req_length - insize)];
end
end
