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 =29; end % There are a total of 9 entries in each of the rate and state variable arrays. % There are a total of 45 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 (millisecond)'); LEGEND_CONSTANTS(:,1) = strpad('RT in component parameters (joule_per_mole)'); LEGEND_STATES(:,1) = strpad('V_m in component membrane (millivolt)'); LEGEND_CONSTANTS(:,2) = strpad('C_m in component membrane (picofarad)'); LEGEND_ALGEBRAIC(:,17) = strpad('I_Na in component I_Na (picoampere)'); LEGEND_ALGEBRAIC(:,19) = strpad('I_T in component I_T (picoampere)'); LEGEND_ALGEBRAIC(:,21) = strpad('I_KCa in component I_KCa (picoampere)'); LEGEND_ALGEBRAIC(:,26) = strpad('I_Ca in component I_Ca (picoampere)'); LEGEND_ALGEBRAIC(:,27) = strpad('I_L in component I_L (picoampere)'); LEGEND_ALGEBRAIC(:,29) = strpad('I_K in component I_K (picoampere)'); LEGEND_ALGEBRAIC(:,14) = strpad('I_stim in component I_stim (picoampere)'); LEGEND_CONSTANTS(:,3) = strpad('I_mag in component I_stim (picoampere)'); LEGEND_CONSTANTS(:,4) = strpad('t_0 in component I_stim (millisecond)'); LEGEND_CONSTANTS(:,5) = strpad('t_1 in component I_stim (millisecond)'); LEGEND_ALGEBRAIC(:,4) = strpad('H_0 in component I_stim (dimensionless)'); LEGEND_ALGEBRAIC(:,10) = strpad('H_1 in component I_stim (dimensionless)'); LEGEND_CONSTANTS(:,6) = strpad('g_Na in component I_Na (nanosiemens)'); LEGEND_CONSTANTS(:,7) = strpad('E_Na in component I_Na (millivolt)'); LEGEND_STATES(:,2) = strpad('m in component m (dimensionless)'); LEGEND_STATES(:,3) = strpad('h in component h (dimensionless)'); LEGEND_CONSTANTS(:,8) = strpad('E_m in component m (millivolt)'); LEGEND_CONSTANTS(:,9) = strpad('V_alpha_m in component m (millivolt)'); LEGEND_CONSTANTS(:,10) = strpad('V_beta_m in component m (millivolt)'); LEGEND_ALGEBRAIC(:,1) = strpad('alpha_m in component m (per_millisecond)'); LEGEND_ALGEBRAIC(:,7) = strpad('beta_m in component m (per_millisecond)'); LEGEND_CONSTANTS(:,11) = strpad('alpha_m_max in component m (per_millivolt_per_millisecond)'); LEGEND_CONSTANTS(:,12) = strpad('beta_m_max in component m (per_millisecond)'); LEGEND_CONSTANTS(:,13) = strpad('E_h in component h (millivolt)'); LEGEND_CONSTANTS(:,14) = strpad('V_alpha_h in component h (millivolt)'); LEGEND_CONSTANTS(:,15) = strpad('V_beta_h in component h (millivolt)'); LEGEND_ALGEBRAIC(:,2) = strpad('alpha_h in component h (per_millisecond)'); LEGEND_ALGEBRAIC(:,8) = strpad('beta_h in component h (per_millisecond)'); LEGEND_CONSTANTS(:,16) = strpad('alpha_h_max in component h (per_millisecond)'); LEGEND_CONSTANTS(:,17) = strpad('beta_h_max in component h (per_millisecond)'); LEGEND_CONSTANTS(:,18) = strpad('R_s in component I_T (per_nanosiemens)'); LEGEND_CONSTANTS(:,19) = strpad('C_t in component I_T (picofarad)'); LEGEND_STATES(:,4) = strpad('V_T in component V_T (millivolt)'); LEGEND_CONSTANTS(:,20) = strpad('g_KCa in component I_KCa (nanosiemens)'); LEGEND_CONSTANTS(:,21) = strpad('E_K in component I_K (millivolt)'); LEGEND_STATES(:,5) = strpad('o in component o (dimensionless)'); LEGEND_ALGEBRAIC(:,20) = strpad('w in component w (dimensionless)'); LEGEND_STATES(:,6) = strpad('c in component calcium_handling (dimensionless)'); LEGEND_ALGEBRAIC(:,16) = strpad('o_oinf in component o (dimensionless)'); LEGEND_ALGEBRAIC(:,3) = strpad('alpha_Vm in component o (per_millisecond)'); LEGEND_ALGEBRAIC(:,9) = strpad('beta_Vm in component o (per_millisecond)'); LEGEND_ALGEBRAIC(:,13) = strpad('tau_Vm in component o (millisecond)'); LEGEND_CONSTANTS(:,22) = strpad('d_1 in component o (dimensionless)'); LEGEND_CONSTANTS(:,23) = strpad('d_2 in component o (dimensionless)'); LEGEND_CONSTANTS(:,24) = strpad('k_1 in component o (dimensionless)'); LEGEND_CONSTANTS(:,25) = strpad('k_2 in component o (dimensionless)'); LEGEND_CONSTANTS(:,26) = strpad('a_bar in component o (per_millisecond)'); LEGEND_CONSTANTS(:,27) = strpad('b_bar in component o (per_millisecond)'); LEGEND_CONSTANTS(:,28) = strpad('kd in component w (dimensionless)'); LEGEND_STATES(:,7) = strpad('cer in component calcium_handling (dimensionless)'); LEGEND_ALGEBRAIC(:,28) = strpad('j_mem in component calcium_handling (picoampere)'); LEGEND_ALGEBRAIC(:,22) = strpad('j_leak in component calcium_handling (picoampere)'); LEGEND_ALGEBRAIC(:,23) = strpad('j_serca in component calcium_handling (picoampere)'); LEGEND_ALGEBRAIC(:,24) = strpad('j_er in component calcium_handling (picoampere)'); LEGEND_CONSTANTS(:,29) = strpad('alpha in component calcium_handling (dimensionless)'); LEGEND_CONSTANTS(:,30) = strpad('k_pmca in component calcium_handling (dimensionless)'); LEGEND_CONSTANTS(:,31) = strpad('k_serca in component calcium_handling (picoampere)'); LEGEND_CONSTANTS(:,32) = strpad('p_leak in component calcium_handling (picoampere)'); LEGEND_CONSTANTS(:,33) = strpad('f_er in component calcium_handling (per_picoampere_per_millisecond)'); LEGEND_CONSTANTS(:,34) = strpad('f_cyt in component calcium_handling (per_picoampere_per_millisecond)'); LEGEND_CONSTANTS(:,35) = strpad('v_cytver in component calcium_handling (dimensionless)'); LEGEND_STATES(:,8) = strpad('d in component d (dimensionless)'); LEGEND_ALGEBRAIC(:,25) = strpad('g_Ca in component I_Ca (nanosiemens)'); LEGEND_CONSTANTS(:,36) = strpad('g_Ca0 in component I_Ca (nanosiemens_per_millivolt)'); LEGEND_CONSTANTS(:,37) = strpad('E_Ca in component I_Ca (millivolt)'); LEGEND_ALGEBRAIC(:,15) = strpad('alpha_d in component d (per_millisecond)'); LEGEND_ALGEBRAIC(:,18) = strpad('beta_d in component d (per_millisecond)'); LEGEND_ALGEBRAIC(:,11) = strpad('tau_d in component d (millisecond)'); LEGEND_ALGEBRAIC(:,5) = strpad('d_infinity in component d (dimensionless)'); LEGEND_CONSTANTS(:,38) = strpad('E_L in component I_L (millivolt)'); LEGEND_CONSTANTS(:,39) = strpad('g_Lmax in component I_L (nanosiemens)'); LEGEND_STATES(:,9) = strpad('n in component n (dimensionless)'); LEGEND_CONSTANTS(:,40) = strpad('g_K in component I_K (nanosiemens)'); LEGEND_CONSTANTS(:,41) = strpad('E_n in component n (millivolt)'); LEGEND_CONSTANTS(:,42) = strpad('V_alpha_n in component n (millivolt)'); LEGEND_CONSTANTS(:,43) = strpad('V_beta_n in component n (millivolt)'); LEGEND_ALGEBRAIC(:,6) = strpad('alpha_n in component n (per_millisecond)'); LEGEND_ALGEBRAIC(:,12) = strpad('beta_n in component n (per_millisecond)'); LEGEND_CONSTANTS(:,44) = strpad('alpha_n_max in component n (per_millivolt_per_millisecond)'); LEGEND_CONSTANTS(:,45) = strpad('beta_n_max in component n (per_millisecond)'); LEGEND_RATES(:,1) = strpad('d/dt V_m in component membrane (millivolt)'); LEGEND_RATES(:,2) = strpad('d/dt m in component m (dimensionless)'); LEGEND_RATES(:,3) = strpad('d/dt h in component h (dimensionless)'); LEGEND_RATES(:,4) = strpad('d/dt V_T in component V_T (millivolt)'); LEGEND_RATES(:,5) = strpad('d/dt o in component o (dimensionless)'); LEGEND_RATES(:,6) = strpad('d/dt c in component calcium_handling (dimensionless)'); LEGEND_RATES(:,7) = strpad('d/dt cer in component calcium_handling (dimensionless)'); LEGEND_RATES(:,8) = strpad('d/dt d in component d (dimensionless)'); LEGEND_RATES(:,9) = strpad('d/dt n in component n (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 = []; CONSTANTS(:,1) = 2577; STATES(:,1) = -75; CONSTANTS(:,2) = 0.009; CONSTANTS(:,3) = 2; CONSTANTS(:,4) = 5; CONSTANTS(:,5) = 6; CONSTANTS(:,6) = 0.45; CONSTANTS(:,7) = 50; STATES(:,2) = 0; STATES(:,3) = 1; CONSTANTS(:,8) = -42; CONSTANTS(:,9) = 10; CONSTANTS(:,10) = 18; CONSTANTS(:,11) = 0.208; CONSTANTS(:,12) = 2.081; CONSTANTS(:,13) = -41; CONSTANTS(:,14) = 14.7; CONSTANTS(:,15) = 7.6; CONSTANTS(:,16) = 0.0156; CONSTANTS(:,17) = 3.382; CONSTANTS(:,18) = 15; CONSTANTS(:,19) = 0.04; STATES(:,4) = -70; CONSTANTS(:,20) = 0.5; CONSTANTS(:,21) = -70; STATES(:,5) = 0.15; STATES(:,6) = 0.15; CONSTANTS(:,22) = 0.84; CONSTANTS(:,23) = 1; CONSTANTS(:,24) = 0.18; CONSTANTS(:,25) = 0.011; CONSTANTS(:,26) = 0.48; CONSTANTS(:,27) = 0.28; CONSTANTS(:,28) = 0.18; STATES(:,7) = 200; CONSTANTS(:,29) = 4.5e-6; CONSTANTS(:,30) = 0.2; CONSTANTS(:,31) = 0.4; CONSTANTS(:,32) = 0.0005; CONSTANTS(:,33) = 0.01; CONSTANTS(:,34) = 0.01; CONSTANTS(:,35) = 5; STATES(:,8) = 0; CONSTANTS(:,36) = 0.05; CONSTANTS(:,37) = 50; CONSTANTS(:,38) = -75; CONSTANTS(:,39) = 0.0024; STATES(:,9) = 0; CONSTANTS(:,40) = 0.415; CONSTANTS(:,41) = -40; CONSTANTS(:,42) = 7; CONSTANTS(:,43) = 40; CONSTANTS(:,44) = 0.0229; CONSTANTS(:,45) = 0.09616; 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(:,4) = (STATES(:,1) - STATES(:,4))./( CONSTANTS(:,18).*CONSTANTS(:,19)); ALGEBRAIC(:,1) = ( CONSTANTS(:,11).*(STATES(:,1) - CONSTANTS(:,8)))./(1.00000 - exp((CONSTANTS(:,8) - STATES(:,1))./CONSTANTS(:,9))); ALGEBRAIC(:,7) = CONSTANTS(:,12).*exp((CONSTANTS(:,8) - STATES(:,1))./CONSTANTS(:,10)); RATES(:,2) = ALGEBRAIC(:,1).*(1.00000 - STATES(:,2)) - ALGEBRAIC(:,7).*STATES(:,2); ALGEBRAIC(:,2) = CONSTANTS(:,16).*exp((STATES(:,1) - CONSTANTS(:,13))./CONSTANTS(:,14)); ALGEBRAIC(:,8) = CONSTANTS(:,17)./(1.00000+exp((CONSTANTS(:,13) - STATES(:,1))./CONSTANTS(:,15))); RATES(:,3) = ALGEBRAIC(:,2).*(1.00000 - STATES(:,3)) - ALGEBRAIC(:,8).*STATES(:,3); ALGEBRAIC(:,6) = ( CONSTANTS(:,44).*(STATES(:,1) - CONSTANTS(:,41)))./(1.00000 - exp((CONSTANTS(:,41) - STATES(:,1))./CONSTANTS(:,42))); ALGEBRAIC(:,12) = CONSTANTS(:,45).*exp((CONSTANTS(:,41) - STATES(:,1))./CONSTANTS(:,43)); RATES(:,9) = ALGEBRAIC(:,6).*(1.00000 - STATES(:,9)) - ALGEBRAIC(:,12).*STATES(:,9); ALGEBRAIC(:,3) = CONSTANTS(:,26)./(1.00000+ CONSTANTS(:,24).*exp(( - 2.00000.*CONSTANTS(:,22).*96.4850.*STATES(:,1))./( CONSTANTS(:,1).*STATES(:,6)))); ALGEBRAIC(:,9) = CONSTANTS(:,27)./(1.00000+STATES(:,6)./( CONSTANTS(:,25).*exp(( - 2.00000.*CONSTANTS(:,23).*96.4850.*STATES(:,1))./CONSTANTS(:,1)))); ALGEBRAIC(:,13) = 1.00000./(ALGEBRAIC(:,3)+ALGEBRAIC(:,9)); ALGEBRAIC(:,16) = ALGEBRAIC(:,3).*ALGEBRAIC(:,13); RATES(:,5) = (ALGEBRAIC(:,16) - STATES(:,5))./ALGEBRAIC(:,13); ALGEBRAIC(:,11) = ( 80.0000.*1.00000)./cosh( - 0.0310000.*(STATES(:,1)+37.1000)); ALGEBRAIC(:,5) = 1.00000./(1.00000+exp(( - 24.6000 - STATES(:,1))./11.3000)); ALGEBRAIC(:,15) = ALGEBRAIC(:,5)./ALGEBRAIC(:,11); ALGEBRAIC(:,18) = (1.00000 - ALGEBRAIC(:,5))./ALGEBRAIC(:,11); RATES(:,8) = ALGEBRAIC(:,15).*(1.00000 - STATES(:,8)) - ALGEBRAIC(:,18).*STATES(:,8); ALGEBRAIC(:,22) = CONSTANTS(:,32).*(STATES(:,7) - STATES(:,6)); ALGEBRAIC(:,23) = CONSTANTS(:,31).*STATES(:,6); ALGEBRAIC(:,24) = ALGEBRAIC(:,22) - ALGEBRAIC(:,23); RATES(:,7) = - CONSTANTS(:,33).*CONSTANTS(:,35).*ALGEBRAIC(:,24); ALGEBRAIC(:,25) = ( - CONSTANTS(:,36).*STATES(:,1))./(exp( 0.117000.*STATES(:,1)) - 1.00000); ALGEBRAIC(:,26) = ALGEBRAIC(:,25).*power(STATES(:,8), 2.00000).*(STATES(:,1) - CONSTANTS(:,37)); ALGEBRAIC(:,28) = - CONSTANTS(:,29).*ALGEBRAIC(:,26).*CONSTANTS(:,30).*STATES(:,6); RATES(:,6) = CONSTANTS(:,34).*(ALGEBRAIC(:,28)+ALGEBRAIC(:,24)); ALGEBRAIC(:,17) = CONSTANTS(:,6).*power(STATES(:,2), 3.00000).*STATES(:,3).*(STATES(:,1) - CONSTANTS(:,7)); ALGEBRAIC(:,19) = (STATES(:,1) - STATES(:,4))./CONSTANTS(:,18); ALGEBRAIC(:,20) = power(STATES(:,6), 5.00000)./(power(STATES(:,6), 5.00000)+power(CONSTANTS(:,28), 5.00000)); ALGEBRAIC(:,21) = CONSTANTS(:,20).*STATES(:,5).*ALGEBRAIC(:,20).*(STATES(:,1) - CONSTANTS(:,21)); ALGEBRAIC(:,27) = CONSTANTS(:,39).*(STATES(:,1) - CONSTANTS(:,38)); ALGEBRAIC(:,29) = CONSTANTS(:,40).*power(STATES(:,9), 4.00000).*(STATES(:,1) - CONSTANTS(:,21)); ALGEBRAIC(:,4) = piecewise({VOI<CONSTANTS(:,4), 0.00000 }, 1.00000); ALGEBRAIC(:,10) = piecewise({VOI<CONSTANTS(:,5), 0.00000 }, 1.00000); ALGEBRAIC(:,14) = CONSTANTS(:,3).*(ALGEBRAIC(:,4) - ALGEBRAIC(:,10)); RATES(:,1) = (ALGEBRAIC(:,14) - (ALGEBRAIC(:,17)+ALGEBRAIC(:,26)+ALGEBRAIC(:,29)+ALGEBRAIC(:,27)+ALGEBRAIC(:,19)+ALGEBRAIC(:,21)))./CONSTANTS(:,2); 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) = ( CONSTANTS(:,11).*(STATES(:,1) - CONSTANTS(:,8)))./(1.00000 - exp((CONSTANTS(:,8) - STATES(:,1))./CONSTANTS(:,9))); ALGEBRAIC(:,7) = CONSTANTS(:,12).*exp((CONSTANTS(:,8) - STATES(:,1))./CONSTANTS(:,10)); ALGEBRAIC(:,2) = CONSTANTS(:,16).*exp((STATES(:,1) - CONSTANTS(:,13))./CONSTANTS(:,14)); ALGEBRAIC(:,8) = CONSTANTS(:,17)./(1.00000+exp((CONSTANTS(:,13) - STATES(:,1))./CONSTANTS(:,15))); ALGEBRAIC(:,6) = ( CONSTANTS(:,44).*(STATES(:,1) - CONSTANTS(:,41)))./(1.00000 - exp((CONSTANTS(:,41) - STATES(:,1))./CONSTANTS(:,42))); ALGEBRAIC(:,12) = CONSTANTS(:,45).*exp((CONSTANTS(:,41) - STATES(:,1))./CONSTANTS(:,43)); ALGEBRAIC(:,3) = CONSTANTS(:,26)./(1.00000+ CONSTANTS(:,24).*exp(( - 2.00000.*CONSTANTS(:,22).*96.4850.*STATES(:,1))./( CONSTANTS(:,1).*STATES(:,6)))); ALGEBRAIC(:,9) = CONSTANTS(:,27)./(1.00000+STATES(:,6)./( CONSTANTS(:,25).*exp(( - 2.00000.*CONSTANTS(:,23).*96.4850.*STATES(:,1))./CONSTANTS(:,1)))); ALGEBRAIC(:,13) = 1.00000./(ALGEBRAIC(:,3)+ALGEBRAIC(:,9)); ALGEBRAIC(:,16) = ALGEBRAIC(:,3).*ALGEBRAIC(:,13); ALGEBRAIC(:,11) = ( 80.0000.*1.00000)./cosh( - 0.0310000.*(STATES(:,1)+37.1000)); ALGEBRAIC(:,5) = 1.00000./(1.00000+exp(( - 24.6000 - STATES(:,1))./11.3000)); ALGEBRAIC(:,15) = ALGEBRAIC(:,5)./ALGEBRAIC(:,11); ALGEBRAIC(:,18) = (1.00000 - ALGEBRAIC(:,5))./ALGEBRAIC(:,11); ALGEBRAIC(:,22) = CONSTANTS(:,32).*(STATES(:,7) - STATES(:,6)); ALGEBRAIC(:,23) = CONSTANTS(:,31).*STATES(:,6); ALGEBRAIC(:,24) = ALGEBRAIC(:,22) - ALGEBRAIC(:,23); ALGEBRAIC(:,25) = ( - CONSTANTS(:,36).*STATES(:,1))./(exp( 0.117000.*STATES(:,1)) - 1.00000); ALGEBRAIC(:,26) = ALGEBRAIC(:,25).*power(STATES(:,8), 2.00000).*(STATES(:,1) - CONSTANTS(:,37)); ALGEBRAIC(:,28) = - CONSTANTS(:,29).*ALGEBRAIC(:,26).*CONSTANTS(:,30).*STATES(:,6); ALGEBRAIC(:,17) = CONSTANTS(:,6).*power(STATES(:,2), 3.00000).*STATES(:,3).*(STATES(:,1) - CONSTANTS(:,7)); ALGEBRAIC(:,19) = (STATES(:,1) - STATES(:,4))./CONSTANTS(:,18); ALGEBRAIC(:,20) = power(STATES(:,6), 5.00000)./(power(STATES(:,6), 5.00000)+power(CONSTANTS(:,28), 5.00000)); ALGEBRAIC(:,21) = CONSTANTS(:,20).*STATES(:,5).*ALGEBRAIC(:,20).*(STATES(:,1) - CONSTANTS(:,21)); ALGEBRAIC(:,27) = CONSTANTS(:,39).*(STATES(:,1) - CONSTANTS(:,38)); ALGEBRAIC(:,29) = CONSTANTS(:,40).*power(STATES(:,9), 4.00000).*(STATES(:,1) - CONSTANTS(:,21)); ALGEBRAIC(:,4) = piecewise({VOI<CONSTANTS(:,4), 0.00000 }, 1.00000); ALGEBRAIC(:,10) = piecewise({VOI<CONSTANTS(:,5), 0.00000 }, 1.00000); ALGEBRAIC(:,14) = CONSTANTS(:,3).*(ALGEBRAIC(:,4) - ALGEBRAIC(:,10)); 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