# 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 =23;
end
% There are a total of 13 entries in each of the rate and state variable arrays.
% There are a total of 28 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 (minute)');
LEGEND_STATES(:,1) = strpad('S1 in component S1 (millimolar)');
LEGEND_ALGEBRAIC(:,14) = strpad('v8 in component v8 (flux)');
LEGEND_ALGEBRAIC(:,16) = strpad('v9 in component v9 (flux)');
LEGEND_CONSTANTS(:,1) = strpad('S in component S (millimolar)');
LEGEND_ALGEBRAIC(:,1) = strpad('S2 in component S (millimolar)');
LEGEND_STATES(:,2) = strpad('sul in component sul (millimolar)');
LEGEND_ALGEBRAIC(:,6) = strpad('v1 in component v1 (flux)');
LEGEND_ALGEBRAIC(:,7) = strpad('v2 in component v2 (flux)');
LEGEND_STATES(:,3) = strpad('aps in component aps (millimolar)');
LEGEND_ALGEBRAIC(:,8) = strpad('v3 in component v3 (flux)');
LEGEND_STATES(:,4) = strpad('pap in component pap (millimolar)');
LEGEND_ALGEBRAIC(:,9) = strpad('v4 in component v4 (flux)');
LEGEND_STATES(:,5) = strpad('hyd in component hyd (millimolar)');
LEGEND_ALGEBRAIC(:,10) = strpad('v5 in component v5 (flux)');
LEGEND_ALGEBRAIC(:,12) = strpad('v17 in component v17 (flux)');
LEGEND_STATES(:,6) = strpad('cys in component cys (millimolar)');
LEGEND_ALGEBRAIC(:,13) = strpad('v6 in component v6 (flux)');
LEGEND_STATES(:,7) = strpad('eth in component eth (millimolar)');
LEGEND_CONSTANTS(:,2) = strpad('v13 in component v13 (flux)');
LEGEND_ALGEBRAIC(:,11) = strpad('v7 in component v7 (flux)');
LEGEND_STATES(:,8) = strpad('aco in component aco (millimolar)');
LEGEND_ALGEBRAIC(:,15) = strpad('v15 in component v15 (flux)');
LEGEND_STATES(:,9) = strpad('oxy in component oxy (millimolar)');
LEGEND_CONSTANTS(:,3) = strpad('v10 in component v10 (flux)');
LEGEND_ALGEBRAIC(:,19) = strpad('v11A in component v11A (flux)');
LEGEND_ALGEBRAIC(:,20) = strpad('v14 in component v14 (flux)');
LEGEND_STATES(:,10) = strpad('A3_c in component A3_c (millimolar)');
LEGEND_ALGEBRAIC(:,22) = strpad('v12 in component v12 (flux)');
LEGEND_ALGEBRAIC(:,23) = strpad('v16 in component v16 (flux)');
LEGEND_STATES(:,11) = strpad('A3_m in component A3_m (millimolar)');
LEGEND_ALGEBRAIC(:,21) = strpad('v11B in component v11B (flux)');
LEGEND_CONSTANTS(:,4) = strpad('A_c in component A_c (millimolar)');
LEGEND_ALGEBRAIC(:,2) = strpad('A2_c in component A_c (millimolar)');
LEGEND_CONSTANTS(:,5) = strpad('A_m in component A_m (millimolar)');
LEGEND_ALGEBRAIC(:,3) = strpad('A2_m in component A_m (millimolar)');
LEGEND_STATES(:,12) = strpad('N2 in component N2 (millimolar)');
LEGEND_CONSTANTS(:,6) = strpad('N in component N (millimolar)');
LEGEND_ALGEBRAIC(:,4) = strpad('N1 in component N (millimolar)');
LEGEND_STATES(:,13) = strpad('oah in component oah (millimolar)');
LEGEND_ALGEBRAIC(:,18) = strpad('v18 in component v18 (flux)');
LEGEND_CONSTANTS(:,7) = strpad('v0 in component v1 (flux)');
LEGEND_ALGEBRAIC(:,5) = strpad('f1 in component v1 (dimensionless)');
LEGEND_CONSTANTS(:,8) = strpad('n in component v1 (dimensionless)');
LEGEND_CONSTANTS(:,9) = strpad('Kc in component v1 (millimolar)');
LEGEND_CONSTANTS(:,10) = strpad('k2 in component v2 (second_order_rate_constant)');
LEGEND_CONSTANTS(:,11) = strpad('k3 in component v3 (second_order_rate_constant)');
LEGEND_CONSTANTS(:,12) = strpad('k4 in component v4 (second_order_rate_constant)');
LEGEND_CONSTANTS(:,13) = strpad('k5 in component v5 (second_order_rate_constant)');
LEGEND_CONSTANTS(:,14) = strpad('k6 in component v6 (first_order_rate_constant)');
LEGEND_CONSTANTS(:,15) = strpad('k7 in component v7 (second_order_rate_constant)');
LEGEND_CONSTANTS(:,16) = strpad('k8 in component v8 (second_order_rate_constant)');
LEGEND_CONSTANTS(:,17) = strpad('k9 in component v9 (second_order_rate_constant)');
LEGEND_CONSTANTS(:,18) = strpad('alpha in component v11A (dimensionless)');
LEGEND_ALGEBRAIC(:,17) = strpad('f2 in component v11A (dimensionless)');
LEGEND_CONSTANTS(:,19) = strpad('m in component v11A (dimensionless)');
LEGEND_CONSTANTS(:,20) = strpad('KH in component v11A (millimolar)');
LEGEND_CONSTANTS(:,21) = strpad('k11 in component v11A (first_order_rate_constant)');
LEGEND_CONSTANTS(:,22) = strpad('KA in component v11B (millimolar)');
LEGEND_CONSTANTS(:,23) = strpad('k12 in component v12 (first_order_rate_constant)');
LEGEND_CONSTANTS(:,24) = strpad('k14 in component v14 (first_order_rate_constant)');
LEGEND_CONSTANTS(:,25) = strpad('k15 in component v15 (first_order_rate_constant)');
LEGEND_CONSTANTS(:,26) = strpad('k16 in component v16 (second_order_rate_constant)');
LEGEND_CONSTANTS(:,27) = strpad('k17 in component v17 (first_order_rate_constant)');
LEGEND_CONSTANTS(:,28) = strpad('k18 in component v18 (first_order_rate_constant)');
LEGEND_RATES(:,1) = strpad('d/dt S1 in component S1 (millimolar)');
LEGEND_RATES(:,2) = strpad('d/dt sul in component sul (millimolar)');
LEGEND_RATES(:,3) = strpad('d/dt aps in component aps (millimolar)');
LEGEND_RATES(:,4) = strpad('d/dt pap in component pap (millimolar)');
LEGEND_RATES(:,5) = strpad('d/dt hyd in component hyd (millimolar)');
LEGEND_RATES(:,6) = strpad('d/dt cys in component cys (millimolar)');
LEGEND_RATES(:,7) = strpad('d/dt eth in component eth (millimolar)');
LEGEND_RATES(:,8) = strpad('d/dt aco in component aco (millimolar)');
LEGEND_RATES(:,9) = strpad('d/dt oxy in component oxy (millimolar)');
LEGEND_RATES(:,10) = strpad('d/dt A3_c in component A3_c (millimolar)');
LEGEND_RATES(:,11) = strpad('d/dt A3_m in component A3_m (millimolar)');
LEGEND_RATES(:,12) = strpad('d/dt N2 in component N2 (millimolar)');
LEGEND_RATES(:,13) = strpad('d/dt oah in component oah (millimolar)');
LEGEND_STATES  = LEGEND_STATES';
LEGEND_ALGEBRAIC = LEGEND_ALGEBRAIC';
LEGEND_RATES = LEGEND_RATES';
LEGEND_CONSTANTS = LEGEND_CONSTANTS';
end

