# 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 =10;
end
% There are a total of 5 entries in each of the rate and state variable arrays.
% There are a total of 27 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('k_0 in component Constants (flux)');
LEGEND_CONSTANTS(:,2) = strpad('k_1 in component Constants (per_second)');
LEGEND_CONSTANTS(:,3) = strpad('k_2 in component Constants (per_second)');
LEGEND_CONSTANTS(:,4) = strpad('k_3 in component Constants (per_second)');
LEGEND_CONSTANTS(:,5) = strpad('k_4 in component Constants (per_second)');
LEGEND_CONSTANTS(:,6) = strpad('k_5 in component Constants (per_second)');
LEGEND_CONSTANTS(:,7) = strpad('k_6 in component Constants (per_second)');
LEGEND_CONSTANTS(:,8) = strpad('k_7 in component Constants (per_second)');
LEGEND_CONSTANTS(:,9) = strpad('k_8 in component Constants (flux)');
LEGEND_CONSTANTS(:,10) = strpad('k_9 in component Constants (flux)');
LEGEND_CONSTANTS(:,11) = strpad('k_10 in component Constants (flux)');
LEGEND_CONSTANTS(:,12) = strpad('k_11 in component Constants (flux)');
LEGEND_CONSTANTS(:,13) = strpad('C_PLC_T in component Constants (micromolar)');
LEGEND_CONSTANTS(:,14) = strpad('K_D in component Constants (micromolar)');
LEGEND_CONSTANTS(:,15) = strpad('K_P in component Constants (micromolar)');
LEGEND_CONSTANTS(:,16) = strpad('K_R in component Constants (micromolar)');
LEGEND_CONSTANTS(:,17) = strpad('K_G in component Constants (micromolar)');
LEGEND_CONSTANTS(:,18) = strpad('K_S in component Constants (micromolar)');
LEGEND_CONSTANTS(:,19) = strpad('K_ER in component Constants (micromolar)');
LEGEND_CONSTANTS(:,20) = strpad('K_C1 in component Constants (micromolar)');
LEGEND_CONSTANTS(:,21) = strpad('K_C2 in component Constants (micromolar)');
LEGEND_CONSTANTS(:,22) = strpad('beta in component Constants (dimensionless)');
LEGEND_CONSTANTS(:,23) = strpad('lambda in component Constants (dimensionless)');
LEGEND_CONSTANTS(:,24) = strpad('rho in component Constants (dimensionless)');
LEGEND_CONSTANTS(:,25) = strpad('n in component Constants (dimensionless)');
LEGEND_CONSTANTS(:,26) = strpad('m in component Constants (dimensionless)');
LEGEND_CONSTANTS(:,27) = strpad('w in component Constants (dimensionless)');
LEGEND_ALGEBRAIC(:,2) = strpad('R_APLC in component R_values (dimensionless)');
LEGEND_ALGEBRAIC(:,9) = strpad('R_PKC in component R_values (dimensionless)');
LEGEND_ALGEBRAIC(:,4) = strpad('R_G in component R_values (dimensionless)');
LEGEND_ALGEBRAIC(:,10) = strpad('R_DG in component R_values (dimensionless)');
LEGEND_ALGEBRAIC(:,1) = strpad('R_IP_3 in component R_values (dimensionless)');
LEGEND_ALGEBRAIC(:,3) = strpad('R_Cyt1 in component R_values (dimensionless)');
LEGEND_ALGEBRAIC(:,5) = strpad('R_Cyt2 in component R_values (dimensionless)');
LEGEND_ALGEBRAIC(:,7) = strpad('R_ER in component R_values (dimensionless)');
LEGEND_STATES(:,1) = strpad('APLC in component APLC (micromolar)');
LEGEND_ALGEBRAIC(:,8) = strpad('DG in component DG (micromolar)');
LEGEND_STATES(:,2) = strpad('C_cyt in component C_cyt (micromolar)');
LEGEND_STATES(:,3) = strpad('G in component G_GTP (micromolar)');
LEGEND_STATES(:,4) = strpad('IP_3 in component IP_3 (micromolar)');
LEGEND_STATES(:,5) = strpad('C_ER in component C_ER (micromolar)');
LEGEND_ALGEBRAIC(:,6) = strpad('PLC in component APLC (micromolar)');
LEGEND_RATES(:,3) = strpad('d/dt G in component G_GTP (micromolar)');
LEGEND_RATES(:,1) = strpad('d/dt APLC in component APLC (micromolar)');
LEGEND_RATES(:,4) = strpad('d/dt IP_3 in component IP_3 (micromolar)');
LEGEND_RATES(:,2) = strpad('d/dt C_cyt in component C_cyt (micromolar)');
LEGEND_RATES(:,5) = strpad('d/dt C_ER in component C_ER (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 = [];
CONSTANTS(:,1) = 1e-4;
CONSTANTS(:,2) = 3.4;
CONSTANTS(:,3) = 4;
CONSTANTS(:,4) = 4.5;
CONSTANTS(:,5) = 1.2;
CONSTANTS(:,6) = 0.12;
CONSTANTS(:,7) = 14;
CONSTANTS(:,8) = 2;
CONSTANTS(:,9) = 10.5;
CONSTANTS(:,10) = 0.6;
CONSTANTS(:,11) = 3;
CONSTANTS(:,12) = 0.26;
CONSTANTS(:,13) = 0.01;
CONSTANTS(:,14) = 0.01;
CONSTANTS(:,15) = 0.004;
CONSTANTS(:,16) = 0.2;
CONSTANTS(:,17) = 0.025;
CONSTANTS(:,18) = 0.025;
CONSTANTS(:,19) = 0.075;
CONSTANTS(:,20) = 1;
CONSTANTS(:,21) = 2;
CONSTANTS(:,22) = 0.05;
CONSTANTS(:,23) = 0.001;
CONSTANTS(:,24) = 0.2;
CONSTANTS(:,25) = 4;
CONSTANTS(:,26) = 2;
CONSTANTS(:,27) = 3;
STATES(:,1) = 0.001;
STATES(:,2) = 0.2;
STATES(:,3) = 0.001;
STATES(:,4) = 0.001;
STATES(:,5) = 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(:,4) =  CONSTANTS(:,7).*STATES(:,1) -  CONSTANTS(:,8).*STATES(:,4);
ALGEBRAIC(:,1) = power(STATES(:,4), 3.00000)./(power(CONSTANTS(:,18), 3.00000)+power(STATES(:,4), 3.00000));
ALGEBRAIC(:,3) = STATES(:,2)./(CONSTANTS(:,20)+STATES(:,2));
ALGEBRAIC(:,5) = STATES(:,2)./(CONSTANTS(:,21)+STATES(:,2));
ALGEBRAIC(:,7) = power(STATES(:,5), CONSTANTS(:,27))./(power(CONSTANTS(:,19), CONSTANTS(:,27))+power(STATES(:,5), CONSTANTS(:,27)));
RATES(:,2) =  CONSTANTS(:,22).*(( CONSTANTS(:,24).*( CONSTANTS(:,9).*ALGEBRAIC(:,1).*ALGEBRAIC(:,7) -  CONSTANTS(:,10).*ALGEBRAIC(:,3)) -  CONSTANTS(:,11).*ALGEBRAIC(:,5))+CONSTANTS(:,12));
RATES(:,5) =  CONSTANTS(:,23).*(  - CONSTANTS(:,9).*ALGEBRAIC(:,1).*ALGEBRAIC(:,7)+ CONSTANTS(:,10).*ALGEBRAIC(:,3));
ALGEBRAIC(:,2) = STATES(:,1)./(CONSTANTS(:,15)+STATES(:,1));
ALGEBRAIC(:,8) = STATES(:,4);
ALGEBRAIC(:,9) = ( (ALGEBRAIC(:,8)./(CONSTANTS(:,14)+ALGEBRAIC(:,8))).*STATES(:,2))./(CONSTANTS(:,16)+STATES(:,2));
RATES(:,3) = ((CONSTANTS(:,1)+ CONSTANTS(:,2).*STATES(:,3)) -  CONSTANTS(:,3).*ALGEBRAIC(:,2).*STATES(:,3)) -  CONSTANTS(:,4).*ALGEBRAIC(:,9).*STATES(:,3);
ALGEBRAIC(:,4) = power(STATES(:,3), CONSTANTS(:,25))./(power(CONSTANTS(:,17), CONSTANTS(:,25))+power(STATES(:,3), CONSTANTS(:,25)));
ALGEBRAIC(:,10) = power(ALGEBRAIC(:,8), CONSTANTS(:,26))./(power(CONSTANTS(:,14), CONSTANTS(:,26))+power(ALGEBRAIC(:,8), CONSTANTS(:,26)));
ALGEBRAIC(:,6) = CONSTANTS(:,13) - STATES(:,1);
RATES(:,1) =  CONSTANTS(:,5).*ALGEBRAIC(:,4).*ALGEBRAIC(:,10).*ALGEBRAIC(:,6) -  CONSTANTS(:,6).*STATES(:,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(:,1) = power(STATES(:,4), 3.00000)./(power(CONSTANTS(:,18), 3.00000)+power(STATES(:,4), 3.00000));
ALGEBRAIC(:,3) = STATES(:,2)./(CONSTANTS(:,20)+STATES(:,2));
ALGEBRAIC(:,5) = STATES(:,2)./(CONSTANTS(:,21)+STATES(:,2));
ALGEBRAIC(:,7) = power(STATES(:,5), CONSTANTS(:,27))./(power(CONSTANTS(:,19), CONSTANTS(:,27))+power(STATES(:,5), CONSTANTS(:,27)));
ALGEBRAIC(:,2) = STATES(:,1)./(CONSTANTS(:,15)+STATES(:,1));
ALGEBRAIC(:,8) = STATES(:,4);
ALGEBRAIC(:,9) = ( (ALGEBRAIC(:,8)./(CONSTANTS(:,14)+ALGEBRAIC(:,8))).*STATES(:,2))./(CONSTANTS(:,16)+STATES(:,2));
ALGEBRAIC(:,4) = power(STATES(:,3), CONSTANTS(:,25))./(power(CONSTANTS(:,17), CONSTANTS(:,25))+power(STATES(:,3), CONSTANTS(:,25)));
ALGEBRAIC(:,10) = power(ALGEBRAIC(:,8), CONSTANTS(:,26))./(power(CONSTANTS(:,14), CONSTANTS(:,26))+power(ALGEBRAIC(:,8), CONSTANTS(:,26)));
ALGEBRAIC(:,6) = CONSTANTS(:,13) - STATES(:,1);
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 Wang, Huang, Huang, 2006 at changeset 207a885a9ac9.
Collaboration
To begin collaborating on this work, please use your git client and issue this command: