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 =8; end % There are a total of 7 entries in each of the rate and state variable arrays. % There are a total of 35 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('Y in component Y (dimensionless)'); LEGEND_CONSTANTS(:,1) = strpad('k1 in component Y (first_order_rate_constant)'); LEGEND_ALGEBRAIC(:,7) = strpad('k2 in component kinetic_parameters (first_order_rate_constant)'); LEGEND_CONSTANTS(:,2) = strpad('k3 in component kinetic_parameters (first_order_rate_constant)'); LEGEND_ALGEBRAIC(:,1) = strpad('C in component C (dimensionless)'); LEGEND_STATES(:,2) = strpad('M in component M (dimensionless)'); LEGEND_ALGEBRAIC(:,8) = strpad('kwee in component kinetic_parameters (first_order_rate_constant)'); LEGEND_ALGEBRAIC(:,6) = strpad('kcdc25 in component kinetic_parameters (first_order_rate_constant)'); LEGEND_STATES(:,3) = strpad('preMPF in component preMPF (dimensionless)'); LEGEND_STATES(:,4) = strpad('Cdc25P in component Cdc25P (dimensionless)'); LEGEND_CONSTANTS(:,3) = strpad('k25 in component Cdc25P (first_order_rate_constant)'); LEGEND_CONSTANTS(:,4) = strpad('Km25 in component Cdc25P (dimensionless)'); LEGEND_CONSTANTS(:,5) = strpad('k25r in component Cdc25P (first_order_rate_constant)'); LEGEND_CONSTANTS(:,34) = strpad('k25ro in component Cdc25P (first_order_rate_constant)'); LEGEND_CONSTANTS(:,6) = strpad('Km25r in component Cdc25P (dimensionless)'); LEGEND_CONSTANTS(:,33) = strpad('p in component p (dimensionless)'); LEGEND_ALGEBRAIC(:,3) = strpad('Cdc25 in component Cdc25 (dimensionless)'); LEGEND_STATES(:,5) = strpad('Wee1 in component Wee1 (dimensionless)'); LEGEND_CONSTANTS(:,7) = strpad('kw in component Wee1 (first_order_rate_constant)'); LEGEND_CONSTANTS(:,8) = strpad('Kmw in component Wee1 (dimensionless)'); LEGEND_CONSTANTS(:,9) = strpad('kwr in component Wee1 (first_order_rate_constant)'); LEGEND_CONSTANTS(:,35) = strpad('kwro in component Wee1 (first_order_rate_constant)'); LEGEND_CONSTANTS(:,10) = strpad('Kmwr in component Wee1 (dimensionless)'); LEGEND_ALGEBRAIC(:,4) = strpad('Wee1P in component Wee1P (dimensionless)'); LEGEND_STATES(:,6) = strpad('IEP in component IEP (dimensionless)'); LEGEND_CONSTANTS(:,11) = strpad('kie in component IEP (first_order_rate_constant)'); LEGEND_CONSTANTS(:,12) = strpad('Kmie in component IEP (dimensionless)'); LEGEND_CONSTANTS(:,13) = strpad('kier in component IEP (first_order_rate_constant)'); LEGEND_CONSTANTS(:,14) = strpad('Kmier in component IEP (dimensionless)'); LEGEND_ALGEBRAIC(:,2) = strpad('IE in component IE (dimensionless)'); LEGEND_STATES(:,7) = strpad('APC_ in component APC_ (dimensionless)'); LEGEND_CONSTANTS(:,15) = strpad('kap in component APC_ (first_order_rate_constant)'); LEGEND_CONSTANTS(:,16) = strpad('Kmap in component APC_ (dimensionless)'); LEGEND_CONSTANTS(:,17) = strpad('kapr in component APC_ (first_order_rate_constant)'); LEGEND_CONSTANTS(:,18) = strpad('Kmapr in component APC_ (dimensionless)'); LEGEND_ALGEBRAIC(:,5) = strpad('APC in component APC (dimensionless)'); LEGEND_CONSTANTS(:,19) = strpad('Cdc2tot in component C (dimensionless)'); LEGEND_CONSTANTS(:,20) = strpad('Cdc25tot in component Cdc25 (dimensionless)'); LEGEND_CONSTANTS(:,21) = strpad('Wee1tot in component Wee1P (dimensionless)'); LEGEND_CONSTANTS(:,22) = strpad('IEtot in component IE (dimensionless)'); LEGEND_CONSTANTS(:,23) = strpad('APCtot in component APC (dimensionless)'); LEGEND_CONSTANTS(:,24) = strpad('R in component p (dimensionless)'); LEGEND_CONSTANTS(:,25) = strpad('s in component p (dimensionless)'); LEGEND_CONSTANTS(:,26) = strpad('q in component p (dimensionless)'); LEGEND_CONSTANTS(:,27) = strpad('V2 in component kinetic_parameters (first_order_rate_constant)'); LEGEND_CONSTANTS(:,28) = strpad('V2_ in component kinetic_parameters (first_order_rate_constant)'); LEGEND_CONSTANTS(:,29) = strpad('V25 in component kinetic_parameters (first_order_rate_constant)'); LEGEND_CONSTANTS(:,30) = strpad('V25_ in component kinetic_parameters (first_order_rate_constant)'); LEGEND_CONSTANTS(:,31) = strpad('Vwee in component kinetic_parameters (first_order_rate_constant)'); LEGEND_CONSTANTS(:,32) = strpad('Vwee_ in component kinetic_parameters (first_order_rate_constant)'); LEGEND_RATES(:,1) = strpad('d/dt Y in component Y (dimensionless)'); LEGEND_RATES(:,2) = strpad('d/dt M in component M (dimensionless)'); LEGEND_RATES(:,3) = strpad('d/dt preMPF in component preMPF (dimensionless)'); LEGEND_RATES(:,4) = strpad('d/dt Cdc25P in component Cdc25P (dimensionless)'); LEGEND_RATES(:,5) = strpad('d/dt Wee1 in component Wee1 (dimensionless)'); LEGEND_RATES(:,6) = strpad('d/dt IEP in component IEP (dimensionless)'); LEGEND_RATES(:,7) = strpad('d/dt APC_ in component APC_ (dimensionless)'); 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.01577552; CONSTANTS(:,1) = 0.024; CONSTANTS(:,2) = 1.15; STATES(:,2) = 0.0142077; STATES(:,3) = 0.02541723; STATES(:,4) = 0.4844362; CONSTANTS(:,3) = 18; CONSTANTS(:,4) = 0.1; CONSTANTS(:,5) = 0.8; CONSTANTS(:,6) = 1; STATES(:,5) = 0.5155638; CONSTANTS(:,7) = 18; CONSTANTS(:,8) = 0.1; CONSTANTS(:,9) = 0.8; CONSTANTS(:,10) = 1; STATES(:,6) = 0.002287817; CONSTANTS(:,11) = 4.5; CONSTANTS(:,12) = 0.01; CONSTANTS(:,13) = 0.34; CONSTANTS(:,14) = 0.01; STATES(:,7) = 0.5051103; CONSTANTS(:,15) = 0.3; CONSTANTS(:,16) = 0.01; CONSTANTS(:,17) = 0.3; CONSTANTS(:,18) = 1; CONSTANTS(:,19) = 1; CONSTANTS(:,20) = 1; CONSTANTS(:,21) = 1; CONSTANTS(:,22) = 1; CONSTANTS(:,23) = 1; CONSTANTS(:,24) = 1; CONSTANTS(:,25) = 0.021; CONSTANTS(:,26) = 1; CONSTANTS(:,27) = 0.01; CONSTANTS(:,28) = 0.6; CONSTANTS(:,29) = 0.04; CONSTANTS(:,30) = 0.4; CONSTANTS(:,31) = 0.025; CONSTANTS(:,32) = 2.5; CONSTANTS(:,33) = CONSTANTS(:,25).*CONSTANTS(:,24)+CONSTANTS(:,26); CONSTANTS(:,34) = CONSTANTS(:,5)./CONSTANTS(:,33); CONSTANTS(:,35) = CONSTANTS(:,9)./CONSTANTS(:,33); 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(:,2) = CONSTANTS(:,22) - STATES(:,6); RATES(:,6) = ( CONSTANTS(:,11).*STATES(:,2).*ALGEBRAIC(:,2))./(CONSTANTS(:,12)+ALGEBRAIC(:,2)) - ( CONSTANTS(:,13).*STATES(:,6))./(CONSTANTS(:,14)+STATES(:,6)); ALGEBRAIC(:,3) = CONSTANTS(:,20) - STATES(:,4); RATES(:,4) = ( CONSTANTS(:,3).*STATES(:,2).*ALGEBRAIC(:,3))./(CONSTANTS(:,4)+ALGEBRAIC(:,3)) - ( CONSTANTS(:,5).*STATES(:,4))./(CONSTANTS(:,6)+STATES(:,4)); ALGEBRAIC(:,4) = CONSTANTS(:,21) - STATES(:,5); RATES(:,5) = ( - CONSTANTS(:,7).*STATES(:,2).*STATES(:,5))./(CONSTANTS(:,8)+STATES(:,5))+( CONSTANTS(:,9).*ALGEBRAIC(:,4))./(CONSTANTS(:,10)+ALGEBRAIC(:,4)); ALGEBRAIC(:,5) = CONSTANTS(:,23) - STATES(:,7); RATES(:,7) = ( CONSTANTS(:,15).*STATES(:,6).*ALGEBRAIC(:,5))./(CONSTANTS(:,16)+ALGEBRAIC(:,5)) - ( CONSTANTS(:,17).*STATES(:,7))./(CONSTANTS(:,18)+STATES(:,7)); ALGEBRAIC(:,7) = CONSTANTS(:,27).*ALGEBRAIC(:,5)+ CONSTANTS(:,28).*STATES(:,7); ALGEBRAIC(:,1) = CONSTANTS(:,19) - (STATES(:,2)+STATES(:,3)); RATES(:,1) = CONSTANTS(:,1) - ( ALGEBRAIC(:,7).*STATES(:,1)+ CONSTANTS(:,2).*STATES(:,1).*ALGEBRAIC(:,1)); ALGEBRAIC(:,8) = CONSTANTS(:,31).*ALGEBRAIC(:,4)+ CONSTANTS(:,32).*STATES(:,5); ALGEBRAIC(:,6) = CONSTANTS(:,29).*ALGEBRAIC(:,3)+ CONSTANTS(:,30).*STATES(:,4); RATES(:,2) = ( ALGEBRAIC(:,6).*STATES(:,3)+ CONSTANTS(:,2).*STATES(:,1).*ALGEBRAIC(:,1)) - ( ALGEBRAIC(:,7).*STATES(:,2)+ ALGEBRAIC(:,8).*STATES(:,2)); RATES(:,3) = ALGEBRAIC(:,8).*STATES(:,2) - ( ALGEBRAIC(:,7).*STATES(:,3)+ ALGEBRAIC(:,6).*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 ALGEBRAIC(:,2) = CONSTANTS(:,22) - STATES(:,6); ALGEBRAIC(:,3) = CONSTANTS(:,20) - STATES(:,4); ALGEBRAIC(:,4) = CONSTANTS(:,21) - STATES(:,5); ALGEBRAIC(:,5) = CONSTANTS(:,23) - STATES(:,7); ALGEBRAIC(:,7) = CONSTANTS(:,27).*ALGEBRAIC(:,5)+ CONSTANTS(:,28).*STATES(:,7); ALGEBRAIC(:,1) = CONSTANTS(:,19) - (STATES(:,2)+STATES(:,3)); ALGEBRAIC(:,8) = CONSTANTS(:,31).*ALGEBRAIC(:,4)+ CONSTANTS(:,32).*STATES(:,5); ALGEBRAIC(:,6) = CONSTANTS(:,29).*ALGEBRAIC(:,3)+ CONSTANTS(:,30).*STATES(:,4); 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