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 =25; end % There are a total of 8 entries in each of the rate and state variable arrays. % There are a total of 24 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_STATES(:,1) = strpad('V in component membrane (millivolt)'); LEGEND_CONSTANTS(:,1) = strpad('R in component membrane (joule_per_kilomole_kelvin)'); LEGEND_CONSTANTS(:,2) = strpad('T in component membrane (kelvin)'); LEGEND_CONSTANTS(:,3) = strpad('F in component membrane (coulomb_per_mole)'); LEGEND_CONSTANTS(:,4) = strpad('C in component membrane (microF_per_cm2)'); LEGEND_ALGEBRAIC(:,1) = strpad('I_stim in component membrane (microA_per_cm2)'); LEGEND_ALGEBRAIC(:,8) = strpad('i_Na in component fast_sodium_current (microA_per_cm2)'); LEGEND_ALGEBRAIC(:,16) = strpad('i_si in component slow_inward_current (microA_per_cm2)'); LEGEND_ALGEBRAIC(:,18) = strpad('i_K in component time_dependent_potassium_current (microA_per_cm2)'); LEGEND_ALGEBRAIC(:,22) = strpad('i_K1 in component time_independent_potassium_current (microA_per_cm2)'); LEGEND_ALGEBRAIC(:,24) = strpad('i_Kp in component plateau_potassium_current (microA_per_cm2)'); LEGEND_ALGEBRAIC(:,25) = strpad('i_b in component background_current (microA_per_cm2)'); LEGEND_CONSTANTS(:,5) = strpad('stim_start in component membrane (millisecond)'); LEGEND_CONSTANTS(:,6) = strpad('stim_end in component membrane (millisecond)'); LEGEND_CONSTANTS(:,7) = strpad('stim_period in component membrane (millisecond)'); LEGEND_CONSTANTS(:,8) = strpad('stim_duration in component membrane (millisecond)'); LEGEND_CONSTANTS(:,9) = strpad('stim_amplitude in component membrane (microA_per_cm2)'); LEGEND_CONSTANTS(:,10) = strpad('g_Na in component fast_sodium_current (milliS_per_cm2)'); LEGEND_CONSTANTS(:,19) = strpad('E_Na in component fast_sodium_current (millivolt)'); LEGEND_CONSTANTS(:,11) = strpad('Nao in component ionic_concentrations (millimolar)'); LEGEND_CONSTANTS(:,12) = strpad('Nai in component ionic_concentrations (millimolar)'); LEGEND_STATES(:,2) = strpad('m in component fast_sodium_current_m_gate (dimensionless)'); LEGEND_STATES(:,3) = strpad('h in component fast_sodium_current_h_gate (dimensionless)'); LEGEND_STATES(:,4) = strpad('j in component fast_sodium_current_j_gate (dimensionless)'); LEGEND_ALGEBRAIC(:,2) = strpad('alpha_m in component fast_sodium_current_m_gate (per_millisecond)'); LEGEND_ALGEBRAIC(:,9) = strpad('beta_m in component fast_sodium_current_m_gate (per_millisecond)'); LEGEND_ALGEBRAIC(:,3) = strpad('alpha_h in component fast_sodium_current_h_gate (per_millisecond)'); LEGEND_ALGEBRAIC(:,10) = strpad('beta_h in component fast_sodium_current_h_gate (per_millisecond)'); LEGEND_ALGEBRAIC(:,4) = strpad('alpha_j in component fast_sodium_current_j_gate (per_millisecond)'); LEGEND_ALGEBRAIC(:,11) = strpad('beta_j in component fast_sodium_current_j_gate (per_millisecond)'); LEGEND_ALGEBRAIC(:,15) = strpad('E_si in component slow_inward_current (millivolt)'); LEGEND_STATES(:,5) = strpad('Cai in component intracellular_calcium_concentration (millimolar)'); LEGEND_STATES(:,6) = strpad('d in component slow_inward_current_d_gate (dimensionless)'); LEGEND_STATES(:,7) = strpad('f in component slow_inward_current_f_gate (dimensionless)'); LEGEND_ALGEBRAIC(:,5) = strpad('alpha_d in component slow_inward_current_d_gate (per_millisecond)'); LEGEND_ALGEBRAIC(:,12) = strpad('beta_d in component slow_inward_current_d_gate (per_millisecond)'); LEGEND_ALGEBRAIC(:,6) = strpad('alpha_f in component slow_inward_current_f_gate (per_millisecond)'); LEGEND_ALGEBRAIC(:,13) = strpad('beta_f in component slow_inward_current_f_gate (per_millisecond)'); LEGEND_CONSTANTS(:,20) = strpad('g_K in component time_dependent_potassium_current (milliS_per_cm2)'); LEGEND_CONSTANTS(:,21) = strpad('E_K in component time_dependent_potassium_current (millivolt)'); LEGEND_CONSTANTS(:,13) = strpad('PR_NaK in component time_dependent_potassium_current (dimensionless)'); LEGEND_CONSTANTS(:,14) = strpad('Ko in component ionic_concentrations (millimolar)'); LEGEND_CONSTANTS(:,15) = strpad('Ki in component ionic_concentrations (millimolar)'); LEGEND_STATES(:,8) = strpad('X in component time_dependent_potassium_current_X_gate (dimensionless)'); LEGEND_ALGEBRAIC(:,17) = strpad('Xi in component time_dependent_potassium_current_Xi_gate (dimensionless)'); LEGEND_ALGEBRAIC(:,7) = strpad('alpha_X in component time_dependent_potassium_current_X_gate (per_millisecond)'); LEGEND_ALGEBRAIC(:,14) = strpad('beta_X in component time_dependent_potassium_current_X_gate (per_millisecond)'); LEGEND_CONSTANTS(:,22) = strpad('E_K1 in component time_independent_potassium_current (millivolt)'); LEGEND_CONSTANTS(:,23) = strpad('g_K1 in component time_independent_potassium_current (milliS_per_cm2)'); LEGEND_ALGEBRAIC(:,21) = strpad('K1_infinity in component time_independent_potassium_current_K1_gate (dimensionless)'); LEGEND_ALGEBRAIC(:,19) = strpad('alpha_K1 in component time_independent_potassium_current_K1_gate (per_millisecond)'); LEGEND_ALGEBRAIC(:,20) = strpad('beta_K1 in component time_independent_potassium_current_K1_gate (per_millisecond)'); LEGEND_CONSTANTS(:,24) = strpad('E_Kp in component plateau_potassium_current (millivolt)'); LEGEND_CONSTANTS(:,16) = strpad('g_Kp in component plateau_potassium_current (milliS_per_cm2)'); LEGEND_ALGEBRAIC(:,23) = strpad('Kp in component plateau_potassium_current (dimensionless)'); LEGEND_CONSTANTS(:,17) = strpad('E_b in component background_current (millivolt)'); LEGEND_CONSTANTS(:,18) = strpad('g_b in component background_current (milliS_per_cm2)'); LEGEND_RATES(:,1) = strpad('d/dt V in component membrane (millivolt)'); LEGEND_RATES(:,2) = strpad('d/dt m in component fast_sodium_current_m_gate (dimensionless)'); LEGEND_RATES(:,3) = strpad('d/dt h in component fast_sodium_current_h_gate (dimensionless)'); LEGEND_RATES(:,4) = strpad('d/dt j in component fast_sodium_current_j_gate (dimensionless)'); LEGEND_RATES(:,6) = strpad('d/dt d in component slow_inward_current_d_gate (dimensionless)'); LEGEND_RATES(:,7) = strpad('d/dt f in component slow_inward_current_f_gate (dimensionless)'); LEGEND_RATES(:,8) = strpad('d/dt X in component time_dependent_potassium_current_X_gate (dimensionless)'); LEGEND_RATES(:,5) = strpad('d/dt Cai in component intracellular_calcium_concentration (millimolar)'); 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) = -84.3801107371; CONSTANTS(:,1) = 8314; CONSTANTS(:,2) = 310; CONSTANTS(:,3) = 96484.6; CONSTANTS(:,4) = 1; CONSTANTS(:,5) = 100; CONSTANTS(:,6) = 9000; CONSTANTS(:,7) = 1000; CONSTANTS(:,8) = 2; CONSTANTS(:,9) = -25.5; CONSTANTS(:,10) = 23; CONSTANTS(:,11) = 140; CONSTANTS(:,12) = 18; STATES(:,2) = 0.00171338077730188; STATES(:,3) = 0.982660523699656; STATES(:,4) = 0.989108212766685; STATES(:,5) = 0.00017948816388306; STATES(:,6) = 0.00302126301779861; STATES(:,7) = 0.999967936476325; CONSTANTS(:,13) = 0.01833; CONSTANTS(:,14) = 5.4; CONSTANTS(:,15) = 145; STATES(:,8) = 0.0417603108167287; CONSTANTS(:,16) = 0.0183; CONSTANTS(:,17) = -59.87; CONSTANTS(:,18) = 0.03921; CONSTANTS(:,19) = (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,11)./CONSTANTS(:,12)); CONSTANTS(:,20) = 0.282000.*power((CONSTANTS(:,14)./5.40000), 1.0 ./ 2); CONSTANTS(:,21) = (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log((CONSTANTS(:,14)+ CONSTANTS(:,13).*CONSTANTS(:,11))./(CONSTANTS(:,15)+ CONSTANTS(:,13).*CONSTANTS(:,12))); CONSTANTS(:,22) = (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,14)./CONSTANTS(:,15)); CONSTANTS(:,23) = 0.604700.*power((CONSTANTS(:,14)./5.40000), 1.0 ./ 2); CONSTANTS(:,24) = CONSTANTS(:,22); 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(:,2) = ( 0.320000.*(STATES(:,1)+47.1300))./(1.00000 - exp( - 0.100000.*(STATES(:,1)+47.1300))); ALGEBRAIC(:,9) = 0.0800000.*exp( - STATES(:,1)./11.0000); RATES(:,2) = ALGEBRAIC(:,2).*(1.00000 - STATES(:,2)) - ALGEBRAIC(:,9).*STATES(:,2); ALGEBRAIC(:,3) = piecewise({STATES(:,1)< - 40.0000, 0.135000.*exp((80.0000+STATES(:,1))./ - 6.80000) }, 0.00000); ALGEBRAIC(:,10) = piecewise({STATES(:,1)< - 40.0000, 3.56000.*exp( 0.0790000.*STATES(:,1))+ 310000..*exp( 0.350000.*STATES(:,1)) }, 1.00000./( 0.130000.*(1.00000+exp((STATES(:,1)+10.6600)./ - 11.1000)))); RATES(:,3) = ALGEBRAIC(:,3).*(1.00000 - STATES(:,3)) - ALGEBRAIC(:,10).*STATES(:,3); ALGEBRAIC(:,4) = piecewise({STATES(:,1)< - 40.0000, ( ( - 127140..*exp( 0.244400.*STATES(:,1)) - 3.47400e-05.*exp( - 0.0439100.*STATES(:,1))).*(STATES(:,1)+37.7800))./(1.00000+exp( 0.311000.*(STATES(:,1)+79.2300))) }, 0.00000); ALGEBRAIC(:,11) = piecewise({STATES(:,1)< - 40.0000, ( 0.121200.*exp( - 0.0105200.*STATES(:,1)))./(1.00000+exp( - 0.137800.*(STATES(:,1)+40.1400))) }, ( 0.300000.*exp( - 2.53500e-07.*STATES(:,1)))./(1.00000+exp( - 0.100000.*(STATES(:,1)+32.0000)))); RATES(:,4) = ALGEBRAIC(:,4).*(1.00000 - STATES(:,4)) - ALGEBRAIC(:,11).*STATES(:,4); ALGEBRAIC(:,5) = ( 0.0950000.*exp( - 0.0100000.*(STATES(:,1) - 5.00000)))./(1.00000+exp( - 0.0720000.*(STATES(:,1) - 5.00000))); ALGEBRAIC(:,12) = ( 0.0700000.*exp( - 0.0170000.*(STATES(:,1)+44.0000)))./(1.00000+exp( 0.0500000.*(STATES(:,1)+44.0000))); RATES(:,6) = ALGEBRAIC(:,5).*(1.00000 - STATES(:,6)) - ALGEBRAIC(:,12).*STATES(:,6); ALGEBRAIC(:,6) = ( 0.0120000.*exp( - 0.00800000.*(STATES(:,1)+28.0000)))./(1.00000+exp( 0.150000.*(STATES(:,1)+28.0000))); ALGEBRAIC(:,13) = ( 0.00650000.*exp( - 0.0200000.*(STATES(:,1)+30.0000)))./(1.00000+exp( - 0.200000.*(STATES(:,1)+30.0000))); RATES(:,7) = ALGEBRAIC(:,6).*(1.00000 - STATES(:,7)) - ALGEBRAIC(:,13).*STATES(:,7); ALGEBRAIC(:,7) = ( 0.000500000.*exp( 0.0830000.*(STATES(:,1)+50.0000)))./(1.00000+exp( 0.0570000.*(STATES(:,1)+50.0000))); ALGEBRAIC(:,14) = ( 0.00130000.*exp( - 0.0600000.*(STATES(:,1)+20.0000)))./(1.00000+exp( - 0.0400000.*(STATES(:,1)+20.0000))); RATES(:,8) = ALGEBRAIC(:,7).*(1.00000 - STATES(:,8)) - ALGEBRAIC(:,14).*STATES(:,8); ALGEBRAIC(:,15) = 7.70000 - 13.0287.*log(STATES(:,5)./1.00000); ALGEBRAIC(:,16) = 0.0900000.*STATES(:,6).*STATES(:,7).*(STATES(:,1) - ALGEBRAIC(:,15)); RATES(:,5) = ( - 0.000100000./1.00000).*ALGEBRAIC(:,16)+ 0.0700000.*(0.000100000 - STATES(:,5)); ALGEBRAIC(:,1) = piecewise({VOI>=CONSTANTS(:,5)&VOI<=CONSTANTS(:,6)&(VOI - CONSTANTS(:,5)) - floor((VOI - CONSTANTS(:,5))./CONSTANTS(:,7)).*CONSTANTS(:,7)<=CONSTANTS(:,8), CONSTANTS(:,9) }, 0.00000); ALGEBRAIC(:,8) = CONSTANTS(:,10).*power(STATES(:,2), 3.00000).*STATES(:,3).*STATES(:,4).*(STATES(:,1) - CONSTANTS(:,19)); ALGEBRAIC(:,17) = piecewise({STATES(:,1)> - 100.000, ( 2.83700.*(exp( 0.0400000.*(STATES(:,1)+77.0000)) - 1.00000))./( (STATES(:,1)+77.0000).*exp( 0.0400000.*(STATES(:,1)+35.0000))) }, 1.00000); ALGEBRAIC(:,18) = CONSTANTS(:,20).*STATES(:,8).*ALGEBRAIC(:,17).*(STATES(:,1) - CONSTANTS(:,21)); ALGEBRAIC(:,19) = 1.02000./(1.00000+exp( 0.238500.*((STATES(:,1) - CONSTANTS(:,22)) - 59.2150))); ALGEBRAIC(:,20) = ( 0.491240.*exp( 0.0803200.*((STATES(:,1)+5.47600) - CONSTANTS(:,22)))+ 1.00000.*exp( 0.0617500.*(STATES(:,1) - (CONSTANTS(:,22)+594.310))))./(1.00000+exp( - 0.514300.*((STATES(:,1) - CONSTANTS(:,22))+4.75300))); ALGEBRAIC(:,21) = ALGEBRAIC(:,19)./(ALGEBRAIC(:,19)+ALGEBRAIC(:,20)); ALGEBRAIC(:,22) = CONSTANTS(:,23).*ALGEBRAIC(:,21).*(STATES(:,1) - CONSTANTS(:,22)); ALGEBRAIC(:,23) = 1.00000./(1.00000+exp((7.48800 - STATES(:,1))./5.98000)); ALGEBRAIC(:,24) = CONSTANTS(:,16).*ALGEBRAIC(:,23).*(STATES(:,1) - CONSTANTS(:,24)); ALGEBRAIC(:,25) = CONSTANTS(:,18).*(STATES(:,1) - CONSTANTS(:,17)); RATES(:,1) = ( - 1.00000./CONSTANTS(:,4)).*(ALGEBRAIC(:,1)+ALGEBRAIC(:,8)+ALGEBRAIC(:,16)+ALGEBRAIC(:,18)+ALGEBRAIC(:,22)+ALGEBRAIC(:,24)+ALGEBRAIC(:,25)); 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(:,2) = ( 0.320000.*(STATES(:,1)+47.1300))./(1.00000 - exp( - 0.100000.*(STATES(:,1)+47.1300))); ALGEBRAIC(:,9) = 0.0800000.*exp( - STATES(:,1)./11.0000); ALGEBRAIC(:,3) = piecewise({STATES(:,1)< - 40.0000, 0.135000.*exp((80.0000+STATES(:,1))./ - 6.80000) }, 0.00000); ALGEBRAIC(:,10) = piecewise({STATES(:,1)< - 40.0000, 3.56000.*exp( 0.0790000.*STATES(:,1))+ 310000..*exp( 0.350000.*STATES(:,1)) }, 1.00000./( 0.130000.*(1.00000+exp((STATES(:,1)+10.6600)./ - 11.1000)))); ALGEBRAIC(:,4) = piecewise({STATES(:,1)< - 40.0000, ( ( - 127140..*exp( 0.244400.*STATES(:,1)) - 3.47400e-05.*exp( - 0.0439100.*STATES(:,1))).*(STATES(:,1)+37.7800))./(1.00000+exp( 0.311000.*(STATES(:,1)+79.2300))) }, 0.00000); ALGEBRAIC(:,11) = piecewise({STATES(:,1)< - 40.0000, ( 0.121200.*exp( - 0.0105200.*STATES(:,1)))./(1.00000+exp( - 0.137800.*(STATES(:,1)+40.1400))) }, ( 0.300000.*exp( - 2.53500e-07.*STATES(:,1)))./(1.00000+exp( - 0.100000.*(STATES(:,1)+32.0000)))); ALGEBRAIC(:,5) = ( 0.0950000.*exp( - 0.0100000.*(STATES(:,1) - 5.00000)))./(1.00000+exp( - 0.0720000.*(STATES(:,1) - 5.00000))); ALGEBRAIC(:,12) = ( 0.0700000.*exp( - 0.0170000.*(STATES(:,1)+44.0000)))./(1.00000+exp( 0.0500000.*(STATES(:,1)+44.0000))); ALGEBRAIC(:,6) = ( 0.0120000.*exp( - 0.00800000.*(STATES(:,1)+28.0000)))./(1.00000+exp( 0.150000.*(STATES(:,1)+28.0000))); ALGEBRAIC(:,13) = ( 0.00650000.*exp( - 0.0200000.*(STATES(:,1)+30.0000)))./(1.00000+exp( - 0.200000.*(STATES(:,1)+30.0000))); ALGEBRAIC(:,7) = ( 0.000500000.*exp( 0.0830000.*(STATES(:,1)+50.0000)))./(1.00000+exp( 0.0570000.*(STATES(:,1)+50.0000))); ALGEBRAIC(:,14) = ( 0.00130000.*exp( - 0.0600000.*(STATES(:,1)+20.0000)))./(1.00000+exp( - 0.0400000.*(STATES(:,1)+20.0000))); ALGEBRAIC(:,15) = 7.70000 - 13.0287.*log(STATES(:,5)./1.00000); ALGEBRAIC(:,16) = 0.0900000.*STATES(:,6).*STATES(:,7).*(STATES(:,1) - ALGEBRAIC(:,15)); ALGEBRAIC(:,1) = piecewise({VOI>=CONSTANTS(:,5)&VOI<=CONSTANTS(:,6)&(VOI - CONSTANTS(:,5)) - floor((VOI - CONSTANTS(:,5))./CONSTANTS(:,7)).*CONSTANTS(:,7)<=CONSTANTS(:,8), CONSTANTS(:,9) }, 0.00000); ALGEBRAIC(:,8) = CONSTANTS(:,10).*power(STATES(:,2), 3.00000).*STATES(:,3).*STATES(:,4).*(STATES(:,1) - CONSTANTS(:,19)); ALGEBRAIC(:,17) = piecewise({STATES(:,1)> - 100.000, ( 2.83700.*(exp( 0.0400000.*(STATES(:,1)+77.0000)) - 1.00000))./( (STATES(:,1)+77.0000).*exp( 0.0400000.*(STATES(:,1)+35.0000))) }, 1.00000); ALGEBRAIC(:,18) = CONSTANTS(:,20).*STATES(:,8).*ALGEBRAIC(:,17).*(STATES(:,1) - CONSTANTS(:,21)); ALGEBRAIC(:,19) = 1.02000./(1.00000+exp( 0.238500.*((STATES(:,1) - CONSTANTS(:,22)) - 59.2150))); ALGEBRAIC(:,20) = ( 0.491240.*exp( 0.0803200.*((STATES(:,1)+5.47600) - CONSTANTS(:,22)))+ 1.00000.*exp( 0.0617500.*(STATES(:,1) - (CONSTANTS(:,22)+594.310))))./(1.00000+exp( - 0.514300.*((STATES(:,1) - CONSTANTS(:,22))+4.75300))); ALGEBRAIC(:,21) = ALGEBRAIC(:,19)./(ALGEBRAIC(:,19)+ALGEBRAIC(:,20)); ALGEBRAIC(:,22) = CONSTANTS(:,23).*ALGEBRAIC(:,21).*(STATES(:,1) - CONSTANTS(:,22)); ALGEBRAIC(:,23) = 1.00000./(1.00000+exp((7.48800 - STATES(:,1))./5.98000)); ALGEBRAIC(:,24) = CONSTANTS(:,16).*ALGEBRAIC(:,23).*(STATES(:,1) - CONSTANTS(:,24)); ALGEBRAIC(:,25) = CONSTANTS(:,18).*(STATES(:,1) - CONSTANTS(:,17)); 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