# 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 =3;
end
% There are a total of 9 entries in each of the rate and state variable arrays.
% There are a total of 18 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_CONSTANTS(:,1) = strpad('NGF in component NGF (dimensionless)');
LEGEND_CONSTANTS(:,2) = strpad('pro_TrkA in component pro_TrkA (dimensionless)');
LEGEND_STATES(:,1) = strpad('TrkA in component TrkA (dimensionless)');
LEGEND_STATES(:,2) = strpad('NGF_TrkA in component NGF_TrkA (dimensionless)');
LEGEND_CONSTANTS(:,3) = strpad('k2_NGF_TrkA in component model_parameters (first_order_rate_constant)');
LEGEND_CONSTANTS(:,4) = strpad('k1_NGF_TrkA in component model_parameters (first_order_rate_constant)');
LEGEND_CONSTANTS(:,5) = strpad('TrkA_turnover in component model_parameters (first_order_rate_constant)');
LEGEND_CONSTANTS(:,6) = strpad('k1_TrkA_phosphorylation in component model_parameters (first_order_rate_constant)');
LEGEND_STATES(:,3) = strpad('pTrkA in component pTrkA (dimensionless)');
LEGEND_STATES(:,4) = strpad('pTrkA_Akt in component pTrkA_Akt (dimensionless)');
LEGEND_STATES(:,5) = strpad('Akt in component Akt (dimensionless)');
LEGEND_CONSTANTS(:,8) = strpad('k1_Akt_phosphorylation in component model_parameters (first_order_rate_constant)');
LEGEND_CONSTANTS(:,9) = strpad('k1_pTrkA_Akt in component model_parameters (first_order_rate_constant)');
LEGEND_CONSTANTS(:,10) = strpad('k2_pTrkA_Akt in component model_parameters (first_order_rate_constant)');
LEGEND_STATES(:,6) = strpad('pAkt in component pAkt (dimensionless)');
LEGEND_CONSTANTS(:,11) = strpad('k1_pAkt_dephosphorylation in component model_parameters (first_order_rate_constant)');
LEGEND_STATES(:,7) = strpad('S6 in component S6 (dimensionless)');
LEGEND_STATES(:,8) = strpad('pAkt_S6 in component pAkt_S6 (dimensionless)');
LEGEND_CONSTANTS(:,12) = strpad('k1_pAkt_S6 in component model_parameters (first_order_rate_constant)');
LEGEND_CONSTANTS(:,13) = strpad('k2_pAkt_S6 in component model_parameters (first_order_rate_constant)');
LEGEND_CONSTANTS(:,14) = strpad('k1_S6_phosphorylation in component model_parameters (first_order_rate_constant)');
LEGEND_STATES(:,9) = strpad('pS6 in component pS6 (dimensionless)');
LEGEND_CONSTANTS(:,15) = strpad('k1_pS6_dephosphorylation in component model_parameters (first_order_rate_constant)');
LEGEND_ALGEBRAIC(:,1) = strpad('pTrkA_total in component pTrkA_total (dimensionless)');
LEGEND_CONSTANTS(:,16) = strpad('pTrkA_scalefactor in component pTrkA_total (dimensionless)');
LEGEND_ALGEBRAIC(:,2) = strpad('pAkt_total in component pAkt_total (dimensionless)');
LEGEND_CONSTANTS(:,17) = strpad('pAkt_scalefactor in component pAkt_total (dimensionless)');
LEGEND_ALGEBRAIC(:,3) = strpad('pS6_total in component pS6_total (dimensionless)');
LEGEND_CONSTANTS(:,18) = strpad('pS6_scalefactor in component pS6_total (dimensionless)');
LEGEND_RATES(:,1) = strpad('d/dt TrkA in component TrkA (dimensionless)');
LEGEND_RATES(:,2) = strpad('d/dt NGF_TrkA in component NGF_TrkA (dimensionless)');
LEGEND_RATES(:,3) = strpad('d/dt pTrkA in component pTrkA (dimensionless)');
LEGEND_RATES(:,4) = strpad('d/dt pTrkA_Akt in component pTrkA_Akt (dimensionless)');
LEGEND_RATES(:,5) = strpad('d/dt Akt in component Akt (dimensionless)');
LEGEND_RATES(:,6) = strpad('d/dt pAkt in component pAkt (dimensionless)');
LEGEND_RATES(:,8) = strpad('d/dt pAkt_S6 in component pAkt_S6 (dimensionless)');
LEGEND_RATES(:,7) = strpad('d/dt S6 in component S6 (dimensionless)');
LEGEND_RATES(:,9) = strpad('d/dt pS6 in component pS6 (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) = 30.0;
CONSTANTS(:,2) = 8.52065e0;
STATES(:,1) = 8.52065e0;
STATES(:,2) = 0.0;
CONSTANTS(:,3) = 1.33747e-2;
CONSTANTS(:,4) = 2.69408e-3;
CONSTANTS(:,5) = 0.0011032440769796;
CONSTANTS(:,6) = 8.33178e-3;
STATES(:,3) = 0.0;
STATES(:,4) = 0.0;
STATES(:,5) = 1.15595e0;
CONSTANTS(:,7) = 6.8084e-2;
CONSTANTS(:,8) = 2.02517e-2;
CONSTANTS(:,9) = 8.82701e-2;
CONSTANTS(:,10) = 1.47518e-10;
STATES(:,6) = 0.0;
CONSTANTS(:,11) = 1.28135e0;
STATES(:,7) = 3.55234e0;
STATES(:,8) = 0.0;
CONSTANTS(:,12) = 6.83666e1;
CONSTANTS(:,13) = 5.23519e-00;
CONSTANTS(:,14) = 5.65150e-3;
STATES(:,9) = 0.0;
CONSTANTS(:,15) = 2.93167e-4;
CONSTANTS(:,16) = 8.48783e-1;
CONSTANTS(:,17) = 2.42381e0;
CONSTANTS(:,18) = 5.25843e-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
RATES(:,1) = ( CONSTANTS(:,3).*STATES(:,2)+ CONSTANTS(:,5).*(CONSTANTS(:,2) - STATES(:,1))) -  CONSTANTS(:,4).*CONSTANTS(:,1).*STATES(:,1);
RATES(:,2) =  CONSTANTS(:,4).*CONSTANTS(:,1).*STATES(:,1) - ( CONSTANTS(:,3).*STATES(:,2)+ CONSTANTS(:,6).*STATES(:,2));
RATES(:,3) = ( CONSTANTS(:,6).*STATES(:,2)+ CONSTANTS(:,8).*STATES(:,4)+ CONSTANTS(:,10).*STATES(:,4)) - ( CONSTANTS(:,7).*STATES(:,3)+ CONSTANTS(:,9).*STATES(:,3).*STATES(:,5));
RATES(:,4) =  CONSTANTS(:,9).*STATES(:,3).*STATES(:,5) - ( CONSTANTS(:,10).*STATES(:,4)+ CONSTANTS(:,8).*STATES(:,4));
RATES(:,5) = ( CONSTANTS(:,10).*STATES(:,4)+ CONSTANTS(:,11).*STATES(:,6)) -  CONSTANTS(:,9).*STATES(:,3).*STATES(:,5);
RATES(:,6) = ( CONSTANTS(:,8).*STATES(:,4)+ CONSTANTS(:,13).*STATES(:,8)+ CONSTANTS(:,14).*STATES(:,8)) - ( CONSTANTS(:,11).*STATES(:,6)+ CONSTANTS(:,12).*STATES(:,6).*STATES(:,7));
RATES(:,8) =  CONSTANTS(:,12).*STATES(:,6).*STATES(:,7) - ( CONSTANTS(:,13).*STATES(:,8)+ CONSTANTS(:,14).*STATES(:,8));
RATES(:,7) = ( CONSTANTS(:,13).*STATES(:,8)+ CONSTANTS(:,15).*STATES(:,9)) -  CONSTANTS(:,12).*STATES(:,6).*STATES(:,7);
RATES(:,9) =  CONSTANTS(:,14).*STATES(:,8) -  CONSTANTS(:,15).*STATES(:,9);
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) =  (STATES(:,3)+STATES(:,4)).*CONSTANTS(:,16);
ALGEBRAIC(:,2) =  (STATES(:,6)+STATES(:,8)).*CONSTANTS(:,17);
ALGEBRAIC(:,3) =  STATES(:,9).*CONSTANTS(:,18);
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 Fujita, Toyoshima, Uda, Ozaki, Kubota and Kuroda 2010 at changeset e404cee704e9.
Collaboration
To begin collaborating on this work, please use your git client and issue this command: