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 =35; end % There are a total of 19 entries in each of the rate and state variable arrays. % There are a total of 40 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 (second)'); LEGEND_STATES(:,1) = strpad('q_RB1_inactive in component environment (fmol)'); LEGEND_STATES(:,2) = strpad('q_L_RB1_inactive in component environment (fmol)'); LEGEND_STATES(:,3) = strpad('q_LB1_ode in component environment (fmol)'); LEGEND_ALGEBRAIC(:,1) = strpad('q_LB1_stim in component environment (fmol)'); LEGEND_ALGEBRAIC(:,4) = strpad('q_LB1 in component environment (fmol)'); LEGEND_STATES(:,4) = strpad('q_RB1 in component environment (fmol)'); LEGEND_STATES(:,5) = strpad('q_Gs in component environment (fmol)'); LEGEND_STATES(:,6) = strpad('q_RB1_Gs in component environment (fmol)'); LEGEND_STATES(:,7) = strpad('q_L_RB1 in component environment (fmol)'); LEGEND_STATES(:,8) = strpad('q_L_RB1_Gs in component environment (fmol)'); LEGEND_STATES(:,9) = strpad('q_Gsa_GTP in component environment (fmol)'); LEGEND_STATES(:,10) = strpad('q_Gsbetagamma in component environment (fmol)'); LEGEND_STATES(:,11) = strpad('q_Gsa_GDP in component environment (fmol)'); LEGEND_STATES(:,12) = strpad('q_GTP in component environment (fmol)'); LEGEND_STATES(:,13) = strpad('q_GDP in component environment (fmol)'); LEGEND_STATES(:,14) = strpad('q_Pi in component environment (fmol)'); LEGEND_STATES(:,15) = strpad('q_RB1_tag in component environment (fmol)'); LEGEND_STATES(:,16) = strpad('q_L_RB1_tag in component environment (fmol)'); LEGEND_STATES(:,17) = strpad('q_RB1_GRKArr in component environment (fmol)'); LEGEND_STATES(:,18) = strpad('q_L_RB1_GRKArr in component environment (fmol)'); LEGEND_STATES(:,19) = strpad('q_GRKArr in component environment (fmol)'); LEGEND_CONSTANTS(:,1) = strpad('stimSt in component environment (second)'); LEGEND_CONSTANTS(:,2) = strpad('stimDur in component environment (second)'); LEGEND_CONSTANTS(:,3) = strpad('tR in component environment (second)'); LEGEND_CONSTANTS(:,4) = strpad('stimMag in component environment (fmol)'); LEGEND_CONSTANTS(:,5) = strpad('stimHolding in component environment (fmol)'); LEGEND_CONSTANTS(:,39) = strpad('m in component environment (fmol_per_sec)'); LEGEND_ALGEBRAIC(:,25) = strpad('v_Rswitch_B1 in component GPCR_B1AR_reduced (fmol_per_sec)'); LEGEND_ALGEBRAIC(:,26) = strpad('v_LRswitch_B1 in component GPCR_B1AR_reduced (fmol_per_sec)'); LEGEND_ALGEBRAIC(:,27) = strpad('v_C_B1 in component GPCR_B1AR_reduced (fmol_per_sec)'); LEGEND_ALGEBRAIC(:,28) = strpad('v_R_B1 in component GPCR_B1AR_reduced (fmol_per_sec)'); LEGEND_ALGEBRAIC(:,29) = strpad('v_L_B1 in component GPCR_B1AR_reduced (fmol_per_sec)'); LEGEND_ALGEBRAIC(:,30) = strpad('v_Act1_Gs in component GPCR_B1AR_reduced (fmol_per_sec)'); LEGEND_ALGEBRAIC(:,31) = strpad('v_Act2_Gs in component GPCR_B1AR_reduced (fmol_per_sec)'); LEGEND_ALGEBRAIC(:,32) = strpad('v_Hyd_Gs in component GPCR_B1AR_reduced (fmol_per_sec)'); LEGEND_ALGEBRAIC(:,34) = strpad('v_Reassoc_Gs in component GPCR_B1AR_reduced (fmol_per_sec)'); LEGEND_ALGEBRAIC(:,33) = strpad('v_InternR_B1 in component GPCR_B1AR_reduced (fmol_per_sec)'); LEGEND_ALGEBRAIC(:,35) = strpad('v_InternLR_B1 in component GPCR_B1AR_reduced (fmol_per_sec)'); LEGEND_CONSTANTS(:,40) = strpad('v_Rsynthesis in component environment (fmol_per_sec)'); LEGEND_ALGEBRAIC(:,2) = strpad('conserv_R_T in component environment (fmol)'); LEGEND_ALGEBRAIC(:,6) = strpad('conserv_L_T in component environment (fmol)'); LEGEND_ALGEBRAIC(:,3) = strpad('conserv_G_T in component environment (fmol)'); LEGEND_CONSTANTS(:,6) = strpad('kappa_Rswitch_B1 in component GPCR_B1AR_reduced_parameters (fmol_per_sec)'); LEGEND_CONSTANTS(:,7) = strpad('kappa_LRswitch_B1 in component GPCR_B1AR_reduced_parameters (fmol_per_sec)'); LEGEND_CONSTANTS(:,8) = strpad('kappa_C_B1 in component GPCR_B1AR_reduced_parameters (fmol_per_sec)'); LEGEND_CONSTANTS(:,9) = strpad('kappa_R_B1 in component GPCR_B1AR_reduced_parameters (fmol_per_sec)'); LEGEND_CONSTANTS(:,10) = strpad('kappa_L_B1 in component GPCR_B1AR_reduced_parameters (fmol_per_sec)'); LEGEND_CONSTANTS(:,11) = strpad('kappa_Act1_Gs in component GPCR_B1AR_reduced_parameters (fmol_per_sec)'); LEGEND_CONSTANTS(:,12) = strpad('kappa_Act2_Gs in component GPCR_B1AR_reduced_parameters (fmol_per_sec)'); LEGEND_CONSTANTS(:,13) = strpad('kappa_Hyd_Gs in component GPCR_B1AR_reduced_parameters (fmol_per_sec)'); LEGEND_CONSTANTS(:,14) = strpad('kappa_Reassoc_Gs in component GPCR_B1AR_reduced_parameters (fmol_per_sec)'); LEGEND_CONSTANTS(:,15) = strpad('kappa_InternR_B1 in component GPCR_B1AR_reduced_parameters (fmol_per_sec)'); LEGEND_CONSTANTS(:,16) = strpad('kappa_InternLR_B1 in component GPCR_B1AR_reduced_parameters (fmol_per_sec)'); LEGEND_CONSTANTS(:,17) = strpad('K_RB1_inactive in component GPCR_B1AR_reduced_parameters (per_fmol)'); LEGEND_CONSTANTS(:,18) = strpad('K_L_RB1_inactive in component GPCR_B1AR_reduced_parameters (per_fmol)'); LEGEND_CONSTANTS(:,19) = strpad('K_LB1 in component GPCR_B1AR_reduced_parameters (per_fmol)'); LEGEND_CONSTANTS(:,20) = strpad('K_RB1 in component GPCR_B1AR_reduced_parameters (per_fmol)'); LEGEND_CONSTANTS(:,21) = strpad('K_Gs in component GPCR_B1AR_reduced_parameters (per_fmol)'); LEGEND_CONSTANTS(:,22) = strpad('K_RB1_Gs in component GPCR_B1AR_reduced_parameters (per_fmol)'); LEGEND_CONSTANTS(:,23) = strpad('K_L_RB1 in component GPCR_B1AR_reduced_parameters (per_fmol)'); LEGEND_CONSTANTS(:,24) = strpad('K_L_RB1_Gs in component GPCR_B1AR_reduced_parameters (per_fmol)'); LEGEND_CONSTANTS(:,25) = strpad('K_Gsa_GTP in component GPCR_B1AR_reduced_parameters (per_fmol)'); LEGEND_CONSTANTS(:,26) = strpad('K_Gsbetagamma in component GPCR_B1AR_reduced_parameters (per_fmol)'); LEGEND_CONSTANTS(:,27) = strpad('K_Gsa_GDP in component GPCR_B1AR_reduced_parameters (per_fmol)'); LEGEND_CONSTANTS(:,28) = strpad('K_GTP in component GPCR_B1AR_reduced_parameters (per_fmol)'); LEGEND_CONSTANTS(:,29) = strpad('K_GDP in component GPCR_B1AR_reduced_parameters (per_fmol)'); LEGEND_CONSTANTS(:,30) = strpad('K_Pi in component GPCR_B1AR_reduced_parameters (per_fmol)'); LEGEND_CONSTANTS(:,31) = strpad('K_RB1_tag in component GPCR_B1AR_reduced_parameters (per_fmol)'); LEGEND_CONSTANTS(:,32) = strpad('K_L_RB1_tag in component GPCR_B1AR_reduced_parameters (per_fmol)'); LEGEND_CONSTANTS(:,33) = strpad('K_RB1_GRKArr in component GPCR_B1AR_reduced_parameters (per_fmol)'); LEGEND_CONSTANTS(:,34) = strpad('K_L_RB1_GRKArr in component GPCR_B1AR_reduced_parameters (per_fmol)'); LEGEND_CONSTANTS(:,35) = strpad('K_GRKArr in component GPCR_B1AR_reduced_parameters (per_fmol)'); LEGEND_CONSTANTS(:,36) = strpad('R in component constants (J_per_K_per_mol)'); LEGEND_CONSTANTS(:,37) = strpad('T in component constants (kelvin)'); LEGEND_ALGEBRAIC(:,5) = strpad('mu_RB1_inactive in component GPCR_B1AR_reduced (J_per_mol)'); LEGEND_ALGEBRAIC(:,7) = strpad('mu_L_RB1_inactive in component GPCR_B1AR_reduced (J_per_mol)'); LEGEND_ALGEBRAIC(:,8) = strpad('mu_LB1 in component GPCR_B1AR_reduced (J_per_mol)'); LEGEND_ALGEBRAIC(:,9) = strpad('mu_RB1 in component GPCR_B1AR_reduced (J_per_mol)'); LEGEND_ALGEBRAIC(:,10) = strpad('mu_Gs in component GPCR_B1AR_reduced (J_per_mol)'); LEGEND_ALGEBRAIC(:,11) = strpad('mu_RB1_Gs in component GPCR_B1AR_reduced (J_per_mol)'); LEGEND_ALGEBRAIC(:,12) = strpad('mu_L_RB1 in component GPCR_B1AR_reduced (J_per_mol)'); LEGEND_ALGEBRAIC(:,13) = strpad('mu_L_RB1_Gs in component GPCR_B1AR_reduced (J_per_mol)'); LEGEND_ALGEBRAIC(:,14) = strpad('mu_Gsa_GTP in component GPCR_B1AR_reduced (J_per_mol)'); LEGEND_ALGEBRAIC(:,15) = strpad('mu_Gsbetagamma in component GPCR_B1AR_reduced (J_per_mol)'); LEGEND_ALGEBRAIC(:,16) = strpad('mu_Gsa_GDP in component GPCR_B1AR_reduced (J_per_mol)'); LEGEND_ALGEBRAIC(:,17) = strpad('mu_GTP in component GPCR_B1AR_reduced (J_per_mol)'); LEGEND_ALGEBRAIC(:,18) = strpad('mu_GDP in component GPCR_B1AR_reduced (J_per_mol)'); LEGEND_ALGEBRAIC(:,19) = strpad('mu_Pi in component GPCR_B1AR_reduced (J_per_mol)'); LEGEND_ALGEBRAIC(:,20) = strpad('mu_RB1_tag in component GPCR_B1AR_reduced (J_per_mol)'); LEGEND_ALGEBRAIC(:,21) = strpad('mu_L_RB1_tag in component GPCR_B1AR_reduced (J_per_mol)'); LEGEND_ALGEBRAIC(:,22) = strpad('mu_RB1_GRKArr in component GPCR_B1AR_reduced (J_per_mol)'); LEGEND_ALGEBRAIC(:,23) = strpad('mu_L_RB1_GRKArr in component GPCR_B1AR_reduced (J_per_mol)'); LEGEND_ALGEBRAIC(:,24) = strpad('mu_GRKArr in component GPCR_B1AR_reduced (J_per_mol)'); LEGEND_CONSTANTS(:,38) = strpad('F in component constants (C_per_mol)'); LEGEND_RATES(:,1) = strpad('d/dt q_RB1_inactive in component environment (fmol)'); LEGEND_RATES(:,2) = strpad('d/dt q_L_RB1_inactive in component environment (fmol)'); LEGEND_RATES(:,3) = strpad('d/dt q_LB1_ode in component environment (fmol)'); LEGEND_RATES(:,4) = strpad('d/dt q_RB1 in component environment (fmol)'); LEGEND_RATES(:,5) = strpad('d/dt q_Gs in component environment (fmol)'); LEGEND_RATES(:,6) = strpad('d/dt q_RB1_Gs in component environment (fmol)'); LEGEND_RATES(:,7) = strpad('d/dt q_L_RB1 in component environment (fmol)'); LEGEND_RATES(:,8) = strpad('d/dt q_L_RB1_Gs in component environment (fmol)'); LEGEND_RATES(:,9) = strpad('d/dt q_Gsa_GTP in component environment (fmol)'); LEGEND_RATES(:,10) = strpad('d/dt q_Gsbetagamma in component environment (fmol)'); LEGEND_RATES(:,11) = strpad('d/dt q_Gsa_GDP in component environment (fmol)'); LEGEND_RATES(:,12) = strpad('d/dt q_GTP in component environment (fmol)'); LEGEND_RATES(:,13) = strpad('d/dt q_GDP in component environment (fmol)'); LEGEND_RATES(:,14) = strpad('d/dt q_Pi in component environment (fmol)'); LEGEND_RATES(:,15) = strpad('d/dt q_RB1_tag in component environment (fmol)'); LEGEND_RATES(:,16) = strpad('d/dt q_L_RB1_tag in component environment (fmol)'); LEGEND_RATES(:,17) = strpad('d/dt q_RB1_GRKArr in component environment (fmol)'); LEGEND_RATES(:,18) = strpad('d/dt q_L_RB1_GRKArr in component environment (fmol)'); LEGEND_RATES(:,19) = strpad('d/dt q_GRKArr in component environment (fmol)'); 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.0004579000e0; STATES(:,2) = 1e-18; STATES(:,3) = 0; STATES(:,4) = 1e-18; STATES(:,5) = 0.1455400000; STATES(:,6) = 1e-18; STATES(:,7) = 1e-18; STATES(:,8) = 1e-18; STATES(:,9) = 0.01; STATES(:,10) = 0.02; STATES(:,11) = 0.01; STATES(:,12) = 2.2; STATES(:,13) = 1.1; STATES(:,14) = 570; STATES(:,15) = 1e-18; STATES(:,16) = 1e-18; STATES(:,17) = 1e-18; STATES(:,18) = 1e-18; STATES(:,19) = 1e-3; CONSTANTS(:,1) = 0.5e1; CONSTANTS(:,2) = 5e-1; CONSTANTS(:,3) = 5e-1; CONSTANTS(:,4) = 1e1; CONSTANTS(:,5) = 1e-8; CONSTANTS(:,6) = 1036.38; CONSTANTS(:,7) = 1.83921e-07; CONSTANTS(:,8) = 891573; CONSTANTS(:,9) = 1.58222e+06; CONSTANTS(:,10) = 52417.5; CONSTANTS(:,11) = 0.000610519; CONSTANTS(:,12) = 0.576677; CONSTANTS(:,13) = 0.0661821; CONSTANTS(:,14) = 8.60273e-06; CONSTANTS(:,15) = 0.00230556; CONSTANTS(:,16) = 2.17775; CONSTANTS(:,17) = 28.0492; CONSTANTS(:,18) = 1.58056e+11; CONSTANTS(:,19) = 0.0574759; CONSTANTS(:,20) = 0.280492; CONSTANTS(:,21) = 0.00337913; CONSTANTS(:,22) = 1.07597; CONSTANTS(:,23) = 0.158056; CONSTANTS(:,24) = 0.00113911; CONSTANTS(:,25) = 0.00878478; CONSTANTS(:,26) = 736.699; CONSTANTS(:,27) = 161.34; CONSTANTS(:,28) = 823.314; CONSTANTS(:,29) = 3.61368e-10; CONSTANTS(:,30) = 7.91408e-11; CONSTANTS(:,31) = 0.500146; CONSTANTS(:,32) = 0.000529497; CONSTANTS(:,33) = 1.26086e-05; CONSTANTS(:,34) = 1.33485e-08; CONSTANTS(:,35) = 732843; CONSTANTS(:,36) = 8.31; CONSTANTS(:,37) = 310; CONSTANTS(:,38) = 96485; CONSTANTS(:,39) = CONSTANTS(:,4)./CONSTANTS(:,3); CONSTANTS(:,40) = 0.000100000; 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(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,17).*STATES(:,1)); ALGEBRAIC(:,9) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,20).*STATES(:,4)); ALGEBRAIC(:,25) = CONSTANTS(:,6).*(exp(ALGEBRAIC(:,5)./( CONSTANTS(:,36).*CONSTANTS(:,37))) - exp(ALGEBRAIC(:,9)./( CONSTANTS(:,36).*CONSTANTS(:,37)))); RATES(:,1) = - ALGEBRAIC(:,25)+ 0.00000.*CONSTANTS(:,40); ALGEBRAIC(:,7) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,18).*STATES(:,2)); ALGEBRAIC(:,12) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,23).*STATES(:,7)); ALGEBRAIC(:,26) = CONSTANTS(:,7).*(exp(ALGEBRAIC(:,7)./( CONSTANTS(:,36).*CONSTANTS(:,37))) - exp(ALGEBRAIC(:,12)./( CONSTANTS(:,36).*CONSTANTS(:,37)))); RATES(:,2) = - ALGEBRAIC(:,26); ALGEBRAIC(:,1) = piecewise({VOI<CONSTANTS(:,1)&VOI>CONSTANTS(:,1) - CONSTANTS(:,3), CONSTANTS(:,5)+ CONSTANTS(:,39).*((VOI - CONSTANTS(:,1))+CONSTANTS(:,3)) , VOI>=CONSTANTS(:,1)&VOI<CONSTANTS(:,1)+CONSTANTS(:,2), CONSTANTS(:,4)+CONSTANTS(:,5) , VOI<=CONSTANTS(:,1)+CONSTANTS(:,3)+CONSTANTS(:,2)&VOI>=CONSTANTS(:,1)+CONSTANTS(:,2), CONSTANTS(:,5)+ - CONSTANTS(:,39).*(((VOI - CONSTANTS(:,1)) - CONSTANTS(:,3)) - CONSTANTS(:,2)) }, CONSTANTS(:,5)); ALGEBRAIC(:,4) = ALGEBRAIC(:,1)+STATES(:,3); ALGEBRAIC(:,8) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,19).*ALGEBRAIC(:,4)); ALGEBRAIC(:,29) = CONSTANTS(:,10).*(exp((ALGEBRAIC(:,9)+ALGEBRAIC(:,8))./( CONSTANTS(:,36).*CONSTANTS(:,37))) - exp(ALGEBRAIC(:,12)./( CONSTANTS(:,36).*CONSTANTS(:,37)))); RATES(:,3) = - ALGEBRAIC(:,29); ALGEBRAIC(:,10) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,21).*STATES(:,5)); ALGEBRAIC(:,11) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,22).*STATES(:,6)); ALGEBRAIC(:,27) = CONSTANTS(:,8).*(exp((ALGEBRAIC(:,9)+ALGEBRAIC(:,10))./( CONSTANTS(:,36).*CONSTANTS(:,37))) - exp(ALGEBRAIC(:,11)./( CONSTANTS(:,36).*CONSTANTS(:,37)))); RATES(:,4) = (ALGEBRAIC(:,25) - ALGEBRAIC(:,27)) - ALGEBRAIC(:,29); ALGEBRAIC(:,14) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,25).*STATES(:,9)); ALGEBRAIC(:,15) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,26).*STATES(:,10)); ALGEBRAIC(:,17) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,28).*STATES(:,12)); ALGEBRAIC(:,18) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,29).*STATES(:,13)); ALGEBRAIC(:,20) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,31).*STATES(:,15)); ALGEBRAIC(:,30) = CONSTANTS(:,11).*(exp((ALGEBRAIC(:,11)+ALGEBRAIC(:,17))./( CONSTANTS(:,36).*CONSTANTS(:,37))) - exp((ALGEBRAIC(:,14)+ALGEBRAIC(:,15)+ALGEBRAIC(:,20)+ALGEBRAIC(:,18))./( CONSTANTS(:,36).*CONSTANTS(:,37)))); RATES(:,6) = ALGEBRAIC(:,27) - ALGEBRAIC(:,30); ALGEBRAIC(:,13) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,24).*STATES(:,8)); ALGEBRAIC(:,28) = CONSTANTS(:,9).*(exp((ALGEBRAIC(:,12)+ALGEBRAIC(:,10))./( CONSTANTS(:,36).*CONSTANTS(:,37))) - exp(ALGEBRAIC(:,13)./( CONSTANTS(:,36).*CONSTANTS(:,37)))); RATES(:,7) = (ALGEBRAIC(:,26) - ALGEBRAIC(:,28))+ALGEBRAIC(:,29); ALGEBRAIC(:,21) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,32).*STATES(:,16)); ALGEBRAIC(:,31) = CONSTANTS(:,12).*(exp((ALGEBRAIC(:,13)+ALGEBRAIC(:,17))./( CONSTANTS(:,36).*CONSTANTS(:,37))) - exp((ALGEBRAIC(:,14)+ALGEBRAIC(:,15)+ALGEBRAIC(:,21)+ALGEBRAIC(:,18))./( CONSTANTS(:,36).*CONSTANTS(:,37)))); RATES(:,8) = ALGEBRAIC(:,28) - ALGEBRAIC(:,31); RATES(:,12) = - ALGEBRAIC(:,30) - ALGEBRAIC(:,31); RATES(:,13) = ALGEBRAIC(:,30)+ALGEBRAIC(:,31); ALGEBRAIC(:,16) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,27).*STATES(:,11)); ALGEBRAIC(:,19) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,30).*STATES(:,14)); ALGEBRAIC(:,32) = CONSTANTS(:,13).*(exp(ALGEBRAIC(:,14)./( CONSTANTS(:,36).*CONSTANTS(:,37))) - exp((ALGEBRAIC(:,16)+ALGEBRAIC(:,19))./( CONSTANTS(:,36).*CONSTANTS(:,37)))); RATES(:,9) = (ALGEBRAIC(:,30)+ALGEBRAIC(:,31)) - ALGEBRAIC(:,32); RATES(:,14) = ALGEBRAIC(:,32); ALGEBRAIC(:,22) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,33).*STATES(:,17)); ALGEBRAIC(:,24) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,35).*STATES(:,19)); ALGEBRAIC(:,33) = CONSTANTS(:,15).*(exp((ALGEBRAIC(:,20)+ALGEBRAIC(:,24))./( CONSTANTS(:,36).*CONSTANTS(:,37))) - exp(ALGEBRAIC(:,22)./( CONSTANTS(:,36).*CONSTANTS(:,37)))); RATES(:,15) = ALGEBRAIC(:,30) - ALGEBRAIC(:,33); RATES(:,17) = ALGEBRAIC(:,33); ALGEBRAIC(:,34) = CONSTANTS(:,14).*(exp((ALGEBRAIC(:,16)+ALGEBRAIC(:,15))./( CONSTANTS(:,36).*CONSTANTS(:,37))) - exp(ALGEBRAIC(:,10)./( CONSTANTS(:,36).*CONSTANTS(:,37)))); RATES(:,5) = ( - ALGEBRAIC(:,27) - ALGEBRAIC(:,28))+ALGEBRAIC(:,34); RATES(:,10) = (ALGEBRAIC(:,30)+ALGEBRAIC(:,31)) - ALGEBRAIC(:,34); RATES(:,11) = ALGEBRAIC(:,32) - ALGEBRAIC(:,34); ALGEBRAIC(:,23) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,34).*STATES(:,18)); ALGEBRAIC(:,35) = CONSTANTS(:,16).*(exp((ALGEBRAIC(:,21)+ALGEBRAIC(:,24))./( CONSTANTS(:,36).*CONSTANTS(:,37))) - exp(ALGEBRAIC(:,23)./( CONSTANTS(:,36).*CONSTANTS(:,37)))); RATES(:,16) = ALGEBRAIC(:,31) - ALGEBRAIC(:,35); RATES(:,18) = ALGEBRAIC(:,35); RATES(:,19) = - ALGEBRAIC(:,33) - ALGEBRAIC(:,35); 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(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,17).*STATES(:,1)); ALGEBRAIC(:,9) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,20).*STATES(:,4)); ALGEBRAIC(:,25) = CONSTANTS(:,6).*(exp(ALGEBRAIC(:,5)./( CONSTANTS(:,36).*CONSTANTS(:,37))) - exp(ALGEBRAIC(:,9)./( CONSTANTS(:,36).*CONSTANTS(:,37)))); ALGEBRAIC(:,7) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,18).*STATES(:,2)); ALGEBRAIC(:,12) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,23).*STATES(:,7)); ALGEBRAIC(:,26) = CONSTANTS(:,7).*(exp(ALGEBRAIC(:,7)./( CONSTANTS(:,36).*CONSTANTS(:,37))) - exp(ALGEBRAIC(:,12)./( CONSTANTS(:,36).*CONSTANTS(:,37)))); ALGEBRAIC(:,1) = piecewise({VOI<CONSTANTS(:,1)&VOI>CONSTANTS(:,1) - CONSTANTS(:,3), CONSTANTS(:,5)+ CONSTANTS(:,39).*((VOI - CONSTANTS(:,1))+CONSTANTS(:,3)) , VOI>=CONSTANTS(:,1)&VOI<CONSTANTS(:,1)+CONSTANTS(:,2), CONSTANTS(:,4)+CONSTANTS(:,5) , VOI<=CONSTANTS(:,1)+CONSTANTS(:,3)+CONSTANTS(:,2)&VOI>=CONSTANTS(:,1)+CONSTANTS(:,2), CONSTANTS(:,5)+ - CONSTANTS(:,39).*(((VOI - CONSTANTS(:,1)) - CONSTANTS(:,3)) - CONSTANTS(:,2)) }, CONSTANTS(:,5)); ALGEBRAIC(:,4) = ALGEBRAIC(:,1)+STATES(:,3); ALGEBRAIC(:,8) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,19).*ALGEBRAIC(:,4)); ALGEBRAIC(:,29) = CONSTANTS(:,10).*(exp((ALGEBRAIC(:,9)+ALGEBRAIC(:,8))./( CONSTANTS(:,36).*CONSTANTS(:,37))) - exp(ALGEBRAIC(:,12)./( CONSTANTS(:,36).*CONSTANTS(:,37)))); ALGEBRAIC(:,10) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,21).*STATES(:,5)); ALGEBRAIC(:,11) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,22).*STATES(:,6)); ALGEBRAIC(:,27) = CONSTANTS(:,8).*(exp((ALGEBRAIC(:,9)+ALGEBRAIC(:,10))./( CONSTANTS(:,36).*CONSTANTS(:,37))) - exp(ALGEBRAIC(:,11)./( CONSTANTS(:,36).*CONSTANTS(:,37)))); ALGEBRAIC(:,14) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,25).*STATES(:,9)); ALGEBRAIC(:,15) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,26).*STATES(:,10)); ALGEBRAIC(:,17) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,28).*STATES(:,12)); ALGEBRAIC(:,18) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,29).*STATES(:,13)); ALGEBRAIC(:,20) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,31).*STATES(:,15)); ALGEBRAIC(:,30) = CONSTANTS(:,11).*(exp((ALGEBRAIC(:,11)+ALGEBRAIC(:,17))./( CONSTANTS(:,36).*CONSTANTS(:,37))) - exp((ALGEBRAIC(:,14)+ALGEBRAIC(:,15)+ALGEBRAIC(:,20)+ALGEBRAIC(:,18))./( CONSTANTS(:,36).*CONSTANTS(:,37)))); ALGEBRAIC(:,13) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,24).*STATES(:,8)); ALGEBRAIC(:,28) = CONSTANTS(:,9).*(exp((ALGEBRAIC(:,12)+ALGEBRAIC(:,10))./( CONSTANTS(:,36).*CONSTANTS(:,37))) - exp(ALGEBRAIC(:,13)./( CONSTANTS(:,36).*CONSTANTS(:,37)))); ALGEBRAIC(:,21) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,32).*STATES(:,16)); ALGEBRAIC(:,31) = CONSTANTS(:,12).*(exp((ALGEBRAIC(:,13)+ALGEBRAIC(:,17))./( CONSTANTS(:,36).*CONSTANTS(:,37))) - exp((ALGEBRAIC(:,14)+ALGEBRAIC(:,15)+ALGEBRAIC(:,21)+ALGEBRAIC(:,18))./( CONSTANTS(:,36).*CONSTANTS(:,37)))); ALGEBRAIC(:,16) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,27).*STATES(:,11)); ALGEBRAIC(:,19) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,30).*STATES(:,14)); ALGEBRAIC(:,32) = CONSTANTS(:,13).*(exp(ALGEBRAIC(:,14)./( CONSTANTS(:,36).*CONSTANTS(:,37))) - exp((ALGEBRAIC(:,16)+ALGEBRAIC(:,19))./( CONSTANTS(:,36).*CONSTANTS(:,37)))); ALGEBRAIC(:,22) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,33).*STATES(:,17)); ALGEBRAIC(:,24) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,35).*STATES(:,19)); ALGEBRAIC(:,33) = CONSTANTS(:,15).*(exp((ALGEBRAIC(:,20)+ALGEBRAIC(:,24))./( CONSTANTS(:,36).*CONSTANTS(:,37))) - exp(ALGEBRAIC(:,22)./( CONSTANTS(:,36).*CONSTANTS(:,37)))); ALGEBRAIC(:,34) = CONSTANTS(:,14).*(exp((ALGEBRAIC(:,16)+ALGEBRAIC(:,15))./( CONSTANTS(:,36).*CONSTANTS(:,37))) - exp(ALGEBRAIC(:,10)./( CONSTANTS(:,36).*CONSTANTS(:,37)))); ALGEBRAIC(:,23) = CONSTANTS(:,36).*CONSTANTS(:,37).*log( CONSTANTS(:,34).*STATES(:,18)); ALGEBRAIC(:,35) = CONSTANTS(:,16).*(exp((ALGEBRAIC(:,21)+ALGEBRAIC(:,24))./( CONSTANTS(:,36).*CONSTANTS(:,37))) - exp(ALGEBRAIC(:,23)./( CONSTANTS(:,36).*CONSTANTS(:,37)))); ALGEBRAIC(:,2) = STATES(:,1)+STATES(:,2)+STATES(:,4)+STATES(:,6)+STATES(:,7)+STATES(:,8)+STATES(:,15)+STATES(:,16)+STATES(:,17)+STATES(:,18); ALGEBRAIC(:,3) = STATES(:,5)+STATES(:,6)+STATES(:,8)+STATES(:,9)+STATES(:,11); ALGEBRAIC(:,6) = STATES(:,2)+ALGEBRAIC(:,4)+STATES(:,7)+STATES(:,8)+STATES(:,16)+STATES(:,18); 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