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 =11;
end
% There are a total of 10 entries in each of the rate and state variable arrays.
% There are a total of 31 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('ATP in component ATP (micromolar)');
LEGEND_CONSTANTS(:,1) = strpad('V_hyd in component V_hyd (flux)');
LEGEND_ALGEBRAIC(:,2) = strpad('V_MMCK in component V_MMCK (flux)');
LEGEND_ALGEBRAIC(:,9) = strpad('J_ATP in component J_ATP (flux)');
LEGEND_CONSTANTS(:,2) = strpad('V_cyt in component fractional_volumes (dimensionless)');
LEGEND_STATES(:,3) = strpad('PCr in component PCr (micromolar)');
LEGEND_ALGEBRAIC(:,6) = strpad('J_PCr in component J_PCr (flux)');
LEGEND_STATES(:,4) = strpad('Cr in component Cr (micromolar)');
LEGEND_ALGEBRAIC(:,7) = strpad('J_Cr in component J_Cr (flux)');
LEGEND_STATES(:,5) = strpad('Pi in component Pi (micromolar)');
LEGEND_ALGEBRAIC(:,11) = strpad('J_Pi in component J_Pi (flux)');
LEGEND_STATES(:,6) = strpad('ATP_i in component ATP_i (micromolar)');
LEGEND_ALGEBRAIC(:,4) = strpad('V_MiCK in component V_MiCK (flux)');
LEGEND_ALGEBRAIC(:,8) = strpad('V_syn in component V_syn (flux)');
LEGEND_CONSTANTS(:,3) = strpad('V_ims in component fractional_volumes (dimensionless)');
LEGEND_STATES(:,8) = strpad('PCr_i in component PCr_i (micromolar)');
LEGEND_STATES(:,9) = strpad('Cr_i in component Cr_i (micromolar)');
LEGEND_STATES(:,10) = strpad('Pi_i in component Pi_i (micromolar)');
LEGEND_ALGEBRAIC(:,1) = strpad('Den_MMCK in component V_MMCK (dimensionless)');
LEGEND_CONSTANTS(:,4) = strpad('Kia in component V_MMCK (micromolar)');
LEGEND_CONSTANTS(:,5) = strpad('Kb in component V_MMCK (micromolar)');
LEGEND_CONSTANTS(:,6) = strpad('Kib in component V_MMCK (micromolar)');
LEGEND_CONSTANTS(:,28) = strpad('KIb in component V_MMCK (micromolar)');
LEGEND_CONSTANTS(:,29) = strpad('Kc in component V_MMCK (micromolar)');
LEGEND_CONSTANTS(:,7) = strpad('Kic in component V_MMCK (micromolar)');
LEGEND_CONSTANTS(:,8) = strpad('Kd in component V_MMCK (micromolar)');
LEGEND_CONSTANTS(:,9) = strpad('Kid in component V_MMCK (micromolar)');
LEGEND_CONSTANTS(:,10) = strpad('Vf in component V_MMCK (flux)');
LEGEND_CONSTANTS(:,11) = strpad('Vb in component V_MMCK (flux)');
LEGEND_ALGEBRAIC(:,3) = strpad('Den_MiCK in component V_MiCK (dimensionless)');
LEGEND_CONSTANTS(:,12) = strpad('Kia in component V_MiCK (micromolar)');
LEGEND_CONSTANTS(:,13) = strpad('Kb in component V_MiCK (micromolar)');
LEGEND_CONSTANTS(:,14) = strpad('Kib in component V_MiCK (micromolar)');
LEGEND_CONSTANTS(:,30) = strpad('KIb in component V_MiCK (micromolar)');
LEGEND_CONSTANTS(:,31) = strpad('Kc in component V_MiCK (micromolar)');
LEGEND_CONSTANTS(:,15) = strpad('Kic in component V_MiCK (micromolar)');
LEGEND_CONSTANTS(:,16) = strpad('Kd in component V_MiCK (micromolar)');
LEGEND_CONSTANTS(:,17) = strpad('Kid in component V_MiCK (micromolar)');
LEGEND_CONSTANTS(:,18) = strpad('Vf in component V_MiCK (flux)');
LEGEND_CONSTANTS(:,19) = strpad('Vb in component V_MiCK (flux)');
LEGEND_ALGEBRAIC(:,5) = strpad('Den_syn in component V_syn (dimensionless)');
LEGEND_CONSTANTS(:,20) = strpad('KPi in component V_syn (micromolar)');
LEGEND_CONSTANTS(:,22) = strpad('V_syn_max in component V_syn (flux)');
LEGEND_CONSTANTS(:,23) = strpad('R_ATP in component J_ATP (first_order_rate_constant)');
LEGEND_CONSTANTS(:,25) = strpad('R_PCr in component J_PCr (first_order_rate_constant)');
LEGEND_CONSTANTS(:,26) = strpad('R_Cr in component J_Cr (first_order_rate_constant)');
LEGEND_CONSTANTS(:,27) = strpad('R_Pi in component J_Pi (first_order_rate_constant)');
LEGEND_RATES(:,1) = strpad('d/dt ATP in component ATP (micromolar)');
LEGEND_RATES(:,3) = strpad('d/dt PCr in component PCr (micromolar)');
LEGEND_RATES(:,4) = strpad('d/dt Cr in component Cr (micromolar)');
LEGEND_RATES(:,5) = strpad('d/dt Pi in component Pi (micromolar)');
LEGEND_RATES(:,6) = strpad('d/dt ATP_i in component ATP_i (micromolar)');
LEGEND_RATES(:,8) = strpad('d/dt PCr_i in component PCr_i (micromolar)');
LEGEND_RATES(:,9) = strpad('d/dt Cr_i in component Cr_i (micromolar)');
LEGEND_RATES(:,10) = strpad('d/dt Pi_i in component Pi_i (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) = 9644.425;
CONSTANTS(:,1) = 4.6E3;
CONSTANTS(:,2) = 0.75;
STATES(:,2) = 60.0;
STATES(:,3) = 12500.0;
STATES(:,4) = 13500.0;
STATES(:,5) = 8000.0;
STATES(:,6) = 9644.425;
CONSTANTS(:,3) = 0.0625;
STATES(:,7) = 2.5;
STATES(:,8) = 12500.0;
STATES(:,9) = 13500.0;
STATES(:,10) = 8000.0;
CONSTANTS(:,4) = 9.0E2;
CONSTANTS(:,5) = 1.55E4;
CONSTANTS(:,6) = 3.49E4;
CONSTANTS(:,7) = 2.224E2;
CONSTANTS(:,8) = 1.67E3;
CONSTANTS(:,9) = 4.73E3;
CONSTANTS(:,10) = 6.966E3;
CONSTANTS(:,11) = 2.925E4;
CONSTANTS(:,12) = 7.5E2;
CONSTANTS(:,13) = 5.2E3;
CONSTANTS(:,14) = 2.88E4;
CONSTANTS(:,15) = 2.048E2;
CONSTANTS(:,16) = 5.0E2;
CONSTANTS(:,17) = 1.6E3;
CONSTANTS(:,18) = 2.658E3;
CONSTANTS(:,19) = 1.116E4;
CONSTANTS(:,20) = 20.0;
CONSTANTS(:,21) = 8.0E2;
CONSTANTS(:,22) = 4.6E3;
CONSTANTS(:,23) = 8.16;
CONSTANTS(:,24) = 8.16;
CONSTANTS(:,25) = 14.6;
CONSTANTS(:,26) = 14.6;
CONSTANTS(:,27) = 18.4;
CONSTANTS(:,28) = CONSTANTS(:,6);
CONSTANTS(:,29) = ( CONSTANTS(:,7).*CONSTANTS(:,8))./CONSTANTS(:,9);
CONSTANTS(:,30) = CONSTANTS(:,14);
CONSTANTS(:,31) = ( CONSTANTS(:,15).*CONSTANTS(:,16))./CONSTANTS(:,17);
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(:,1) = 1.00000+STATES(:,4)./CONSTANTS(:,6)+STATES(:,3)./CONSTANTS(:,9)+ STATES(:,1).*(1.00000./CONSTANTS(:,4)+STATES(:,4)./( CONSTANTS(:,4).*CONSTANTS(:,5)))+ STATES(:,2).*(1.00000./CONSTANTS(:,7)+STATES(:,3)./( CONSTANTS(:,9).*CONSTANTS(:,29))+STATES(:,4)./( CONSTANTS(:,7).*CONSTANTS(:,28)));
ALGEBRAIC(:,2) = ( CONSTANTS(:,10).*(( STATES(:,1).*STATES(:,4))./( CONSTANTS(:,4).*CONSTANTS(:,5))) -  CONSTANTS(:,11).*(( STATES(:,2).*STATES(:,3))./( CONSTANTS(:,7).*CONSTANTS(:,8))))./ALGEBRAIC(:,1);
ALGEBRAIC(:,6) =  CONSTANTS(:,25).*(STATES(:,8) - STATES(:,3));
RATES(:,3) = (ALGEBRAIC(:,6)+ALGEBRAIC(:,2))./CONSTANTS(:,2);
ALGEBRAIC(:,7) =  CONSTANTS(:,26).*(STATES(:,9) - STATES(:,4));
RATES(:,4) = (ALGEBRAIC(:,7) - ALGEBRAIC(:,2))./CONSTANTS(:,2);
ALGEBRAIC(:,3) = 1.00000+STATES(:,9)./CONSTANTS(:,14)+STATES(:,8)./CONSTANTS(:,17)+ STATES(:,6).*(1.00000./CONSTANTS(:,12)+STATES(:,9)./( CONSTANTS(:,12).*CONSTANTS(:,13)))+ STATES(:,7).*(1.00000./CONSTANTS(:,15)+STATES(:,8)./( CONSTANTS(:,17).*CONSTANTS(:,31))+STATES(:,9)./( CONSTANTS(:,15).*CONSTANTS(:,30)));
ALGEBRAIC(:,4) = ( CONSTANTS(:,18).*(( STATES(:,6).*STATES(:,9))./( CONSTANTS(:,12).*CONSTANTS(:,13))) -  CONSTANTS(:,19).*(( STATES(:,7).*STATES(:,8))./( CONSTANTS(:,15).*CONSTANTS(:,16))))./ALGEBRAIC(:,3);
RATES(:,8) = (ALGEBRAIC(:,4) - ALGEBRAIC(:,6))./CONSTANTS(:,3);
RATES(:,9) =  - (ALGEBRAIC(:,4)+ALGEBRAIC(:,7))./CONSTANTS(:,3);
ALGEBRAIC(:,9) =  CONSTANTS(:,23).*(STATES(:,6) - STATES(:,1));
RATES(:,1) = (ALGEBRAIC(:,9) - (CONSTANTS(:,1)+ALGEBRAIC(:,2)))./CONSTANTS(:,2);
ALGEBRAIC(:,10) =  CONSTANTS(:,24).*(STATES(:,7) - STATES(:,2));
RATES(:,2) = (ALGEBRAIC(:,10)+CONSTANTS(:,1)+ALGEBRAIC(:,2))./CONSTANTS(:,2);
ALGEBRAIC(:,11) =  CONSTANTS(:,27).*(STATES(:,10) - STATES(:,5));
RATES(:,5) = (ALGEBRAIC(:,11)+CONSTANTS(:,1))./CONSTANTS(:,2);
ALGEBRAIC(:,5) = 1.00000+STATES(:,7)./CONSTANTS(:,21)+STATES(:,10)./CONSTANTS(:,20)+( STATES(:,7).*STATES(:,10))./( CONSTANTS(:,21).*CONSTANTS(:,20));
ALGEBRAIC(:,8) =  CONSTANTS(:,22).*(( STATES(:,7).*STATES(:,10))./( CONSTANTS(:,20).*CONSTANTS(:,21).*ALGEBRAIC(:,5)));
RATES(:,6) =  - (ALGEBRAIC(:,9)+ALGEBRAIC(:,8)+ALGEBRAIC(:,4))./CONSTANTS(:,3);
RATES(:,7) = ((ALGEBRAIC(:,8)+ALGEBRAIC(:,4)) - ALGEBRAIC(:,10))./CONSTANTS(:,3);
RATES(:,10) = (ALGEBRAIC(:,8) - ALGEBRAIC(:,11))./CONSTANTS(:,3);
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) = 1.00000+STATES(:,4)./CONSTANTS(:,6)+STATES(:,3)./CONSTANTS(:,9)+ STATES(:,1).*(1.00000./CONSTANTS(:,4)+STATES(:,4)./( CONSTANTS(:,4).*CONSTANTS(:,5)))+ STATES(:,2).*(1.00000./CONSTANTS(:,7)+STATES(:,3)./( CONSTANTS(:,9).*CONSTANTS(:,29))+STATES(:,4)./( CONSTANTS(:,7).*CONSTANTS(:,28)));
ALGEBRAIC(:,2) = ( CONSTANTS(:,10).*(( STATES(:,1).*STATES(:,4))./( CONSTANTS(:,4).*CONSTANTS(:,5))) -  CONSTANTS(:,11).*(( STATES(:,2).*STATES(:,3))./( CONSTANTS(:,7).*CONSTANTS(:,8))))./ALGEBRAIC(:,1);
ALGEBRAIC(:,6) =  CONSTANTS(:,25).*(STATES(:,8) - STATES(:,3));
ALGEBRAIC(:,7) =  CONSTANTS(:,26).*(STATES(:,9) - STATES(:,4));
ALGEBRAIC(:,3) = 1.00000+STATES(:,9)./CONSTANTS(:,14)+STATES(:,8)./CONSTANTS(:,17)+ STATES(:,6).*(1.00000./CONSTANTS(:,12)+STATES(:,9)./( CONSTANTS(:,12).*CONSTANTS(:,13)))+ STATES(:,7).*(1.00000./CONSTANTS(:,15)+STATES(:,8)./( CONSTANTS(:,17).*CONSTANTS(:,31))+STATES(:,9)./( CONSTANTS(:,15).*CONSTANTS(:,30)));
ALGEBRAIC(:,4) = ( CONSTANTS(:,18).*(( STATES(:,6).*STATES(:,9))./( CONSTANTS(:,12).*CONSTANTS(:,13))) -  CONSTANTS(:,19).*(( STATES(:,7).*STATES(:,8))./( CONSTANTS(:,15).*CONSTANTS(:,16))))./ALGEBRAIC(:,3);
ALGEBRAIC(:,9) =  CONSTANTS(:,23).*(STATES(:,6) - STATES(:,1));
ALGEBRAIC(:,10) =  CONSTANTS(:,24).*(STATES(:,7) - STATES(:,2));
ALGEBRAIC(:,11) =  CONSTANTS(:,27).*(STATES(:,10) - STATES(:,5));
ALGEBRAIC(:,5) = 1.00000+STATES(:,7)./CONSTANTS(:,21)+STATES(:,10)./CONSTANTS(:,20)+( STATES(:,7).*STATES(:,10))./( CONSTANTS(:,21).*CONSTANTS(:,20));
ALGEBRAIC(:,8) =  CONSTANTS(:,22).*(( STATES(:,7).*STATES(:,10))./( CONSTANTS(:,20).*CONSTANTS(:,21).*ALGEBRAIC(:,5)));
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 Kongas, Vanbeek, 2001 at changeset c74eebdbd4a8.
Collaboration
To begin collaborating on this work, please use your git client and issue this command: