# 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 =0;
end
% There are a total of 10 entries in each of the rate and state variable arrays.
% There are a total of 55 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 (hour)');
LEGEND_STATES(:,1) = strpad('Per_m in component Per_m (nanomolar)');
LEGEND_CONSTANTS(:,1) = strpad('B1 in component Per_m (dimensionless)');
LEGEND_CONSTANTS(:,2) = strpad('C1 in component Per_m (flux)');
LEGEND_CONSTANTS(:,3) = strpad('S1 in component Per_m (flux)');
LEGEND_CONSTANTS(:,4) = strpad('D1 in component Per_m (flux)');
LEGEND_CONSTANTS(:,5) = strpad('L1 in component Per_m (nanomolar)');
LEGEND_CONSTANTS(:,6) = strpad('R1 in component Per_m (nanomolar)');
LEGEND_CONSTANTS(:,7) = strpad('A1 in component Per_m (nanomolar)');
LEGEND_STATES(:,2) = strpad('PT_n in component PT_n (nanomolar)');
LEGEND_STATES(:,3) = strpad('CC_n in component CC_n (nanomolar)');
LEGEND_CONSTANTS(:,8) = strpad('D0 in component parameters (first_order_rate_constant)');
LEGEND_CONSTANTS(:,9) = strpad('a in component parameters (dimensionless)');
LEGEND_CONSTANTS(:,10) = strpad('r in component parameters (dimensionless)');
LEGEND_STATES(:,4) = strpad('Per_c in component Per_c (nanomolar)');
LEGEND_CONSTANTS(:,11) = strpad('S2 in component Per_c (first_order_rate_constant)');
LEGEND_CONSTANTS(:,12) = strpad('D2 in component Per_c (first_order_rate_constant)');
LEGEND_CONSTANTS(:,13) = strpad('L2 in component Per_c (nanomolar)');
LEGEND_CONSTANTS(:,14) = strpad('Dbt_c in component Per_c (nanomolar)');
LEGEND_CONSTANTS(:,15) = strpad('V1 in component parameters (second_order_rate_constant)');
LEGEND_CONSTANTS(:,16) = strpad('V2 in component parameters (first_order_rate_constant)');
LEGEND_STATES(:,5) = strpad('Tim_c in component Tim_c (nanomolar)');
LEGEND_STATES(:,6) = strpad('PT_c in component PT_c (nanomolar)');
LEGEND_STATES(:,7) = strpad('Tim_m in component Tim_m (nanomolar)');
LEGEND_CONSTANTS(:,17) = strpad('B2 in component Tim_m (dimensionless)');
LEGEND_CONSTANTS(:,18) = strpad('C2 in component Tim_m (flux)');
LEGEND_CONSTANTS(:,19) = strpad('S3 in component Tim_m (flux)');
LEGEND_CONSTANTS(:,20) = strpad('D3 in component Tim_m (flux)');
LEGEND_CONSTANTS(:,21) = strpad('L3 in component Tim_m (nanomolar)');
LEGEND_CONSTANTS(:,22) = strpad('R2 in component Tim_m (nanomolar)');
LEGEND_CONSTANTS(:,23) = strpad('A2 in component Tim_m (nanomolar)');
LEGEND_CONSTANTS(:,24) = strpad('S4 in component Tim_c (first_order_rate_constant)');
LEGEND_CONSTANTS(:,25) = strpad('D4 in component Tim_c (flux)');
LEGEND_CONSTANTS(:,26) = strpad('L4 in component Tim_c (nanomolar)');
LEGEND_CONSTANTS(:,27) = strpad('D5 in component PT_c (flux)');
LEGEND_CONSTANTS(:,28) = strpad('L5 in component PT_c (nanomolar)');
LEGEND_CONSTANTS(:,29) = strpad('K1 in component parameters (nanomolar)');
LEGEND_CONSTANTS(:,30) = strpad('K2 in component parameters (nanomolar)');
LEGEND_CONSTANTS(:,31) = strpad('T1 in component parameters (flux)');
LEGEND_CONSTANTS(:,32) = strpad('T2 in component parameters (flux)');
LEGEND_CONSTANTS(:,33) = strpad('D6 in component PT_n (flux)');
LEGEND_CONSTANTS(:,34) = strpad('L6 in component PT_n (nanomolar)');
LEGEND_STATES(:,8) = strpad('Clk_m in component Clk_m (nanomolar)');
LEGEND_CONSTANTS(:,35) = strpad('B3 in component Clk_m (dimensionless)');
LEGEND_CONSTANTS(:,36) = strpad('C3 in component Clk_m (flux)');
LEGEND_CONSTANTS(:,37) = strpad('S5 in component Clk_m (flux)');
LEGEND_CONSTANTS(:,38) = strpad('D7 in component Clk_m (flux)');
LEGEND_CONSTANTS(:,39) = strpad('L7 in component Clk_m (nanomolar)');
LEGEND_CONSTANTS(:,40) = strpad('R3 in component Clk_m (nanomolar)');
LEGEND_CONSTANTS(:,41) = strpad('A3 in component Clk_m (nanomolar)');
LEGEND_STATES(:,9) = strpad('Clk_c in component Clk_c (nanomolar)');
LEGEND_CONSTANTS(:,42) = strpad('S6 in component Clk_c (first_order_rate_constant)');
LEGEND_CONSTANTS(:,43) = strpad('D8 in component Clk_c (flux)');
LEGEND_CONSTANTS(:,44) = strpad('L8 in component Clk_c (nanomolar)');
LEGEND_CONSTANTS(:,45) = strpad('V3 in component parameters (second_order_rate_constant)');
LEGEND_CONSTANTS(:,46) = strpad('V4 in component parameters (first_order_rate_constant)');
LEGEND_CONSTANTS(:,47) = strpad('Cyc_c in component Cyc_c (nanomolar)');
LEGEND_STATES(:,10) = strpad('CC_c in component CC_c (nanomolar)');
LEGEND_CONSTANTS(:,48) = strpad('D9 in component CC_c (flux)');
LEGEND_CONSTANTS(:,49) = strpad('L9 in component CC_c (nanomolar)');
LEGEND_CONSTANTS(:,50) = strpad('K3 in component parameters (nanomolar)');
LEGEND_CONSTANTS(:,51) = strpad('K4 in component parameters (nanomolar)');
LEGEND_CONSTANTS(:,52) = strpad('T3 in component parameters (flux)');
LEGEND_CONSTANTS(:,53) = strpad('T4 in component parameters (flux)');
LEGEND_CONSTANTS(:,54) = strpad('D10 in component CC_n (flux)');
LEGEND_CONSTANTS(:,55) = strpad('L10 in component CC_n (nanomolar)');
LEGEND_RATES(:,1) = strpad('d/dt Per_m in component Per_m (nanomolar)');
LEGEND_RATES(:,4) = strpad('d/dt Per_c in component Per_c (nanomolar)');
LEGEND_RATES(:,7) = strpad('d/dt Tim_m in component Tim_m (nanomolar)');
LEGEND_RATES(:,5) = strpad('d/dt Tim_c in component Tim_c (nanomolar)');
LEGEND_RATES(:,6) = strpad('d/dt PT_c in component PT_c (nanomolar)');
LEGEND_RATES(:,2) = strpad('d/dt PT_n in component PT_n (nanomolar)');
LEGEND_RATES(:,8) = strpad('d/dt Clk_m in component Clk_m (nanomolar)');
LEGEND_RATES(:,9) = strpad('d/dt Clk_c in component Clk_c (nanomolar)');
LEGEND_RATES(:,10) = strpad('d/dt CC_c in component CC_c (nanomolar)');
LEGEND_RATES(:,3) = strpad('d/dt CC_n in component CC_n (nanomolar)');
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.5;
CONSTANTS(:,1) = 0.0;
CONSTANTS(:,2) = 0.0;
CONSTANTS(:,3) = 1.45;
CONSTANTS(:,4) = 0.94;
CONSTANTS(:,5) = 0.3;
CONSTANTS(:,6) = 1.02;
CONSTANTS(:,7) = 0.45;
STATES(:,2) = 1.0;
STATES(:,3) = 0.4;
CONSTANTS(:,8) = 0.012;
CONSTANTS(:,9) = 1.0;
CONSTANTS(:,10) = 4.0;
STATES(:,4) = 0.6;
CONSTANTS(:,11) = 0.48;
CONSTANTS(:,12) = 0.44;
CONSTANTS(:,13) = 0.2;
CONSTANTS(:,14) = 1.0;
CONSTANTS(:,15) = 1.45;
CONSTANTS(:,16) = 1.45;
STATES(:,5) = 0.8;
STATES(:,6) = 0.9;
STATES(:,7) = 0.7;
CONSTANTS(:,17) = 0.0;
CONSTANTS(:,18) = 0.0;
CONSTANTS(:,19) = 1.45;
CONSTANTS(:,20) = 0.94;
CONSTANTS(:,21) = 0.3;
CONSTANTS(:,22) = 1.02;
CONSTANTS(:,23) = 0.45;
CONSTANTS(:,24) = 0.48;
CONSTANTS(:,25) = 0.44;
CONSTANTS(:,26) = 0.2;
CONSTANTS(:,27) = 0.44;
CONSTANTS(:,28) = 0.2;
CONSTANTS(:,29) = 2.0;
CONSTANTS(:,30) = 2.0;
CONSTANTS(:,31) = 1.73;
CONSTANTS(:,32) = 0.72;
CONSTANTS(:,33) = 0.29;
CONSTANTS(:,34) = 0.2;
STATES(:,8) = 0.1;
CONSTANTS(:,35) = 0.6;
CONSTANTS(:,36) = 0.0;
CONSTANTS(:,37) = 1.63;
CONSTANTS(:,38) = 0.54;
CONSTANTS(:,39) = 0.13;
CONSTANTS(:,40) = 0.89;
CONSTANTS(:,41) = 0.8;
STATES(:,9) = 0.2;
CONSTANTS(:,42) = 0.47;
CONSTANTS(:,43) = 0.6;
CONSTANTS(:,44) = 0.2;
CONSTANTS(:,45) = 1.63;
CONSTANTS(:,46) = 1.63;
CONSTANTS(:,47) = 1.0;
STATES(:,10) = 0.3;
CONSTANTS(:,48) = 0.6;
CONSTANTS(:,49) = 0.2;
CONSTANTS(:,50) = 2.0;
CONSTANTS(:,51) = 2.0;
CONSTANTS(:,52) = 1.63;
CONSTANTS(:,53) = 0.52;
CONSTANTS(:,54) = 0.3;
CONSTANTS(:,55) = 0.2;
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(:,2)+ CONSTANTS(:,3).*((power(STATES(:,3)./CONSTANTS(:,7), CONSTANTS(:,9))+CONSTANTS(:,1))./(1.00000+power(STATES(:,2)./CONSTANTS(:,6), CONSTANTS(:,10))+power(STATES(:,3)./CONSTANTS(:,7), CONSTANTS(:,9))+CONSTANTS(:,1)))) - ( CONSTANTS(:,4).*(STATES(:,1)./(CONSTANTS(:,5)+STATES(:,1)))+ CONSTANTS(:,8).*STATES(:,1));
RATES(:,4) = ( CONSTANTS(:,11).*STATES(:,1)+ CONSTANTS(:,16).*STATES(:,6)) - ( CONSTANTS(:,15).*STATES(:,4).*STATES(:,5)+ CONSTANTS(:,12).*CONSTANTS(:,14).*(STATES(:,4)./(CONSTANTS(:,13)+STATES(:,4)))+ CONSTANTS(:,8).*STATES(:,4));
RATES(:,7) = (CONSTANTS(:,18)+ CONSTANTS(:,19).*((power(STATES(:,3)./CONSTANTS(:,23), CONSTANTS(:,9))+CONSTANTS(:,17))./(1.00000+power(STATES(:,2)./CONSTANTS(:,22), CONSTANTS(:,10))+power(STATES(:,3)./CONSTANTS(:,23), CONSTANTS(:,9))+CONSTANTS(:,17)))) - ( CONSTANTS(:,20).*(STATES(:,7)./(CONSTANTS(:,21)+STATES(:,7)))+ CONSTANTS(:,8).*STATES(:,7));
RATES(:,5) = ( CONSTANTS(:,24).*STATES(:,7)+ CONSTANTS(:,16).*STATES(:,6)) - ( CONSTANTS(:,15).*STATES(:,4).*STATES(:,5)+ CONSTANTS(:,25).*(STATES(:,5)./(CONSTANTS(:,26)+STATES(:,5)))+ CONSTANTS(:,8).*STATES(:,5));
RATES(:,6) = ( CONSTANTS(:,15).*STATES(:,4).*STATES(:,5)+ CONSTANTS(:,32).*(STATES(:,2)./(CONSTANTS(:,30)+STATES(:,2)))) - ( CONSTANTS(:,16).*STATES(:,6)+ CONSTANTS(:,31).*(STATES(:,6)./(CONSTANTS(:,29)+STATES(:,6)))+ CONSTANTS(:,27).*(STATES(:,6)./(CONSTANTS(:,28)+STATES(:,6)))+ CONSTANTS(:,8).*STATES(:,6));
RATES(:,2) =  CONSTANTS(:,31).*(STATES(:,6)./(CONSTANTS(:,29)+STATES(:,6))) - ( CONSTANTS(:,32).*(STATES(:,2)./(CONSTANTS(:,30)+STATES(:,2)))+ CONSTANTS(:,33).*(STATES(:,2)./(CONSTANTS(:,34)+STATES(:,2)))+ CONSTANTS(:,8).*STATES(:,2));
RATES(:,8) = (CONSTANTS(:,36)+ CONSTANTS(:,37).*((power(STATES(:,2)./CONSTANTS(:,41), CONSTANTS(:,9))+CONSTANTS(:,35))./(1.00000+power(STATES(:,3)./CONSTANTS(:,40), CONSTANTS(:,10))+power(STATES(:,2)./CONSTANTS(:,41), CONSTANTS(:,9))+CONSTANTS(:,35)))) - ( CONSTANTS(:,38).*(STATES(:,8)./(CONSTANTS(:,39)+STATES(:,8)))+ CONSTANTS(:,8).*STATES(:,8));
RATES(:,9) = ( CONSTANTS(:,42).*STATES(:,8)+ CONSTANTS(:,46).*STATES(:,10)) - ( CONSTANTS(:,45).*STATES(:,9).*CONSTANTS(:,47)+ CONSTANTS(:,43).*(STATES(:,9)./(CONSTANTS(:,44)+STATES(:,9)))+ CONSTANTS(:,8).*STATES(:,9));
RATES(:,10) = ( CONSTANTS(:,45).*STATES(:,9).*CONSTANTS(:,47)+ CONSTANTS(:,53).*(STATES(:,3)./(CONSTANTS(:,51)+STATES(:,3)))) - ( CONSTANTS(:,46).*STATES(:,10)+ CONSTANTS(:,52).*(STATES(:,10)./(CONSTANTS(:,50)+STATES(:,10)))+ CONSTANTS(:,48).*(STATES(:,10)./(CONSTANTS(:,49)+STATES(:,10)))+ CONSTANTS(:,8).*STATES(:,10));
RATES(:,3) =  CONSTANTS(:,52).*(STATES(:,10)./(CONSTANTS(:,50)+STATES(:,10))) - ( CONSTANTS(:,53).*(STATES(:,3)./(CONSTANTS(:,51)+STATES(:,3)))+ CONSTANTS(:,54).*(STATES(:,3)./(CONSTANTS(:,55)+STATES(:,3)))+ CONSTANTS(:,8).*STATES(:,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
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 Ueda, Hagiwara, Kitano, 2001 at changeset 09b8be601036.
Collaboration
To begin collaborating on this work, please use your git client and issue this command: