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 =17; end % There are a total of 5 entries in each of the rate and state variable arrays. % There are a total of 25 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 (ms)'); LEGEND_ALGEBRAIC(:,2) = strpad('Ca_i in component intracellular_ion_concentrations (mM)'); LEGEND_ALGEBRAIC(:,1) = strpad('Ca_b in component intracellular_ion_concentrations (mM)'); LEGEND_STATES(:,1) = strpad('TRPN in component intracellular_ion_concentrations (mM)'); LEGEND_CONSTANTS(:,1) = strpad('Ca_TRPN_Max in component troponin (mM)'); LEGEND_ALGEBRAIC(:,17) = strpad('J_TRPN in component troponin (mM_per_ms)'); LEGEND_STATES(:,2) = strpad('z in component tropomyosin (dimensionless)'); LEGEND_ALGEBRAIC(:,10) = strpad('z_max in component tropomyosin (dimensionless)'); LEGEND_CONSTANTS(:,2) = strpad('k_on in component troponin (per_mM_per_ms)'); LEGEND_CONSTANTS(:,3) = strpad('k_Ref_off in component troponin (per_ms)'); LEGEND_CONSTANTS(:,4) = strpad('gamma_trpn in component troponin (dimensionless)'); LEGEND_CONSTANTS(:,5) = strpad('alpha_0 in component tropomyosin (per_ms)'); LEGEND_CONSTANTS(:,6) = strpad('alpha_r1 in component tropomyosin (per_ms)'); LEGEND_CONSTANTS(:,7) = strpad('alpha_r2 in component tropomyosin (per_ms)'); LEGEND_CONSTANTS(:,8) = strpad('n_Rel in component tropomyosin (dimensionless)'); LEGEND_CONSTANTS(:,9) = strpad('K_z in component tropomyosin (dimensionless)'); LEGEND_CONSTANTS(:,10) = strpad('n_Hill in component tropomyosin (dimensionless)'); LEGEND_CONSTANTS(:,11) = strpad('Ca_50ref in component tropomyosin (mM)'); LEGEND_CONSTANTS(:,12) = strpad('z_p in component tropomyosin (dimensionless)'); LEGEND_CONSTANTS(:,13) = strpad('beta_1 in component tropomyosin (dimensionless)'); LEGEND_ALGEBRAIC(:,7) = strpad('Ca_50 in component tropomyosin (mM)'); LEGEND_ALGEBRAIC(:,8) = strpad('Ca_TRPN_50 in component tropomyosin (mM)'); LEGEND_CONSTANTS(:,23) = strpad('K_2 in component tropomyosin (per_ms)'); LEGEND_CONSTANTS(:,25) = strpad('K_1 in component tropomyosin (per_ms)'); LEGEND_ALGEBRAIC(:,9) = strpad('alpha_Tm in component tropomyosin (per_ms)'); LEGEND_ALGEBRAIC(:,3) = strpad('beta_Tm in component tropomyosin (per_ms)'); LEGEND_CONSTANTS(:,14) = strpad('beta_0 in component filament_overlap (dimensionless)'); LEGEND_ALGEBRAIC(:,5) = strpad('lambda in component Myofilaments (dimensionless)'); LEGEND_ALGEBRAIC(:,16) = strpad('k_off in component troponin (per_ms)'); LEGEND_ALGEBRAIC(:,15) = strpad('Tension in component Cross_Bridges (N_per_mm2)'); LEGEND_CONSTANTS(:,15) = strpad('T_ref in component length_independent_tension (N_per_mm2)'); LEGEND_ALGEBRAIC(:,4) = strpad('ExtensionRatio in component Myofilaments (dimensionless)'); LEGEND_CONSTANTS(:,24) = strpad('dExtensionRatiodt in component Myofilaments (per_ms)'); LEGEND_ALGEBRAIC(:,6) = strpad('lambda_prev in component Myofilaments (dimensionless)'); LEGEND_ALGEBRAIC(:,11) = strpad('overlap in component filament_overlap (dimensionless)'); LEGEND_ALGEBRAIC(:,12) = strpad('T_Base in component length_independent_tension (N_per_mm2)'); LEGEND_ALGEBRAIC(:,13) = strpad('T_0 in component isometric_tension (N_per_mm2)'); LEGEND_ALGEBRAIC(:,14) = strpad('Q in component Cross_Bridges (dimensionless)'); LEGEND_CONSTANTS(:,16) = strpad('a in component Cross_Bridges (dimensionless)'); LEGEND_STATES(:,3) = strpad('Q_1 in component Cross_Bridges (dimensionless)'); LEGEND_STATES(:,4) = strpad('Q_2 in component Cross_Bridges (dimensionless)'); LEGEND_STATES(:,5) = strpad('Q_3 in component Cross_Bridges (dimensionless)'); LEGEND_CONSTANTS(:,17) = strpad('A_1 in component Cross_Bridges (dimensionless)'); LEGEND_CONSTANTS(:,18) = strpad('A_2 in component Cross_Bridges (dimensionless)'); LEGEND_CONSTANTS(:,19) = strpad('A_3 in component Cross_Bridges (dimensionless)'); LEGEND_CONSTANTS(:,20) = strpad('alpha_1 in component Cross_Bridges (per_ms)'); LEGEND_CONSTANTS(:,21) = strpad('alpha_2 in component Cross_Bridges (per_ms)'); LEGEND_CONSTANTS(:,22) = strpad('alpha_3 in component Cross_Bridges (per_ms)'); LEGEND_RATES(:,1) = strpad('d/dt TRPN in component intracellular_ion_concentrations (mM)'); LEGEND_RATES(:,2) = strpad('d/dt z in component tropomyosin (dimensionless)'); LEGEND_RATES(:,3) = strpad('d/dt Q_1 in component Cross_Bridges (dimensionless)'); LEGEND_RATES(:,4) = strpad('d/dt Q_2 in component Cross_Bridges (dimensionless)'); LEGEND_RATES(:,5) = strpad('d/dt Q_3 in component Cross_Bridges (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 = []; STATES(:,1) = 0.067593139865; CONSTANTS(:,1) = 70e-3; STATES(:,2) = 0.014417937837; CONSTANTS(:,2) = 100; CONSTANTS(:,3) = 0.2; CONSTANTS(:,4) = 2; CONSTANTS(:,5) = 8e-3; CONSTANTS(:,6) = 2e-3; CONSTANTS(:,7) = 1.75e-3; CONSTANTS(:,8) = 3; CONSTANTS(:,9) = 0.15; CONSTANTS(:,10) = 3; CONSTANTS(:,11) = 1.05e-3; CONSTANTS(:,12) = 0.85; CONSTANTS(:,13) = -4; CONSTANTS(:,14) = 4.9; CONSTANTS(:,15) = 56.2; CONSTANTS(:,16) = 0.35; STATES(:,3) = 0; STATES(:,4) = 0; STATES(:,5) = 0; CONSTANTS(:,17) = -29; CONSTANTS(:,18) = 138; CONSTANTS(:,19) = 129; CONSTANTS(:,20) = 0.03; CONSTANTS(:,21) = 0.13; CONSTANTS(:,22) = 0.625; CONSTANTS(:,23) = (( CONSTANTS(:,7).*power(CONSTANTS(:,12), CONSTANTS(:,8)))./(power(CONSTANTS(:,12), CONSTANTS(:,8))+power(CONSTANTS(:,9), CONSTANTS(:,8)))).*(1.00000 - ( CONSTANTS(:,8).*power(CONSTANTS(:,9), CONSTANTS(:,8)))./(power(CONSTANTS(:,12), CONSTANTS(:,8))+power(CONSTANTS(:,9), CONSTANTS(:,8)))); CONSTANTS(:,24) = 0.00000; CONSTANTS(:,25) = ( CONSTANTS(:,7).*power(CONSTANTS(:,12), CONSTANTS(:,8) - 1.00000).*CONSTANTS(:,8).*power(CONSTANTS(:,9), CONSTANTS(:,8)))./power(power(CONSTANTS(:,12), CONSTANTS(:,8))+power(CONSTANTS(:,9), CONSTANTS(:,8)), 2.00000); 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(:,3) = CONSTANTS(:,17).*CONSTANTS(:,24) - CONSTANTS(:,20).*STATES(:,3); RATES(:,4) = CONSTANTS(:,18).*CONSTANTS(:,24) - CONSTANTS(:,21).*STATES(:,4); RATES(:,5) = CONSTANTS(:,19).*CONSTANTS(:,24) - CONSTANTS(:,22).*STATES(:,5); ALGEBRAIC(:,1) = CONSTANTS(:,1) - STATES(:,1); ALGEBRAIC(:,4) = piecewise({VOI>1000.00, 1.00000 }, 1.00000); ALGEBRAIC(:,5) = piecewise({ALGEBRAIC(:,4)>0.800000&ALGEBRAIC(:,4)<=1.15000, ALGEBRAIC(:,4) , ALGEBRAIC(:,4)>1.15000, 1.15000 }, 0.800000); ALGEBRAIC(:,7) = CONSTANTS(:,11).*(1.00000+ CONSTANTS(:,13).*(ALGEBRAIC(:,5) - 1.00000)); ALGEBRAIC(:,8) = ( ALGEBRAIC(:,7).*CONSTANTS(:,1))./(ALGEBRAIC(:,7)+ (CONSTANTS(:,3)./CONSTANTS(:,2)).*(1.00000 - ( (1.00000+ CONSTANTS(:,14).*(ALGEBRAIC(:,5) - 1.00000)).*0.500000)./CONSTANTS(:,4))); ALGEBRAIC(:,9) = CONSTANTS(:,5).*power(ALGEBRAIC(:,1)./ALGEBRAIC(:,8), CONSTANTS(:,10)); ALGEBRAIC(:,3) = CONSTANTS(:,6)+( CONSTANTS(:,7).*power(STATES(:,2), CONSTANTS(:,8) - 1.00000))./(power(STATES(:,2), CONSTANTS(:,8))+power(CONSTANTS(:,9), CONSTANTS(:,8))); RATES(:,2) = ALGEBRAIC(:,9).*(1.00000 - STATES(:,2)) - ALGEBRAIC(:,3).*STATES(:,2); ALGEBRAIC(:,2) = piecewise({VOI<1.00000, 1000.00.*1.84330e-07 , VOI>=10.0000&VOI<15.0000, 1000.00.*((( 1.05500.*power(VOI./1000.00, 3.00000) - 0.0350700.*power(VOI./1000.00, 2.00000))+( 0.000399200.*VOI)./1000.00) - 1.35600e-06) , VOI>=15.0000&VOI<55.0000, 1000.00.*((( 0.0140000.*power(VOI./1000.00, 3.00000) - 0.00255500.*power(VOI./1000.00, 2.00000))+( 0.000149400.*VOI)./1000.00) - 1.42800e-06) , VOI>=55.0000&VOI<250.000, 1000.00.*((( 1.73900e-05.*power(VOI./1000.00, 3.00000) - 3.20900e-06.*power(VOI./1000.00, 2.00000)) - ( 5.68900e-06.*VOI)./1000.00)+1.71900e-06) , VOI>=250.000&VOI<490.000, 1000.00.*(((( 0.000132100.*power(VOI./1000.00, 4.00000) - 0.000219700.*power(VOI./1000.00, 3.00000))+ 0.000137400.*power(VOI./1000.00, 2.00000)) - ( 3.89500e-05.*VOI)./1000.00)+4.44100e-06) }, 1000.00.*1.21480e-07); ALGEBRAIC(:,11) = 1.00000+ CONSTANTS(:,14).*(ALGEBRAIC(:,5) - 1.00000); ALGEBRAIC(:,10) = (CONSTANTS(:,5)./power(ALGEBRAIC(:,8)./CONSTANTS(:,1), CONSTANTS(:,10)) - CONSTANTS(:,23))./(CONSTANTS(:,6)+CONSTANTS(:,25)+CONSTANTS(:,5)./power(ALGEBRAIC(:,8)./CONSTANTS(:,1), CONSTANTS(:,10))); ALGEBRAIC(:,12) = ( CONSTANTS(:,15).*STATES(:,2))./ALGEBRAIC(:,10); ALGEBRAIC(:,13) = ALGEBRAIC(:,12).*ALGEBRAIC(:,11); ALGEBRAIC(:,14) = STATES(:,3)+STATES(:,4)+STATES(:,5); ALGEBRAIC(:,15) = piecewise({ALGEBRAIC(:,14)<0.00000, ( ALGEBRAIC(:,13).*( CONSTANTS(:,16).*ALGEBRAIC(:,14)+1.00000))./(1.00000 - ALGEBRAIC(:,14)) }, ( ALGEBRAIC(:,13).*(1.00000+ (CONSTANTS(:,16)+2.00000).*ALGEBRAIC(:,14)))./(1.00000+ALGEBRAIC(:,14))); ALGEBRAIC(:,16) = piecewise({1.00000 - ALGEBRAIC(:,15)./( CONSTANTS(:,4).*CONSTANTS(:,15))>0.100000, CONSTANTS(:,3).*(1.00000 - ALGEBRAIC(:,15)./( CONSTANTS(:,4).*CONSTANTS(:,15))) }, CONSTANTS(:,3).*0.100000); ALGEBRAIC(:,17) = (CONSTANTS(:,1) - STATES(:,1)).*ALGEBRAIC(:,16) - ALGEBRAIC(:,2).*STATES(:,1).*CONSTANTS(:,2); RATES(:,1) = ALGEBRAIC(:,17); 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(:,1) - STATES(:,1); ALGEBRAIC(:,4) = piecewise({VOI>1000.00, 1.00000 }, 1.00000); ALGEBRAIC(:,5) = piecewise({ALGEBRAIC(:,4)>0.800000&ALGEBRAIC(:,4)<=1.15000, ALGEBRAIC(:,4) , ALGEBRAIC(:,4)>1.15000, 1.15000 }, 0.800000); ALGEBRAIC(:,7) = CONSTANTS(:,11).*(1.00000+ CONSTANTS(:,13).*(ALGEBRAIC(:,5) - 1.00000)); ALGEBRAIC(:,8) = ( ALGEBRAIC(:,7).*CONSTANTS(:,1))./(ALGEBRAIC(:,7)+ (CONSTANTS(:,3)./CONSTANTS(:,2)).*(1.00000 - ( (1.00000+ CONSTANTS(:,14).*(ALGEBRAIC(:,5) - 1.00000)).*0.500000)./CONSTANTS(:,4))); ALGEBRAIC(:,9) = CONSTANTS(:,5).*power(ALGEBRAIC(:,1)./ALGEBRAIC(:,8), CONSTANTS(:,10)); ALGEBRAIC(:,3) = CONSTANTS(:,6)+( CONSTANTS(:,7).*power(STATES(:,2), CONSTANTS(:,8) - 1.00000))./(power(STATES(:,2), CONSTANTS(:,8))+power(CONSTANTS(:,9), CONSTANTS(:,8))); ALGEBRAIC(:,2) = piecewise({VOI<1.00000, 1000.00.*1.84330e-07 , VOI>=10.0000&VOI<15.0000, 1000.00.*((( 1.05500.*power(VOI./1000.00, 3.00000) - 0.0350700.*power(VOI./1000.00, 2.00000))+( 0.000399200.*VOI)./1000.00) - 1.35600e-06) , VOI>=15.0000&VOI<55.0000, 1000.00.*((( 0.0140000.*power(VOI./1000.00, 3.00000) - 0.00255500.*power(VOI./1000.00, 2.00000))+( 0.000149400.*VOI)./1000.00) - 1.42800e-06) , VOI>=55.0000&VOI<250.000, 1000.00.*((( 1.73900e-05.*power(VOI./1000.00, 3.00000) - 3.20900e-06.*power(VOI./1000.00, 2.00000)) - ( 5.68900e-06.*VOI)./1000.00)+1.71900e-06) , VOI>=250.000&VOI<490.000, 1000.00.*(((( 0.000132100.*power(VOI./1000.00, 4.00000) - 0.000219700.*power(VOI./1000.00, 3.00000))+ 0.000137400.*power(VOI./1000.00, 2.00000)) - ( 3.89500e-05.*VOI)./1000.00)+4.44100e-06) }, 1000.00.*1.21480e-07); ALGEBRAIC(:,11) = 1.00000+ CONSTANTS(:,14).*(ALGEBRAIC(:,5) - 1.00000); ALGEBRAIC(:,10) = (CONSTANTS(:,5)./power(ALGEBRAIC(:,8)./CONSTANTS(:,1), CONSTANTS(:,10)) - CONSTANTS(:,23))./(CONSTANTS(:,6)+CONSTANTS(:,25)+CONSTANTS(:,5)./power(ALGEBRAIC(:,8)./CONSTANTS(:,1), CONSTANTS(:,10))); ALGEBRAIC(:,12) = ( CONSTANTS(:,15).*STATES(:,2))./ALGEBRAIC(:,10); ALGEBRAIC(:,13) = ALGEBRAIC(:,12).*ALGEBRAIC(:,11); ALGEBRAIC(:,14) = STATES(:,3)+STATES(:,4)+STATES(:,5); ALGEBRAIC(:,15) = piecewise({ALGEBRAIC(:,14)<0.00000, ( ALGEBRAIC(:,13).*( CONSTANTS(:,16).*ALGEBRAIC(:,14)+1.00000))./(1.00000 - ALGEBRAIC(:,14)) }, ( ALGEBRAIC(:,13).*(1.00000+ (CONSTANTS(:,16)+2.00000).*ALGEBRAIC(:,14)))./(1.00000+ALGEBRAIC(:,14))); ALGEBRAIC(:,16) = piecewise({1.00000 - ALGEBRAIC(:,15)./( CONSTANTS(:,4).*CONSTANTS(:,15))>0.100000, CONSTANTS(:,3).*(1.00000 - ALGEBRAIC(:,15)./( CONSTANTS(:,4).*CONSTANTS(:,15))) }, CONSTANTS(:,3).*0.100000); ALGEBRAIC(:,17) = (CONSTANTS(:,1) - STATES(:,1)).*ALGEBRAIC(:,16) - ALGEBRAIC(:,2).*STATES(:,1).*CONSTANTS(:,2); ALGEBRAIC(:,6) = ALGEBRAIC(:,4); 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