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 =1; end % There are a total of 2 entries in each of the rate and state variable arrays. % There are a total of 34 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('t in component environment (second)'); LEGEND_CONSTANTS(:,1) = strpad('x in component environment (nanometer)'); LEGEND_STATES(:,1) = strpad('n in component Crossbridges_attached (dimensionless)'); LEGEND_STATES(:,2) = strpad('A_c in component Actin_free (dimensionless)'); LEGEND_CONSTANTS(:,24) = strpad('f in component f (per_second)'); LEGEND_CONSTANTS(:,25) = strpad('g in component g (per_second)'); LEGEND_CONSTANTS(:,2) = strpad('h in component Crossbridges_attached (nanometer)'); LEGEND_CONSTANTS(:,3) = strpad('f_1 in component f (per_second)'); LEGEND_CONSTANTS(:,4) = strpad('g_1 in component g (per_second)'); LEGEND_CONSTANTS(:,5) = strpad('g_2 in component g (per_second)'); LEGEND_ALGEBRAIC(:,1) = strpad('Ca_f in component Ca_sarcoplasm (molar)'); LEGEND_CONSTANTS(:,6) = strpad('t_d in component Ca_sarcoplasm (second)'); LEGEND_CONSTANTS(:,7) = strpad('a_1 in component Ca_sarcoplasm (per_second_squared)'); LEGEND_CONSTANTS(:,8) = strpad('b_1 in component Ca_sarcoplasm (per_second_squared)'); LEGEND_CONSTANTS(:,9) = strpad('Ca_0 in component Ca_sarcoplasm (molar)'); LEGEND_CONSTANTS(:,10) = strpad('c_1 in component Actin_free (per_second)'); LEGEND_CONSTANTS(:,27) = strpad('c_2 in component Actin_free (per_second)'); LEGEND_CONSTANTS(:,11) = strpad('c_2_0 in component Actin_free (per_second)'); LEGEND_CONSTANTS(:,12) = strpad('k_i in component Actin_free (dimensionless)'); LEGEND_CONSTANTS(:,26) = strpad('s_h in component s_h (muscle_length)'); LEGEND_CONSTANTS(:,13) = strpad('q in component Actin_free (dimensionless)'); LEGEND_CONSTANTS(:,14) = strpad('AT_0 in component Actin_free (dimensionless)'); LEGEND_CONSTANTS(:,33) = strpad('F_SE in component Series_Elastic_Element (force)'); LEGEND_CONSTANTS(:,15) = strpad('alpha_s in component Series_Elastic_Element (force)'); LEGEND_CONSTANTS(:,16) = strpad('beta_s in component Series_Elastic_Element (muscle_length)'); LEGEND_CONSTANTS(:,32) = strpad('x_s in component SE_constants (muscle_length)'); LEGEND_CONSTANTS(:,17) = strpad('x_so in component Series_Elastic_Element (muscle_length)'); LEGEND_CONSTANTS(:,31) = strpad('X_M_0 in component X_0 (muscle_length)'); LEGEND_CONSTANTS(:,18) = strpad('L_max in component Series_Elastic_Element (muscle_length)'); LEGEND_CONSTANTS(:,29) = strpad('F_PE in component Parallel_Elastic_Element (force)'); LEGEND_CONSTANTS(:,19) = strpad('alpha_p in component Parallel_Elastic_Element (force)'); LEGEND_CONSTANTS(:,20) = strpad('beta_p in component Parallel_Elastic_Element (muscle_length)'); LEGEND_CONSTANTS(:,28) = strpad('x_p in component PE_constants (muscle_length)'); LEGEND_CONSTANTS(:,21) = strpad('x_po in component Parallel_Elastic_Element (muscle_length)'); LEGEND_CONSTANTS(:,34) = strpad('F_CE in component Contractile_Element (force)'); LEGEND_CONSTANTS(:,22) = strpad('F_PL in component s_h (force)'); LEGEND_CONSTANTS(:,30) = strpad('X_S_0 in component X_0 (muscle_length)'); LEGEND_CONSTANTS(:,23) = strpad('F_PL in component X_0 (force)'); LEGEND_RATES(:,1) = strpad('d/dt n in component Crossbridges_attached (dimensionless)'); LEGEND_RATES(:,2) = strpad('d/dt A_c in component Actin_free (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) = 10; STATES(:,1) = 0; STATES(:,2) = 1; CONSTANTS(:,2) = 12; CONSTANTS(:,3) = 70; CONSTANTS(:,4) = 40; CONSTANTS(:,5) = 240; CONSTANTS(:,6) = 0.3; CONSTANTS(:,7) = 200; CONSTANTS(:,8) = 5; CONSTANTS(:,9) = 0.45e-6; CONSTANTS(:,10) = 200e12; CONSTANTS(:,11) = 20; CONSTANTS(:,12) = 30.9; CONSTANTS(:,13) = 1.45; CONSTANTS(:,14) = 2; CONSTANTS(:,15) = 0.1027; CONSTANTS(:,16) = 20; CONSTANTS(:,17) = 0.0387; CONSTANTS(:,18) = 1; CONSTANTS(:,19) = 0.00224; CONSTANTS(:,20) = 20; CONSTANTS(:,21) = 0.221; CONSTANTS(:,22) = 3; CONSTANTS(:,23) = 3; CONSTANTS(:,24) = piecewise({CONSTANTS(:,1)<0.00000, 0.00000 , CONSTANTS(:,1)>=0.00000&CONSTANTS(:,1)=0.00000&CONSTANTS(:,1) req_length strout = strin(1:req_length); else strout = [strin, blanks(req_length - insize)]; end end