function [STATES, CONSTANTS] = initConsts()
VOI = 0; CONSTANTS = []; STATES = []; ALGEBRAIC = [];
STATES(:,1) = 1.892468811;
CONSTANTS(:,1) = 2;
STATES(:,2) = 0.012871557;
STATES(:,3) = 0.053366179;
STATES(:,4) = 0.082791522;
STATES(:,5) = 0.159317029;
STATES(:,6) = 0.805117739;
STATES(:,7) = 10.25246999;
CONSTANTS(:,2) = 4;
STATES(:,8) = 1.139360412;
STATES(:,9) = 6.146549084;
CONSTANTS(:,3) = 80;
STATES(:,10) = 1.570847601;
STATES(:,11) = 1.835158493;
CONSTANTS(:,4) = 2;
CONSTANTS(:,5) = 2;
STATES(:,12) = 1.933616149;
CONSTANTS(:,6) = 2;
STATES(:,13) = 5.571685096;
CONSTANTS(:,7) = 1.6;
CONSTANTS(:,8) = 4;
CONSTANTS(:,9) = 0.1;
CONSTANTS(:,10) = 0.2;
CONSTANTS(:,11) = 0.2;
CONSTANTS(:,12) = 0.2;
CONSTANTS(:,13) = 0.1;
CONSTANTS(:,14) = 0.12;
CONSTANTS(:,15) = 10;
CONSTANTS(:,16) = 10;
CONSTANTS(:,17) = 10;
CONSTANTS(:,18) = 0.1;
CONSTANTS(:,19) = 4;
CONSTANTS(:,20) = 0.5;
CONSTANTS(:,21) = 10;
CONSTANTS(:,22) = 1;
CONSTANTS(:,23) = 5;
CONSTANTS(:,24) = 10;
CONSTANTS(:,25) = 5;
CONSTANTS(:,26) = 10;
CONSTANTS(:,27) = 0.02;
CONSTANTS(:,28) = 1;
if (isempty(STATES)), warning('Initial values for states not set');, end
end

