# 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 =34;
end
% There are a total of 19 entries in each of the rate and state variable arrays.
% There are a total of 60 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('t in component Environment (second)');
LEGEND_CONSTANTS(:,1) = strpad('Mg_tot in component Environment (molar)');
LEGEND_CONSTANTS(:,2) = strpad('Pi_e in component Environment (molar)');
LEGEND_CONSTANTS(:,3) = strpad('ADP_e in component Environment (molar)');
LEGEND_CONSTANTS(:,4) = strpad('RT in component Fixed_parameters (kilojoule_per_mole)');
LEGEND_CONSTANTS(:,5) = strpad('F in component Fixed_parameters (kilojoule_per_mole_per_millivolt)');
LEGEND_CONSTANTS(:,6) = strpad('n_A in component Fixed_parameters (dimensionless)');
LEGEND_CONSTANTS(:,7) = strpad('dG_C1o in component Fixed_parameters (kilojoule_per_mole)');
LEGEND_CONSTANTS(:,8) = strpad('dG_C3o in component Fixed_parameters (kilojoule_per_mole)');
LEGEND_CONSTANTS(:,9) = strpad('dG_C4o in component Fixed_parameters (kilojoule_per_mole)');
LEGEND_CONSTANTS(:,10) = strpad('dG_F1o in component Fixed_parameters (kilojoule_per_mole)');
LEGEND_CONSTANTS(:,11) = strpad('pH_e in component Fixed_parameters (dimensionless)');
LEGEND_CONSTANTS(:,48) = strpad('H_e in component Fixed_parameters (molar)');
LEGEND_CONSTANTS(:,12) = strpad('K_e in component Fixed_parameters (molar)');
LEGEND_CONSTANTS(:,13) = strpad('ATP_e in component Fixed_parameters (molar)');
LEGEND_CONSTANTS(:,14) = strpad('AMP_e in component Fixed_parameters (molar)');
LEGEND_CONSTANTS(:,49) = strpad('k_dHPi in component Fixed_parameters (molar)');
LEGEND_CONSTANTS(:,50) = strpad('k_dHatp in component Fixed_parameters (molar)');
LEGEND_CONSTANTS(:,51) = strpad('k_dHadp in component Fixed_parameters (molar)');
LEGEND_CONSTANTS(:,15) = strpad('K_DT in component Fixed_parameters (molar)');
LEGEND_CONSTANTS(:,16) = strpad('K_DD in component Fixed_parameters (molar)');
LEGEND_CONSTANTS(:,17) = strpad('K_AK in component Fixed_parameters (dimensionless)');
LEGEND_CONSTANTS(:,18) = strpad('W_m in component Fixed_parameters (l_water_per_l_mito)');
LEGEND_CONSTANTS(:,53) = strpad('W_x in component Fixed_parameters (l_water_per_l_mito)');
LEGEND_CONSTANTS(:,56) = strpad('W_i in component Fixed_parameters (l_water_per_l_mito)');
LEGEND_CONSTANTS(:,19) = strpad('gamma in component Fixed_parameters (per_micron)');
LEGEND_CONSTANTS(:,20) = strpad('Ctot in component Fixed_parameters (molar)');
LEGEND_CONSTANTS(:,21) = strpad('Qtot in component Fixed_parameters (molar)');
LEGEND_CONSTANTS(:,22) = strpad('NADtot in component Fixed_parameters (molar)');
LEGEND_CONSTANTS(:,55) = strpad('H_i in component Fixed_parameters (molar)');
LEGEND_CONSTANTS(:,52) = strpad('K_i in component Fixed_parameters (molar)');
LEGEND_CONSTANTS(:,23) = strpad('k_Pi1 in component Adjustable_parameters (molar)');
LEGEND_CONSTANTS(:,24) = strpad('k_Pi2 in component Adjustable_parameters (molar)');
LEGEND_CONSTANTS(:,25) = strpad('k_Pi3 in component Adjustable_parameters (molar)');
LEGEND_CONSTANTS(:,26) = strpad('k_Pi4 in component Adjustable_parameters (molar)');
LEGEND_CONSTANTS(:,27) = strpad('k_PiH in component Adjustable_parameters (molar)');
LEGEND_CONSTANTS(:,28) = strpad('r in component Adjustable_parameters (dimensionless)');
LEGEND_CONSTANTS(:,29) = strpad('x_DH in component Adjustable_parameters (mole_per_second_per_l_mito_per_molar)');
LEGEND_CONSTANTS(:,30) = strpad('x_C1 in component Adjustable_parameters (mole_per_second_per_l_mito_per_molar)');
LEGEND_CONSTANTS(:,31) = strpad('x_C3 in component Adjustable_parameters (mole_per_second_per_l_mito_per_molar)');
LEGEND_CONSTANTS(:,32) = strpad('x_C4 in component Adjustable_parameters (mole_per_second_per_l_mito_per_molar)');
LEGEND_CONSTANTS(:,33) = strpad('x_F1 in component Adjustable_parameters (mole_per_second_per_l_mito_per_molar_per_molar)');
LEGEND_CONSTANTS(:,34) = strpad('x_ANT in component Adjustable_parameters (mole_per_second_per_l_mito)');
LEGEND_CONSTANTS(:,35) = strpad('x_Pi1 in component Adjustable_parameters (mole_per_second_per_l_mito_per_molar)');
LEGEND_CONSTANTS(:,36) = strpad('x_KH in component Adjustable_parameters (mole_per_second_per_l_mito_per_molar_per_molar)');
LEGEND_CONSTANTS(:,37) = strpad('x_Hle in component Adjustable_parameters (mole_per_second_per_l_mito_per_molar_per_millivolt)');
LEGEND_CONSTANTS(:,38) = strpad('x_K in component Adjustable_parameters (mole_per_second_per_l_mito_per_molar_per_millivolt)');
LEGEND_CONSTANTS(:,40) = strpad('x_AK in component Adjustable_parameters (mole_per_second_per_l_mito_per_molar_per_molar)');
LEGEND_CONSTANTS(:,41) = strpad('p_A in component Adjustable_parameters (micron_per_second)');
LEGEND_CONSTANTS(:,42) = strpad('k_O2 in component Adjustable_parameters (molar)');
LEGEND_CONSTANTS(:,43) = strpad('x_buff in component Adjustable_parameters (per_molar)');
LEGEND_CONSTANTS(:,44) = strpad('x_MgA in component Adjustable_parameters (mole_per_second_per_l_mito_per_molar_per_molar)');
LEGEND_CONSTANTS(:,45) = strpad('x_Pi2 in component Adjustable_parameters (micron_per_second)');
LEGEND_ALGEBRAIC(:,1) = strpad('dG_H in component Proton_motive_force (kilojoule_per_mole)');
LEGEND_STATES(:,1) = strpad('dPsi in component dPsi_dt (millivolt)');
LEGEND_STATES(:,2) = strpad('H_x in component dH_x_dt (molar)');
LEGEND_ALGEBRAIC(:,27) = strpad('J_DH in component Dehydrogenase_flux (mole_per_second_per_l_mito)');
LEGEND_STATES(:,4) = strpad('Pi_x in component dPi_x_dt (molar)');
LEGEND_ALGEBRAIC(:,30) = strpad('J_C1 in component Electron_flux_complex_I (mole_per_second_per_l_mito)');
LEGEND_ALGEBRAIC(:,29) = strpad('dG_C1op in component Electron_flux_complex_I (kilojoule_per_mole)');
LEGEND_ALGEBRAIC(:,28) = strpad('Q in component Q_concentration (molar)');
LEGEND_STATES(:,5) = strpad('QH2 in component dQH2_dt (molar)');
LEGEND_ALGEBRAIC(:,33) = strpad('J_C3 in component Electron_flux_complex_III (mole_per_second_per_l_mito)');
LEGEND_ALGEBRAIC(:,31) = strpad('dG_C3op in component Electron_flux_complex_III (kilojoule_per_mole)');
LEGEND_ALGEBRAIC(:,32) = strpad('Cox in component Cox_concentration (molar)');
LEGEND_STATES(:,6) = strpad('Cred in component dCred_dt (molar)');
LEGEND_ALGEBRAIC(:,34) = strpad('J_C4 in component Electron_flux_complex_IV (mole_per_second_per_l_mito)');
LEGEND_ALGEBRAIC(:,2) = strpad('dG_C4op in component Electron_flux_complex_IV (kilojoule_per_mole)');
LEGEND_STATES(:,7) = strpad('O2 in component dO2_dt (molar)');
LEGEND_ALGEBRAIC(:,3) = strpad('J_F1 in component ATP_synthesis_flux (mole_per_second_per_l_mito)');
LEGEND_STATES(:,9) = strpad('ATP_mx in component dATP_mx_dt (molar)');
LEGEND_ALGEBRAIC(:,13) = strpad('J_ANT in component ANT_flux (mole_per_second_per_l_mito)');
LEGEND_ALGEBRAIC(:,4) = strpad('Psi_x in component ANT_flux (millivolt)');
LEGEND_ALGEBRAIC(:,5) = strpad('Psi_i in component ANT_flux (millivolt)');
LEGEND_ALGEBRAIC(:,9) = strpad('ATP_fi in component MgATPi_binding_flux (molar)');
LEGEND_ALGEBRAIC(:,6) = strpad('ATP_fx in component MgATPx_binding_flux (molar)');
LEGEND_CONSTANTS(:,46) = strpad('mincond in component ANT_flux (molar)');
LEGEND_ALGEBRAIC(:,7) = strpad('J_MgATPx in component MgATPx_binding_flux (mole_per_second_per_l_mito)');
LEGEND_STATES(:,10) = strpad('ATP_x in component dATP_x_dt (molar)');
LEGEND_STATES(:,11) = strpad('Mg_x in component dMg_x_dt (molar)');
LEGEND_ALGEBRAIC(:,12) = strpad('J_MgATPi in component MgATPi_binding_flux (mole_per_second_per_l_mito)');
LEGEND_STATES(:,13) = strpad('ATP_i in component dATP_i_dt (molar)');
LEGEND_STATES(:,14) = strpad('ATP_mi in component dATP_mi_dt (molar)');
LEGEND_CONSTANTS(:,59) = strpad('Mg_i in component Mg_binding (molar)');
LEGEND_ALGEBRAIC(:,16) = strpad('J_ATP in component ATP_substrate_flux (mole_per_second_per_l_mito)');
LEGEND_ALGEBRAIC(:,20) = strpad('J_AMP in component AMP_substrate_flux (mole_per_second_per_l_mito)');
LEGEND_STATES(:,17) = strpad('AMP_i in component dAMP_i_dt (molar)');
LEGEND_ALGEBRAIC(:,15) = strpad('J_Pi2 in component Pi_substrate_flux (mole_per_second_per_l_mito)');
LEGEND_STATES(:,18) = strpad('Pi_i in component dPi_i_dt (molar)');
LEGEND_ALGEBRAIC(:,21) = strpad('J_Pi1 in component Phosphate_hydrogen_cotransporter_flux (mole_per_second_per_l_mito)');
LEGEND_ALGEBRAIC(:,17) = strpad('H2PIi in component Phosphate_hydrogen_cotransporter_flux (molar)');
LEGEND_ALGEBRAIC(:,19) = strpad('H2PIx in component Phosphate_hydrogen_cotransporter_flux (molar)');
LEGEND_ALGEBRAIC(:,22) = strpad('J_AKi in component Adenylate_kinase_flux (mole_per_second_per_l_mito)');
LEGEND_ALGEBRAIC(:,23) = strpad('J_Hle in component Hydrogen_leak_flux (mole_per_second_per_l_mito)');
LEGEND_ALGEBRAIC(:,24) = strpad('J_K in component Passive_potassium_flux (mole_per_second_per_l_mito)');
LEGEND_STATES(:,19) = strpad('K_x in component dK_x_dt (molar)');
LEGEND_ALGEBRAIC(:,25) = strpad('J_KH in component Potassium_hydrogen_flux (mole_per_second_per_l_mito)');
LEGEND_CONSTANTS(:,58) = strpad('Mg_e in component Mg_binding (molar)');
LEGEND_CONSTANTS(:,47) = strpad('C_im in component dPsi_dt (mole_per_l_mito_per_millivolt)');
LEGEND_RATES(:,2) = strpad('d/dt H_x in component dH_x_dt (molar)');
LEGEND_RATES(:,19) = strpad('d/dt K_x in component dK_x_dt (molar)');
LEGEND_RATES(:,11) = strpad('d/dt Mg_x in component dMg_x_dt (molar)');
LEGEND_RATES(:,5) = strpad('d/dt QH2 in component dQH2_dt (molar)');
LEGEND_RATES(:,6) = strpad('d/dt Cred in component dCred_dt (molar)');
LEGEND_RATES(:,10) = strpad('d/dt ATP_x in component dATP_x_dt (molar)');
LEGEND_RATES(:,9) = strpad('d/dt ATP_mx in component dATP_mx_dt (molar)');
LEGEND_RATES(:,4) = strpad('d/dt Pi_x in component dPi_x_dt (molar)');
LEGEND_RATES(:,13) = strpad('d/dt ATP_i in component dATP_i_dt (molar)');
LEGEND_RATES(:,17) = strpad('d/dt AMP_i in component dAMP_i_dt (molar)');
LEGEND_RATES(:,14) = strpad('d/dt ATP_mi in component dATP_mi_dt (molar)');
LEGEND_RATES(:,18) = strpad('d/dt Pi_i in component dPi_i_dt (molar)');
LEGEND_RATES(:,1) = strpad('d/dt dPsi in component dPsi_dt (millivolt)');
LEGEND_RATES(:,7) = strpad('d/dt O2 in component dO2_dt (molar)');
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.005;
CONSTANTS(:,2) = 0.000125;
CONSTANTS(:,3) = 0;
CONSTANTS(:,4) = 2.4734;
CONSTANTS(:,5) = 0.096484;
CONSTANTS(:,6) = 3;
CONSTANTS(:,7) = -69.37;
CONSTANTS(:,8) = -32.53;
CONSTANTS(:,9) = -122.94;
CONSTANTS(:,10) = 36.03;
CONSTANTS(:,11) = 7.1;
CONSTANTS(:,12) = 0.15;
CONSTANTS(:,13) = 0;
CONSTANTS(:,14) = 0;
CONSTANTS(:,15) = 2.4e-5;
CONSTANTS(:,16) = 3.47e-4;
CONSTANTS(:,17) = 0.4331;
CONSTANTS(:,18) = 0.72376;
CONSTANTS(:,19) = 5.99;
CONSTANTS(:,20) = 0.0027;
CONSTANTS(:,21) = 0.00135;
CONSTANTS(:,22) = 0.00297;
CONSTANTS(:,23) = 1.3413e-4;
CONSTANTS(:,24) = 6.7668e-4;
CONSTANTS(:,25) = 1.9172e-4;
CONSTANTS(:,26) = 0.02531;
CONSTANTS(:,27) = 4.5082e-4;
CONSTANTS(:,28) = 4.5807;
CONSTANTS(:,29) = 0.09183;
CONSTANTS(:,30) = 0.36923;
CONSTANTS(:,31) = 0.091737;
CONSTANTS(:,32) = 3.2562e-5;
CONSTANTS(:,33) = 150.93;
CONSTANTS(:,34) = 0.0079204;
CONSTANTS(:,35) = 339430;
CONSTANTS(:,36) = 2.9802e7;
CONSTANTS(:,37) = 250;
CONSTANTS(:,38) = 0;
CONSTANTS(:,39) = 3.5e-6;
CONSTANTS(:,40) = 0;
CONSTANTS(:,41) = 85;
CONSTANTS(:,42) = 1.2e-4;
CONSTANTS(:,43) = 100;
CONSTANTS(:,44) = 1000000;
CONSTANTS(:,45) = 327;
STATES(:,1) = 160;
STATES(:,2) = 6.30957344480193e-8;
STATES(:,3) = 0.0015;
STATES(:,4) = 0.001;
STATES(:,5) = 8e-4;
STATES(:,6) = 0.001;
STATES(:,7) = 2.6e-5;
STATES(:,8) = 0;
STATES(:,9) = 0;
CONSTANTS(:,46) = 1e-12;
STATES(:,10) = 0;
STATES(:,11) = 0.005;
STATES(:,12) = 0.01;
STATES(:,13) = 0;
STATES(:,14) = 0;
STATES(:,15) = 0;
STATES(:,16) = 0;
STATES(:,17) = 0;
STATES(:,18) = 0.001;
STATES(:,19) = 0.14;
CONSTANTS(:,47) = 6.756756756756757e-6;
CONSTANTS(:,48) =  1.00000.*power(10.0000,  - CONSTANTS(:,11));
CONSTANTS(:,49) =  1.00000.*power(10.0000,  - 6.75000);
CONSTANTS(:,50) =  1.00000.*power(10.0000,  - 6.48000);
CONSTANTS(:,51) =  1.00000.*power(10.0000,  - 6.29000);
CONSTANTS(:,52) = CONSTANTS(:,12);
CONSTANTS(:,53) =  0.900000.*CONSTANTS(:,18);
CONSTANTS(:,54) = ((CONSTANTS(:,16)+CONSTANTS(:,3)+CONSTANTS(:,1)) - power((power(CONSTANTS(:,16)+CONSTANTS(:,3)+CONSTANTS(:,1), 2.00000) -  4.00000.*CONSTANTS(:,1).*CONSTANTS(:,3)), 1.0 ./ 2))./2.00000;
CONSTANTS(:,59) = 0.00000;
CONSTANTS(:,55) = CONSTANTS(:,48);
CONSTANTS(:,56) =  0.100000.*CONSTANTS(:,18);
CONSTANTS(:,57) = CONSTANTS(:,3) - CONSTANTS(:,54);
CONSTANTS(:,58) = CONSTANTS(:,1) - CONSTANTS(:,54);
CONSTANTS(:,59) = CONSTANTS(:,58);
if (isempty(STATES)), warning('Initial values for states not set');, end
end

