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 =34; end % There are a total of 16 entries in each of the rate and state variable arrays. % There are a total of 47 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('v1 in component v1 (flux)'); LEGEND_CONSTANTS(:,1) = strpad('Vmax in component v1 (flux)'); LEGEND_CONSTANTS(:,2) = strpad('Km in component v1 (umol_per_g)'); LEGEND_STATES(:,1) = strpad('GL in component GL (umol_per_g)'); LEGEND_ALGEBRAIC(:,2) = strpad('v2 in component v2 (flux)'); LEGEND_CONSTANTS(:,3) = strpad('Vmax in component v2 (flux)'); LEGEND_CONSTANTS(:,4) = strpad('Km in component v2 (umol_per_g)'); LEGEND_STATES(:,2) = strpad('O2 in component O2 (umol_per_g)'); LEGEND_ALGEBRAIC(:,16) = strpad('v3 in component v3 (flux)'); LEGEND_CONSTANTS(:,5) = strpad('Vmax in component v3 (first_order_rate_constant)'); LEGEND_ALGEBRAIC(:,15) = strpad('k3 in component v3 (first_order_rate_constant)'); LEGEND_STATES(:,3) = strpad('FA in component FA (umol_per_g)'); LEGEND_ALGEBRAIC(:,14) = strpad('PS in component PS (dimensionless)'); LEGEND_CONSTANTS(:,6) = strpad('PS0 in component PS0 (dimensionless)'); LEGEND_ALGEBRAIC(:,31) = strpad('v4 in component v4 (flux)'); LEGEND_CONSTANTS(:,7) = strpad('Vmax in component v4 (first_order_rate_constant)'); LEGEND_ALGEBRAIC(:,30) = strpad('k4 in component v4 (first_order_rate_constant)'); LEGEND_CONSTANTS(:,8) = strpad('epsilon in component v4 (dimensionless)'); LEGEND_ALGEBRAIC(:,5) = strpad('RS in component RS (dimensionless)'); LEGEND_CONSTANTS(:,9) = strpad('RS0 in component RS0 (dimensionless)'); LEGEND_ALGEBRAIC(:,29) = strpad('AF in component AF (dimensionless)'); LEGEND_CONSTANTS(:,10) = strpad('AF0 in component AF0 (dimensionless)'); LEGEND_ALGEBRAIC(:,18) = strpad('v5 in component v5 (flux)'); LEGEND_CONSTANTS(:,11) = strpad('Vmax in component v5 (first_order_rate_constant)'); LEGEND_ALGEBRAIC(:,17) = strpad('k5 in component v5 (first_order_rate_constant)'); LEGEND_CONSTANTS(:,12) = strpad('epsilon in component v5 (dimensionless)'); LEGEND_STATES(:,4) = strpad('GP in component GP (umol_per_g)'); LEGEND_ALGEBRAIC(:,20) = strpad('v6 in component v6 (flux)'); LEGEND_CONSTANTS(:,13) = strpad('Vmax in component v6 (first_order_rate_constant)'); LEGEND_ALGEBRAIC(:,19) = strpad('k6 in component v6 (first_order_rate_constant)'); LEGEND_CONSTANTS(:,14) = strpad('epsilon in component v6 (dimensionless)'); LEGEND_ALGEBRAIC(:,4) = strpad('CS in component CS (dimensionless)'); LEGEND_CONSTANTS(:,15) = strpad('CS0 in component CS0 (dimensionless)'); LEGEND_ALGEBRAIC(:,24) = strpad('v7 in component v7 (flux)'); LEGEND_CONSTANTS(:,16) = strpad('Vmax in component v7 (first_order_rate_constant)'); LEGEND_ALGEBRAIC(:,22) = strpad('k7 in component v7 (first_order_rate_constant)'); LEGEND_CONSTANTS(:,17) = strpad('epsilon in component v7 (dimensionless)'); LEGEND_STATES(:,5) = strpad('GY in component GY (umol_per_g)'); LEGEND_ALGEBRAIC(:,3) = strpad('v8 in component v8 (flux)'); LEGEND_CONSTANTS(:,18) = strpad('Vmax in component v8 (first_order_rate_constant)'); LEGEND_CONSTANTS(:,46) = strpad('k8 in component v8 (first_order_rate_constant)'); LEGEND_STATES(:,6) = strpad('TG in component TG (umol_per_g)'); LEGEND_ALGEBRAIC(:,7) = strpad('v9 in component v9 (flux)'); LEGEND_CONSTANTS(:,19) = strpad('Vmax in component v9 (first_order_rate_constant)'); LEGEND_ALGEBRAIC(:,6) = strpad('k9 in component v9 (first_order_rate_constant)'); LEGEND_STATES(:,7) = strpad('PY in component PY (umol_per_g)'); LEGEND_ALGEBRAIC(:,33) = strpad('v10 in component v10 (flux)'); LEGEND_CONSTANTS(:,20) = strpad('Vmax in component v10 (first_order_rate_constant)'); LEGEND_ALGEBRAIC(:,32) = strpad('k10 in component v10 (first_order_rate_constant)'); LEGEND_CONSTANTS(:,21) = strpad('epsilon in component v10 (dimensionless)'); LEGEND_ALGEBRAIC(:,9) = strpad('v11 in component v11 (flux)'); LEGEND_CONSTANTS(:,22) = strpad('Vmax in component v11 (first_order_rate_constant)'); LEGEND_ALGEBRAIC(:,8) = strpad('k11 in component v11 (first_order_rate_constant)'); LEGEND_STATES(:,8) = strpad('LA in component LA (umol_per_g)'); LEGEND_ALGEBRAIC(:,23) = strpad('v12 in component v12 (flux)'); LEGEND_CONSTANTS(:,23) = strpad('Vmax in component v12 (first_order_rate_constant)'); LEGEND_ALGEBRAIC(:,21) = strpad('k12 in component v12 (first_order_rate_constant)'); LEGEND_CONSTANTS(:,24) = strpad('epsilon in component v12 (dimensionless)'); LEGEND_STATES(:,9) = strpad('AC in component AC (umol_per_g)'); LEGEND_ALGEBRAIC(:,26) = strpad('v13 in component v13 (flux)'); LEGEND_CONSTANTS(:,25) = strpad('Vmax in component v13 (first_order_rate_constant)'); LEGEND_ALGEBRAIC(:,25) = strpad('k13 in component v13 (first_order_rate_constant)'); LEGEND_STATES(:,10) = strpad('CR in component CR (umol_per_g)'); LEGEND_ALGEBRAIC(:,28) = strpad('v14 in component v14 (flux)'); LEGEND_CONSTANTS(:,26) = strpad('Vmax in component v14 (first_order_rate_constant)'); LEGEND_ALGEBRAIC(:,27) = strpad('k14 in component v14 (first_order_rate_constant)'); LEGEND_STATES(:,11) = strpad('PC in component PC (umol_per_g)'); LEGEND_ALGEBRAIC(:,11) = strpad('v15 in component v15 (flux)'); LEGEND_CONSTANTS(:,27) = strpad('Vmax in component v15 (first_order_rate_constant)'); LEGEND_ALGEBRAIC(:,10) = strpad('k15 in component v15 (first_order_rate_constant)'); LEGEND_CONSTANTS(:,28) = strpad('epsilon in component v15 (dimensionless)'); LEGEND_STATES(:,12) = strpad('CoA_pool in component CoA_pool (umol_per_g)'); LEGEND_STATES(:,13) = strpad('FC in component FC (umol_per_g)'); LEGEND_CONSTANTS(:,29) = strpad('FC0 in component FC0 (umol_per_g)'); LEGEND_ALGEBRAIC(:,13) = strpad('v16 in component v16 (flux)'); LEGEND_CONSTANTS(:,30) = strpad('Vmax in component v16 (first_order_rate_constant)'); LEGEND_ALGEBRAIC(:,12) = strpad('k16 in component v16 (first_order_rate_constant)'); LEGEND_CONSTANTS(:,31) = strpad('epsilon in component v16 (dimensionless)'); LEGEND_CONSTANTS(:,47) = strpad('v17 in component v17 (flux)'); LEGEND_CONSTANTS(:,32) = strpad('Vmax in component v17 (first_order_rate_constant)'); LEGEND_CONSTANTS(:,45) = strpad('k17 in component v17 (first_order_rate_constant)'); LEGEND_CONSTANTS(:,33) = strpad('ATP in component ATP (umol_per_g)'); LEGEND_CONSTANTS(:,34) = strpad('aGL in component GL (umol_per_ml)'); LEGEND_CONSTANTS(:,35) = strpad('sigmaGL in component GL (g_per_ml)'); LEGEND_ALGEBRAIC(:,34) = strpad('F in component model_parameters (ml_per_g_min)'); LEGEND_CONSTANTS(:,36) = strpad('aFA in component FA (umol_per_ml)'); LEGEND_CONSTANTS(:,37) = strpad('sigmaFA in component FA (g_per_ml)'); LEGEND_CONSTANTS(:,38) = strpad('aLA in component LA (umol_per_ml)'); LEGEND_CONSTANTS(:,39) = strpad('sigmaLA in component LA (g_per_ml)'); LEGEND_CONSTANTS(:,40) = strpad('aO2 in component O2 (umol_per_ml)'); LEGEND_CONSTANTS(:,41) = strpad('sigmaO2 in component O2 (g_per_ml)'); LEGEND_STATES(:,14) = strpad('CO2 in component CO2 (umol_per_g)'); LEGEND_CONSTANTS(:,42) = strpad('aCO2 in component CO2 (umol_per_ml)'); LEGEND_CONSTANTS(:,43) = strpad('sigmaCO2 in component CO2 (g_per_ml)'); LEGEND_STATES(:,15) = strpad('NAD in component NAD (umol_per_g)'); LEGEND_STATES(:,16) = strpad('ADP in component ADP (umol_per_g)'); LEGEND_CONSTANTS(:,44) = strpad('NADH in component NADH (umol_per_g)'); LEGEND_RATES(:,1) = strpad('d/dt GL in component GL (umol_per_g)'); LEGEND_RATES(:,3) = strpad('d/dt FA in component FA (umol_per_g)'); LEGEND_RATES(:,4) = strpad('d/dt GP in component GP (umol_per_g)'); LEGEND_RATES(:,5) = strpad('d/dt GY in component GY (umol_per_g)'); LEGEND_RATES(:,6) = strpad('d/dt TG in component TG (umol_per_g)'); LEGEND_RATES(:,7) = strpad('d/dt PY in component PY (umol_per_g)'); LEGEND_RATES(:,8) = strpad('d/dt LA in component LA (umol_per_g)'); LEGEND_RATES(:,9) = strpad('d/dt AC in component AC (umol_per_g)'); LEGEND_RATES(:,13) = strpad('d/dt FC in component FC (umol_per_g)'); LEGEND_RATES(:,12) = strpad('d/dt CoA_pool in component CoA_pool (umol_per_g)'); LEGEND_RATES(:,2) = strpad('d/dt O2 in component O2 (umol_per_g)'); LEGEND_RATES(:,14) = strpad('d/dt CO2 in component CO2 (umol_per_g)'); LEGEND_RATES(:,15) = strpad('d/dt NAD in component NAD (umol_per_g)'); LEGEND_RATES(:,16) = strpad('d/dt ADP in component ADP (umol_per_g)'); LEGEND_RATES(:,11) = strpad('d/dt PC in component PC (umol_per_g)'); LEGEND_RATES(:,10) = strpad('d/dt CR in component CR (umol_per_g)'); 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 = []; CONSTANTS(:,1) = 5.90; CONSTANTS(:,2) = 0.05; STATES(:,1) = 0.998; CONSTANTS(:,3) = 67.6; CONSTANTS(:,4) = 0.01; STATES(:,2) = 0.963; CONSTANTS(:,5) = 4.90; STATES(:,3) = 0.021; CONSTANTS(:,6) = 0.2; CONSTANTS(:,7) = 21.3; CONSTANTS(:,8) = 0.6; CONSTANTS(:,9) = 0.111; CONSTANTS(:,10) = 0.523; CONSTANTS(:,11) = 2.82; CONSTANTS(:,12) = 0.254; STATES(:,4) = 0.171; CONSTANTS(:,13) = 3.14; CONSTANTS(:,14) = 0.5; CONSTANTS(:,15) = 1.0; CONSTANTS(:,16) = 0.0162; CONSTANTS(:,17) = 0.5; STATES(:,5) = 33.0; CONSTANTS(:,18) = 0.005; STATES(:,6) = 3.96; CONSTANTS(:,19) = 1.8; STATES(:,7) = 0.20; CONSTANTS(:,20) = 12.6; CONSTANTS(:,21) = 0.98; CONSTANTS(:,22) = 0.96; STATES(:,8) = 1.98; CONSTANTS(:,23) = 695.7; CONSTANTS(:,24) = 0.75; STATES(:,9) = 0.0046; CONSTANTS(:,25) = 0.455; STATES(:,10) = 3.5; CONSTANTS(:,26) = 0.455; STATES(:,11) = 8.80; CONSTANTS(:,27) = 626.1; CONSTANTS(:,28) = 0.669; STATES(:,12) = 0.043; STATES(:,13) = 0.0088; CONSTANTS(:,29) = 0.0088; CONSTANTS(:,30) = 67.0; CONSTANTS(:,31) = 0.775; CONSTANTS(:,32) = 7.76; CONSTANTS(:,33) = 4.5; CONSTANTS(:,34) = 4.0; CONSTANTS(:,35) = 3.76; CONSTANTS(:,36) = 0.5; CONSTANTS(:,37) = 13.2; CONSTANTS(:,38) = 1.8; CONSTANTS(:,39) = 0.51; CONSTANTS(:,40) = 6.53; CONSTANTS(:,41) = 1.0; STATES(:,14) = 20.0; CONSTANTS(:,42) = 15.5; CONSTANTS(:,43) = 1.0; STATES(:,15) = 1.81; STATES(:,16) = 0.90; CONSTANTS(:,44) = 0.19; CONSTANTS(:,45) = CONSTANTS(:,32); CONSTANTS(:,46) = CONSTANTS(:,18); CONSTANTS(:,47) = CONSTANTS(:,45).*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(:,5) = CONSTANTS(:,44)./STATES(:,15); ALGEBRAIC(:,10) = CONSTANTS(:,27).*( CONSTANTS(:,28).*(power(ALGEBRAIC(:,5), -1.00000)./(power(CONSTANTS(:,9), -1.00000)+power(ALGEBRAIC(:,5), -1.00000)))+ (1.00000 - CONSTANTS(:,28)).*(power(STATES(:,13), -1.00000)./(power(CONSTANTS(:,29), -1.00000)+power(STATES(:,13), -1.00000)))); ALGEBRAIC(:,11) = ALGEBRAIC(:,10).*STATES(:,12); ALGEBRAIC(:,12) = CONSTANTS(:,30).*( CONSTANTS(:,31).*(power(ALGEBRAIC(:,5), -1.00000)./(power(CONSTANTS(:,9), -1.00000)+power(ALGEBRAIC(:,5), -1.00000)))+ (1.00000 - CONSTANTS(:,31)).*(power(STATES(:,13), -1.00000)./(power(CONSTANTS(:,29), -1.00000)+power(STATES(:,13), -1.00000)))); ALGEBRAIC(:,13) = ALGEBRAIC(:,12).*STATES(:,9); RATES(:,12) = ALGEBRAIC(:,13) - ALGEBRAIC(:,11); ALGEBRAIC(:,14) = STATES(:,16)./CONSTANTS(:,33); ALGEBRAIC(:,15) = CONSTANTS(:,5).*(power(ALGEBRAIC(:,14), -1.00000)./(power(CONSTANTS(:,6), -1.00000)+power(ALGEBRAIC(:,14), -1.00000))); ALGEBRAIC(:,16) = ALGEBRAIC(:,15).*STATES(:,3); ALGEBRAIC(:,3) = CONSTANTS(:,46).*STATES(:,6); RATES(:,6) = (1.00000./3.00000).*ALGEBRAIC(:,16) - ALGEBRAIC(:,3); ALGEBRAIC(:,1) = CONSTANTS(:,1).*(STATES(:,1)./(CONSTANTS(:,2)+STATES(:,1))); ALGEBRAIC(:,17) = CONSTANTS(:,11).*( CONSTANTS(:,12).*(ALGEBRAIC(:,14)./(CONSTANTS(:,6)+ALGEBRAIC(:,14)))+ (1.00000 - CONSTANTS(:,12)).*(power(ALGEBRAIC(:,5), -1.00000)./(power(CONSTANTS(:,9), -1.00000)+power(ALGEBRAIC(:,5), -1.00000)))); ALGEBRAIC(:,18) = ALGEBRAIC(:,17).*STATES(:,4); ALGEBRAIC(:,4) = STATES(:,10)./STATES(:,11); ALGEBRAIC(:,19) = CONSTANTS(:,13).*( CONSTANTS(:,14).*(power(ALGEBRAIC(:,14), -1.00000)./(power(CONSTANTS(:,6), -1.00000)+power(ALGEBRAIC(:,14), -1.00000)))+ (1.00000 - CONSTANTS(:,14)).*power(power(ALGEBRAIC(:,4), -1.00000)./(power(CONSTANTS(:,15), -1.00000)+power(ALGEBRAIC(:,4), -1.00000)), 2.00000)); ALGEBRAIC(:,20) = ALGEBRAIC(:,19).*STATES(:,4); ALGEBRAIC(:,22) = CONSTANTS(:,16).*( CONSTANTS(:,17).*(ALGEBRAIC(:,14)./(CONSTANTS(:,6)+ALGEBRAIC(:,14)))+ (1.00000 - CONSTANTS(:,17)).*power(ALGEBRAIC(:,4)./(CONSTANTS(:,15)+ALGEBRAIC(:,4)), 2.00000)); ALGEBRAIC(:,24) = ALGEBRAIC(:,22).*STATES(:,5); RATES(:,4) = (ALGEBRAIC(:,1)+ALGEBRAIC(:,24)) - (ALGEBRAIC(:,18)+ALGEBRAIC(:,20)); RATES(:,5) = ALGEBRAIC(:,20) - ALGEBRAIC(:,24); ALGEBRAIC(:,25) = CONSTANTS(:,25).*(power(ALGEBRAIC(:,14), -1.00000)./(power(CONSTANTS(:,6), -1.00000)+power(ALGEBRAIC(:,14), -1.00000))); ALGEBRAIC(:,26) = ALGEBRAIC(:,25).*STATES(:,10); ALGEBRAIC(:,27) = CONSTANTS(:,26).*(ALGEBRAIC(:,14)./(CONSTANTS(:,6)+ALGEBRAIC(:,14))); ALGEBRAIC(:,28) = ALGEBRAIC(:,27).*STATES(:,11); RATES(:,11) = ALGEBRAIC(:,26) - ALGEBRAIC(:,28); RATES(:,10) = ALGEBRAIC(:,28) - ALGEBRAIC(:,26); ALGEBRAIC(:,2) = CONSTANTS(:,3).*(STATES(:,2)./(CONSTANTS(:,4)+STATES(:,2))); ALGEBRAIC(:,29) = STATES(:,9)./STATES(:,13); ALGEBRAIC(:,30) = CONSTANTS(:,7).*( CONSTANTS(:,8).*(power(ALGEBRAIC(:,29), -1.00000)./(power(CONSTANTS(:,10), -1.00000)+power(ALGEBRAIC(:,29), -1.00000)))+ (1.00000 - CONSTANTS(:,8)).*(power(ALGEBRAIC(:,5), -1.00000)./(power(CONSTANTS(:,9), -1.00000)+power(ALGEBRAIC(:,5), -1.00000)))); ALGEBRAIC(:,31) = ALGEBRAIC(:,30).*STATES(:,3); ALGEBRAIC(:,21) = CONSTANTS(:,23).*( CONSTANTS(:,24).*(power(ALGEBRAIC(:,5), -1.00000)./(power(CONSTANTS(:,9), -1.00000)+power(ALGEBRAIC(:,5), -1.00000)))+ (1.00000 - CONSTANTS(:,24)).*(ALGEBRAIC(:,14)./(CONSTANTS(:,6)+ALGEBRAIC(:,14)))); ALGEBRAIC(:,23) = ALGEBRAIC(:,21).*STATES(:,9); RATES(:,16) = (ALGEBRAIC(:,1)+ALGEBRAIC(:,20)+ 2.00000.*ALGEBRAIC(:,31)+ 2.00000.*ALGEBRAIC(:,16)+ALGEBRAIC(:,26)+CONSTANTS(:,47)) - ( 3.00000.*ALGEBRAIC(:,18)+ALGEBRAIC(:,23)+ 6.00000.*ALGEBRAIC(:,2)+ALGEBRAIC(:,28)); ALGEBRAIC(:,6) = CONSTANTS(:,19).*(ALGEBRAIC(:,5)./(CONSTANTS(:,9)+ALGEBRAIC(:,5))); ALGEBRAIC(:,7) = ALGEBRAIC(:,6).*STATES(:,7); ALGEBRAIC(:,32) = CONSTANTS(:,20).*( CONSTANTS(:,21).*(power(ALGEBRAIC(:,5), -1.00000)./(power(CONSTANTS(:,9), -1.00000)+power(ALGEBRAIC(:,5), -1.00000)))+ (1.00000 - CONSTANTS(:,21)).*(power(ALGEBRAIC(:,29), -1.00000)./(power(CONSTANTS(:,10), -1.00000)+power(ALGEBRAIC(:,29), -1.00000)))); ALGEBRAIC(:,33) = ALGEBRAIC(:,32).*STATES(:,7); ALGEBRAIC(:,8) = CONSTANTS(:,22).*(power(ALGEBRAIC(:,5), -1.00000)./(power(CONSTANTS(:,9), -1.00000)+power(ALGEBRAIC(:,5), -1.00000))); ALGEBRAIC(:,9) = ALGEBRAIC(:,8).*STATES(:,8); RATES(:,7) = ( 2.00000.*ALGEBRAIC(:,18)+ALGEBRAIC(:,9)) - (ALGEBRAIC(:,7)+ALGEBRAIC(:,33)); RATES(:,9) = (ALGEBRAIC(:,33)+ALGEBRAIC(:,31)) - (ALGEBRAIC(:,23)+ALGEBRAIC(:,13)); RATES(:,13) = (ALGEBRAIC(:,23)+ALGEBRAIC(:,11)+ALGEBRAIC(:,13)) - (ALGEBRAIC(:,33)+ALGEBRAIC(:,31)); RATES(:,15) = (ALGEBRAIC(:,7)+ 2.00000.*ALGEBRAIC(:,2)) - ( 2.00000.*ALGEBRAIC(:,18)+ALGEBRAIC(:,33)+ALGEBRAIC(:,9)+ (11.0000./3.00000).*ALGEBRAIC(:,23)+ (35.0000./3.00000).*ALGEBRAIC(:,31)); ALGEBRAIC(:,34) = piecewise({VOI>0.00000&VOI<5.00000, 1.00000 }, 0.400000); RATES(:,1) = ALGEBRAIC(:,34).*(CONSTANTS(:,34) - CONSTANTS(:,35).*STATES(:,1)) - ALGEBRAIC(:,1); RATES(:,3) = ( 3.00000.*ALGEBRAIC(:,3)+ ALGEBRAIC(:,34).*(CONSTANTS(:,36) - CONSTANTS(:,37).*STATES(:,3))) - (ALGEBRAIC(:,16)+ALGEBRAIC(:,31)); RATES(:,8) = (ALGEBRAIC(:,7)+ ALGEBRAIC(:,34).*(CONSTANTS(:,38) - CONSTANTS(:,39).*STATES(:,8))) - ALGEBRAIC(:,9); RATES(:,2) = ALGEBRAIC(:,34).*(CONSTANTS(:,40) - CONSTANTS(:,41).*STATES(:,2)) - ALGEBRAIC(:,2); RATES(:,14) = ALGEBRAIC(:,33)+ 2.00000.*ALGEBRAIC(:,23)+ ALGEBRAIC(:,34).*(CONSTANTS(:,42) - CONSTANTS(:,43).*STATES(:,14)); 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(:,5) = CONSTANTS(:,44)./STATES(:,15); ALGEBRAIC(:,10) = CONSTANTS(:,27).*( CONSTANTS(:,28).*(power(ALGEBRAIC(:,5), -1.00000)./(power(CONSTANTS(:,9), -1.00000)+power(ALGEBRAIC(:,5), -1.00000)))+ (1.00000 - CONSTANTS(:,28)).*(power(STATES(:,13), -1.00000)./(power(CONSTANTS(:,29), -1.00000)+power(STATES(:,13), -1.00000)))); ALGEBRAIC(:,11) = ALGEBRAIC(:,10).*STATES(:,12); ALGEBRAIC(:,12) = CONSTANTS(:,30).*( CONSTANTS(:,31).*(power(ALGEBRAIC(:,5), -1.00000)./(power(CONSTANTS(:,9), -1.00000)+power(ALGEBRAIC(:,5), -1.00000)))+ (1.00000 - CONSTANTS(:,31)).*(power(STATES(:,13), -1.00000)./(power(CONSTANTS(:,29), -1.00000)+power(STATES(:,13), -1.00000)))); ALGEBRAIC(:,13) = ALGEBRAIC(:,12).*STATES(:,9); ALGEBRAIC(:,14) = STATES(:,16)./CONSTANTS(:,33); ALGEBRAIC(:,15) = CONSTANTS(:,5).*(power(ALGEBRAIC(:,14), -1.00000)./(power(CONSTANTS(:,6), -1.00000)+power(ALGEBRAIC(:,14), -1.00000))); ALGEBRAIC(:,16) = ALGEBRAIC(:,15).*STATES(:,3); ALGEBRAIC(:,3) = CONSTANTS(:,46).*STATES(:,6); ALGEBRAIC(:,1) = CONSTANTS(:,1).*(STATES(:,1)./(CONSTANTS(:,2)+STATES(:,1))); ALGEBRAIC(:,17) = CONSTANTS(:,11).*( CONSTANTS(:,12).*(ALGEBRAIC(:,14)./(CONSTANTS(:,6)+ALGEBRAIC(:,14)))+ (1.00000 - CONSTANTS(:,12)).*(power(ALGEBRAIC(:,5), -1.00000)./(power(CONSTANTS(:,9), -1.00000)+power(ALGEBRAIC(:,5), -1.00000)))); ALGEBRAIC(:,18) = ALGEBRAIC(:,17).*STATES(:,4); ALGEBRAIC(:,4) = STATES(:,10)./STATES(:,11); ALGEBRAIC(:,19) = CONSTANTS(:,13).*( CONSTANTS(:,14).*(power(ALGEBRAIC(:,14), -1.00000)./(power(CONSTANTS(:,6), -1.00000)+power(ALGEBRAIC(:,14), -1.00000)))+ (1.00000 - CONSTANTS(:,14)).*power(power(ALGEBRAIC(:,4), -1.00000)./(power(CONSTANTS(:,15), -1.00000)+power(ALGEBRAIC(:,4), -1.00000)), 2.00000)); ALGEBRAIC(:,20) = ALGEBRAIC(:,19).*STATES(:,4); ALGEBRAIC(:,22) = CONSTANTS(:,16).*( CONSTANTS(:,17).*(ALGEBRAIC(:,14)./(CONSTANTS(:,6)+ALGEBRAIC(:,14)))+ (1.00000 - CONSTANTS(:,17)).*power(ALGEBRAIC(:,4)./(CONSTANTS(:,15)+ALGEBRAIC(:,4)), 2.00000)); ALGEBRAIC(:,24) = ALGEBRAIC(:,22).*STATES(:,5); ALGEBRAIC(:,25) = CONSTANTS(:,25).*(power(ALGEBRAIC(:,14), -1.00000)./(power(CONSTANTS(:,6), -1.00000)+power(ALGEBRAIC(:,14), -1.00000))); ALGEBRAIC(:,26) = ALGEBRAIC(:,25).*STATES(:,10); ALGEBRAIC(:,27) = CONSTANTS(:,26).*(ALGEBRAIC(:,14)./(CONSTANTS(:,6)+ALGEBRAIC(:,14))); ALGEBRAIC(:,28) = ALGEBRAIC(:,27).*STATES(:,11); ALGEBRAIC(:,2) = CONSTANTS(:,3).*(STATES(:,2)./(CONSTANTS(:,4)+STATES(:,2))); ALGEBRAIC(:,29) = STATES(:,9)./STATES(:,13); ALGEBRAIC(:,30) = CONSTANTS(:,7).*( CONSTANTS(:,8).*(power(ALGEBRAIC(:,29), -1.00000)./(power(CONSTANTS(:,10), -1.00000)+power(ALGEBRAIC(:,29), -1.00000)))+ (1.00000 - CONSTANTS(:,8)).*(power(ALGEBRAIC(:,5), -1.00000)./(power(CONSTANTS(:,9), -1.00000)+power(ALGEBRAIC(:,5), -1.00000)))); ALGEBRAIC(:,31) = ALGEBRAIC(:,30).*STATES(:,3); ALGEBRAIC(:,21) = CONSTANTS(:,23).*( CONSTANTS(:,24).*(power(ALGEBRAIC(:,5), -1.00000)./(power(CONSTANTS(:,9), -1.00000)+power(ALGEBRAIC(:,5), -1.00000)))+ (1.00000 - CONSTANTS(:,24)).*(ALGEBRAIC(:,14)./(CONSTANTS(:,6)+ALGEBRAIC(:,14)))); ALGEBRAIC(:,23) = ALGEBRAIC(:,21).*STATES(:,9); ALGEBRAIC(:,6) = CONSTANTS(:,19).*(ALGEBRAIC(:,5)./(CONSTANTS(:,9)+ALGEBRAIC(:,5))); ALGEBRAIC(:,7) = ALGEBRAIC(:,6).*STATES(:,7); ALGEBRAIC(:,32) = CONSTANTS(:,20).*( CONSTANTS(:,21).*(power(ALGEBRAIC(:,5), -1.00000)./(power(CONSTANTS(:,9), -1.00000)+power(ALGEBRAIC(:,5), -1.00000)))+ (1.00000 - CONSTANTS(:,21)).*(power(ALGEBRAIC(:,29), -1.00000)./(power(CONSTANTS(:,10), -1.00000)+power(ALGEBRAIC(:,29), -1.00000)))); ALGEBRAIC(:,33) = ALGEBRAIC(:,32).*STATES(:,7); ALGEBRAIC(:,8) = CONSTANTS(:,22).*(power(ALGEBRAIC(:,5), -1.00000)./(power(CONSTANTS(:,9), -1.00000)+power(ALGEBRAIC(:,5), -1.00000))); ALGEBRAIC(:,9) = ALGEBRAIC(:,8).*STATES(:,8); ALGEBRAIC(:,34) = piecewise({VOI>0.00000&VOI<5.00000, 1.00000 }, 0.400000); 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