# 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 =1;
end
% There are a total of 14 entries in each of the rate and state variable arrays.
% There are a total of 20 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 (second)');
LEGEND_STATES(:,1) = strpad('Fe3 in component Fe3 (micromolar)');
LEGEND_CONSTANTS(:,1) = strpad('Arg in component model_constants (micromolar)');
LEGEND_STATES(:,2) = strpad('Fe3_Arg in component Fe3_Arg (micromolar)');
LEGEND_STATES(:,3) = strpad('Fe3_NO in component Fe3_NO (micromolar)');
LEGEND_STATES(:,4) = strpad('Fe2_NO in component Fe2_NO (micromolar)');
LEGEND_CONSTANTS(:,2) = strpad('O2 in component model_constants (micromolar)');
LEGEND_CONSTANTS(:,3) = strpad('k1 in component model_constants (second_order_rate_constant)');
LEGEND_CONSTANTS(:,4) = strpad('k_1 in component model_constants (first_order_rate_constant)');
LEGEND_CONSTANTS(:,5) = strpad('k2 in component model_constants (first_order_rate_constant)');
LEGEND_CONSTANTS(:,6) = strpad('k13 in component model_constants (first_order_rate_constant)');
LEGEND_CONSTANTS(:,7) = strpad('k12 in component model_constants (second_order_rate_constant)');
LEGEND_CONSTANTS(:,8) = strpad('k3 in component model_constants (first_order_rate_constant)');
LEGEND_STATES(:,5) = strpad('Fe2 in component Fe2 (micromolar)');
LEGEND_STATES(:,6) = strpad('Fe2_Arg in component Fe2_Arg (micromolar)');
LEGEND_CONSTANTS(:,9) = strpad('k_4 in component model_constants (first_order_rate_constant)');
LEGEND_CONSTANTS(:,10) = strpad('k4 in component model_constants (second_order_rate_constant)');
LEGEND_STATES(:,7) = strpad('Fe3_O2_Arg in component Fe3_O2_Arg (micromolar)');
LEGEND_CONSTANTS(:,11) = strpad('k5 in component model_constants (second_order_rate_constant)');
LEGEND_CONSTANTS(:,12) = strpad('k_5 in component model_constants (first_order_rate_constant)');
LEGEND_CONSTANTS(:,13) = strpad('k6 in component model_constants (first_order_rate_constant)');
LEGEND_STATES(:,8) = strpad('Fe3_NOHA in component Fe3_NOHA (micromolar)');
LEGEND_CONSTANTS(:,14) = strpad('k7 in component model_constants (first_order_rate_constant)');
LEGEND_STATES(:,9) = strpad('Fe2_NOHA in component Fe2_NOHA (micromolar)');
LEGEND_STATES(:,10) = strpad('NOHA in component NOHA (micromolar)');
LEGEND_STATES(:,11) = strpad('Fe3_O2_NOHA in component Fe3_O2_NOHA (micromolar)');
LEGEND_CONSTANTS(:,15) = strpad('k9 in component model_constants (second_order_rate_constant)');
LEGEND_CONSTANTS(:,16) = strpad('k_9 in component model_constants (first_order_rate_constant)');
LEGEND_CONSTANTS(:,17) = strpad('k_8 in component model_constants (first_order_rate_constant)');
LEGEND_CONSTANTS(:,18) = strpad('k8 in component model_constants (second_order_rate_constant)');
LEGEND_CONSTANTS(:,19) = strpad('k10 in component model_constants (first_order_rate_constant)');
LEGEND_CONSTANTS(:,20) = strpad('k11 in component model_constants (first_order_rate_constant)');
LEGEND_STATES(:,12) = strpad('NO in component NO (micromolar)');
LEGEND_ALGEBRAIC(:,1) = strpad('dNOdt in component NO (flux)');
LEGEND_STATES(:,13) = strpad('citrulline in component citrulline (micromolar)');
LEGEND_STATES(:,14) = strpad('NO3 in component NO3 (micromolar)');
LEGEND_RATES(:,1) = strpad('d/dt Fe3 in component Fe3 (micromolar)');
LEGEND_RATES(:,2) = strpad('d/dt Fe3_Arg in component Fe3_Arg (micromolar)');
LEGEND_RATES(:,5) = strpad('d/dt Fe2 in component Fe2 (micromolar)');
LEGEND_RATES(:,6) = strpad('d/dt Fe2_Arg in component Fe2_Arg (micromolar)');
LEGEND_RATES(:,7) = strpad('d/dt Fe3_O2_Arg in component Fe3_O2_Arg (micromolar)');
LEGEND_RATES(:,8) = strpad('d/dt Fe3_NOHA in component Fe3_NOHA (micromolar)');
LEGEND_RATES(:,9) = strpad('d/dt Fe2_NOHA in component Fe2_NOHA (micromolar)');
LEGEND_RATES(:,11) = strpad('d/dt Fe3_O2_NOHA in component Fe3_O2_NOHA (micromolar)');
LEGEND_RATES(:,3) = strpad('d/dt Fe3_NO in component Fe3_NO (micromolar)');
LEGEND_RATES(:,4) = strpad('d/dt Fe2_NO in component Fe2_NO (micromolar)');
LEGEND_RATES(:,12) = strpad('d/dt NO in component NO (micromolar)');
LEGEND_RATES(:,13) = strpad('d/dt citrulline in component citrulline (micromolar)');
LEGEND_RATES(:,14) = strpad('d/dt NO3 in component NO3 (micromolar)');
LEGEND_RATES(:,10) = strpad('d/dt NOHA in component NOHA (micromolar)');
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) = 0.9;
CONSTANTS(:,1) = 100.0;
STATES(:,2) = 0.0;
STATES(:,3) = 0.0;
STATES(:,4) = 0.0;
CONSTANTS(:,2) = 100.0;
CONSTANTS(:,3) = 6.6;
CONSTANTS(:,4) = 6.6;
CONSTANTS(:,5) = 20.8;
CONSTANTS(:,6) = 39.9;
CONSTANTS(:,7) = 0.01;
CONSTANTS(:,8) = 20.8;
STATES(:,5) = 0.0;
STATES(:,6) = 0.0;
CONSTANTS(:,9) = 6.6;
CONSTANTS(:,10) = 6.6;
STATES(:,7) = 0.0;
CONSTANTS(:,11) = 8.5;
CONSTANTS(:,12) = 215.6;
CONSTANTS(:,13) = 175.6;
STATES(:,8) = 0.0;
CONSTANTS(:,14) = 20.8;
STATES(:,9) = 0.0;
STATES(:,10) = 0.0;
STATES(:,11) = 0.0;
CONSTANTS(:,15) = 8.6;
CONSTANTS(:,16) = 399.2;
CONSTANTS(:,17) = 13.2;
CONSTANTS(:,18) = 13.2;
CONSTANTS(:,19) = 39.1;
CONSTANTS(:,20) = 20.8;
STATES(:,12) = 0.0;
STATES(:,13) = 0.0;
STATES(:,14) = 0.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);
utilOnes = 1;
else
statesRowCount = statesSize(1);
ALGEBRAIC = zeros(statesRowCount, algebraicVariableCount);
RATES = zeros(statesRowCount, statesColumnCount);
utilOnes = ones(statesRowCount, 1);
end
RATES(:,12) =  CONSTANTS(:,6).*STATES(:,3);
RATES(:,1) = ( CONSTANTS(:,4).*STATES(:,2)+ CONSTANTS(:,6).*STATES(:,3)+ CONSTANTS(:,7).*STATES(:,4).*CONSTANTS(:,2)) - ( CONSTANTS(:,3).*CONSTANTS(:,1).*STATES(:,1)+ CONSTANTS(:,5).*STATES(:,1));
RATES(:,2) =  CONSTANTS(:,3).*STATES(:,1).*CONSTANTS(:,1) - ( CONSTANTS(:,4).*STATES(:,2)+ CONSTANTS(:,8).*STATES(:,2));
RATES(:,5) = ( CONSTANTS(:,5).*STATES(:,1)+ CONSTANTS(:,9).*STATES(:,6)) -  CONSTANTS(:,10).*STATES(:,5).*CONSTANTS(:,1);
RATES(:,6) = ( CONSTANTS(:,8).*STATES(:,2)+ CONSTANTS(:,12).*STATES(:,7)+ CONSTANTS(:,10).*STATES(:,5).*CONSTANTS(:,1)) - ( CONSTANTS(:,11).*STATES(:,6).*CONSTANTS(:,2)+ CONSTANTS(:,9).*STATES(:,6));
RATES(:,7) =  CONSTANTS(:,11).*STATES(:,6).*CONSTANTS(:,2) - ( CONSTANTS(:,13).*STATES(:,7)+ CONSTANTS(:,12).*STATES(:,7));
RATES(:,8) =  CONSTANTS(:,13).*STATES(:,7) -  CONSTANTS(:,14).*STATES(:,8);
RATES(:,9) = ( CONSTANTS(:,14).*STATES(:,8)+ CONSTANTS(:,16).*STATES(:,11)+ CONSTANTS(:,18).*STATES(:,5).*STATES(:,10)) - ( CONSTANTS(:,17).*STATES(:,9)+ CONSTANTS(:,15).*STATES(:,9).*CONSTANTS(:,2));
RATES(:,11) =  CONSTANTS(:,15).*STATES(:,9).*CONSTANTS(:,2) - ( CONSTANTS(:,19).*STATES(:,11)+ CONSTANTS(:,16).*STATES(:,11));
RATES(:,3) =  CONSTANTS(:,19).*STATES(:,11) - ( CONSTANTS(:,6).*STATES(:,3)+ CONSTANTS(:,20).*STATES(:,3));
RATES(:,4) =  CONSTANTS(:,20).*STATES(:,3) -  CONSTANTS(:,7).*STATES(:,4).*CONSTANTS(:,2);
RATES(:,13) =  CONSTANTS(:,19).*STATES(:,11);
RATES(:,14) =  CONSTANTS(:,7).*STATES(:,4).*CONSTANTS(:,2);
RATES(:,10) =  CONSTANTS(:,17).*STATES(:,9) -  CONSTANTS(:,18).*STATES(:,5).*STATES(:,10);
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(:,1) = RATES(:,12);
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 Chen, Popel, 2007 at changeset adf8055ffe57.
Collaboration
To begin collaborating on this work, please use your git client and issue this command:
Tools