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 13 entries in each of the rate and state variable arrays. % There are a total of 23 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('Cdk2_CycE in component Cdk2_CycE (dimensionless)'); LEGEND_CONSTANTS(:,1) = strpad('kwee in component kinetic_parameters (first_order_rate_constant)'); LEGEND_CONSTANTS(:,2) = strpad('kon in component kinetic_parameters (first_order_rate_constant)'); LEGEND_CONSTANTS(:,3) = strpad('k25A in component kinetic_parameters (first_order_rate_constant)'); LEGEND_CONSTANTS(:,4) = strpad('koff in component kinetic_parameters (first_order_rate_constant)'); LEGEND_CONSTANTS(:,5) = strpad('kassoc in component kinetic_parameters (first_order_rate_constant)'); LEGEND_CONSTANTS(:,6) = strpad('kdissoc in component kinetic_parameters (first_order_rate_constant)'); LEGEND_ALGEBRAIC(:,5) = strpad('phi in component kinetic_parameters (dimensionless)'); LEGEND_STATES(:,2) = strpad('Wee1_a in component Wee1_a (dimensionless)'); LEGEND_STATES(:,3) = strpad('PCdk2_CycE in component PCdk2_CycE (dimensionless)'); LEGEND_STATES(:,4) = strpad('Xic in component Xic (dimensionless)'); LEGEND_STATES(:,5) = strpad('Cdk2_CycErem in component Cdk2_CycErem (dimensionless)'); LEGEND_STATES(:,6) = strpad('Xic_Cdk2_CycE in component Xic_Cdk2_CycE (dimensionless)'); LEGEND_STATES(:,7) = strpad('PCdk2_CycErem in component PCdk2_CycErem (dimensionless)'); LEGEND_STATES(:,8) = strpad('Xic_PCdk2_CycE in component Xic_PCdk2_CycE (dimensionless)'); LEGEND_CONSTANTS(:,7) = strpad('Jwact in component Wee1_a (dimensionless)'); LEGEND_CONSTANTS(:,8) = strpad('Jwinact in component Wee1_a (dimensionless)'); LEGEND_CONSTANTS(:,9) = strpad('Wee1_total in component Wee1_a (dimensionless)'); LEGEND_CONSTANTS(:,10) = strpad('kwact in component Wee1_a (first_order_rate_constant)'); LEGEND_CONSTANTS(:,11) = strpad('kwinact in component Wee1_a (first_order_rate_constant)'); LEGEND_STATES(:,9) = strpad('Kin_a in component Kin_a (dimensionless)'); LEGEND_CONSTANTS(:,12) = strpad('Jiact in component Kin_a (dimensionless)'); LEGEND_CONSTANTS(:,13) = strpad('Jiinact in component Kin_a (dimensionless)'); LEGEND_CONSTANTS(:,14) = strpad('kiact in component Kin_a (first_order_rate_constant)'); LEGEND_CONSTANTS(:,15) = strpad('kiinact in component Kin_a (first_order_rate_constant)'); LEGEND_CONSTANTS(:,16) = strpad('kedeg in component kinetic_parameters (first_order_rate_constant)'); LEGEND_CONSTANTS(:,17) = strpad('kxdeg in component kinetic_parameters (first_order_rate_constant)'); LEGEND_STATES(:,10) = strpad('Deg_a in component Deg_a (dimensionless)'); LEGEND_STATES(:,11) = strpad('Xic_Cdk2_CycErem in component Xic_Cdk2_CycErem (dimensionless)'); LEGEND_STATES(:,12) = strpad('Xic_PCdk2_CycErem in component Xic_PCdk2_CycErem (dimensionless)'); LEGEND_ALGEBRAIC(:,6) = strpad('Heav in component Deg_a (dimensionless)'); LEGEND_CONSTANTS(:,18) = strpad('kdact in component Deg_a (first_order_rate_constant)'); LEGEND_CONSTANTS(:,19) = strpad('theta in component Deg_a (dimensionless)'); LEGEND_ALGEBRAIC(:,2) = strpad('x in component Deg_a (dimensionless)'); LEGEND_CONSTANTS(:,20) = strpad('Deg in component kinetic_parameters (dimensionless)'); LEGEND_STATES(:,13) = strpad('Xicrem in component Xicrem (dimensionless)'); LEGEND_ALGEBRAIC(:,3) = strpad('Cyc_total in component Cyc_total (dimensionless)'); LEGEND_ALGEBRAIC(:,4) = strpad('Xic_total in component Xic_total (dimensionless)'); LEGEND_CONSTANTS(:,21) = strpad('epsilon in component kinetic_parameters (dimensionless)'); LEGEND_ALGEBRAIC(:,1) = strpad('pool in component kinetic_parameters (dimensionless)'); LEGEND_CONSTANTS(:,22) = strpad('n in component kinetic_parameters (dimensionless)'); LEGEND_CONSTANTS(:,23) = strpad('L in component kinetic_parameters (dimensionless)'); LEGEND_RATES(:,1) = strpad('d/dt Cdk2_CycE in component Cdk2_CycE (dimensionless)'); LEGEND_RATES(:,3) = strpad('d/dt PCdk2_CycE in component PCdk2_CycE (dimensionless)'); LEGEND_RATES(:,2) = strpad('d/dt Wee1_a in component Wee1_a (dimensionless)'); LEGEND_RATES(:,9) = strpad('d/dt Kin_a in component Kin_a (dimensionless)'); LEGEND_RATES(:,5) = strpad('d/dt Cdk2_CycErem in component Cdk2_CycErem (dimensionless)'); LEGEND_RATES(:,7) = strpad('d/dt PCdk2_CycErem in component PCdk2_CycErem (dimensionless)'); LEGEND_RATES(:,10) = strpad('d/dt Deg_a in component Deg_a (dimensionless)'); LEGEND_RATES(:,4) = strpad('d/dt Xic in component Xic (dimensionless)'); LEGEND_RATES(:,6) = strpad('d/dt Xic_Cdk2_CycE in component Xic_Cdk2_CycE (dimensionless)'); LEGEND_RATES(:,8) = strpad('d/dt Xic_PCdk2_CycE in component Xic_PCdk2_CycE (dimensionless)'); LEGEND_RATES(:,11) = strpad('d/dt Xic_Cdk2_CycErem in component Xic_Cdk2_CycErem (dimensionless)'); LEGEND_RATES(:,12) = strpad('d/dt Xic_PCdk2_CycErem in component Xic_PCdk2_CycErem (dimensionless)'); LEGEND_RATES(:,13) = strpad('d/dt Xicrem in component Xicrem (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.06; CONSTANTS(:,1) = 1.5; CONSTANTS(:,2) = 0.02; CONSTANTS(:,3) = 0.1; CONSTANTS(:,4) = 0.0001; CONSTANTS(:,5) = 0.1; CONSTANTS(:,6) = 0.001; STATES(:,2) = 1.02; STATES(:,3) = 0.94; STATES(:,4) = 3; STATES(:,5) = 0; STATES(:,6) = 0; STATES(:,7) = 0; STATES(:,8) = 0; CONSTANTS(:,7) = 0.01; CONSTANTS(:,8) = 0.01; CONSTANTS(:,9) = 8; CONSTANTS(:,10) = 0.75; CONSTANTS(:,11) = 1.5; STATES(:,9) = 0.6; CONSTANTS(:,12) = 0.01; CONSTANTS(:,13) = 0.01; CONSTANTS(:,14) = 0.15; CONSTANTS(:,15) = 0.6; CONSTANTS(:,16) = 0.017; CONSTANTS(:,17) = 0.01; STATES(:,10) = 0; STATES(:,11) = 0; STATES(:,12) = 0; CONSTANTS(:,18) = 0.023; CONSTANTS(:,19) = 0.3; CONSTANTS(:,20) = 0; STATES(:,13) = 0; CONSTANTS(:,21) = 0.001; CONSTANTS(:,22) = 4; CONSTANTS(:,23) = 0.4; 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(:,2) = ( CONSTANTS(:,10).*(CONSTANTS(:,9) - STATES(:,2)))./((CONSTANTS(:,7)+CONSTANTS(:,9)) - STATES(:,2)) - ( CONSTANTS(:,11).*STATES(:,9).*STATES(:,2))./(CONSTANTS(:,8)+STATES(:,2)); RATES(:,9) = ( CONSTANTS(:,14).*(1.00000 - STATES(:,9)))./((CONSTANTS(:,12)+1.00000) - STATES(:,9)) - ( CONSTANTS(:,15).*STATES(:,1).*STATES(:,9))./(CONSTANTS(:,13)+STATES(:,9)); RATES(:,4) = CONSTANTS(:,6).*(STATES(:,6)+STATES(:,8)+STATES(:,11)+STATES(:,12)) - CONSTANTS(:,5).*STATES(:,4).*(STATES(:,1)+STATES(:,3)+STATES(:,5)+STATES(:,7)); RATES(:,13) = ( CONSTANTS(:,16).*STATES(:,10).*STATES(:,11)+ CONSTANTS(:,16).*STATES(:,10).*STATES(:,12)) - CONSTANTS(:,17).*STATES(:,13); ALGEBRAIC(:,1) = STATES(:,5)+STATES(:,7)+STATES(:,11)+STATES(:,12); ALGEBRAIC(:,5) = (CONSTANTS(:,21)+power(ALGEBRAIC(:,1), CONSTANTS(:,22)))./(power(CONSTANTS(:,23), CONSTANTS(:,22))+power(ALGEBRAIC(:,1), CONSTANTS(:,22))); RATES(:,1) = ( CONSTANTS(:,3).*STATES(:,3)+ CONSTANTS(:,4).*STATES(:,5)+ CONSTANTS(:,6).*STATES(:,6)) - ( CONSTANTS(:,1).*STATES(:,2).*STATES(:,1)+ CONSTANTS(:,2).*ALGEBRAIC(:,5).*STATES(:,1)+ CONSTANTS(:,5).*STATES(:,4).*STATES(:,1)); RATES(:,3) = ( CONSTANTS(:,1).*STATES(:,2).*STATES(:,1)+ CONSTANTS(:,4).*STATES(:,7)+ CONSTANTS(:,6).*STATES(:,8)) - ( CONSTANTS(:,3).*STATES(:,3)+ CONSTANTS(:,2).*ALGEBRAIC(:,5).*STATES(:,3)+ CONSTANTS(:,5).*STATES(:,4).*STATES(:,3)); RATES(:,5) = ( CONSTANTS(:,2).*ALGEBRAIC(:,5).*STATES(:,1)+ CONSTANTS(:,17).*STATES(:,11)+ CONSTANTS(:,6).*STATES(:,11)) - ( CONSTANTS(:,4).*STATES(:,5)+ CONSTANTS(:,16).*STATES(:,10).*STATES(:,5)+ CONSTANTS(:,5).*STATES(:,4).*STATES(:,5)); RATES(:,7) = ( CONSTANTS(:,2).*ALGEBRAIC(:,5).*STATES(:,3)+ CONSTANTS(:,17).*STATES(:,12)+ CONSTANTS(:,6).*STATES(:,12)) - ( CONSTANTS(:,4).*STATES(:,7)+ CONSTANTS(:,16).*STATES(:,10).*STATES(:,7)+ CONSTANTS(:,5).*STATES(:,4).*STATES(:,7)); ALGEBRAIC(:,2) = STATES(:,5) - CONSTANTS(:,19); ALGEBRAIC(:,6) = piecewise({ALGEBRAIC(:,2)<0.00000, 0.00000 }, 1.00000); RATES(:,10) = CONSTANTS(:,18).*ALGEBRAIC(:,6); RATES(:,6) = ( CONSTANTS(:,5).*STATES(:,4).*STATES(:,1)+ CONSTANTS(:,4).*STATES(:,11)+ CONSTANTS(:,3).*STATES(:,8)) - ( CONSTANTS(:,6).*STATES(:,6)+ CONSTANTS(:,2).*ALGEBRAIC(:,5).*STATES(:,6)+ CONSTANTS(:,1).*STATES(:,2).*STATES(:,6)); RATES(:,8) = ( CONSTANTS(:,5).*STATES(:,4).*STATES(:,3)+ CONSTANTS(:,4).*STATES(:,12)+ CONSTANTS(:,1).*STATES(:,2).*STATES(:,6)) - ( CONSTANTS(:,6).*STATES(:,8)+ CONSTANTS(:,2).*ALGEBRAIC(:,5).*STATES(:,8)+ CONSTANTS(:,3).*STATES(:,8)); RATES(:,11) = ( CONSTANTS(:,5).*STATES(:,4).*STATES(:,5)+ CONSTANTS(:,2).*ALGEBRAIC(:,5).*STATES(:,6)) - ( CONSTANTS(:,6).*STATES(:,11)+ CONSTANTS(:,4).*STATES(:,11)+ CONSTANTS(:,16).*STATES(:,10).*STATES(:,11)+ CONSTANTS(:,17).*STATES(:,11)); RATES(:,12) = ( CONSTANTS(:,5).*STATES(:,4).*STATES(:,7)+ CONSTANTS(:,2).*ALGEBRAIC(:,5).*STATES(:,8)) - ( CONSTANTS(:,6).*STATES(:,12)+ CONSTANTS(:,4).*STATES(:,12)+ CONSTANTS(:,16).*CONSTANTS(:,20).*STATES(:,12)+ CONSTANTS(:,17).*STATES(:,12)); 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) = STATES(:,5)+STATES(:,7)+STATES(:,11)+STATES(:,12); ALGEBRAIC(:,5) = (CONSTANTS(:,21)+power(ALGEBRAIC(:,1), CONSTANTS(:,22)))./(power(CONSTANTS(:,23), CONSTANTS(:,22))+power(ALGEBRAIC(:,1), CONSTANTS(:,22))); ALGEBRAIC(:,2) = STATES(:,5) - CONSTANTS(:,19); ALGEBRAIC(:,6) = piecewise({ALGEBRAIC(:,2)<0.00000, 0.00000 }, 1.00000); ALGEBRAIC(:,3) = STATES(:,8)+STATES(:,6)+STATES(:,12)+STATES(:,11)+STATES(:,7)+STATES(:,5)+STATES(:,1)+STATES(:,3); ALGEBRAIC(:,4) = (STATES(:,4)+STATES(:,8)+STATES(:,6)+STATES(:,12)+STATES(:,11)+STATES(:,13))./3.00000; end % Compute result of a piecewise function function x = piecewise(cases, default) set = [0]; for i = 1:2:length(cases) if (length(cases{i+1}) == 1) x(cases{i} & ~set,:) = cases{i+1}; else x(cases{i} & ~set,:) = cases{i+1}(cases{i} & ~set); end set = set | cases{i}; if(set), break, end end if (length(default) == 1) x(~set,:) = default; else x(~set,:) = default(~set); end 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