function [RATES, ALGEBRAIC] = computeRates(VOI, STATES, CONSTANTS)
global algebraicVariableCount;
statesSize = size(STATES);
statesColumnCount = statesSize(2);
if ( statesColumnCount == 1)
STATES = STATES';
ALGEBRAIC = zeros(1, algebraicVariableCount);
utilOnes = 1;
else
statesRowCount = statesSize(1);
ALGEBRAIC = zeros(statesRowCount, algebraicVariableCount);
RATES = zeros(statesRowCount, statesColumnCount);
utilOnes = ones(statesRowCount, 1);
end
RATES(:,7) = CONSTANTS(:,59);
ALGEBRAIC(:,6) = STATES(:,10) - STATES(:,9);
ALGEBRAIC(:,7) =  CONSTANTS(:,44).*( ALGEBRAIC(:,6).*STATES(:,11) -  CONSTANTS(:,15).*STATES(:,9));
RATES(:,9) = ALGEBRAIC(:,7)./CONSTANTS(:,53);
ALGEBRAIC(:,8) = STATES(:,12) - STATES(:,8);
ALGEBRAIC(:,10) =  CONSTANTS(:,44).*( ALGEBRAIC(:,8).*STATES(:,11) -  CONSTANTS(:,16).*STATES(:,8));
RATES(:,11) = ( - ALGEBRAIC(:,7) - ALGEBRAIC(:,10))./CONSTANTS(:,53);
RATES(:,8) = ALGEBRAIC(:,10)./CONSTANTS(:,53);
ALGEBRAIC(:,9) = STATES(:,13) - STATES(:,14);
ALGEBRAIC(:,12) =  CONSTANTS(:,44).*( ALGEBRAIC(:,9).*CONSTANTS(:,59) -  CONSTANTS(:,15).*STATES(:,14));
RATES(:,14) = ALGEBRAIC(:,12)./CONSTANTS(:,56);
ALGEBRAIC(:,1) =  CONSTANTS(:,5).*STATES(:,1)+ CONSTANTS(:,4).*log(CONSTANTS(:,55)./STATES(:,2));
ALGEBRAIC(:,3) =  CONSTANTS(:,33).*( (( exp( - (CONSTANTS(:,10) -  CONSTANTS(:,6).*ALGEBRAIC(:,1))./CONSTANTS(:,4)).*CONSTANTS(:,16))./CONSTANTS(:,15)).*STATES(:,8).*STATES(:,4) -  STATES(:,9).*1.00000);
ALGEBRAIC(:,4) =   - 0.650000.*STATES(:,1);
ALGEBRAIC(:,5) =  0.350000.*STATES(:,1);
ALGEBRAIC(:,11) = STATES(:,15) - STATES(:,16);
ALGEBRAIC(:,13) = piecewise({ALGEBRAIC(:,11)>CONSTANTS(:,46)||ALGEBRAIC(:,9)>CONSTANTS(:,46), ( CONSTANTS(:,34).*(ALGEBRAIC(:,11)./(ALGEBRAIC(:,11)+ ALGEBRAIC(:,9).*exp((  - CONSTANTS(:,5).*ALGEBRAIC(:,5))./CONSTANTS(:,4))) - ALGEBRAIC(:,8)./(ALGEBRAIC(:,8)+ ALGEBRAIC(:,6).*exp((  - CONSTANTS(:,5).*ALGEBRAIC(:,4))./CONSTANTS(:,4)))).*ALGEBRAIC(:,11))./(CONSTANTS(:,39)+ALGEBRAIC(:,11)) }, 0.00000);
RATES(:,10) = (ALGEBRAIC(:,3) - ALGEBRAIC(:,13))./CONSTANTS(:,53);
RATES(:,12) = ( - ALGEBRAIC(:,3)+ALGEBRAIC(:,13))./CONSTANTS(:,53);
ALGEBRAIC(:,14) =  CONSTANTS(:,44).*( ALGEBRAIC(:,11).*CONSTANTS(:,59) -  CONSTANTS(:,16).*STATES(:,16));
RATES(:,16) = ALGEBRAIC(:,14)./CONSTANTS(:,56);
ALGEBRAIC(:,17) = ( STATES(:,18).*CONSTANTS(:,55))./(CONSTANTS(:,55)+CONSTANTS(:,49));
ALGEBRAIC(:,19) = ( STATES(:,4).*STATES(:,2))./(STATES(:,2)+CONSTANTS(:,49));
ALGEBRAIC(:,21) = ( CONSTANTS(:,35).*( STATES(:,2).*ALGEBRAIC(:,17) -  CONSTANTS(:,55).*ALGEBRAIC(:,19)))./(ALGEBRAIC(:,17)+CONSTANTS(:,27));
RATES(:,4) = ( - ALGEBRAIC(:,3)+ALGEBRAIC(:,21))./CONSTANTS(:,53);
ALGEBRAIC(:,16) =  CONSTANTS(:,19).*CONSTANTS(:,41).*(CONSTANTS(:,13) - STATES(:,13));
ALGEBRAIC(:,22) =  CONSTANTS(:,40).*( CONSTANTS(:,17).*STATES(:,15).*STATES(:,15) -  STATES(:,17).*STATES(:,13));
RATES(:,13) = (ALGEBRAIC(:,16)+ALGEBRAIC(:,13)+ALGEBRAIC(:,22))./CONSTANTS(:,56);
ALGEBRAIC(:,18) =  CONSTANTS(:,19).*CONSTANTS(:,41).*(CONSTANTS(:,3) - STATES(:,15));
RATES(:,15) = ((ALGEBRAIC(:,18) - ALGEBRAIC(:,13)) -  2.00000.*ALGEBRAIC(:,22))./CONSTANTS(:,56);
ALGEBRAIC(:,20) =  CONSTANTS(:,19).*CONSTANTS(:,41).*(CONSTANTS(:,14) - STATES(:,17));
RATES(:,17) = (ALGEBRAIC(:,20)+ALGEBRAIC(:,22))./CONSTANTS(:,56);
ALGEBRAIC(:,15) =  CONSTANTS(:,19).*CONSTANTS(:,45).*(CONSTANTS(:,2) - STATES(:,18));
RATES(:,18) = ( - ALGEBRAIC(:,21)+ALGEBRAIC(:,15))./CONSTANTS(:,56);
ALGEBRAIC(:,24) = ( CONSTANTS(:,38).*STATES(:,1).*( CONSTANTS(:,52).*exp(( CONSTANTS(:,5).*STATES(:,1))./CONSTANTS(:,4)) - STATES(:,19)))./(exp(( CONSTANTS(:,5).*STATES(:,1))./CONSTANTS(:,4)) - 1.00000);
ALGEBRAIC(:,25) =  CONSTANTS(:,36).*( CONSTANTS(:,52).*STATES(:,2) -  STATES(:,19).*CONSTANTS(:,55));
RATES(:,19) = (ALGEBRAIC(:,25)+ALGEBRAIC(:,24))./CONSTANTS(:,53);
ALGEBRAIC(:,26) = CONSTANTS(:,22) - STATES(:,3);
ALGEBRAIC(:,27) = ( CONSTANTS(:,29).*( CONSTANTS(:,28).*ALGEBRAIC(:,26) - STATES(:,3)).*(1.00000+STATES(:,4)./CONSTANTS(:,23)))./(1.00000+STATES(:,4)./CONSTANTS(:,24));
ALGEBRAIC(:,28) = CONSTANTS(:,21) - STATES(:,5);
ALGEBRAIC(:,29) = (CONSTANTS(:,7) -  CONSTANTS(:,4).*log(STATES(:,2)./1.00000e-07)) -  CONSTANTS(:,4).*log(ALGEBRAIC(:,28)./STATES(:,5));
ALGEBRAIC(:,30) =  CONSTANTS(:,30).*( exp( - (ALGEBRAIC(:,29)+ 4.00000.*ALGEBRAIC(:,1))./CONSTANTS(:,4)).*STATES(:,3) - ALGEBRAIC(:,26));
RATES(:,3) = (ALGEBRAIC(:,27) - ALGEBRAIC(:,30))./CONSTANTS(:,53);
ALGEBRAIC(:,31) = (CONSTANTS(:,8)+ 2.00000.*CONSTANTS(:,4).*log(STATES(:,2)./1.00000e-07)) -  CONSTANTS(:,4).*log(STATES(:,5)./ALGEBRAIC(:,28));
ALGEBRAIC(:,32) = CONSTANTS(:,20) - STATES(:,6);
ALGEBRAIC(:,33) =  (( CONSTANTS(:,31).*(1.00000+STATES(:,4)./CONSTANTS(:,25)))./(1.00000+STATES(:,4)./CONSTANTS(:,26))).*( exp( - ((ALGEBRAIC(:,31)+ 4.00000.*ALGEBRAIC(:,1)) -  2.00000.*CONSTANTS(:,5).*STATES(:,1))./( 2.00000.*CONSTANTS(:,4))).*ALGEBRAIC(:,32) - STATES(:,6));
RATES(:,5) = (ALGEBRAIC(:,30) - ALGEBRAIC(:,33))./CONSTANTS(:,53);
ALGEBRAIC(:,2) = (CONSTANTS(:,9) -  2.00000.*CONSTANTS(:,4).*log(STATES(:,2)./1.00000e-07)) -  (CONSTANTS(:,4)./2.00000).*log(STATES(:,7)./1.00000);
ALGEBRAIC(:,34) =  (( (( CONSTANTS(:,32).*1.00000)./(1.00000+CONSTANTS(:,42)./STATES(:,7))).*STATES(:,6))./CONSTANTS(:,20)).*( exp( - (ALGEBRAIC(:,2)+ 2.00000.*ALGEBRAIC(:,1))./( 2.00000.*CONSTANTS(:,4))).*STATES(:,6) -  ALGEBRAIC(:,32).*exp(( CONSTANTS(:,5).*STATES(:,1))./CONSTANTS(:,4)));
ALGEBRAIC(:,23) = ( CONSTANTS(:,37).*STATES(:,1).*( CONSTANTS(:,55).*exp(( CONSTANTS(:,5).*STATES(:,1))./CONSTANTS(:,4)) - STATES(:,2)))./(exp(( CONSTANTS(:,5).*STATES(:,1))./CONSTANTS(:,4)) - 1.00000);
RATES(:,2) = ( CONSTANTS(:,43).*STATES(:,2).*(((((ALGEBRAIC(:,27) -  5.00000.*ALGEBRAIC(:,30)) -  2.00000.*ALGEBRAIC(:,33)) -  4.00000.*ALGEBRAIC(:,34))+ (CONSTANTS(:,6) - 1.00000).*ALGEBRAIC(:,3)+ 2.00000.*ALGEBRAIC(:,21)+ALGEBRAIC(:,23)) - ALGEBRAIC(:,25)))./CONSTANTS(:,53);
RATES(:,6) = ( 2.00000.*ALGEBRAIC(:,33) -  2.00000.*ALGEBRAIC(:,34))./CONSTANTS(:,56);
RATES(:,1) = ((((( 4.00000.*ALGEBRAIC(:,30)+ 2.00000.*ALGEBRAIC(:,33)+ 4.00000.*ALGEBRAIC(:,34)) -  CONSTANTS(:,6).*ALGEBRAIC(:,3)) - ALGEBRAIC(:,13)) - ALGEBRAIC(:,23)) - ALGEBRAIC(:,24))./CONSTANTS(:,47);
RATES = RATES';
end

