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 =7; end % There are a total of 5 entries in each of the rate and state variable arrays. % There are a total of 42 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_CONSTANTS(:,1) = strpad('V_init in component Vstim_para (mV)'); LEGEND_CONSTANTS(:,2) = strpad('V_rate in component Vstim_para (mV_per_s)'); LEGEND_CONSTANTS(:,3) = strpad('Nai in component control_para (mM)'); LEGEND_CONSTANTS(:,4) = strpad('Cai in component control_para (mM)'); LEGEND_CONSTANTS(:,5) = strpad('inhPump in component control_para (dimensionless)'); LEGEND_CONSTANTS(:,6) = strpad('K_Cahalf in component control_para (mV)'); LEGEND_VOI = strpad('time in component time_s (second)'); LEGEND_STATES(:,1) = strpad('V in component vramp_protocol_s (mV)'); LEGEND_ALGEBRAIC(:,7) = strpad('J_VOCC in component J_VOCC (mM_per_s)'); LEGEND_CONSTANTS(:,37) = strpad('J_CaPump in component J_CaPump (mM_per_s)'); LEGEND_ALGEBRAIC(:,1) = strpad('J_NaCa in component J_NaCa (mM_per_s)'); LEGEND_ALGEBRAIC(:,4) = strpad('rho_vCa in component J_VOCC (dimensionless)'); LEGEND_CONSTANTS(:,38) = strpad('K_1 in component K_1 (per_s)'); LEGEND_ALGEBRAIC(:,2) = strpad('stress in component CB4HM (dimensionless)'); LEGEND_ALGEBRAIC(:,3) = strpad('phosphorylation in component CB4HM (dimensionless)'); LEGEND_CONSTANTS(:,7) = strpad('R in component constants (J_per_K_mol)'); LEGEND_CONSTANTS(:,8) = strpad('F in component constants (C_per_mmol)'); LEGEND_CONSTANTS(:,9) = strpad('T in component model_para (kelvin)'); LEGEND_CONSTANTS(:,10) = strpad('Nao in component model_para (mM)'); LEGEND_CONSTANTS(:,11) = strpad('Cao in component model_para (mM)'); LEGEND_CONSTANTS(:,12) = strpad('V_cell in component model_para (fm3)'); LEGEND_CONSTANTS(:,13) = strpad('V_Cahalf in component model_para (mV)'); LEGEND_CONSTANTS(:,14) = strpad('g_mCa in component model_para (nS)'); LEGEND_CONSTANTS(:,15) = strpad('V_pmax in component model_para (mM_per_s)'); LEGEND_CONSTANTS(:,16) = strpad('n in component model_para (dimensionless)'); LEGEND_CONSTANTS(:,17) = strpad('K_ph in component model_para (mM)'); LEGEND_CONSTANTS(:,18) = strpad('K_NaCa in component model_para (mM)'); LEGEND_CONSTANTS(:,19) = strpad('G_NaCa in component model_para (mM_per_s_mV)'); LEGEND_CONSTANTS(:,20) = strpad('n_M in component model_para (dimensionless)'); LEGEND_CONSTANTS(:,21) = strpad('Ca_halfMLCK in component model_para (mM)'); LEGEND_CONSTANTS(:,22) = strpad('M_init in component initials (dimensionless)'); LEGEND_CONSTANTS(:,23) = strpad('Mp_init in component initials (dimensionless)'); LEGEND_CONSTANTS(:,24) = strpad('AM_init in component initials (dimensionless)'); LEGEND_CONSTANTS(:,25) = strpad('AMp_init in component initials (dimensionless)'); LEGEND_CONSTANTS(:,26) = strpad('K_7 in component model_para (per_s)'); LEGEND_CONSTANTS(:,27) = strpad('K_2 in component model_para (per_s)'); LEGEND_CONSTANTS(:,28) = strpad('K_3 in component model_para (per_s)'); LEGEND_CONSTANTS(:,29) = strpad('K_4 in component model_para (per_s)'); LEGEND_CONSTANTS(:,30) = strpad('K_5 in component model_para (per_s)'); LEGEND_CONSTANTS(:,31) = strpad('Nai in component model_para (mM)'); LEGEND_CONSTANTS(:,32) = strpad('K_Cahalf in component model_para (mV)'); LEGEND_CONSTANTS(:,33) = strpad('inhPump in component model_para (dimensionless)'); LEGEND_CONSTANTS(:,34) = strpad('Cai_init in component initials (mM)'); LEGEND_CONSTANTS(:,35) = strpad('z_Ca in component E_Ca (dimensionless)'); LEGEND_CONSTANTS(:,40) = strpad('E in component Nernst_potential (mV)'); LEGEND_CONSTANTS(:,36) = strpad('z_Na in component E_Na (dimensionless)'); LEGEND_CONSTANTS(:,39) = strpad('E in component Nernst_potential (mV)'); LEGEND_ALGEBRAIC(:,6) = strpad('I in component Ionic_currents (pA)'); LEGEND_CONSTANTS(:,41) = strpad('V_mNaCa in component J_NaCa (mV)'); LEGEND_ALGEBRAIC(:,5) = strpad('norm in component CB4HM (dimensionless)'); LEGEND_STATES(:,2) = strpad('M in component CB4HM (dimensionless)'); LEGEND_STATES(:,3) = strpad('Mp in component CB4HM (dimensionless)'); LEGEND_STATES(:,4) = strpad('AM in component CB4HM (dimensionless)'); LEGEND_STATES(:,5) = strpad('AMp in component CB4HM (dimensionless)'); LEGEND_RATES(:,1) = strpad('d/dt V in component vramp_protocol_s (mV)'); LEGEND_RATES(:,2) = strpad('d/dt M in component CB4HM (dimensionless)'); LEGEND_RATES(:,3) = strpad('d/dt Mp in component CB4HM (dimensionless)'); LEGEND_RATES(:,4) = strpad('d/dt AM in component CB4HM (dimensionless)'); LEGEND_RATES(:,5) = strpad('d/dt AMp in component CB4HM (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) = -100; CONSTANTS(:,2) = 1; CONSTANTS(:,3) = 16.55; CONSTANTS(:,4) = 0.0001; CONSTANTS(:,5) = 1; CONSTANTS(:,6) = 11; CONSTANTS(:,7) = 8.314; CONSTANTS(:,8) = 96.48534; CONSTANTS(:,9) = 310; CONSTANTS(:,10) = 140; CONSTANTS(:,11) = 2; CONSTANTS(:,12) = 21; CONSTANTS(:,13) = -27; CONSTANTS(:,14) = 0.046842; CONSTANTS(:,15) = 5.1449e-4; CONSTANTS(:,16) = 1.9015; CONSTANTS(:,17) = 0.6e-3; CONSTANTS(:,18) = 7e-3; CONSTANTS(:,19) = 5.7297e-5; CONSTANTS(:,20) = 8.7613; CONSTANTS(:,21) = 256.98e-6; CONSTANTS(:,22) = 1; CONSTANTS(:,23) = 0; CONSTANTS(:,24) = 0; CONSTANTS(:,25) = 0; CONSTANTS(:,26) = 0.0378; CONSTANTS(:,27) = 1.2387; CONSTANTS(:,28) = 0.1419; CONSTANTS(:,29) = 0.035475; CONSTANTS(:,30) = 1.2387; CONSTANTS(:,31) = 2.9836; CONSTANTS(:,32) = 11; CONSTANTS(:,33) = 1; CONSTANTS(:,34) = 0.1e-6; CONSTANTS(:,35) = 2; CONSTANTS(:,36) = 1; CONSTANTS(:,37) = ( - CONSTANTS(:,15).*power(CONSTANTS(:,4), CONSTANTS(:,16)))./(power(CONSTANTS(:,17), CONSTANTS(:,16))+power(CONSTANTS(:,4), CONSTANTS(:,16))); CONSTANTS(:,38) = (power(CONSTANTS(:,4), CONSTANTS(:,20))./(power(CONSTANTS(:,21), CONSTANTS(:,20))+power(CONSTANTS(:,4), CONSTANTS(:,20)))).*1.00000; CONSTANTS(:,39) = (( CONSTANTS(:,7).*CONSTANTS(:,9))./( CONSTANTS(:,36).*CONSTANTS(:,8))).*log(CONSTANTS(:,10)./CONSTANTS(:,3)); CONSTANTS(:,41) = CONSTANTS(:,2); CONSTANTS(:,40) = (( CONSTANTS(:,7).*CONSTANTS(:,9))./( CONSTANTS(:,35).*CONSTANTS(:,8))).*log(CONSTANTS(:,11)./CONSTANTS(:,4)); CONSTANTS(:,41) = 3.00000.*CONSTANTS(:,39) - 2.00000.*CONSTANTS(:,40); STATES(:,1) = CONSTANTS(:,1); STATES(:,2) = CONSTANTS(:,22); STATES(:,3) = CONSTANTS(:,23); STATES(:,4) = CONSTANTS(:,24); STATES(:,5) = CONSTANTS(:,25); 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(:,1) = CONSTANTS(:,41); ALGEBRAIC(:,5) = STATES(:,2)+STATES(:,3)+STATES(:,4)+STATES(:,5); RATES(:,2) = ( - CONSTANTS(:,38).*STATES(:,2))./ALGEBRAIC(:,5)+( CONSTANTS(:,27).*STATES(:,3))./ALGEBRAIC(:,5)+( CONSTANTS(:,26).*STATES(:,4))./ALGEBRAIC(:,5); RATES(:,3) = (( CONSTANTS(:,29).*STATES(:,5))./ALGEBRAIC(:,5)+( CONSTANTS(:,38).*STATES(:,2))./ALGEBRAIC(:,5)) - ( (CONSTANTS(:,27)+CONSTANTS(:,28)).*STATES(:,3))./ALGEBRAIC(:,5); RATES(:,4) = ( CONSTANTS(:,30).*STATES(:,5))./ALGEBRAIC(:,5) - ( (CONSTANTS(:,38)+CONSTANTS(:,26)).*STATES(:,4))./ALGEBRAIC(:,5); RATES(:,5) = (( CONSTANTS(:,28).*STATES(:,3))./ALGEBRAIC(:,5)+( CONSTANTS(:,38).*STATES(:,4))./ALGEBRAIC(:,5)) - ( (CONSTANTS(:,29)+CONSTANTS(:,30)).*STATES(:,5))./ALGEBRAIC(:,5); 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) = STATES(:,2)+STATES(:,3)+STATES(:,4)+STATES(:,5); ALGEBRAIC(:,1) = (( CONSTANTS(:,19).*CONSTANTS(:,4))./(CONSTANTS(:,4)+CONSTANTS(:,18))).*(STATES(:,1) - CONSTANTS(:,41)); ALGEBRAIC(:,2) = STATES(:,5)+STATES(:,4); ALGEBRAIC(:,3) = STATES(:,5)+STATES(:,3); ALGEBRAIC(:,4) = 1.00000./(1.00000+exp((CONSTANTS(:,13) - STATES(:,1))./CONSTANTS(:,6))); ALGEBRAIC(:,6) = CONSTANTS(:,14).*ALGEBRAIC(:,4).*(STATES(:,1) - CONSTANTS(:,40)); ALGEBRAIC(:,7) = - ALGEBRAIC(:,6)./( 2.00000.*CONSTANTS(:,12).*CONSTANTS(:,8)); 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