# 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 =17;
end
% There are a total of 13 entries in each of the rate and state variable arrays.
% There are a total of 38 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 all (s)');
LEGEND_STATES(:,1) = strpad('Ca in component all (uM)');
LEGEND_ALGEBRAIC(:,11) = strpad('L in component all (uM)');
LEGEND_CONSTANTS(:,1) = strpad('Ls in component all (uM)');
LEGEND_CONSTANTS(:,2) = strpad('ts in component all (s)');
LEGEND_STATES(:,2) = strpad('Gd in component all (per_um2)');
LEGEND_STATES(:,3) = strpad('Gt in component all (per_um2)');
LEGEND_STATES(:,4) = strpad('R in component all (per_um2)');
LEGEND_STATES(:,5) = strpad('Rl in component all (per_um2)');
LEGEND_STATES(:,6) = strpad('Rg in component all (per_um2)');
LEGEND_STATES(:,7) = strpad('Rlg in component all (per_um2)');
LEGEND_STATES(:,8) = strpad('Rlgp in component all (per_um2)');
LEGEND_STATES(:,9) = strpad('IP3 in component all (uM)');
LEGEND_CONSTANTS(:,3) = strpad('PIP2 in component all (per_um2)');
LEGEND_STATES(:,10) = strpad('Pc in component all (per_um2)');
LEGEND_STATES(:,11) = strpad('Pcg in component all (per_um2)');
LEGEND_STATES(:,12) = strpad('P in component all (per_um2)');
LEGEND_STATES(:,13) = strpad('Pg in component all (per_um2)');
LEGEND_ALGEBRAIC(:,12) = strpad('J1 in component all (per_um2_per_s)');
LEGEND_CONSTANTS(:,4) = strpad('kf1 in component all (per_uM_per_s)');
LEGEND_CONSTANTS(:,32) = strpad('kr1 in component all (per_s)');
LEGEND_CONSTANTS(:,5) = strpad('Kd1 in component all (uM)');
LEGEND_ALGEBRAIC(:,13) = strpad('J2 in component all (per_um2_per_s)');
LEGEND_CONSTANTS(:,6) = strpad('kf2 in component all (um2_per_s)');
LEGEND_CONSTANTS(:,33) = strpad('kr2 in component all (per_s)');
LEGEND_CONSTANTS(:,7) = strpad('Kd2 in component all (per_um2)');
LEGEND_ALGEBRAIC(:,14) = strpad('J3 in component all (per_um2_per_s)');
LEGEND_CONSTANTS(:,8) = strpad('kf3 in component all (um2_per_s)');
LEGEND_CONSTANTS(:,9) = strpad('kr3 in component all (per_s)');
LEGEND_ALGEBRAIC(:,15) = strpad('J4 in component all (per_um2_per_s)');
LEGEND_CONSTANTS(:,10) = strpad('kf4 in component all (per_uM_per_s)');
LEGEND_CONSTANTS(:,34) = strpad('kr4 in component all (per_s)');
LEGEND_CONSTANTS(:,11) = strpad('Kd4 in component all (uM)');
LEGEND_ALGEBRAIC(:,16) = strpad('J5 in component all (per_um2_per_s)');
LEGEND_CONSTANTS(:,12) = strpad('kf5 in component all (per_s)');
LEGEND_ALGEBRAIC(:,17) = strpad('J6 in component all (per_um2_per_s)');
LEGEND_CONSTANTS(:,13) = strpad('kf6 in component all (per_s)');
LEGEND_ALGEBRAIC(:,10) = strpad('J7 in component all (per_um2_per_s)');
LEGEND_CONSTANTS(:,14) = strpad('kf7 in component all (per_s)');
LEGEND_ALGEBRAIC(:,8) = strpad('J8 in component all (per_um2_per_s)');
LEGEND_CONSTANTS(:,15) = strpad('kf8 in component all (per_uM_per_s)');
LEGEND_CONSTANTS(:,16) = strpad('kr8 in component all (per_s)');
LEGEND_ALGEBRAIC(:,9) = strpad('J9 in component all (per_um2_per_s)');
LEGEND_CONSTANTS(:,17) = strpad('kf9 in component all (um2_per_s)');
LEGEND_CONSTANTS(:,18) = strpad('kr9 in component all (per_s)');
LEGEND_ALGEBRAIC(:,7) = strpad('J10 in component all (per_um2_per_s)');
LEGEND_CONSTANTS(:,19) = strpad('kf10 in component all (um2_per_s)');
LEGEND_CONSTANTS(:,20) = strpad('kr10 in component all (per_s)');
LEGEND_ALGEBRAIC(:,5) = strpad('J11 in component all (per_um2_per_s)');
LEGEND_CONSTANTS(:,21) = strpad('kf11 in component all (per_uM_per_s)');
LEGEND_CONSTANTS(:,35) = strpad('kr11 in component all (per_s)');
LEGEND_CONSTANTS(:,22) = strpad('Kd11 in component all (uM)');
LEGEND_ALGEBRAIC(:,3) = strpad('J12 in component all (per_um2_per_s)');
LEGEND_CONSTANTS(:,23) = strpad('kf12 in component all (per_s)');
LEGEND_ALGEBRAIC(:,1) = strpad('J13 in component all (per_um2_per_s)');
LEGEND_CONSTANTS(:,24) = strpad('kf13 in component all (per_s)');
LEGEND_ALGEBRAIC(:,4) = strpad('J14 in component all (per_um2_per_s)');
LEGEND_CONSTANTS(:,25) = strpad('kf14 in component all (per_s)');
LEGEND_CONSTANTS(:,26) = strpad('Km14 in component all (uM)');
LEGEND_ALGEBRAIC(:,6) = strpad('J15 in component all (per_um2_per_s)');
LEGEND_CONSTANTS(:,27) = strpad('kf15 in component all (per_s)');
LEGEND_CONSTANTS(:,28) = strpad('Km15 in component all (uM)');
LEGEND_ALGEBRAIC(:,2) = strpad('J16 in component all (uM_per_s)');
LEGEND_CONSTANTS(:,29) = strpad('kf16 in component all (per_s)');
LEGEND_CONSTANTS(:,38) = strpad('Cpc in component all (uM_um2)');
LEGEND_CONSTANTS(:,36) = strpad('Cc in component all (uM)');
LEGEND_CONSTANTS(:,37) = strpad('Cp in component all (per_um2)');
LEGEND_CONSTANTS(:,30) = strpad('Vc in component all (um3)');
LEGEND_CONSTANTS(:,31) = strpad('Rpc in component all (per_um)');
LEGEND_RATES(:,12) = strpad('d/dt P in component all (per_um2)');
LEGEND_RATES(:,13) = strpad('d/dt Pg in component all (per_um2)');
LEGEND_RATES(:,10) = strpad('d/dt Pc in component all (per_um2)');
LEGEND_RATES(:,11) = strpad('d/dt Pcg in component all (per_um2)');
LEGEND_RATES(:,9) = strpad('d/dt IP3 in component all (uM)');
LEGEND_RATES(:,2) = strpad('d/dt Gd in component all (per_um2)');
LEGEND_RATES(:,3) = strpad('d/dt Gt in component all (per_um2)');
LEGEND_RATES(:,1) = strpad('d/dt Ca in component all (uM)');
LEGEND_RATES(:,4) = strpad('d/dt R in component all (per_um2)');
LEGEND_RATES(:,5) = strpad('d/dt Rl in component all (per_um2)');
LEGEND_RATES(:,6) = strpad('d/dt Rg in component all (per_um2)');
LEGEND_RATES(:,8) = strpad('d/dt Rlgp in component all (per_um2)');
LEGEND_RATES(:,7) = strpad('d/dt Rlg in component all (per_um2)');
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.1;
CONSTANTS(:,1) = 0.1;
CONSTANTS(:,2) = 10;
STATES(:,2) = 10000;
STATES(:,3) = 0;
STATES(:,4) = 13.9;
STATES(:,5) = 0;
STATES(:,6) = 5.06;
STATES(:,7) = 0;
STATES(:,8) = 0;
STATES(:,9) = 0.015;
CONSTANTS(:,3) = 4000;
STATES(:,10) = 9.09;
STATES(:,11) = 0;
STATES(:,12) = 90.9;
STATES(:,13) = 0;
CONSTANTS(:,4) = 0.0003;
CONSTANTS(:,5) = 3e-5;
CONSTANTS(:,6) = 2.75e-4;
CONSTANTS(:,7) = 27500;
CONSTANTS(:,8) = 1;
CONSTANTS(:,9) = 0.001;
CONSTANTS(:,10) = 0.3;
CONSTANTS(:,11) = 3e-5;
CONSTANTS(:,12) = 0.0004;
CONSTANTS(:,13) = 1;
CONSTANTS(:,14) = 0.15;
CONSTANTS(:,15) = 0.0167;
CONSTANTS(:,16) = 0.0167;
CONSTANTS(:,17) = 0.0042;
CONSTANTS(:,18) = 1;
CONSTANTS(:,19) = 0.042;
CONSTANTS(:,20) = 1;
CONSTANTS(:,21) = 0.0334;
CONSTANTS(:,22) = 0.1;
CONSTANTS(:,23) = 6;
CONSTANTS(:,24) = 6;
CONSTANTS(:,25) = 0.444;
CONSTANTS(:,26) = 19.8;
CONSTANTS(:,27) = 3.8;
CONSTANTS(:,28) = 5;
CONSTANTS(:,29) = 1.25;
CONSTANTS(:,30) = 2550;
CONSTANTS(:,31) = 4.61;
CONSTANTS(:,32) =  CONSTANTS(:,4).*CONSTANTS(:,5);
CONSTANTS(:,33) =  CONSTANTS(:,6).*CONSTANTS(:,7);
CONSTANTS(:,34) =  CONSTANTS(:,10).*CONSTANTS(:,11);
CONSTANTS(:,35) =  CONSTANTS(:,21).*CONSTANTS(:,22);
CONSTANTS(:,36) = 1.00000./( CONSTANTS(:,30).*602.200);
CONSTANTS(:,37) = 1.00000./( CONSTANTS(:,30).*CONSTANTS(:,31));
CONSTANTS(:,38) = CONSTANTS(:,36)./CONSTANTS(:,37);
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(:,4) = ( CONSTANTS(:,25).*STATES(:,10).*CONSTANTS(:,3))./(CONSTANTS(:,26)./CONSTANTS(:,38)+CONSTANTS(:,3));
ALGEBRAIC(:,6) = ( CONSTANTS(:,27).*STATES(:,11).*CONSTANTS(:,3))./(CONSTANTS(:,28)./CONSTANTS(:,38)+CONSTANTS(:,3));
ALGEBRAIC(:,2) =  CONSTANTS(:,29).*STATES(:,9);
RATES(:,9) =  CONSTANTS(:,38).*(ALGEBRAIC(:,4)+ALGEBRAIC(:,6)) - ALGEBRAIC(:,2);
ALGEBRAIC(:,7) =  CONSTANTS(:,19).*STATES(:,10).*STATES(:,3) -  CONSTANTS(:,20).*STATES(:,11);
ALGEBRAIC(:,5) =  CONSTANTS(:,21).*STATES(:,13).*STATES(:,1) -  CONSTANTS(:,35).*STATES(:,11);
ALGEBRAIC(:,3) =  CONSTANTS(:,23).*STATES(:,11);
RATES(:,11) = (ALGEBRAIC(:,7)+ALGEBRAIC(:,5)) - ALGEBRAIC(:,3);
ALGEBRAIC(:,8) =  CONSTANTS(:,15).*STATES(:,12).*STATES(:,1) -  CONSTANTS(:,16).*STATES(:,10);
RATES(:,10) = (ALGEBRAIC(:,8)+ALGEBRAIC(:,3)) - ALGEBRAIC(:,7);
RATES(:,1) =  CONSTANTS(:,38).* - 1.00000.*(ALGEBRAIC(:,8)+ALGEBRAIC(:,5));
ALGEBRAIC(:,9) =  CONSTANTS(:,17).*STATES(:,12).*STATES(:,3) -  CONSTANTS(:,18).*STATES(:,13);
ALGEBRAIC(:,1) =  CONSTANTS(:,24).*STATES(:,13);
RATES(:,12) = ALGEBRAIC(:,1) - (ALGEBRAIC(:,9)+ALGEBRAIC(:,8));
RATES(:,13) = ALGEBRAIC(:,9) - (ALGEBRAIC(:,5)+ALGEBRAIC(:,1));
ALGEBRAIC(:,11) = piecewise({VOI<CONSTANTS(:,2)+0.150000&VOI>=CONSTANTS(:,2), CONSTANTS(:,1)./(1.00000+exp(  - 80.0000.*((VOI - CONSTANTS(:,2)) - 0.0500000))) , VOI>=CONSTANTS(:,2)+0.150000, CONSTANTS(:,1) }, 0.00000);
ALGEBRAIC(:,12) =  CONSTANTS(:,4).*STATES(:,4).*ALGEBRAIC(:,11) -  CONSTANTS(:,32).*STATES(:,5);
ALGEBRAIC(:,13) =  CONSTANTS(:,6).*STATES(:,4).*STATES(:,2) -  CONSTANTS(:,33).*STATES(:,6);
RATES(:,4) =   - 1.00000.*(ALGEBRAIC(:,12)+ALGEBRAIC(:,13));
ALGEBRAIC(:,14) =  CONSTANTS(:,8).*STATES(:,5).*STATES(:,2) -  CONSTANTS(:,9).*STATES(:,7);
ALGEBRAIC(:,10) =  CONSTANTS(:,14).*STATES(:,3);
RATES(:,2) = (ALGEBRAIC(:,10)+ALGEBRAIC(:,1)+ALGEBRAIC(:,3)) - (ALGEBRAIC(:,13)+ALGEBRAIC(:,14));
ALGEBRAIC(:,15) =  CONSTANTS(:,10).*ALGEBRAIC(:,11).*STATES(:,6) -  CONSTANTS(:,34).*STATES(:,7);
RATES(:,6) = ALGEBRAIC(:,13) - ALGEBRAIC(:,15);
ALGEBRAIC(:,16) =  CONSTANTS(:,12).*STATES(:,7);
RATES(:,8) = ALGEBRAIC(:,16);
ALGEBRAIC(:,17) =  CONSTANTS(:,13).*STATES(:,7);
RATES(:,3) = ALGEBRAIC(:,17) - (ALGEBRAIC(:,10)+ALGEBRAIC(:,9)+ALGEBRAIC(:,7));
RATES(:,5) = (ALGEBRAIC(:,12)+ALGEBRAIC(:,17)) - ALGEBRAIC(:,14);
RATES(:,7) = ((ALGEBRAIC(:,14) - ALGEBRAIC(:,16))+ALGEBRAIC(:,15)) - ALGEBRAIC(:,17);
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(:,4) = ( CONSTANTS(:,25).*STATES(:,10).*CONSTANTS(:,3))./(CONSTANTS(:,26)./CONSTANTS(:,38)+CONSTANTS(:,3));
ALGEBRAIC(:,6) = ( CONSTANTS(:,27).*STATES(:,11).*CONSTANTS(:,3))./(CONSTANTS(:,28)./CONSTANTS(:,38)+CONSTANTS(:,3));
ALGEBRAIC(:,2) =  CONSTANTS(:,29).*STATES(:,9);
ALGEBRAIC(:,7) =  CONSTANTS(:,19).*STATES(:,10).*STATES(:,3) -  CONSTANTS(:,20).*STATES(:,11);
ALGEBRAIC(:,5) =  CONSTANTS(:,21).*STATES(:,13).*STATES(:,1) -  CONSTANTS(:,35).*STATES(:,11);
ALGEBRAIC(:,3) =  CONSTANTS(:,23).*STATES(:,11);
ALGEBRAIC(:,8) =  CONSTANTS(:,15).*STATES(:,12).*STATES(:,1) -  CONSTANTS(:,16).*STATES(:,10);
ALGEBRAIC(:,9) =  CONSTANTS(:,17).*STATES(:,12).*STATES(:,3) -  CONSTANTS(:,18).*STATES(:,13);
ALGEBRAIC(:,1) =  CONSTANTS(:,24).*STATES(:,13);
ALGEBRAIC(:,11) = piecewise({VOI<CONSTANTS(:,2)+0.150000&VOI>=CONSTANTS(:,2), CONSTANTS(:,1)./(1.00000+exp(  - 80.0000.*((VOI - CONSTANTS(:,2)) - 0.0500000))) , VOI>=CONSTANTS(:,2)+0.150000, CONSTANTS(:,1) }, 0.00000);
ALGEBRAIC(:,12) =  CONSTANTS(:,4).*STATES(:,4).*ALGEBRAIC(:,11) -  CONSTANTS(:,32).*STATES(:,5);
ALGEBRAIC(:,13) =  CONSTANTS(:,6).*STATES(:,4).*STATES(:,2) -  CONSTANTS(:,33).*STATES(:,6);
ALGEBRAIC(:,14) =  CONSTANTS(:,8).*STATES(:,5).*STATES(:,2) -  CONSTANTS(:,9).*STATES(:,7);
ALGEBRAIC(:,10) =  CONSTANTS(:,14).*STATES(:,3);
ALGEBRAIC(:,15) =  CONSTANTS(:,10).*ALGEBRAIC(:,11).*STATES(:,6) -  CONSTANTS(:,34).*STATES(:,7);
ALGEBRAIC(:,16) =  CONSTANTS(:,12).*STATES(:,7);
ALGEBRAIC(:,17) =  CONSTANTS(:,13).*STATES(:,7);
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
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 Cooling, Hunter, Crampin, 2007 at changeset ee11a10f3f8f.
Collaboration
To begin collaborating on this work, please use your git client and issue this command: