# 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 =13;
end
% There are a total of 9 entries in each of the rate and state variable arrays.
% There are a total of 19 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 (minute)');
LEGEND_STATES(:,1) = strpad('S1 in component S1 (millimolar)');
LEGEND_CONSTANTS(:,1) = strpad('Jo in component glucose_influx_rate (flux)');
LEGEND_ALGEBRAIC(:,4) = strpad('v1 in component v1 (flux)');
LEGEND_STATES(:,2) = strpad('S2 in component S2 (millimolar)');
LEGEND_ALGEBRAIC(:,5) = strpad('v2 in component v2 (flux)');
LEGEND_STATES(:,3) = strpad('S3 in component S3 (millimolar)');
LEGEND_ALGEBRAIC(:,6) = strpad('v3 in component v3 (flux)');
LEGEND_ALGEBRAIC(:,11) = strpad('v8 in component v8 (flux)');
LEGEND_STATES(:,4) = strpad('S4 in component S4 (millimolar)');
LEGEND_ALGEBRAIC(:,7) = strpad('v4 in component v4 (flux)');
LEGEND_STATES(:,5) = strpad('S5 in component S5 (millimolar)');
LEGEND_ALGEBRAIC(:,8) = strpad('v5 in component v5 (flux)');
LEGEND_STATES(:,6) = strpad('S6 in component S6 (millimolar)');
LEGEND_ALGEBRAIC(:,10) = strpad('v6 in component v6 (flux)');
LEGEND_ALGEBRAIC(:,13) = strpad('J in component S6_flux_rate_across_the_plasma_membrane (flux)');
LEGEND_STATES(:,7) = strpad('S6_ex in component S6_ex (millimolar)');
LEGEND_CONSTANTS(:,2) = strpad('phi in component S6_ex (dimensionless)');
LEGEND_ALGEBRAIC(:,12) = strpad('v9 in component v9 (flux)');
LEGEND_STATES(:,8) = strpad('A3 in component A3 (millimolar)');
LEGEND_ALGEBRAIC(:,9) = strpad('v7 in component v7 (flux)');
LEGEND_CONSTANTS(:,3) = strpad('A in component A (millimolar)');
LEGEND_ALGEBRAIC(:,1) = strpad('A2 in component A (millimolar)');
LEGEND_STATES(:,9) = strpad('N2 in component N2 (millimolar)');
LEGEND_CONSTANTS(:,4) = strpad('N in component N (millimolar)');
LEGEND_ALGEBRAIC(:,2) = strpad('N1 in component N (millimolar)');
LEGEND_CONSTANTS(:,5) = strpad('K_i in component v1 (millimolar)');
LEGEND_CONSTANTS(:,6) = strpad('k_1 in component v1 (second_order_rate_constant)');
LEGEND_CONSTANTS(:,7) = strpad('n in component v1 (dimensionless)');
LEGEND_ALGEBRAIC(:,3) = strpad('f_A3 in component v1 (dimensionless)');
LEGEND_CONSTANTS(:,8) = strpad('k_2 in component v2 (first_order_rate_constant)');
LEGEND_CONSTANTS(:,9) = strpad('k_GAPDH_plus in component v3 (second_order_rate_constant)');
LEGEND_CONSTANTS(:,10) = strpad('k_GAPDH_minus in component v3 (second_order_rate_constant)');
LEGEND_CONSTANTS(:,11) = strpad('k_PGK_plus in component v3 (second_order_rate_constant)');
LEGEND_CONSTANTS(:,12) = strpad('k_PGK_minus in component v3 (second_order_rate_constant)');
LEGEND_CONSTANTS(:,13) = strpad('k_4 in component v4 (second_order_rate_constant)');
LEGEND_CONSTANTS(:,14) = strpad('k_5 in component v5 (first_order_rate_constant)');
LEGEND_CONSTANTS(:,15) = strpad('k_6 in component v6 (second_order_rate_constant)');
LEGEND_CONSTANTS(:,16) = strpad('k_7 in component v7 (first_order_rate_constant)');
LEGEND_CONSTANTS(:,17) = strpad('k_8 in component v8 (second_order_rate_constant)');
LEGEND_CONSTANTS(:,18) = strpad('k_9 in component v9 (first_order_rate_constant)');
LEGEND_CONSTANTS(:,19) = strpad('k in component S6_flux_rate_across_the_plasma_membrane (first_order_rate_constant)');
LEGEND_RATES(:,1) = strpad('d/dt S1 in component S1 (millimolar)');
LEGEND_RATES(:,2) = strpad('d/dt S2 in component S2 (millimolar)');
LEGEND_RATES(:,3) = strpad('d/dt S3 in component S3 (millimolar)');
LEGEND_RATES(:,4) = strpad('d/dt S4 in component S4 (millimolar)');
LEGEND_RATES(:,5) = strpad('d/dt S5 in component S5 (millimolar)');
LEGEND_RATES(:,6) = strpad('d/dt S6 in component S6 (millimolar)');
LEGEND_RATES(:,7) = strpad('d/dt S6_ex in component S6_ex (millimolar)');
LEGEND_RATES(:,8) = strpad('d/dt A3 in component A3 (millimolar)');
LEGEND_RATES(:,9) = strpad('d/dt N2 in component N2 (millimolar)');
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) = 1.57981839;
CONSTANTS(:,1) = 50;
STATES(:,2) = 4.8279999;
STATES(:,3) = 0.468657507;
STATES(:,4) = 0.589391932;
STATES(:,5) = 8.210114438;
STATES(:,6) = 0.078042624;
STATES(:,7) = 0.025277594;
CONSTANTS(:,2) = 0.1;
STATES(:,8) = 1.972814237;
CONSTANTS(:,3) = 4;
STATES(:,9) = 0.384873894;
CONSTANTS(:,4) = 1;
CONSTANTS(:,5) = 1;
CONSTANTS(:,6) = 550;
CONSTANTS(:,7) = 4;
CONSTANTS(:,8) = 9.8;
CONSTANTS(:,9) = 323.8;
CONSTANTS(:,10) = 57823.1;
CONSTANTS(:,11) = 76411.1;
CONSTANTS(:,12) = 23.7;
CONSTANTS(:,13) = 80;
CONSTANTS(:,14) = 9.7;
CONSTANTS(:,15) = 2000;
CONSTANTS(:,16) = 28;
CONSTANTS(:,17) = 85.7;
CONSTANTS(:,18) = 80;
CONSTANTS(:,19) = 375;
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);
else
statesRowCount = statesSize(1);
ALGEBRAIC = zeros(statesRowCount, algebraicVariableCount);
RATES = zeros(statesRowCount, statesColumnCount);
end
ALGEBRAIC(:,3) = power(1.00000+power(STATES(:,8)./CONSTANTS(:,5), CONSTANTS(:,7)),  - 1.00000);
ALGEBRAIC(:,4) =  CONSTANTS(:,6).*STATES(:,1).*STATES(:,8).*ALGEBRAIC(:,3);
RATES(:,1) = CONSTANTS(:,1) - ALGEBRAIC(:,4);
ALGEBRAIC(:,5) =  CONSTANTS(:,8).*STATES(:,2);
RATES(:,2) = ALGEBRAIC(:,4) - ALGEBRAIC(:,5);
ALGEBRAIC(:,1) = CONSTANTS(:,3) - STATES(:,8);
ALGEBRAIC(:,2) = CONSTANTS(:,4) - STATES(:,9);
ALGEBRAIC(:,6) = ( CONSTANTS(:,9).*CONSTANTS(:,11).*STATES(:,3).*ALGEBRAIC(:,2).*ALGEBRAIC(:,1) -  CONSTANTS(:,10).*CONSTANTS(:,12).*STATES(:,4).*STATES(:,8).*STATES(:,9))./( CONSTANTS(:,10).*STATES(:,9)+ CONSTANTS(:,11).*ALGEBRAIC(:,1));
ALGEBRAIC(:,7) =  CONSTANTS(:,13).*STATES(:,4).*ALGEBRAIC(:,1);
RATES(:,4) = ALGEBRAIC(:,6) - ALGEBRAIC(:,7);
ALGEBRAIC(:,8) =  CONSTANTS(:,14).*STATES(:,5);
RATES(:,5) = ALGEBRAIC(:,7) - ALGEBRAIC(:,8);
ALGEBRAIC(:,9) =  CONSTANTS(:,16).*STATES(:,8);
RATES(:,8) = (ALGEBRAIC(:,6)+ALGEBRAIC(:,7)) - ( 2.00000.*ALGEBRAIC(:,4)+ALGEBRAIC(:,9));
ALGEBRAIC(:,11) =  CONSTANTS(:,17).*STATES(:,3).*STATES(:,9);
RATES(:,3) =  2.00000.*ALGEBRAIC(:,5) - (ALGEBRAIC(:,6)+ALGEBRAIC(:,11));
ALGEBRAIC(:,10) =  CONSTANTS(:,15).*STATES(:,6).*STATES(:,9);
RATES(:,9) = ALGEBRAIC(:,6) - (ALGEBRAIC(:,10)+ALGEBRAIC(:,11));
ALGEBRAIC(:,13) =  CONSTANTS(:,19).*(STATES(:,6) - STATES(:,7));
RATES(:,6) = ALGEBRAIC(:,8) - (ALGEBRAIC(:,10)+ALGEBRAIC(:,13));
ALGEBRAIC(:,12) =  CONSTANTS(:,18).*STATES(:,7);
RATES(:,7) =  CONSTANTS(:,2).*ALGEBRAIC(:,13) - ALGEBRAIC(:,12);
RATES = RATES';
end

% Calculate algebraic variables
function ALGEBRAIC = computeAlgebraic(ALGEBRAIC, CONSTANTS, STATES, VOI)
ALGEBRAIC(:,3) = power(1.00000+power(STATES(:,8)./CONSTANTS(:,5), CONSTANTS(:,7)),  - 1.00000);
ALGEBRAIC(:,4) =  CONSTANTS(:,6).*STATES(:,1).*STATES(:,8).*ALGEBRAIC(:,3);
ALGEBRAIC(:,5) =  CONSTANTS(:,8).*STATES(:,2);
ALGEBRAIC(:,1) = CONSTANTS(:,3) - STATES(:,8);
ALGEBRAIC(:,2) = CONSTANTS(:,4) - STATES(:,9);
ALGEBRAIC(:,6) = ( CONSTANTS(:,9).*CONSTANTS(:,11).*STATES(:,3).*ALGEBRAIC(:,2).*ALGEBRAIC(:,1) -  CONSTANTS(:,10).*CONSTANTS(:,12).*STATES(:,4).*STATES(:,8).*STATES(:,9))./( CONSTANTS(:,10).*STATES(:,9)+ CONSTANTS(:,11).*ALGEBRAIC(:,1));
ALGEBRAIC(:,7) =  CONSTANTS(:,13).*STATES(:,4).*ALGEBRAIC(:,1);
ALGEBRAIC(:,8) =  CONSTANTS(:,14).*STATES(:,5);
ALGEBRAIC(:,9) =  CONSTANTS(:,16).*STATES(:,8);
ALGEBRAIC(:,11) =  CONSTANTS(:,17).*STATES(:,3).*STATES(:,9);
ALGEBRAIC(:,10) =  CONSTANTS(:,15).*STATES(:,6).*STATES(:,9);
ALGEBRAIC(:,13) =  CONSTANTS(:,19).*(STATES(:,6) - STATES(:,7));
ALGEBRAIC(:,12) =  CONSTANTS(:,18).*STATES(:,7);
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 Wolf, Passarge, Somsen, Snoep, Heinrich, Westerhoff, 2000 at changeset 780e7c5eb2b7.
Collaboration
To begin collaborating on this work, please use your git client and issue this command: