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 =6;
end
% There are a total of 12 entries in each of the rate and state variable arrays.
% There are a total of 43 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('Asp in component Asp (millimolar)');
    LEGEND_ALGEBRAIC(:,1) = strpad('vAKI in component vAKI (flux)');
    LEGEND_ALGEBRAIC(:,5) = strpad('vAKIII in component vAKIII (flux)');
    LEGEND_STATES(:,2) = strpad('aspp in component aspp (millimolar)');
    LEGEND_ALGEBRAIC(:,2) = strpad('vASD in component vASD (flux)');
    LEGEND_STATES(:,3) = strpad('ASA in component ASA (millimolar)');
    LEGEND_ALGEBRAIC(:,3) = strpad('vHDH in component vHDH (flux)');
    LEGEND_STATES(:,4) = strpad('hs in component hs (millimolar)');
    LEGEND_ALGEBRAIC(:,4) = strpad('vHK in component vHK (flux)');
    LEGEND_STATES(:,5) = strpad('hsp in component hsp (millimolar)');
    LEGEND_ALGEBRAIC(:,6) = strpad('vTS in component vTS (flux)');
    LEGEND_STATES(:,6) = strpad('Thr in component Thr (millimolar)');
    LEGEND_STATES(:,7) = strpad('ATP in component ATP (millimolar)');
    LEGEND_STATES(:,8) = strpad('ADP in component ADP (millimolar)');
    LEGEND_STATES(:,9) = strpad('NADPH in component NADPH (millimolar)');
    LEGEND_STATES(:,10) = strpad('NADP in component NADP (millimolar)');
    LEGEND_STATES(:,11) = strpad('Pi in component Pi (millimolar)');
    LEGEND_STATES(:,12) = strpad('Lys in component Lys (millimolar)');
    LEGEND_CONSTANTS(:,1) = strpad('K_asp in component vAKI (millimolar)');
    LEGEND_CONSTANTS(:,2) = strpad('K_ATP in component vAKI (millimolar)');
    LEGEND_CONSTANTS(:,3) = strpad('K_aspp in component vAKI (millimolar)');
    LEGEND_CONSTANTS(:,4) = strpad('K_ADP in component vAKI (millimolar)');
    LEGEND_CONSTANTS(:,5) = strpad('K_iThr in component vAKI (millimolar)');
    LEGEND_CONSTANTS(:,6) = strpad('alpha in component vAKI (dimensionless)');
    LEGEND_CONSTANTS(:,7) = strpad('h_Thr in component vAKI (dimensionless)');
    LEGEND_CONSTANTS(:,8) = strpad('K_eq in component vAKI (dimensionless)');
    LEGEND_CONSTANTS(:,9) = strpad('V_max_AK_I in component vAKI (flux)');
    LEGEND_CONSTANTS(:,10) = strpad('K_aspp in component vASD (millimolar)');
    LEGEND_CONSTANTS(:,11) = strpad('K_NADPH in component vASD (millimolar)');
    LEGEND_CONSTANTS(:,12) = strpad('K_ASA in component vASD (millimolar)');
    LEGEND_CONSTANTS(:,13) = strpad('K_NADP in component vASD (millimolar)');
    LEGEND_CONSTANTS(:,14) = strpad('K_Pi in component vASD (millimolar)');
    LEGEND_CONSTANTS(:,15) = strpad('K_eq in component vASD (millimolar)');
    LEGEND_CONSTANTS(:,16) = strpad('V_max_ASD in component vASD (flux)');
    LEGEND_CONSTANTS(:,17) = strpad('K_ASA in component vHDH (millimolar)');
    LEGEND_CONSTANTS(:,18) = strpad('K_NADPH in component vHDH (millimolar)');
    LEGEND_CONSTANTS(:,19) = strpad('K_hs in component vHDH (millimolar)');
    LEGEND_CONSTANTS(:,20) = strpad('K_NADP in component vHDH (millimolar)');
    LEGEND_CONSTANTS(:,21) = strpad('K_iThr in component vHDH (millimolar)');
    LEGEND_CONSTANTS(:,22) = strpad('alpha in component vHDH (dimensionless)');
    LEGEND_CONSTANTS(:,23) = strpad('h in component vHDH (dimensionless)');
    LEGEND_CONSTANTS(:,24) = strpad('K_eq in component vHDH (dimensionless)');
    LEGEND_CONSTANTS(:,25) = strpad('V_max_HDH in component vHDH (flux)');
    LEGEND_CONSTANTS(:,26) = strpad('K_hs in component vHK (millimolar)');
    LEGEND_CONSTANTS(:,27) = strpad('K_ATP in component vHK (millimolar)');
    LEGEND_CONSTANTS(:,28) = strpad('K_iThr in component vHK (millimolar)');
    LEGEND_CONSTANTS(:,29) = strpad('K_iLys in component vHK (millimolar)');
    LEGEND_CONSTANTS(:,30) = strpad('K_ihs in component vHK (millimolar)');
    LEGEND_CONSTANTS(:,31) = strpad('K_iATP in component vHK (millimolar)');
    LEGEND_CONSTANTS(:,32) = strpad('V_max_HK in component vHK (flux)');
    LEGEND_CONSTANTS(:,33) = strpad('K_hsp in component vTS (millimolar)');
    LEGEND_CONSTANTS(:,34) = strpad('V_max_TS in component vTS (flux)');
    LEGEND_CONSTANTS(:,35) = strpad('K_asp in component vAKIII (millimolar)');
    LEGEND_CONSTANTS(:,36) = strpad('K_ATP in component vAKIII (millimolar)');
    LEGEND_CONSTANTS(:,37) = strpad('K_aspp in component vAKIII (millimolar)');
    LEGEND_CONSTANTS(:,38) = strpad('K_ADP in component vAKIII (millimolar)');
    LEGEND_CONSTANTS(:,39) = strpad('K_iLys in component vAKIII (millimolar)');
    LEGEND_CONSTANTS(:,40) = strpad('h_Lys in component vAKIII (dimensionless)');
    LEGEND_CONSTANTS(:,41) = strpad('K_eq in component vAKIII (dimensionless)');
    LEGEND_CONSTANTS(:,42) = strpad('V_max_AK_III in component vAKIII (flux)');
    LEGEND_RATES(:,1) = strpad('d/dt Asp in component Asp (millimolar)');
    LEGEND_RATES(:,2) = strpad('d/dt aspp in component aspp (millimolar)');
    LEGEND_RATES(:,3) = strpad('d/dt ASA in component ASA (millimolar)');
    LEGEND_RATES(:,4) = strpad('d/dt hs in component hs (millimolar)');
    LEGEND_RATES(:,5) = strpad('d/dt hsp in component hsp (millimolar)');
    LEGEND_RATES(:,6) = strpad('d/dt Thr in component Thr (millimolar)');
    LEGEND_RATES(:,7) = strpad('d/dt ATP in component ATP (millimolar)');
    LEGEND_RATES(:,8) = strpad('d/dt ADP in component ADP (millimolar)');
    LEGEND_RATES(:,9) = strpad('d/dt NADPH in component NADPH (millimolar)');
    LEGEND_RATES(:,10) = strpad('d/dt NADP in component NADP (millimolar)');
    LEGEND_RATES(:,11) = strpad('d/dt Pi in component Pi (millimolar)');
    LEGEND_RATES(:,12) = strpad('d/dt Lys in component Lys (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) = 10;
    STATES(:,2) = 0;
    STATES(:,3) = 0;
    STATES(:,4) = 0;
    STATES(:,5) = 0;
    STATES(:,6) = 0;
    STATES(:,7) = 30;
    STATES(:,8) = 0;
    STATES(:,9) = 0;
    STATES(:,10) = 0;
    STATES(:,11) = 0;
    STATES(:,12) = 0;
    CONSTANTS(:,1) = 0.97;
    CONSTANTS(:,2) = 0.98;
    CONSTANTS(:,3) = 0.017;
    CONSTANTS(:,4) = 0.25;
    CONSTANTS(:,5) = 0.167;
    CONSTANTS(:,6) = 2.47;
    CONSTANTS(:,7) = 4.09;
    CONSTANTS(:,8) = 0.00064;
    CONSTANTS(:,9) = 463;
    CONSTANTS(:,10) = 0.022;
    CONSTANTS(:,11) = 0.029;
    CONSTANTS(:,12) = 0.11;
    CONSTANTS(:,13) = 0.144;
    CONSTANTS(:,14) = 10.2;
    CONSTANTS(:,15) = 284000;
    CONSTANTS(:,16) = 598;
    CONSTANTS(:,17) = 0.24;
    CONSTANTS(:,18) = 0.037;
    CONSTANTS(:,19) = 3.39;
    CONSTANTS(:,20) = 0.067;
    CONSTANTS(:,21) = 0.097;
    CONSTANTS(:,22) = 3.93;
    CONSTANTS(:,23) = 1.41;
    CONSTANTS(:,24) = 100000000000;
    CONSTANTS(:,25) = 2585;
    CONSTANTS(:,26) = 0.11;
    CONSTANTS(:,27) = 0.072;
    CONSTANTS(:,28) = 1.09;
    CONSTANTS(:,29) = 9.45;
    CONSTANTS(:,30) = 4.7;
    CONSTANTS(:,31) = 4.35;
    CONSTANTS(:,32) = 483;
    CONSTANTS(:,33) = 0.31;
    CONSTANTS(:,34) = 208;
    CONSTANTS(:,35) = 0.32;
    CONSTANTS(:,36) = 0.22;
    CONSTANTS(:,37) = 0.017;
    CONSTANTS(:,38) = 0.25;
    CONSTANTS(:,39) = 0.391;
    CONSTANTS(:,40) = 2.8;
    CONSTANTS(:,41) = 0.00064;
    CONSTANTS(:,42) = 299;
    CONSTANTS(:,42) = 0.00000;
    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(:,12) = CONSTANTS(:,42);
    ALGEBRAIC(:,2) = ( CONSTANTS(:,16).*( STATES(:,2).*STATES(:,9) - ( STATES(:,3).*STATES(:,10).*STATES(:,11))./CONSTANTS(:,15)))./( ( CONSTANTS(:,10).*(1.00000+STATES(:,3)./CONSTANTS(:,12)).*(1.00000+STATES(:,11)./CONSTANTS(:,14))+STATES(:,2)).*( CONSTANTS(:,11).*(1.00000+STATES(:,10)./CONSTANTS(:,13))+STATES(:,9)));
    ALGEBRAIC(:,3) = ( CONSTANTS(:,25).*( STATES(:,3).*STATES(:,9) - ( STATES(:,4).*STATES(:,10))./CONSTANTS(:,24)))./( ((1.00000+power(STATES(:,6)./CONSTANTS(:,21), CONSTANTS(:,23)))./(1.00000+power(STATES(:,6)./( CONSTANTS(:,22).*CONSTANTS(:,21)), CONSTANTS(:,23)))).*(CONSTANTS(:,17)+( STATES(:,4).*CONSTANTS(:,17))./CONSTANTS(:,19)+STATES(:,3)).*( CONSTANTS(:,18).*(1.00000+STATES(:,10)./CONSTANTS(:,20))+STATES(:,9)));
    RATES(:,3) = ALGEBRAIC(:,2) - ALGEBRAIC(:,3);
    RATES(:,9) =  - ALGEBRAIC(:,2) - ALGEBRAIC(:,3);
    RATES(:,10) = ALGEBRAIC(:,2)+ALGEBRAIC(:,3);
    ALGEBRAIC(:,4) = ( CONSTANTS(:,32).*STATES(:,4).*STATES(:,7))./( (( CONSTANTS(:,26).*(1.00000+STATES(:,7)./CONSTANTS(:,31)))./(1.00000+STATES(:,6)./CONSTANTS(:,28))+STATES(:,4)).*( CONSTANTS(:,27).*(1.00000+STATES(:,4)./CONSTANTS(:,30))+STATES(:,7)).*(1.00000+STATES(:,12)./CONSTANTS(:,29)));
    RATES(:,4) = ALGEBRAIC(:,3) - ALGEBRAIC(:,4);
    ALGEBRAIC(:,1) = ( CONSTANTS(:,9).*( STATES(:,1).*STATES(:,7) - ( STATES(:,2).*STATES(:,8))./CONSTANTS(:,8)))./( (( CONSTANTS(:,1).*(1.00000+power(STATES(:,6)./CONSTANTS(:,5), CONSTANTS(:,7))))./(1.00000+power(STATES(:,6)./( CONSTANTS(:,5).*CONSTANTS(:,6)), CONSTANTS(:,7)))+( STATES(:,2).*CONSTANTS(:,1))./CONSTANTS(:,3)+STATES(:,1)).*( CONSTANTS(:,2).*(1.00000+STATES(:,8)./CONSTANTS(:,4))+STATES(:,7)));
    ALGEBRAIC(:,5) = ( CONSTANTS(:,42).*( STATES(:,1).*STATES(:,7) - ( STATES(:,2).*STATES(:,8))./CONSTANTS(:,41)))./( (1.00000+power(STATES(:,12)./CONSTANTS(:,39), CONSTANTS(:,40))).*( CONSTANTS(:,35).*(1.00000+STATES(:,2)./CONSTANTS(:,37))+STATES(:,1)).*( CONSTANTS(:,36).*(1.00000+STATES(:,8)./CONSTANTS(:,38))+STATES(:,7)));
    RATES(:,1) =  - ALGEBRAIC(:,1) - ALGEBRAIC(:,5);
    RATES(:,2) = (ALGEBRAIC(:,1)+ALGEBRAIC(:,5)) - ALGEBRAIC(:,2);
    ALGEBRAIC(:,6) = ( CONSTANTS(:,34).*STATES(:,5))./(CONSTANTS(:,33)+STATES(:,5));
    RATES(:,5) = ALGEBRAIC(:,4)+ALGEBRAIC(:,6);
    RATES(:,6) = ALGEBRAIC(:,6);
    RATES(:,7) = ( - ALGEBRAIC(:,1) - ALGEBRAIC(:,5)) - ALGEBRAIC(:,4);
    RATES(:,8) = ALGEBRAIC(:,1)+ALGEBRAIC(:,5)+ALGEBRAIC(:,4);
    RATES(:,11) = ALGEBRAIC(:,2)+ALGEBRAIC(:,6);
   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(:,2) = ( CONSTANTS(:,16).*( STATES(:,2).*STATES(:,9) - ( STATES(:,3).*STATES(:,10).*STATES(:,11))./CONSTANTS(:,15)))./( ( CONSTANTS(:,10).*(1.00000+STATES(:,3)./CONSTANTS(:,12)).*(1.00000+STATES(:,11)./CONSTANTS(:,14))+STATES(:,2)).*( CONSTANTS(:,11).*(1.00000+STATES(:,10)./CONSTANTS(:,13))+STATES(:,9)));
    ALGEBRAIC(:,3) = ( CONSTANTS(:,25).*( STATES(:,3).*STATES(:,9) - ( STATES(:,4).*STATES(:,10))./CONSTANTS(:,24)))./( ((1.00000+power(STATES(:,6)./CONSTANTS(:,21), CONSTANTS(:,23)))./(1.00000+power(STATES(:,6)./( CONSTANTS(:,22).*CONSTANTS(:,21)), CONSTANTS(:,23)))).*(CONSTANTS(:,17)+( STATES(:,4).*CONSTANTS(:,17))./CONSTANTS(:,19)+STATES(:,3)).*( CONSTANTS(:,18).*(1.00000+STATES(:,10)./CONSTANTS(:,20))+STATES(:,9)));
    ALGEBRAIC(:,4) = ( CONSTANTS(:,32).*STATES(:,4).*STATES(:,7))./( (( CONSTANTS(:,26).*(1.00000+STATES(:,7)./CONSTANTS(:,31)))./(1.00000+STATES(:,6)./CONSTANTS(:,28))+STATES(:,4)).*( CONSTANTS(:,27).*(1.00000+STATES(:,4)./CONSTANTS(:,30))+STATES(:,7)).*(1.00000+STATES(:,12)./CONSTANTS(:,29)));
    ALGEBRAIC(:,1) = ( CONSTANTS(:,9).*( STATES(:,1).*STATES(:,7) - ( STATES(:,2).*STATES(:,8))./CONSTANTS(:,8)))./( (( CONSTANTS(:,1).*(1.00000+power(STATES(:,6)./CONSTANTS(:,5), CONSTANTS(:,7))))./(1.00000+power(STATES(:,6)./( CONSTANTS(:,5).*CONSTANTS(:,6)), CONSTANTS(:,7)))+( STATES(:,2).*CONSTANTS(:,1))./CONSTANTS(:,3)+STATES(:,1)).*( CONSTANTS(:,2).*(1.00000+STATES(:,8)./CONSTANTS(:,4))+STATES(:,7)));
    ALGEBRAIC(:,5) = ( CONSTANTS(:,42).*( STATES(:,1).*STATES(:,7) - ( STATES(:,2).*STATES(:,8))./CONSTANTS(:,41)))./( (1.00000+power(STATES(:,12)./CONSTANTS(:,39), CONSTANTS(:,40))).*( CONSTANTS(:,35).*(1.00000+STATES(:,2)./CONSTANTS(:,37))+STATES(:,1)).*( CONSTANTS(:,36).*(1.00000+STATES(:,8)./CONSTANTS(:,38))+STATES(:,7)));
    ALGEBRAIC(:,6) = ( CONSTANTS(:,34).*STATES(:,5))./(CONSTANTS(:,33)+STATES(:,5));
end

% Pad out or shorten strings to a set length
function strout = strpad(strin)
    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