function [RATES, ALGEBRAIC] = computeRates(VOI, STATES, CONSTANTS)
global algebraicVariableCount;
statesSize = size(STATES);
statesColumnCount = statesSize(2);
if ( statesColumnCount == 1)
STATES = STATES';
ALGEBRAIC = zeros(1, algebraicVariableCount);
utilOnes = 1;
else
statesRowCount = statesSize(1);
ALGEBRAIC = zeros(statesRowCount, algebraicVariableCount);
RATES = zeros(statesRowCount, statesColumnCount);
utilOnes = ones(statesRowCount, 1);
end
ALGEBRAIC(:,5) = power(1.00000+power(STATES(:,6)./CONSTANTS(:,9), CONSTANTS(:,8)),  - 1.00000);
ALGEBRAIC(:,6) =  CONSTANTS(:,7).*ALGEBRAIC(:,5);
ALGEBRAIC(:,7) =  CONSTANTS(:,10).*STATES(:,2).*STATES(:,10);
RATES(:,2) = ALGEBRAIC(:,6) - ALGEBRAIC(:,7);
ALGEBRAIC(:,8) =  CONSTANTS(:,11).*STATES(:,3).*STATES(:,10);
RATES(:,3) = ALGEBRAIC(:,7) - ALGEBRAIC(:,8);
ALGEBRAIC(:,9) =  CONSTANTS(:,12).*STATES(:,4).*STATES(:,12);
RATES(:,4) = ALGEBRAIC(:,8) - ALGEBRAIC(:,9);
ALGEBRAIC(:,10) =  CONSTANTS(:,13).*STATES(:,5).*STATES(:,13);
ALGEBRAIC(:,12) =  CONSTANTS(:,27).*STATES(:,5);
RATES(:,5) = ALGEBRAIC(:,9) - (ALGEBRAIC(:,10)+ALGEBRAIC(:,12));
ALGEBRAIC(:,13) =  CONSTANTS(:,14).*STATES(:,6);
RATES(:,6) = ALGEBRAIC(:,10) - ALGEBRAIC(:,13);
ALGEBRAIC(:,4) = CONSTANTS(:,6) - STATES(:,12);
ALGEBRAIC(:,11) =  CONSTANTS(:,15).*STATES(:,7).*ALGEBRAIC(:,4);
RATES(:,7) = CONSTANTS(:,2) - ALGEBRAIC(:,11);
ALGEBRAIC(:,1) = CONSTANTS(:,1) - STATES(:,1);
ALGEBRAIC(:,14) =  CONSTANTS(:,16).*STATES(:,8).*ALGEBRAIC(:,1);
ALGEBRAIC(:,16) =  CONSTANTS(:,17).*STATES(:,1).*ALGEBRAIC(:,4);
RATES(:,1) = ALGEBRAIC(:,14) - ALGEBRAIC(:,16);
ALGEBRAIC(:,15) =  CONSTANTS(:,25).*STATES(:,8);
RATES(:,8) = ALGEBRAIC(:,11) - (ALGEBRAIC(:,14)+ALGEBRAIC(:,15));
ALGEBRAIC(:,18) =  CONSTANTS(:,28).*STATES(:,13);
RATES(:,13) = ALGEBRAIC(:,15) - (ALGEBRAIC(:,10)+ALGEBRAIC(:,18));
ALGEBRAIC(:,17) = power(1.00000+power(STATES(:,5)./CONSTANTS(:,20), CONSTANTS(:,19)),  - 1.00000);
ALGEBRAIC(:,19) = ( CONSTANTS(:,21).*STATES(:,12).*STATES(:,9).*ALGEBRAIC(:,17))./( CONSTANTS(:,18).*STATES(:,12)+STATES(:,9));
RATES(:,12) = ( 2.00000.*ALGEBRAIC(:,11)+ 4.00000.*ALGEBRAIC(:,16)) - ( 3.00000.*ALGEBRAIC(:,9)+ALGEBRAIC(:,19));
ALGEBRAIC(:,20) =  CONSTANTS(:,24).*STATES(:,9);
RATES(:,9) = CONSTANTS(:,3) - (ALGEBRAIC(:,19)+ALGEBRAIC(:,20));
ALGEBRAIC(:,22) =  CONSTANTS(:,23).*STATES(:,10);
ALGEBRAIC(:,2) = CONSTANTS(:,4) - STATES(:,10);
ALGEBRAIC(:,23) =  CONSTANTS(:,26).*STATES(:,11).*ALGEBRAIC(:,2);
RATES(:,10) = ALGEBRAIC(:,23) - (ALGEBRAIC(:,7)+ALGEBRAIC(:,8)+ALGEBRAIC(:,22));
ALGEBRAIC(:,3) = CONSTANTS(:,5) - STATES(:,11);
ALGEBRAIC(:,21) = ( 3.00000.*ALGEBRAIC(:,19).*ALGEBRAIC(:,3))./(CONSTANTS(:,22)+ALGEBRAIC(:,3));
RATES(:,11) = ALGEBRAIC(:,21) - ALGEBRAIC(:,23);
RATES = RATES';
end

% Calculate algebraic variables
function ALGEBRAIC = computeAlgebraic(ALGEBRAIC, CONSTANTS, STATES, VOI)
statesSize = size(STATES);
statesColumnCount = statesSize(2);
if ( statesColumnCount == 1)
STATES = STATES';
utilOnes = 1;
else
statesRowCount = statesSize(1);
utilOnes = ones(statesRowCount, 1);
end
ALGEBRAIC(:,5) = power(1.00000+power(STATES(:,6)./CONSTANTS(:,9), CONSTANTS(:,8)),  - 1.00000);
ALGEBRAIC(:,6) =  CONSTANTS(:,7).*ALGEBRAIC(:,5);
ALGEBRAIC(:,7) =  CONSTANTS(:,10).*STATES(:,2).*STATES(:,10);
ALGEBRAIC(:,8) =  CONSTANTS(:,11).*STATES(:,3).*STATES(:,10);
ALGEBRAIC(:,9) =  CONSTANTS(:,12).*STATES(:,4).*STATES(:,12);
ALGEBRAIC(:,10) =  CONSTANTS(:,13).*STATES(:,5).*STATES(:,13);
ALGEBRAIC(:,12) =  CONSTANTS(:,27).*STATES(:,5);
ALGEBRAIC(:,13) =  CONSTANTS(:,14).*STATES(:,6);
ALGEBRAIC(:,4) = CONSTANTS(:,6) - STATES(:,12);
ALGEBRAIC(:,11) =  CONSTANTS(:,15).*STATES(:,7).*ALGEBRAIC(:,4);
ALGEBRAIC(:,1) = CONSTANTS(:,1) - STATES(:,1);
ALGEBRAIC(:,14) =  CONSTANTS(:,16).*STATES(:,8).*ALGEBRAIC(:,1);
ALGEBRAIC(:,16) =  CONSTANTS(:,17).*STATES(:,1).*ALGEBRAIC(:,4);
ALGEBRAIC(:,15) =  CONSTANTS(:,25).*STATES(:,8);
ALGEBRAIC(:,18) =  CONSTANTS(:,28).*STATES(:,13);
ALGEBRAIC(:,17) = power(1.00000+power(STATES(:,5)./CONSTANTS(:,20), CONSTANTS(:,19)),  - 1.00000);
ALGEBRAIC(:,19) = ( CONSTANTS(:,21).*STATES(:,12).*STATES(:,9).*ALGEBRAIC(:,17))./( CONSTANTS(:,18).*STATES(:,12)+STATES(:,9));
ALGEBRAIC(:,20) =  CONSTANTS(:,24).*STATES(:,9);
ALGEBRAIC(:,22) =  CONSTANTS(:,23).*STATES(:,10);
ALGEBRAIC(:,2) = CONSTANTS(:,4) - STATES(:,10);
ALGEBRAIC(:,23) =  CONSTANTS(:,26).*STATES(:,11).*ALGEBRAIC(:,2);
ALGEBRAIC(:,3) = CONSTANTS(:,5) - STATES(:,11);
ALGEBRAIC(:,21) = ( 3.00000.*ALGEBRAIC(:,19).*ALGEBRAIC(:,3))./(CONSTANTS(:,22)+ALGEBRAIC(:,3));
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 Wolf, Sohn, Heinrich, Kuriyama, 2001 at changeset 3a6924b88a89.
Collaboration
To begin collaborating on this work, please use your git client and issue this command: