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 9 entries in each of the rate and state variable arrays. % There are a total of 49 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_CONSTANTS(:,45) = strpad('E_Na in component reversal_potentials (millivolt)'); LEGEND_ALGEBRAIC(:,25) = strpad('E_Ca in component reversal_potentials (millivolt)'); LEGEND_CONSTANTS(:,46) = strpad('E_K in component reversal_potentials (millivolt)'); LEGEND_CONSTANTS(:,47) = strpad('E_Cl in component reversal_potentials (millivolt)'); LEGEND_CONSTANTS(:,1) = strpad('R in component model_parameters (millijoule_per_mole_kelvin)'); LEGEND_CONSTANTS(:,2) = strpad('T in component model_parameters (kelvin)'); LEGEND_CONSTANTS(:,3) = strpad('F in component model_parameters (coulomb_per_mole)'); LEGEND_CONSTANTS(:,4) = strpad('Nai in component model_parameters (millimolar)'); LEGEND_CONSTANTS(:,5) = strpad('Nao in component model_parameters (millimolar)'); LEGEND_ALGEBRAIC(:,23) = strpad('Cai in component model_parameters (millimolar)'); LEGEND_CONSTANTS(:,6) = strpad('Cao in component model_parameters (millimolar)'); LEGEND_CONSTANTS(:,7) = strpad('Ki in component model_parameters (millimolar)'); LEGEND_CONSTANTS(:,8) = strpad('Ko in component model_parameters (millimolar)'); LEGEND_CONSTANTS(:,9) = strpad('Cli in component model_parameters (millimolar)'); LEGEND_CONSTANTS(:,10) = strpad('Clo in component model_parameters (millimolar)'); LEGEND_ALGEBRAIC(:,1) = strpad('i_Kdr in component delayed_rectifier_K_current (nanoA)'); LEGEND_CONSTANTS(:,11) = strpad('g_Kdr in component delayed_rectifier_K_current (microS)'); LEGEND_CONSTANTS(:,12) = strpad('gamma_KSS in component delayed_rectifier_K_current (dimensionless)'); LEGEND_STATES(:,1) = strpad('V in component membrane (millivolt)'); LEGEND_STATES(:,2) = strpad('xa in component delayed_rectifier_K_current_xa_gate (dimensionless)'); LEGEND_STATES(:,3) = strpad('xi1 in component delayed_rectifier_K_current_xi1_gate (dimensionless)'); LEGEND_STATES(:,4) = strpad('xi2 in component delayed_rectifier_K_current_xi2_gate (dimensionless)'); LEGEND_ALGEBRAIC(:,2) = strpad('xa_infinity in component delayed_rectifier_K_current_xa_gate (dimensionless)'); LEGEND_ALGEBRAIC(:,9) = strpad('tau_xa in component delayed_rectifier_K_current_xa_gate (second)'); LEGEND_ALGEBRAIC(:,3) = strpad('xi1_infinity in component delayed_rectifier_K_current_xi1_gate (dimensionless)'); LEGEND_CONSTANTS(:,13) = strpad('tau_xi1 in component delayed_rectifier_K_current_xi1_gate (second)'); LEGEND_ALGEBRAIC(:,4) = strpad('xi2_infinity in component delayed_rectifier_K_current_xi2_gate (dimensionless)'); LEGEND_CONSTANTS(:,14) = strpad('tau_xi2 in component delayed_rectifier_K_current_xi2_gate (second)'); LEGEND_ALGEBRAIC(:,27) = strpad('i_CaL in component L_type_Ca_current (nanoA)'); LEGEND_CONSTANTS(:,15) = strpad('P_CaL in component L_type_Ca_current (nanoA_per_millimolar)'); LEGEND_CONSTANTS(:,16) = strpad('V_surf in component L_type_Ca_current (millivolt)'); LEGEND_ALGEBRAIC(:,8) = strpad('ICaL_perm1 in component L_type_Ca_current (dimensionless)'); LEGEND_ALGEBRAIC(:,26) = strpad('ICaL_perm2 in component L_type_Ca_current (millimolar)'); LEGEND_STATES(:,5) = strpad('d in component L_type_Ca_current_d_gate (dimensionless)'); LEGEND_STATES(:,6) = strpad('f in component L_type_Ca_current_f_gate (dimensionless)'); LEGEND_ALGEBRAIC(:,5) = strpad('alpha_d in component L_type_Ca_current_d_gate (per_second)'); LEGEND_ALGEBRAIC(:,10) = strpad('beta_d in component L_type_Ca_current_d_gate (per_second)'); LEGEND_CONSTANTS(:,17) = strpad('tau_f in component L_type_Ca_current_f_gate (second)'); LEGEND_ALGEBRAIC(:,6) = strpad('f_infinity in component L_type_Ca_current_f_gate (dimensionless)'); LEGEND_ALGEBRAIC(:,12) = strpad('i_KCa in component Ca_activated_K_current (nanoA)'); LEGEND_CONSTANTS(:,18) = strpad('g_KCa in component Ca_activated_K_current (microS)'); LEGEND_STATES(:,7) = strpad('xCa1 in component Ca_activated_K_current_xCa1_gate (dimensionless)'); LEGEND_STATES(:,8) = strpad('B in component Ca_activated_K_current_B_gate (dimensionless)'); LEGEND_ALGEBRAIC(:,24) = strpad('xCa1_infinity in component Ca_activated_K_current_xCa1_gate (dimensionless)'); LEGEND_CONSTANTS(:,19) = strpad('tau_xCa1 in component Ca_activated_K_current_xCa1_gate (second)'); LEGEND_ALGEBRAIC(:,14) = strpad('K2 in component Ca_activated_K_current_xCa1_gate (millimolar)'); LEGEND_ALGEBRAIC(:,13) = strpad('K4 in component Ca_activated_K_current_xCa1_gate (millimolar)'); LEGEND_CONSTANTS(:,20) = strpad('alpha in component Ca_activated_K_current_xCa1_gate (per_second)'); LEGEND_CONSTANTS(:,21) = strpad('beta in component Ca_activated_K_current_xCa1_gate (per_second)'); LEGEND_ALGEBRAIC(:,15) = strpad('K1 in component Ca_activated_K_current_B_gate (per_millimolar_per_second)'); LEGEND_ALGEBRAIC(:,16) = strpad('K_1 in component Ca_activated_K_current_B_gate (per_second)'); LEGEND_ALGEBRAIC(:,28) = strpad('i_ClCa in component Ca_activated_Cl_current (nanoA)'); LEGEND_CONSTANTS(:,22) = strpad('g_Cl in component Ca_activated_Cl_current (microS)'); LEGEND_CONSTANTS(:,23) = strpad('CaCT in component Ca_activated_Cl_current (millimolar)'); LEGEND_CONSTANTS(:,24) = strpad('h in component Ca_activated_Cl_current (dimensionless)'); LEGEND_ALGEBRAIC(:,33) = strpad('i_cationic in component nonspecific_cationic_current (nanoA)'); LEGEND_ALGEBRAIC(:,30) = strpad('i_nsNa in component nonspecific_cationic_current (nanoA)'); LEGEND_ALGEBRAIC(:,31) = strpad('i_nsK in component nonspecific_cationic_current (nanoA)'); LEGEND_ALGEBRAIC(:,32) = strpad('i_nsCa in component nonspecific_cationic_current (nanoA)'); LEGEND_CONSTANTS(:,25) = strpad('P_nsCa in component nonspecific_cationic_current (nanoA_per_millimolar_mole_per_C)'); LEGEND_ALGEBRAIC(:,29) = strpad('alpha_Ca in component nonspecific_cationic_current (dimensionless)'); LEGEND_CONSTANTS(:,26) = strpad('Km_nsCa in component nonspecific_cationic_current (millimolar)'); LEGEND_STATES(:,9) = strpad('ns in component nonspecific_cationic_current_ns_gate (dimensionless)'); LEGEND_ALGEBRAIC(:,11) = strpad('tau_ns in component nonspecific_cationic_current_ns_gate (second)'); LEGEND_ALGEBRAIC(:,7) = strpad('ns_infinity in component nonspecific_cationic_current_ns_gate (dimensionless)'); LEGEND_ALGEBRAIC(:,34) = strpad('i_pCa in component Ca_pump_current (nanoA)'); LEGEND_CONSTANTS(:,27) = strpad('i_pCamax in component Ca_pump_current (nanoA)'); LEGEND_CONSTANTS(:,28) = strpad('Kmp_Ca in component Ca_pump_current (millimolar)'); LEGEND_CONSTANTS(:,48) = strpad('i_NaK in component Na_K_pump_current (nanoA)'); LEGEND_CONSTANTS(:,29) = strpad('i_NaKmax in component Na_K_pump_current (nanoA)'); LEGEND_CONSTANTS(:,30) = strpad('Km_Na in component Na_K_pump_current (millimolar)'); LEGEND_CONSTANTS(:,31) = strpad('Km_K in component Na_K_pump_current (millimolar)'); LEGEND_ALGEBRAIC(:,35) = strpad('i_bCa in component Ca_background_current (nanoA)'); LEGEND_CONSTANTS(:,32) = strpad('g_bCa in component Ca_background_current (microS)'); LEGEND_ALGEBRAIC(:,17) = strpad('i_bK in component K_background_current (nanoA)'); LEGEND_CONSTANTS(:,33) = strpad('g_bK in component K_background_current (microS)'); LEGEND_ALGEBRAIC(:,18) = strpad('i_bNa in component Na_background_current (nanoA)'); LEGEND_CONSTANTS(:,34) = strpad('g_bNa in component Na_background_current (microS)'); LEGEND_CONSTANTS(:,35) = strpad('cap in component membrane (microF)'); LEGEND_ALGEBRAIC(:,20) = strpad('upeak in component model_parameters (millimolar)'); LEGEND_ALGEBRAIC(:,19) = strpad('up in component model_parameters (millimolar)'); LEGEND_ALGEBRAIC(:,21) = strpad('peak in component model_parameters (millimolar)'); LEGEND_ALGEBRAIC(:,22) = strpad('plat in component model_parameters (millimolar)'); LEGEND_CONSTANTS(:,36) = strpad('A in component model_parameters (millimolar)'); LEGEND_CONSTANTS(:,37) = strpad('B in component model_parameters (millimolar)'); LEGEND_CONSTANTS(:,38) = strpad('C in component model_parameters (millimolar)'); LEGEND_CONSTANTS(:,49) = strpad('x0 in component model_parameters (second)'); LEGEND_CONSTANTS(:,39) = strpad('x1 in component model_parameters (second)'); LEGEND_CONSTANTS(:,40) = strpad('x2 in component model_parameters (second)'); LEGEND_CONSTANTS(:,41) = strpad('ds in component model_parameters (second)'); LEGEND_CONSTANTS(:,42) = strpad('p in component model_parameters (second)'); LEGEND_CONSTANTS(:,43) = strpad('n in component model_parameters (second)'); LEGEND_CONSTANTS(:,44) = strpad('t36 in component model_parameters (second)'); LEGEND_RATES(:,2) = strpad('d/dt xa in component delayed_rectifier_K_current_xa_gate (dimensionless)'); LEGEND_RATES(:,3) = strpad('d/dt xi1 in component delayed_rectifier_K_current_xi1_gate (dimensionless)'); LEGEND_RATES(:,4) = strpad('d/dt xi2 in component delayed_rectifier_K_current_xi2_gate (dimensionless)'); LEGEND_RATES(:,5) = strpad('d/dt d in component L_type_Ca_current_d_gate (dimensionless)'); LEGEND_RATES(:,6) = strpad('d/dt f in component L_type_Ca_current_f_gate (dimensionless)'); LEGEND_RATES(:,7) = strpad('d/dt xCa1 in component Ca_activated_K_current_xCa1_gate (dimensionless)'); LEGEND_RATES(:,8) = strpad('d/dt B in component Ca_activated_K_current_B_gate (dimensionless)'); LEGEND_RATES(:,9) = strpad('d/dt ns in component nonspecific_cationic_current_ns_gate (dimensionless)'); LEGEND_RATES(:,1) = strpad('d/dt V in component membrane (millivolt)'); 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) = 8314.472; CONSTANTS(:,2) = 310; CONSTANTS(:,3) = 96485.3415; CONSTANTS(:,4) = 12; CONSTANTS(:,5) = 130; CONSTANTS(:,6) = 2; CONSTANTS(:,7) = 150; CONSTANTS(:,8) = 5; CONSTANTS(:,9) = 55; CONSTANTS(:,10) = 140; CONSTANTS(:,11) = 0.035; CONSTANTS(:,12) = 0.15; STATES(:,1) = -60; STATES(:,2) = 0.001; STATES(:,3) = 0; STATES(:,4) = 0; CONSTANTS(:,13) = 0.25; CONSTANTS(:,14) = 1.98; CONSTANTS(:,15) = 0.003; CONSTANTS(:,16) = 150; STATES(:,5) = 0; STATES(:,6) = 1; CONSTANTS(:,17) = 0.0173; CONSTANTS(:,18) = 2.45; STATES(:,7) = 1; STATES(:,8) = 0.001; CONSTANTS(:,19) = 1; CONSTANTS(:,20) = 280; CONSTANTS(:,21) = 480; CONSTANTS(:,22) = 0.01; CONSTANTS(:,23) = 0.0005; CONSTANTS(:,24) = 3; CONSTANTS(:,25) = 0.000000175; CONSTANTS(:,26) = 0.0012; STATES(:,9) = 1; CONSTANTS(:,27) = 1.15; CONSTANTS(:,28) = 0.05; CONSTANTS(:,29) = 0.7; CONSTANTS(:,30) = 40; CONSTANTS(:,31) = 1; CONSTANTS(:,32) = 1.194e-5; CONSTANTS(:,33) = 0.008729; CONSTANTS(:,34) = 0.003263; CONSTANTS(:,35) = 0.00002; CONSTANTS(:,36) = 0.0008; CONSTANTS(:,37) = 0.00008; CONSTANTS(:,38) = 0.00012; CONSTANTS(:,39) = 15; CONSTANTS(:,40) = 0.8; CONSTANTS(:,41) = 30; CONSTANTS(:,42) = 0.4; CONSTANTS(:,43) = 0.2; CONSTANTS(:,44) = 1.5; CONSTANTS(:,45) = (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,5)./CONSTANTS(:,4)); CONSTANTS(:,46) = (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,8)./CONSTANTS(:,7)); CONSTANTS(:,47) = (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,9)./CONSTANTS(:,10)); CONSTANTS(:,48) = ( (( CONSTANTS(:,29).*CONSTANTS(:,8))./(CONSTANTS(:,8)+CONSTANTS(:,31))).*CONSTANTS(:,4))./(CONSTANTS(:,4)+CONSTANTS(:,30)); CONSTANTS(:,49) = CONSTANTS(:,39)+CONSTANTS(:,40); 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(:,3) = 1.00000./(1.00000+exp((STATES(:,1)+4.30000)./7.50000)); RATES(:,3) = (ALGEBRAIC(:,3) - STATES(:,3))./CONSTANTS(:,13); ALGEBRAIC(:,4) = 1.00000./(1.00000+exp((STATES(:,1)+4.30000)./7.50000)); RATES(:,4) = (ALGEBRAIC(:,4) - STATES(:,4))./CONSTANTS(:,14); ALGEBRAIC(:,6) = 1.00000./(1.00000+exp((23.0000+STATES(:,1))./6.60000)); RATES(:,6) = (ALGEBRAIC(:,6) - STATES(:,6))./CONSTANTS(:,17); ALGEBRAIC(:,2) = 1.00000./(1.00000+exp((5.50000 - STATES(:,1))./6.00000)); ALGEBRAIC(:,9) = 0.00326200 - 3.55200e-05.*STATES(:,1); RATES(:,2) = (ALGEBRAIC(:,2) - STATES(:,2))./ALGEBRAIC(:,9); ALGEBRAIC(:,5) = ( 30.0000.*(STATES(:,1)+18.0000))./(1.00000 - exp( - 0.250000.*(STATES(:,1)+18.0000))); ALGEBRAIC(:,10) = ( 12.0000.*(STATES(:,1)+18.0000))./(exp( 0.100000.*(STATES(:,1)+18.0000)) - 1.00000); RATES(:,5) = ALGEBRAIC(:,5) - (ALGEBRAIC(:,5)+ALGEBRAIC(:,10)).*STATES(:,5); ALGEBRAIC(:,11) = 0.200250 - 0.000898750.*STATES(:,1); ALGEBRAIC(:,7) = 1.00000./(1.00000+exp((STATES(:,1) - 69.8000)./ - 11.9000)); RATES(:,9) = (ALGEBRAIC(:,7) - STATES(:,9))./ALGEBRAIC(:,11); ALGEBRAIC(:,19) = piecewise({VOI<CONSTANTS(:,39), 0.00000 }, ( (VOI - CONSTANTS(:,39)).*CONSTANTS(:,36))./CONSTANTS(:,40)); ALGEBRAIC(:,20) = piecewise({VOI<CONSTANTS(:,39)+CONSTANTS(:,40), ALGEBRAIC(:,19) }, 0.00000); ALGEBRAIC(:,21) = piecewise({VOI<CONSTANTS(:,49), 0.00000 }, CONSTANTS(:,36).*exp( - (VOI - CONSTANTS(:,49))./CONSTANTS(:,44))); ALGEBRAIC(:,22) = CONSTANTS(:,37)./(1.00000+exp((VOI - (CONSTANTS(:,39)+CONSTANTS(:,42)+CONSTANTS(:,41)))./CONSTANTS(:,43))) - CONSTANTS(:,37)./(1.00000+exp((VOI - (CONSTANTS(:,39)+CONSTANTS(:,42)))./CONSTANTS(:,43))); ALGEBRAIC(:,23) = CONSTANTS(:,38)+ALGEBRAIC(:,20)+ALGEBRAIC(:,21)+ALGEBRAIC(:,22); ALGEBRAIC(:,15) = 0.850000.*exp( 0.0400000.*STATES(:,1)); ALGEBRAIC(:,16) = 0.240000.*exp( - 0.0120000.*STATES(:,1)); RATES(:,8) = piecewise({ALGEBRAIC(:,23)>=0.100000, ALGEBRAIC(:,15).*ALGEBRAIC(:,23).*STATES(:,7) - ALGEBRAIC(:,16).*STATES(:,8) }, 1.00000); ALGEBRAIC(:,14) = 0.000275000.*exp(( - 1.51000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))); ALGEBRAIC(:,13) = 1.25000e-05.*exp(( - 1.99000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))); ALGEBRAIC(:,24) = (power(ALGEBRAIC(:,23), 2.00000)+ ALGEBRAIC(:,13).*ALGEBRAIC(:,23))./(power(ALGEBRAIC(:,23), 2.00000)+ ALGEBRAIC(:,13).*ALGEBRAIC(:,23).*(1.00000+CONSTANTS(:,20)./CONSTANTS(:,21))+( ALGEBRAIC(:,13).*ALGEBRAIC(:,14).*CONSTANTS(:,20))./CONSTANTS(:,21)); RATES(:,7) = (ALGEBRAIC(:,24) - STATES(:,7))./CONSTANTS(:,19); ALGEBRAIC(:,1) = CONSTANTS(:,11).*(CONSTANTS(:,12)+ (STATES(:,3)+STATES(:,4)).*(1.00000 - CONSTANTS(:,12))).*power(STATES(:,2), 2.00000).*(STATES(:,1) - CONSTANTS(:,46)); ALGEBRAIC(:,8) = ( (STATES(:,1) - CONSTANTS(:,16)).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2).*(1.00000 - exp(( - (STATES(:,1) - CONSTANTS(:,16)).*2.00000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))))); ALGEBRAIC(:,26) = ALGEBRAIC(:,8).*( ALGEBRAIC(:,23).*exp(CONSTANTS(:,16)./(( 0.500000.*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3))) - CONSTANTS(:,6).*exp( - (STATES(:,1) - CONSTANTS(:,16))./(( 0.500000.*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)))); ALGEBRAIC(:,27) = 4.00000.*CONSTANTS(:,15).*STATES(:,5).*STATES(:,6).*ALGEBRAIC(:,26); ALGEBRAIC(:,12) = CONSTANTS(:,18).*STATES(:,7).*STATES(:,8).*(STATES(:,1) - CONSTANTS(:,46)); ALGEBRAIC(:,28) = ( CONSTANTS(:,22).*(STATES(:,1) - CONSTANTS(:,47)).*1.00000)./(1.00000+power(CONSTANTS(:,23)./ALGEBRAIC(:,23), CONSTANTS(:,24))); ALGEBRAIC(:,29) = 1.00000./(1.00000+power(CONSTANTS(:,26)./ALGEBRAIC(:,23), 3.00000)); ALGEBRAIC(:,30) = ( (( STATES(:,9).*ALGEBRAIC(:,29).*CONSTANTS(:,25).*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( 0.750000.*CONSTANTS(:,4).*exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 0.750000.*CONSTANTS(:,5)))./(exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000); ALGEBRAIC(:,31) = ( (( STATES(:,9).*ALGEBRAIC(:,29).*CONSTANTS(:,25).*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( 0.750000.*CONSTANTS(:,7).*exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 0.750000.*CONSTANTS(:,8)))./(exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000); ALGEBRAIC(:,32) = ( (( STATES(:,9).*ALGEBRAIC(:,29).*CONSTANTS(:,25).*4.00000.*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( 1.50000.*ALGEBRAIC(:,23).*exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.50000.*CONSTANTS(:,6)))./(exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000); ALGEBRAIC(:,33) = ALGEBRAIC(:,30)+ALGEBRAIC(:,31)+ALGEBRAIC(:,32); ALGEBRAIC(:,34) = ( CONSTANTS(:,27).*ALGEBRAIC(:,23))./(CONSTANTS(:,28)+ALGEBRAIC(:,23)); ALGEBRAIC(:,25) = (( CONSTANTS(:,1).*CONSTANTS(:,2))./( 2.00000.*CONSTANTS(:,3))).*log(CONSTANTS(:,6)./ALGEBRAIC(:,23)); ALGEBRAIC(:,35) = CONSTANTS(:,32).*(STATES(:,1) - ALGEBRAIC(:,25)); ALGEBRAIC(:,17) = CONSTANTS(:,33).*(STATES(:,1) - CONSTANTS(:,46)); ALGEBRAIC(:,18) = CONSTANTS(:,34).*(STATES(:,1) - CONSTANTS(:,45)); RATES(:,1) = ( - 1.00000./CONSTANTS(:,35)).*(ALGEBRAIC(:,27)+ALGEBRAIC(:,1)+ALGEBRAIC(:,12)+ALGEBRAIC(:,28)+ALGEBRAIC(:,33)+CONSTANTS(:,48)+ALGEBRAIC(:,34)+ALGEBRAIC(:,35)+ALGEBRAIC(:,17)+ALGEBRAIC(:,18)); 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(:,3) = 1.00000./(1.00000+exp((STATES(:,1)+4.30000)./7.50000)); ALGEBRAIC(:,4) = 1.00000./(1.00000+exp((STATES(:,1)+4.30000)./7.50000)); ALGEBRAIC(:,6) = 1.00000./(1.00000+exp((23.0000+STATES(:,1))./6.60000)); ALGEBRAIC(:,2) = 1.00000./(1.00000+exp((5.50000 - STATES(:,1))./6.00000)); ALGEBRAIC(:,9) = 0.00326200 - 3.55200e-05.*STATES(:,1); ALGEBRAIC(:,5) = ( 30.0000.*(STATES(:,1)+18.0000))./(1.00000 - exp( - 0.250000.*(STATES(:,1)+18.0000))); ALGEBRAIC(:,10) = ( 12.0000.*(STATES(:,1)+18.0000))./(exp( 0.100000.*(STATES(:,1)+18.0000)) - 1.00000); ALGEBRAIC(:,11) = 0.200250 - 0.000898750.*STATES(:,1); ALGEBRAIC(:,7) = 1.00000./(1.00000+exp((STATES(:,1) - 69.8000)./ - 11.9000)); ALGEBRAIC(:,19) = piecewise({VOI<CONSTANTS(:,39), 0.00000 }, ( (VOI - CONSTANTS(:,39)).*CONSTANTS(:,36))./CONSTANTS(:,40)); ALGEBRAIC(:,20) = piecewise({VOI<CONSTANTS(:,39)+CONSTANTS(:,40), ALGEBRAIC(:,19) }, 0.00000); ALGEBRAIC(:,21) = piecewise({VOI<CONSTANTS(:,49), 0.00000 }, CONSTANTS(:,36).*exp( - (VOI - CONSTANTS(:,49))./CONSTANTS(:,44))); ALGEBRAIC(:,22) = CONSTANTS(:,37)./(1.00000+exp((VOI - (CONSTANTS(:,39)+CONSTANTS(:,42)+CONSTANTS(:,41)))./CONSTANTS(:,43))) - CONSTANTS(:,37)./(1.00000+exp((VOI - (CONSTANTS(:,39)+CONSTANTS(:,42)))./CONSTANTS(:,43))); ALGEBRAIC(:,23) = CONSTANTS(:,38)+ALGEBRAIC(:,20)+ALGEBRAIC(:,21)+ALGEBRAIC(:,22); ALGEBRAIC(:,15) = 0.850000.*exp( 0.0400000.*STATES(:,1)); ALGEBRAIC(:,16) = 0.240000.*exp( - 0.0120000.*STATES(:,1)); ALGEBRAIC(:,14) = 0.000275000.*exp(( - 1.51000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))); ALGEBRAIC(:,13) = 1.25000e-05.*exp(( - 1.99000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))); ALGEBRAIC(:,24) = (power(ALGEBRAIC(:,23), 2.00000)+ ALGEBRAIC(:,13).*ALGEBRAIC(:,23))./(power(ALGEBRAIC(:,23), 2.00000)+ ALGEBRAIC(:,13).*ALGEBRAIC(:,23).*(1.00000+CONSTANTS(:,20)./CONSTANTS(:,21))+( ALGEBRAIC(:,13).*ALGEBRAIC(:,14).*CONSTANTS(:,20))./CONSTANTS(:,21)); ALGEBRAIC(:,1) = CONSTANTS(:,11).*(CONSTANTS(:,12)+ (STATES(:,3)+STATES(:,4)).*(1.00000 - CONSTANTS(:,12))).*power(STATES(:,2), 2.00000).*(STATES(:,1) - CONSTANTS(:,46)); ALGEBRAIC(:,8) = ( (STATES(:,1) - CONSTANTS(:,16)).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2).*(1.00000 - exp(( - (STATES(:,1) - CONSTANTS(:,16)).*2.00000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))))); ALGEBRAIC(:,26) = ALGEBRAIC(:,8).*( ALGEBRAIC(:,23).*exp(CONSTANTS(:,16)./(( 0.500000.*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3))) - CONSTANTS(:,6).*exp( - (STATES(:,1) - CONSTANTS(:,16))./(( 0.500000.*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)))); ALGEBRAIC(:,27) = 4.00000.*CONSTANTS(:,15).*STATES(:,5).*STATES(:,6).*ALGEBRAIC(:,26); ALGEBRAIC(:,12) = CONSTANTS(:,18).*STATES(:,7).*STATES(:,8).*(STATES(:,1) - CONSTANTS(:,46)); ALGEBRAIC(:,28) = ( CONSTANTS(:,22).*(STATES(:,1) - CONSTANTS(:,47)).*1.00000)./(1.00000+power(CONSTANTS(:,23)./ALGEBRAIC(:,23), CONSTANTS(:,24))); ALGEBRAIC(:,29) = 1.00000./(1.00000+power(CONSTANTS(:,26)./ALGEBRAIC(:,23), 3.00000)); ALGEBRAIC(:,30) = ( (( STATES(:,9).*ALGEBRAIC(:,29).*CONSTANTS(:,25).*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( 0.750000.*CONSTANTS(:,4).*exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 0.750000.*CONSTANTS(:,5)))./(exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000); ALGEBRAIC(:,31) = ( (( STATES(:,9).*ALGEBRAIC(:,29).*CONSTANTS(:,25).*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( 0.750000.*CONSTANTS(:,7).*exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 0.750000.*CONSTANTS(:,8)))./(exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000); ALGEBRAIC(:,32) = ( (( STATES(:,9).*ALGEBRAIC(:,29).*CONSTANTS(:,25).*4.00000.*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( 1.50000.*ALGEBRAIC(:,23).*exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.50000.*CONSTANTS(:,6)))./(exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000); ALGEBRAIC(:,33) = ALGEBRAIC(:,30)+ALGEBRAIC(:,31)+ALGEBRAIC(:,32); ALGEBRAIC(:,34) = ( CONSTANTS(:,27).*ALGEBRAIC(:,23))./(CONSTANTS(:,28)+ALGEBRAIC(:,23)); ALGEBRAIC(:,25) = (( CONSTANTS(:,1).*CONSTANTS(:,2))./( 2.00000.*CONSTANTS(:,3))).*log(CONSTANTS(:,6)./ALGEBRAIC(:,23)); ALGEBRAIC(:,35) = CONSTANTS(:,32).*(STATES(:,1) - ALGEBRAIC(:,25)); ALGEBRAIC(:,17) = CONSTANTS(:,33).*(STATES(:,1) - CONSTANTS(:,46)); ALGEBRAIC(:,18) = CONSTANTS(:,34).*(STATES(:,1) - CONSTANTS(:,45)); 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