www.gusucode.com > simbio 案例源码程序 matlab代码 > simbio/CreateARateRuleForAnExponentialRateOfChangeExample.m
%% Create a Rate Rule for an Exponential Rate of Change % This example shows how to change the amount of a species similar to a % first-order reaction using the first-order rate rule. For example, suppose % the species |x| decays exponentially. The rate of change of species |x| % is: % % $$dx/dt=-k*x$ % % The analytical solution is: % % $$C_t=C_0*e^{-kt}$ % % where $$C_t$ is the amount of species at time t, and $$C_0$ is the initial % amount. % Use the following commands to set up a SimBiology model accordingly and % simulate it. % Copyright 2015 The MathWorks, Inc. m = sbiomodel('m'); c = addcompartment(m,'comp'); s = addspecies(m,'x','InitialAmount',2); p = addparameter(m,'k','Value',1); r = addrule(m,'x = -k * x','RuleType','rate'); [t,sd,species] = sbiosimulate(m); plot(t,sd); legend(species); xlabel('Time'); ylabel('Species Amount'); %% % If the amount of a species |x| is determined by a rate rule and |x| is % also in a reaction, |x| must have its <docid:simbio_ref.bqcdxi4-1> property set to % |true|. For example, with a reaction |a -> x| and a rate rule ${{dx} % \over {dt}} = k*x$, set the <docid:simbio_ref.bqcdxi4-1> property of species |x| % to |true| so that a differential rate term is not created from the % reaction. The amount of |x| is determined solely by a differential rate % term from the rate rule. If the <docid:simbio_ref.bqcdxi4-1> property is set to % |false|, you will get the following error message such as |Invalid rule % variable 'x' in rate rule or reaction|.