% Calculate algebraic variables
function ALGEBRAIC = computeAlgebraic(ALGEBRAIC, CONSTANTS, STATES, VOI)
statesSize = size(STATES);
statesColumnCount = statesSize(2);
if ( statesColumnCount == 1)
STATES = STATES';
utilOnes = 1;
else
statesRowCount = statesSize(1);
utilOnes = ones(statesRowCount, 1);
end
ALGEBRAIC(:,6) = STATES(:,10) - STATES(:,9);
ALGEBRAIC(:,7) =  CONSTANTS(:,44).*( ALGEBRAIC(:,6).*STATES(:,11) -  CONSTANTS(:,15).*STATES(:,9));
ALGEBRAIC(:,8) = STATES(:,12) - STATES(:,8);
ALGEBRAIC(:,10) =  CONSTANTS(:,44).*( ALGEBRAIC(:,8).*STATES(:,11) -  CONSTANTS(:,16).*STATES(:,8));
ALGEBRAIC(:,9) = STATES(:,13) - STATES(:,14);
ALGEBRAIC(:,12) =  CONSTANTS(:,44).*( ALGEBRAIC(:,9).*CONSTANTS(:,59) -  CONSTANTS(:,15).*STATES(:,14));
ALGEBRAIC(:,1) =  CONSTANTS(:,5).*STATES(:,1)+ CONSTANTS(:,4).*log(CONSTANTS(:,55)./STATES(:,2));
ALGEBRAIC(:,3) =  CONSTANTS(:,33).*( (( exp( - (CONSTANTS(:,10) -  CONSTANTS(:,6).*ALGEBRAIC(:,1))./CONSTANTS(:,4)).*CONSTANTS(:,16))./CONSTANTS(:,15)).*STATES(:,8).*STATES(:,4) -  STATES(:,9).*1.00000);
ALGEBRAIC(:,4) =   - 0.650000.*STATES(:,1);
ALGEBRAIC(:,5) =  0.350000.*STATES(:,1);
ALGEBRAIC(:,11) = STATES(:,15) - STATES(:,16);
ALGEBRAIC(:,13) = piecewise({ALGEBRAIC(:,11)>CONSTANTS(:,46)||ALGEBRAIC(:,9)>CONSTANTS(:,46), ( CONSTANTS(:,34).*(ALGEBRAIC(:,11)./(ALGEBRAIC(:,11)+ ALGEBRAIC(:,9).*exp((  - CONSTANTS(:,5).*ALGEBRAIC(:,5))./CONSTANTS(:,4))) - ALGEBRAIC(:,8)./(ALGEBRAIC(:,8)+ ALGEBRAIC(:,6).*exp((  - CONSTANTS(:,5).*ALGEBRAIC(:,4))./CONSTANTS(:,4)))).*ALGEBRAIC(:,11))./(CONSTANTS(:,39)+ALGEBRAIC(:,11)) }, 0.00000);
ALGEBRAIC(:,14) =  CONSTANTS(:,44).*( ALGEBRAIC(:,11).*CONSTANTS(:,59) -  CONSTANTS(:,16).*STATES(:,16));
ALGEBRAIC(:,17) = ( STATES(:,18).*CONSTANTS(:,55))./(CONSTANTS(:,55)+CONSTANTS(:,49));
ALGEBRAIC(:,19) = ( STATES(:,4).*STATES(:,2))./(STATES(:,2)+CONSTANTS(:,49));
ALGEBRAIC(:,21) = ( CONSTANTS(:,35).*( STATES(:,2).*ALGEBRAIC(:,17) -  CONSTANTS(:,55).*ALGEBRAIC(:,19)))./(ALGEBRAIC(:,17)+CONSTANTS(:,27));
ALGEBRAIC(:,16) =  CONSTANTS(:,19).*CONSTANTS(:,41).*(CONSTANTS(:,13) - STATES(:,13));
ALGEBRAIC(:,22) =  CONSTANTS(:,40).*( CONSTANTS(:,17).*STATES(:,15).*STATES(:,15) -  STATES(:,17).*STATES(:,13));
ALGEBRAIC(:,18) =  CONSTANTS(:,19).*CONSTANTS(:,41).*(CONSTANTS(:,3) - STATES(:,15));
ALGEBRAIC(:,20) =  CONSTANTS(:,19).*CONSTANTS(:,41).*(CONSTANTS(:,14) - STATES(:,17));
ALGEBRAIC(:,15) =  CONSTANTS(:,19).*CONSTANTS(:,45).*(CONSTANTS(:,2) - STATES(:,18));
ALGEBRAIC(:,24) = ( CONSTANTS(:,38).*STATES(:,1).*( CONSTANTS(:,52).*exp(( CONSTANTS(:,5).*STATES(:,1))./CONSTANTS(:,4)) - STATES(:,19)))./(exp(( CONSTANTS(:,5).*STATES(:,1))./CONSTANTS(:,4)) - 1.00000);
ALGEBRAIC(:,25) =  CONSTANTS(:,36).*( CONSTANTS(:,52).*STATES(:,2) -  STATES(:,19).*CONSTANTS(:,55));
ALGEBRAIC(:,26) = CONSTANTS(:,22) - STATES(:,3);
ALGEBRAIC(:,27) = ( CONSTANTS(:,29).*( CONSTANTS(:,28).*ALGEBRAIC(:,26) - STATES(:,3)).*(1.00000+STATES(:,4)./CONSTANTS(:,23)))./(1.00000+STATES(:,4)./CONSTANTS(:,24));
ALGEBRAIC(:,28) = CONSTANTS(:,21) - STATES(:,5);
ALGEBRAIC(:,29) = (CONSTANTS(:,7) -  CONSTANTS(:,4).*log(STATES(:,2)./1.00000e-07)) -  CONSTANTS(:,4).*log(ALGEBRAIC(:,28)./STATES(:,5));
ALGEBRAIC(:,30) =  CONSTANTS(:,30).*( exp( - (ALGEBRAIC(:,29)+ 4.00000.*ALGEBRAIC(:,1))./CONSTANTS(:,4)).*STATES(:,3) - ALGEBRAIC(:,26));
ALGEBRAIC(:,31) = (CONSTANTS(:,8)+ 2.00000.*CONSTANTS(:,4).*log(STATES(:,2)./1.00000e-07)) -  CONSTANTS(:,4).*log(STATES(:,5)./ALGEBRAIC(:,28));
ALGEBRAIC(:,32) = CONSTANTS(:,20) - STATES(:,6);
ALGEBRAIC(:,33) =  (( CONSTANTS(:,31).*(1.00000+STATES(:,4)./CONSTANTS(:,25)))./(1.00000+STATES(:,4)./CONSTANTS(:,26))).*( exp( - ((ALGEBRAIC(:,31)+ 4.00000.*ALGEBRAIC(:,1)) -  2.00000.*CONSTANTS(:,5).*STATES(:,1))./( 2.00000.*CONSTANTS(:,4))).*ALGEBRAIC(:,32) - STATES(:,6));
ALGEBRAIC(:,2) = (CONSTANTS(:,9) -  2.00000.*CONSTANTS(:,4).*log(STATES(:,2)./1.00000e-07)) -  (CONSTANTS(:,4)./2.00000).*log(STATES(:,7)./1.00000);
ALGEBRAIC(:,34) =  (( (( CONSTANTS(:,32).*1.00000)./(1.00000+CONSTANTS(:,42)./STATES(:,7))).*STATES(:,6))./CONSTANTS(:,20)).*( exp( - (ALGEBRAIC(:,2)+ 2.00000.*ALGEBRAIC(:,1))./( 2.00000.*CONSTANTS(:,4))).*STATES(:,6) -  ALGEBRAIC(:,32).*exp(( CONSTANTS(:,5).*STATES(:,1))./CONSTANTS(:,4)));
ALGEBRAIC(:,23) = ( CONSTANTS(:,37).*STATES(:,1).*( CONSTANTS(:,55).*exp(( CONSTANTS(:,5).*STATES(:,1))./CONSTANTS(:,4)) - STATES(:,2)))./(exp(( CONSTANTS(:,5).*STATES(:,1))./CONSTANTS(:,4)) - 1.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

```
Source
Derived from workspace Beard, 2005 at changeset 8ec69b34c31c.
Collaboration
To begin collaborating on this work, please use your git client and issue this command: