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 =7; end % There are a total of 20 entries in each of the rate and state variable arrays. % There are a total of 33 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_ALGEBRAIC(:,1) = strpad('x1 in component x1 (molar)'); LEGEND_STATES(:,1) = strpad('x2 in component x2 (molar)'); LEGEND_CONSTANTS(:,1) = strpad('k1 in component reaction_constants (second_order_rate_constant)'); LEGEND_CONSTANTS(:,2) = strpad('k_minus1 in component reaction_constants (first_order_rate_constant)'); LEGEND_CONSTANTS(:,21) = strpad('k4 in component reaction_constants (first_order_rate_constant)'); LEGEND_CONSTANTS(:,3) = strpad('k_minus4 in component reaction_constants (first_order_rate_constant)'); LEGEND_CONSTANTS(:,22) = strpad('k_minus3 in component reaction_constants (second_order_rate_constant)'); LEGEND_STATES(:,2) = strpad('x3 in component x3 (molar)'); LEGEND_STATES(:,3) = strpad('x5 in component x5 (molar)'); LEGEND_STATES(:,4) = strpad('x6 in component x6 (molar)'); LEGEND_CONSTANTS(:,4) = strpad('PTP in component reaction_constants (molar)'); LEGEND_CONSTANTS(:,5) = strpad('k3 in component reaction_constants (first_order_rate_constant)'); LEGEND_STATES(:,5) = strpad('x4 in component x4 (molar)'); LEGEND_CONSTANTS(:,23) = strpad('k2 in component reaction_constants (second_order_rate_constant)'); LEGEND_CONSTANTS(:,24) = strpad('k_minus2 in component reaction_constants (first_order_rate_constant)'); LEGEND_CONSTANTS(:,6) = strpad('k4b in component reaction_constants (first_order_rate_constant)'); LEGEND_CONSTANTS(:,7) = strpad('k_minus4b in component reaction_constants (first_order_rate_constant)'); LEGEND_STATES(:,6) = strpad('x7 in component x7 (molar)'); LEGEND_STATES(:,7) = strpad('x8 in component x8 (molar)'); LEGEND_ALGEBRAIC(:,2) = strpad('k5 in component reaction_constants (rate)'); LEGEND_CONSTANTS(:,8) = strpad('k_minus5 in component reaction_constants (first_order_rate_constant)'); LEGEND_CONSTANTS(:,9) = strpad('k6 in component reaction_constants (second_order_rate_constant)'); LEGEND_STATES(:,8) = strpad('x9 in component x9 (molar)'); LEGEND_CONSTANTS(:,10) = strpad('k7 in component reaction_constants (first_order_rate_constant)'); LEGEND_CONSTANTS(:,25) = strpad('k_minus7 in component reaction_constants (second_order_rate_constant)'); LEGEND_STATES(:,9) = strpad('x10 in component x10 (molar)'); LEGEND_CONSTANTS(:,11) = strpad('IRp in component reaction_constants (molar)'); LEGEND_CONSTANTS(:,26) = strpad('k8 in component reaction_constants (second_order_rate_constant)'); LEGEND_CONSTANTS(:,12) = strpad('k_minus8 in component reaction_constants (first_order_rate_constant)'); LEGEND_STATES(:,10) = strpad('x11 in component x11 (molar)'); LEGEND_STATES(:,11) = strpad('x12 in component x12 (molar)'); LEGEND_STATES(:,12) = strpad('x13 in component x13 (percentage)'); LEGEND_ALGEBRAIC(:,3) = strpad('k9 in component reaction_constants (first_order_rate_constant)'); LEGEND_CONSTANTS(:,27) = strpad('k_minus9 in component reaction_constants (second_order_rate_constant)'); LEGEND_CONSTANTS(:,28) = strpad('k10 in component reaction_constants (first_order_rate_constant)'); LEGEND_CONSTANTS(:,13) = strpad('k_minus10 in component reaction_constants (second_order_rate_constant)'); LEGEND_STATES(:,13) = strpad('x14 in component x14 (percentage)'); LEGEND_STATES(:,14) = strpad('x15 in component x15 (percentage)'); LEGEND_CONSTANTS(:,14) = strpad('PTEN in component reaction_constants (molar)'); LEGEND_CONSTANTS(:,15) = strpad('SHIP in component reaction_constants (molar)'); LEGEND_STATES(:,15) = strpad('x16 in component x16 (percentage)'); LEGEND_ALGEBRAIC(:,4) = strpad('k11 in component reaction_constants (first_order_rate_constant)'); LEGEND_CONSTANTS(:,29) = strpad('k_minus11 in component reaction_constants (first_order_rate_constant)'); LEGEND_STATES(:,16) = strpad('x17 in component x17 (percentage)'); LEGEND_STATES(:,17) = strpad('x18 in component x18 (percentage)'); LEGEND_ALGEBRAIC(:,5) = strpad('k12 in component reaction_constants (first_order_rate_constant)'); LEGEND_CONSTANTS(:,30) = strpad('k_minus12 in component reaction_constants (first_order_rate_constant)'); LEGEND_STATES(:,18) = strpad('x19 in component x19 (percentage)'); LEGEND_STATES(:,19) = strpad('x20 in component x20 (percentage)'); LEGEND_CONSTANTS(:,31) = strpad('k13 in component reaction_constants (first_order_rate_constant)'); LEGEND_CONSTANTS(:,16) = strpad('k_minus13 in component reaction_constants (first_order_rate_constant)'); LEGEND_ALGEBRAIC(:,7) = strpad('k13b in component reaction_constants (first_order_rate_constant)'); LEGEND_CONSTANTS(:,32) = strpad('k14 in component reaction_constants (first_order_rate_constant)'); LEGEND_CONSTANTS(:,17) = strpad('k_minus14 in component reaction_constants (first_order_rate_constant)'); LEGEND_STATES(:,20) = strpad('x21 in component x21 (percentage)'); LEGEND_CONSTANTS(:,33) = strpad('k9_basal in component reaction_constants (first_order_rate_constant)'); LEGEND_CONSTANTS(:,18) = strpad('k9_stimulated in component reaction_constants (first_order_rate_constant)'); LEGEND_ALGEBRAIC(:,6) = strpad('effect in component reaction_constants (dimensionless)'); LEGEND_CONSTANTS(:,19) = strpad('APequil in component reaction_constants (dimensionless)'); LEGEND_CONSTANTS(:,20) = strpad('PI3K in component reaction_constants (molar)'); LEGEND_RATES(:,1) = strpad('d/dt x2 in component x2 (molar)'); LEGEND_RATES(:,2) = strpad('d/dt x3 in component x3 (molar)'); LEGEND_RATES(:,5) = strpad('d/dt x4 in component x4 (molar)'); LEGEND_RATES(:,3) = strpad('d/dt x5 in component x5 (molar)'); LEGEND_RATES(:,4) = strpad('d/dt x6 in component x6 (molar)'); LEGEND_RATES(:,6) = strpad('d/dt x7 in component x7 (molar)'); LEGEND_RATES(:,7) = strpad('d/dt x8 in component x8 (molar)'); LEGEND_RATES(:,8) = strpad('d/dt x9 in component x9 (molar)'); LEGEND_RATES(:,9) = strpad('d/dt x10 in component x10 (molar)'); LEGEND_RATES(:,10) = strpad('d/dt x11 in component x11 (molar)'); LEGEND_RATES(:,11) = strpad('d/dt x12 in component x12 (molar)'); LEGEND_RATES(:,12) = strpad('d/dt x13 in component x13 (percentage)'); LEGEND_RATES(:,13) = strpad('d/dt x14 in component x14 (percentage)'); LEGEND_RATES(:,14) = strpad('d/dt x15 in component x15 (percentage)'); LEGEND_RATES(:,15) = strpad('d/dt x16 in component x16 (percentage)'); LEGEND_RATES(:,16) = strpad('d/dt x17 in component x17 (percentage)'); LEGEND_RATES(:,17) = strpad('d/dt x18 in component x18 (percentage)'); LEGEND_RATES(:,18) = strpad('d/dt x19 in component x19 (percentage)'); LEGEND_RATES(:,19) = strpad('d/dt x20 in component x20 (percentage)'); LEGEND_RATES(:,20) = strpad('d/dt x21 in component x21 (percentage)'); 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) = 9e-13; CONSTANTS(:,1) = 6e7; CONSTANTS(:,2) = 0.2; CONSTANTS(:,3) = 0.003; STATES(:,2) = 0; STATES(:,3) = 0; STATES(:,4) = 1e-13; CONSTANTS(:,4) = 1; CONSTANTS(:,5) = 2500; STATES(:,5) = 0; CONSTANTS(:,6) = 2.1e-3; CONSTANTS(:,7) = 2.1e-4; STATES(:,6) = 0; STATES(:,7) = 0; CONSTANTS(:,8) = 1.67e-18; CONSTANTS(:,9) = 0.461; STATES(:,8) = 1e-13; CONSTANTS(:,10) = 4.16; STATES(:,9) = 1e-13; CONSTANTS(:,11) = 8.97e-13; CONSTANTS(:,12) = 10; STATES(:,10) = 1e-13; STATES(:,11) = 0; STATES(:,12) = 0.31; CONSTANTS(:,13) = 2.77; STATES(:,13) = 99.4; STATES(:,14) = 0.29; CONSTANTS(:,14) = 1; CONSTANTS(:,15) = 1; STATES(:,15) = 100; STATES(:,16) = 0; STATES(:,17) = 100; STATES(:,18) = 0; STATES(:,19) = 96; CONSTANTS(:,16) = 0.167; CONSTANTS(:,17) = 0.001155; STATES(:,20) = 4; CONSTANTS(:,18) = 1.39; CONSTANTS(:,19) = 9.09; CONSTANTS(:,20) = 5e-15; CONSTANTS(:,21) = CONSTANTS(:,3)./9.00000; CONSTANTS(:,22) = CONSTANTS(:,2)./1.00000; CONSTANTS(:,23) = CONSTANTS(:,1); CONSTANTS(:,24) = 100.000.*CONSTANTS(:,2); CONSTANTS(:,25) = (2.50000./7.45000).*CONSTANTS(:,10); CONSTANTS(:,26) = (( CONSTANTS(:,12).*5.00000)./70.7750).*1.00000e+12; CONSTANTS(:,27) = (94.0000./3.10000).*CONSTANTS(:,18); CONSTANTS(:,28) = (3.10000./2.90000).*CONSTANTS(:,13); CONSTANTS(:,29) = 10.0000.*log(2.00000).*1.00000; CONSTANTS(:,30) = 10.0000.*log(2.00000).*1.00000; CONSTANTS(:,31) = (4.00000./96.0000).*CONSTANTS(:,16); CONSTANTS(:,32) = CONSTANTS(:,17)./96.0000; CONSTANTS(:,33) = (0.310000./99.4000).*CONSTANTS(:,27); 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(:,6) = CONSTANTS(:,6).*STATES(:,5) - ( CONSTANTS(:,7).*STATES(:,6)+ CONSTANTS(:,9).*CONSTANTS(:,4).*STATES(:,6)); RATES(:,7) = CONSTANTS(:,6).*STATES(:,3) - ( CONSTANTS(:,7).*STATES(:,7)+ CONSTANTS(:,9).*CONSTANTS(:,4).*STATES(:,7)); RATES(:,8) = CONSTANTS(:,25).*CONSTANTS(:,4).*STATES(:,9) - ( CONSTANTS(:,10).*STATES(:,8).*(STATES(:,5)+STATES(:,3)))./CONSTANTS(:,11); RATES(:,9) = (( CONSTANTS(:,10).*STATES(:,8).*(STATES(:,5)+STATES(:,3)))./CONSTANTS(:,11)+ CONSTANTS(:,12).*STATES(:,11)) - ( CONSTANTS(:,25).*CONSTANTS(:,4)+ CONSTANTS(:,26).*STATES(:,10)).*STATES(:,9); RATES(:,10) = CONSTANTS(:,12).*STATES(:,11) - CONSTANTS(:,26).*STATES(:,9).*STATES(:,10); RATES(:,11) = CONSTANTS(:,26).*STATES(:,9).*STATES(:,10) - CONSTANTS(:,12).*STATES(:,11); RATES(:,14) = CONSTANTS(:,13).*CONSTANTS(:,15).*STATES(:,12) - CONSTANTS(:,28).*STATES(:,14); ALGEBRAIC(:,1) = piecewise({VOI<15.0000, 1.00000e-07 }, 0.00000); RATES(:,1) = ( CONSTANTS(:,2).*STATES(:,2)+ CONSTANTS(:,22).*CONSTANTS(:,4).*STATES(:,3)+ CONSTANTS(:,3).*STATES(:,4)) - ( CONSTANTS(:,1).*ALGEBRAIC(:,1).*STATES(:,1)+ CONSTANTS(:,21).*STATES(:,1)); RATES(:,2) = CONSTANTS(:,1).*ALGEBRAIC(:,1).*STATES(:,1) - ( CONSTANTS(:,2).*STATES(:,2)+ CONSTANTS(:,5).*STATES(:,2)); RATES(:,5) = ( CONSTANTS(:,23).*ALGEBRAIC(:,1).*STATES(:,3)+ CONSTANTS(:,7).*STATES(:,6)) - ( CONSTANTS(:,24).*STATES(:,5)+ CONSTANTS(:,6).*STATES(:,5)); RATES(:,3) = ( CONSTANTS(:,5).*STATES(:,2)+ CONSTANTS(:,24).*STATES(:,5)+ CONSTANTS(:,7).*STATES(:,7)) - ( CONSTANTS(:,23).*ALGEBRAIC(:,1).*STATES(:,3)+ CONSTANTS(:,22).*CONSTANTS(:,4).*STATES(:,3)+ CONSTANTS(:,6).*STATES(:,3)); ALGEBRAIC(:,2) = piecewise({STATES(:,4)+STATES(:,6)+STATES(:,7)>1.00000e-13, 10.0000.*CONSTANTS(:,8) }, 60.0000.*CONSTANTS(:,8)); RATES(:,4) = (ALGEBRAIC(:,2)+ CONSTANTS(:,9).*CONSTANTS(:,4).*(STATES(:,6)+STATES(:,7))+ CONSTANTS(:,21).*STATES(:,1)) - ( CONSTANTS(:,8).*STATES(:,4)+ CONSTANTS(:,3).*STATES(:,4)); ALGEBRAIC(:,3) = ( (CONSTANTS(:,18) - CONSTANTS(:,33)).*STATES(:,11))./CONSTANTS(:,20)+CONSTANTS(:,33); RATES(:,12) = ( ALGEBRAIC(:,3).*STATES(:,13)+ CONSTANTS(:,28).*STATES(:,14)) - ( CONSTANTS(:,27).*CONSTANTS(:,14)+ CONSTANTS(:,13).*CONSTANTS(:,15)).*STATES(:,12); RATES(:,13) = CONSTANTS(:,27).*CONSTANTS(:,14).*STATES(:,12) - ALGEBRAIC(:,3).*STATES(:,13); ALGEBRAIC(:,4) = ( 0.100000.*CONSTANTS(:,29).*(STATES(:,12) - 0.310000))./(3.10000 - 0.310000); RATES(:,15) = CONSTANTS(:,29).*STATES(:,16) - ALGEBRAIC(:,4).*STATES(:,15); RATES(:,16) = ALGEBRAIC(:,4).*STATES(:,15) - CONSTANTS(:,29).*STATES(:,16); ALGEBRAIC(:,5) = ( 0.100000.*CONSTANTS(:,30).*(STATES(:,12) - 0.310000))./(3.10000 - 0.310000); RATES(:,17) = CONSTANTS(:,30).*STATES(:,18) - ALGEBRAIC(:,5).*STATES(:,17); RATES(:,18) = ALGEBRAIC(:,5).*STATES(:,17) - CONSTANTS(:,30).*STATES(:,18); ALGEBRAIC(:,6) = ( 0.200000.*STATES(:,16)+ 0.800000.*STATES(:,18))./CONSTANTS(:,19); ALGEBRAIC(:,7) = (40.0000./60.0000 - 4.00000./96.0000).*CONSTANTS(:,16).*ALGEBRAIC(:,6); RATES(:,19) = ( CONSTANTS(:,16).*STATES(:,20)+CONSTANTS(:,32)) - ( (CONSTANTS(:,31)+ALGEBRAIC(:,7)).*STATES(:,19)+ CONSTANTS(:,17).*STATES(:,19)); RATES(:,20) = - CONSTANTS(:,16).*STATES(:,20)+ (CONSTANTS(:,31)+ALGEBRAIC(:,7)).*STATES(:,19); 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) = piecewise({VOI<15.0000, 1.00000e-07 }, 0.00000); ALGEBRAIC(:,2) = piecewise({STATES(:,4)+STATES(:,6)+STATES(:,7)>1.00000e-13, 10.0000.*CONSTANTS(:,8) }, 60.0000.*CONSTANTS(:,8)); ALGEBRAIC(:,3) = ( (CONSTANTS(:,18) - CONSTANTS(:,33)).*STATES(:,11))./CONSTANTS(:,20)+CONSTANTS(:,33); ALGEBRAIC(:,4) = ( 0.100000.*CONSTANTS(:,29).*(STATES(:,12) - 0.310000))./(3.10000 - 0.310000); ALGEBRAIC(:,5) = ( 0.100000.*CONSTANTS(:,30).*(STATES(:,12) - 0.310000))./(3.10000 - 0.310000); ALGEBRAIC(:,6) = ( 0.200000.*STATES(:,16)+ 0.800000.*STATES(:,18))./CONSTANTS(:,19); ALGEBRAIC(:,7) = (40.0000./60.0000 - 4.00000./96.0000).*CONSTANTS(:,16).*ALGEBRAIC(:,6); 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