Abstract
This chapter presents many mathematical models that all end up with ODEs of the type \(u^{\prime}=au+b\). The applications are taken from biology, finance, and physics, and cover population growth or decay, interacting predatorprey populations, compound interest and inflation, radioactive decay, chemical and biochemical reaction, spreading of diseases, cooling of objects, compaction of geological media, pressure variations in the atmosphere, viscoelastic response in materials, and air resistance on falling or rising bodies.
You have full access to this open access chapter, Download chapter PDF
Keywords
 Compound Interest
 Central Finite Difference Approximation
 Binomial Experiment
 Geometric Mean Approximation
 Quadratic Drag
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.
This chapter presents many mathematical models that all end up with ODEs of the type \(u^{\prime}=au+b\). The applications are taken from biology, finance, and physics, and cover population growth or decay, interacting predatorprey populations, compound interest and inflation, radioactive decay, chemical and biochemical reaction, spreading of diseases, cooling of objects, compaction of geological media, pressure variations in the atmosphere, viscoelastic response in materials, and air resistance on falling or rising bodies.
Before we turn to the applications, however, we take aÂ brief look at the technique of scaling, which is so useful in many applications.
4.1 Scaling
Real applications of aÂ model \(u^{\prime}=au+b\) will often involve aÂ lot of parameters in the expressions for a and b. It can be quite aÂ challenge to find relevant values of all parameters. In simple problems, however, it turns out that it is not always necessary to estimate all parameters because we can lump them into one or aÂ few dimensionless numbers by using aÂ very attractive technique called scaling. It simply means to stretch the u and t axis in the present problem â€“ and suddenly all parameters in the problem are lumped into one parameter if \(b\neq 0\) and no parameter when bâ€‰=â€‰0!
4.1.1 Dimensionless Variables
Scaling means that we introduce aÂ new function \(\bar{u}(\bar{t})\), with
where u_{m} is aÂ characteristic value of u, u_{c} is aÂ characteristic size of the range of u values, and t_{c} is aÂ characteristic size of the range of t where u shows significant variation. Choosing u_{m}, u_{c}, and t_{c} is not always easy and is often an art in complicated problems. We just state one choice first:
Inserting \(u=u_{m}+u_{c}\bar{u}\) and \(t=t_{c}\bar{t}\) in the problem \(u^{\prime}=au+b\), assuming a and b are constants, results (after some algebra) in the scaled problem
where
4.1.2 Dimensionless Numbers
The parameter Î² is aÂ dimensionless number. From the equation we see that b must have the same unit as the term au. The initial condition I must have the same unit as u, so Ia has the same unit as b, making the fraction \(b/(Ia)\) dimensionless.
An important observation is that \(\bar{u}\) depends on \(\bar{t}\) and Î². That is, only the special combination of \(b/(Ia)\) matters, not what the individual values of b, a, and I are. The original unscaled function u depends on t, b, a, and I.
AÂ second observation is striking: if bâ€‰=â€‰0, the scaled problem is independent of a and I! In practice this means that we can perform aÂ single numerical simulation of the scaled problem and recover the solution of any problem for aÂ given a and I by stretching the axis in the plot: \(u=I\bar{u}\) and \(t=\bar{t}/a\). For \(b\neq 0\), we simulate the scaled problem for aÂ few Î² values and recover the physical solution u by translating and stretching the u axis and stretching the t axis.
In general, scaling combines the parameters in aÂ problem to aÂ set of dimensionless parameters. The number of dimensionless parameters is usually much smaller than the number of original parameters. SectionÂ 4.11 presents an example where 11 parameters are reduced to one!
4.1.3 AÂ Scaling for Vanishing Initial Condition
The scaling breaks down if Iâ€‰=â€‰0. In that case we may choose \(u_{m}=0\), \(u_{c}=b/a\), and \(t_{c}=1/b\), resulting in aÂ slightly different scaled problem:
As with bâ€‰=â€‰0, the case Iâ€‰=â€‰0 has aÂ scaled problem with no physical parameters!
It is common to drop the bars after scaling and write the scaled problem as \(u^{\prime}=u\), \(u(0)=1\beta\), or \(u^{\prime}=1u\), \(u(0)=0\). Any implementation of the problem \(u^{\prime}=au+b\), \(u(0)=I\), can be reused for the scaled problem by setting aâ€‰=â€‰1, bâ€‰=â€‰0, and \(I=1\beta\) in the code, if \(I\neq 0\), or one sets aâ€‰=â€‰1, bâ€‰=â€‰1, and Iâ€‰=â€‰0 when the physical I is zero. Falling bodies in fluids, as described in Sect.Â 4.11, involves \(u^{\prime}=au+b\) with seven physical parameters. All these vanish in the scaled version of the problem if we start the motion from rest!
Many more details about scaling are presented in the authorâ€™s book Scaling of Differential Equations [9].
4.2 Evolution of aÂ Population
4.2.1 Exponential Growth
Let N be the number of individuals in aÂ population occupying some spatial domain. Despite N being an integer in this problem, we shall compute with N as aÂ real number and view \(N(t)\) as aÂ continuous function of time. The basic model assumption is that in aÂ time interval \(\Delta t\) the number of newcomers to the populations (newborns) is proportional to N, with proportionality constant \(\bar{b}\). The amount of newcomers will increase the population and result in
It is obvious that aÂ long time interval \(\Delta t\) will result in more newcomers and hence aÂ larger \(\bar{b}\). Therefore, we introduce \(b=\bar{b}/\Delta t\): the number of newcomers per unit time and per individual. We must then multiply b by the length of the time interval considered and by the population size to get the total number of new individuals, \(b\Delta tN\).
If the number of removals from the population (deaths) is also proportional to N, with proportionality constant \(d\Delta t\), the population evolves according to
Dividing by \(\Delta t\) and letting \(\Delta t\rightarrow 0\), we get the ODE
In aÂ population where the death rate (d) is larger than then newborn rate (b), \(bd<0\), and the population experiences exponential decay rather than exponential growth.
In some populations there is an immigration of individuals into the spatial domain. With I individuals coming in per time unit, the equation for the population change becomes
The corresponding ODE reads
Emigration is also modeled by this I term if we just change its sign: Iâ€‰<â€‰0. So, the I term models migration in and out of the domain in general.
Some simplification arises if we introduce aÂ fractional measure of the population: \(u=N/N_{0}\) and set \(r=bd\). The ODE problem now becomes
where \(f=I/N_{0}\) measures the net immigration per time unit as the fraction of the initial population. Very often, r is approximately constant, but f is usually aÂ function of time.
4.2.2 Logistic Growth
The growth rate r of aÂ population decreases if the environment has limited resources. Suppose the environment can sustain at most \(N_{\max}\) individuals. We may then assume that the growth rate approaches zero as N approaches \(N_{\max}\), i.e., as u approaches \(M=N_{\max}/N_{0}\). The simplest possible evolution of r is then aÂ linear function: \(r(t)={\varrho}(1u(t)/M)\), where \(\varrho\) is the initial growth rate when the population is small relative to the maximum size and there is enough resources. Using this \(r(t)\) in (Ch4.E3) results in the logistic model for the evolution of aÂ population (assuming for the moment that fâ€‰=â€‰0):
Initially, u will grow at rate \(\varrho\), but the growth will decay as u approaches M, and then there is no more change in u, causing \(u\rightarrow M\) as \(t\rightarrow\infty\). Note that the logistic equation \(u^{\prime}={\varrho}(1u/M)u\) is nonlinear because of the quadratic term \(u^{2}{\varrho}/M\).
4.3 Compound Interest and Inflation
Say the annual interest rate is r percent and that the bank adds the interest once aÂ year to your investment. If u^{n} is the investment in year n, the investment in year \(u^{n+1}\) grows to
In reality, the interest rate is added every day. We therefore introduce aÂ parameter m for the number of periods per year when the interest is added. If n counts the periods, we have the fundamental model for compound interest:
This model is aÂ difference equation, but it can be transformed to aÂ continuous differential equation through aÂ limit process. The first step is to derive aÂ formula for the growth of the investment over aÂ time t. Starting with an investment u^{0}, and assuming that r is constant in time, we get
Introducing time t, which here is aÂ realnumbered counter for years, we have that \(n=mt\), so we can write
The second step is to assume continuous compounding, meaning that the interest is added continuously. This implies \(m\rightarrow\infty\), and in the limit one gets the formula
which is nothing but the solution of the ODE problem
This is then taken as the ODE model for compound interest if râ€‰>â€‰0. However, the reasoning applies equally well to inflation, which is just the case râ€‰<â€‰0. One may also take the r in (Ch4.E7) as the net growth of an investment, where r takes both compound interest and inflation into account. Note that for real applications we must use aÂ timedependent r in (Ch4.E7).
Introducing \(a=\frac{r}{100}\), continuous inflation of an initial fortune I is then aÂ process exhibiting exponential decay according to
4.4 Newtonâ€™s Law of Cooling
When aÂ body at some temperature is placed in aÂ cooling environment, experience shows that the temperature falls rapidly in the beginning, and then the change in temperature levels off until the bodyâ€™s temperature equals that of the surroundings. Newton carried out some experiments on cooling hot iron and found that the temperature evolved as a â€˜â€˜geometric progression at times in arithmetic progressionâ€™â€™, meaning that the temperature decayed exponentially. Later, this result was formulated as aÂ differential equation: the rate of change of the temperature in aÂ body is proportional to the temperature difference between the body and its surroundings. This statement is known as Newtonâ€™s law of cooling, which mathematically can be expressed as
where T is the temperature of the body, T_{s} is the temperature of the surroundings (which may be timedependent), t is time, and k is aÂ positive constant. Equation (Ch4.E8) is primarily viewed as an empirical law, valid when heat is efficiently convected away from the surface of the body by aÂ flowing fluid such as air at constant temperature T_{s}. The heat transfer coefficient k reflects the transfer of heat from the body to the surroundings and must be determined from physical experiments.
The cooling law (Ch4.E8) needs an initial condition \(T(0)=T_{0}\).
4.5 Radioactive Decay
An atomic nucleus of an unstable atom may lose energy by emitting ionizing particles and thereby be transformed to aÂ nucleus with aÂ different number of protons and neutrons. This process is known as radioactive decay. Actually, the process is stochastic when viewed for aÂ single atom, because it is impossible to predict exactly when aÂ particular atom emits aÂ particle. Nevertheless, with aÂ large number of atoms, N, one may view the process as deterministic and compute the mean behavior of the decay. Below we reason intuitively about an ODE for the mean behavior. Thereafter, we show mathematically that aÂ detailed stochastic model for single atoms leads to the same mean behavior.
4.5.1 Deterministic Model
Suppose at time t, the number of the original atom type is \(N(t)\). AÂ basic model assumption is that the transformation of the atoms of the original type in aÂ small time interval \(\Delta t\) is proportional to N, so that
where aâ€‰>â€‰0 is aÂ constant. The proportionality factor is \(a\Delta t\), i.e., proportional to \(\Delta t\) since aÂ longer time interval will produce more transformations. We can introduce \(u=N(t)/N(0)\), divide by \(\Delta t\), and let \(\Delta t\rightarrow 0\):
The lefthand side is the derivative of u. Dividing by the N_{0} gives the following ODE for u:
The parameter a can for aÂ given nucleus be expressed through the halflife \(t_{1/2}\), which is the time taken for the decay to reduce the initial amount by one half, i.e., \(u(t_{1/2})=0.5\). With \(u(t)=e^{at}\), we get \(t_{1/2}=a^{1}\ln 2\) or \(a=\ln 2/t_{1/2}\).
4.5.2 Stochastic Model
Originally, we have N_{0} atoms. Up to some particular time t, each atom may either have decayed or not. If not, they have â€˜â€˜survivedâ€™â€™. We want to count how many original atoms that have survived. The survival of aÂ single atom at time t is aÂ random event. Since there are only two outcomes, survival or decay, we have aÂ Bernoulli trial. Let p be the probability of survival (implying that the probability of decay is \(1p\)). If each atom survives independently of the others, and the probability of survival is the same for every atom, we have N_{0} Bernoulli trials, known as aÂ binomial experiment from probability theory. The probability \(P(N)\) that N out of the N_{0} atoms have survived at time t is then given by the famous binomial distribution
The mean (or expected) value \(\hbox{E}[P]\) of \(P(N)\) is known to be \(N_{0}p\).
It remains to estimate p. Let the interval \([0,t]\) be divided into m small subintervals of length \(\Delta t\). We make the assumption that the probability of decay of aÂ single atom in an interval of length \(\Delta t\) is \(\tilde{p}\), and that this probability is proportional to \(\Delta t\): \(\tilde{p}=\lambda\Delta t\) (it sounds natural that the probability of decay increases with \(\Delta t\)). The corresponding probability of survival is \(1\lambda\Delta t\). Believing that Î» is independent of time, we have, for each interval of length \(\Delta t\), aÂ Bernoulli trial: the atom either survives or decays in that interval. Now, p should be the probability that the atom survives in all the intervals, i.e., that we have m successful Bernoulli trials in aÂ row and therefore
The expected number of atoms of the original type at time t is
To see the relation between the two types of Bernoulli trials and the ODE above, we go to the limit \(\Delta t\rightarrow 0\), \(m\rightarrow\infty\). It is possible to show that
This is the famous exponential waiting time (or arrival time) distribution for aÂ Poisson process in probability theory (obtained here, as often done, as the limit of aÂ binomial experiment). The probability of decay, or more precisely that at least one atom has undergone aÂ transition, is \(1p=1e^{\lambda t}\). This is the exponential distribution. The limit means that m is very large, hence \(\Delta t\) is very small, and \(\tilde{p}=\lambda\Delta t\) is very small since the intensity of the events, Î», is assumed finite. This situation corresponds to aÂ very small probability that an atom will decay in aÂ very short time interval, which is aÂ reasonable model. The same model occurs in lots of different applications, e.g., when waiting for aÂ taxi, or when finding defects along aÂ rope.
4.5.3 Relation Between Stochastic and Deterministic Models
With \(p=e^{\lambda t}\) we get the expected number of original atoms at t as \(N_{0}p=N_{0}e^{\lambda t}\), which is exactly the solution of the ODE model \(N^{\prime}=\lambda N\). This also gives an interpretation of a via Î» or vice versa. Our important finding here is that the ODE model captures the mean behavior of the underlying stochastic model. This is, however, not always the common relation between microscopic stochastic models and macroscopic â€˜â€˜averagedâ€™â€™ models.
Also of interest, is that aÂ Forward Euler discretization of \(N^{\prime}=\lambda N\), \(N(0)=N_{0}\), gives \(N^{m}=N_{0}(1\lambda\Delta t)^{m}\) at time \(t_{m}=m\Delta t\), which is exactly the expected value of the stochastic experiment with N_{0} atoms and m small intervals of length \(\Delta t\), where each atom can decay with probability \(\lambda\Delta t\) in an interval.
AÂ fundamental question is how accurate the ODE model is. The underlying stochastic model fluctuates around its expected value. AÂ measure of the fluctuations is the standard deviation of the binomial experiment with N_{0} atoms, which can be shown to be \(\hbox{Std}[P]=\sqrt{N_{0}p(1p)}\). Compared to the size of the expectation, we get the normalized standard deviation
showing that the normalized fluctuations are very small if N_{0} is very large, which is usually the case.
4.5.4 Generalization of the Radioactive Decay Modeling
The modeling in Sect.Â 4.5 is in fact very general, despite aÂ focus on aÂ particular physical process. We may instead of atoms and decay speak about aÂ set of items, where each item can undergo aÂ stochastic transition from one state to another. In Sect.Â 4.6 the item is aÂ molecule and the transition is aÂ chemical reaction, while in Sect.Â 4.7 the item is an ill person and the transition is recovering from the illness (or an immune person who loses her immunity).
From the modeling in Sect.Â 4.5 we can establish aÂ deterministic model for aÂ large number of items and aÂ stochastic model for an arbitrary number of items, even aÂ single one. The stochastic model has aÂ parameter Î» reflecting the probability that aÂ transition takes place in aÂ time interval of unit length (or equivalently, that the probability is \(\lambda\Delta t\) for aÂ transition during aÂ time interval of length \(\Delta t\)). The probability of making aÂ transition before time t is given by
The corresponding probability density is \(f(t)=F^{\prime}(t)=e^{\lambda t}\). The expected value of \(F(t)\), i.e., the expected time to transition, is \(\lambda^{1}\). This interpretation of Î» makes it easy to measure its value: just carry out aÂ large number of experiments, measure the time to transition, and take one over the average of these times as an estimate of Î». The variance is \(\lambda^{2}\).
The deterministic model counts how many items, \(N(t)\), that have undergone the transition (on average), and \(N(t)\) is governed by the ODE
4.6 Chemical Kinetics
4.6.1 Irreversible Reaction of Two Substances
Consider two chemical substances, A and B, and aÂ chemical reaction that turns A into B. In aÂ small time interval, some of the molecules of type A are transformed into molecules of B. This process is, from aÂ mathematical modeling point of view, equivalent to the radioactive decay process described in the previous section. We can therefore apply the same modeling approach. If N_{A} is the number of molecules of substance A, we have that N_{A} is governed by the differential equation
where (the constant) k is called the rate constant of the reaction. Rather than using the number of molecules, we use the concentration of molecules: \([A](t)=N_{A}(t)/N_{A}(0)\). We see that \(d[A]/dt=N_{A}(0)^{1}dN_{A}/dt\). Replacing N_{A} by \([A]\) in the equation for N_{A} leads to the equation for the concentration \([A]\):
Since substance A is transformed to substance B, we have that the concentration of \([B]\) grows by the loss of \([A]\):
The mathematical model can either be (Ch4.E11) or the system
This reaction is known as aÂ firstorder reaction, where each molecule of A makes an independent decision about whether to complete the reaction, i.e., independent of what happens to any other molecule.
An nth order reaction is modeled by
for \(t\in(0,T]\) with initial conditions \([A](0)=1\) and \([B](0)=0\). Here, n can be aÂ real number, but is most often an integer. Note that the sum of the concentrations is constant since
4.6.2 Reversible Reaction of Two Substances
Let the chemical reaction turn substance A into B and substance B into A. The rate of change of \([A]\) has then two contributions: aÂ loss \(k_{A}[A]\) and aÂ gain \(k_{B}[B]\):
Similarly for substance B,
This time we have allowed for arbitrary initial concentrations. Again,
4.6.3 Irreversible Reaction of Two Substances into aÂ Third
Now we consider two chemical substances, A and B, reacting with each other and producing aÂ substance C. In aÂ small time interval \(\Delta t\), molecules of type A and B are occasionally colliding, and in some of the collisions, aÂ chemical reaction occurs, which turns A and B into aÂ molecule of type C. (More generally, M_{A} molecules of A and M_{B} molecules of B react to form M_{C} molecules of C.) The number of possible pairings, and thereby collisions, of A and B is \(N_{A}N_{B}\), where N_{A} is the number of molecules of A, and N_{B} is the number of molecules of B. AÂ fraction k of these collisions, \(\hat{k}\Delta tN_{A}N_{B}\), features aÂ chemical reaction and produce N_{C} molecules of C. The fraction is thought to be proportional to \(\Delta t\): considering aÂ twice as long time interval, twice as many molecules collide, and twice as many reactions occur. The increase in molecules of substance C is now found from the reasoning
Dividing by \(\Delta t\),
and letting \(\Delta t\rightarrow 0\), gives the differential equation
(This equation is known as the important law of mass action discovered by the Norwegian scientists Cato M.Â Guldberg and Peter Waage. AÂ more general form of the righthand side is \(\hat{k}N_{A}^{\alpha}N_{B}^{\beta}\). All the constants \(\hat{k}\), Î±, and Î² must be determined from experiments.)
Working instead with concentrations, we introduce \([C](t)=N_{C}(t)/N_{C}(0)\), with similar definitions for \([A]\) and \([B]\) we get
The constant k is related to \(\hat{k}\) by \(k=\hat{k}N_{A}(0)N_{B}(0)/N_{C}(0)\). The gain in C is aÂ loss of A and B:
4.6.4 AÂ Biochemical Reaction
AÂ common reaction (known as Michaelisâ€“Menten kinetics) turns aÂ substrate S into aÂ product P with aid of an enzyme E. The reaction is aÂ twostage process: first S and E reacts to form aÂ complex ES, where the enzyme and substrate are bound to each other, and then ES is turned into E and P. In the first stage, S and E react to produce aÂ growth of ES according to the law of mass action:
The complex ES reacts and produces the product P at rate \(k_{v}[ES]\) and E at rate \(k_{}[ES]\). The total set of reactions can then be expressed by
The initial conditions are \([ES](0)=[P](0)=0\), and \([S]=S_{0}\), \([E]=E_{0}\). The constants \(k_{+}\), \(k_{}\), and k_{v} must be determined from experiments.
4.7 Spreading of Diseases
The modeling of spreading of diseases is very similar to the modeling of chemical reactions in Sect.Â 4.6. The field of epidemiology speaks about susceptibles: people who can get aÂ disease; infectives: people who are infected and can infect susceptibles; and recovered: people who have recovered from the disease and become immune. Three categories are accordingly defined: S for susceptibles, I for infectives, and R for recovered. The number in each category is tracked by the functions \(S(t)\), \(I(t)\), and \(R(t)\).
To model how many people that get infected in aÂ small time interval \(\Delta t\), we reason as with reactions in Sect.Â 4.6. The possible number of pairings (â€˜â€˜collisionsâ€™â€™) between susceptibles and infected is SI. AÂ fraction of these, \(\beta\Delta tSI\), will actually meet and the infected succeed in infecting the susceptible, where Î² is aÂ parameter to be empirically estimated. This leads to aÂ loss of susceptibles and aÂ gain of infected:
In the same time interval, aÂ fraction \(\nu\Delta tI\) of the infected is recovered. It follows from Sect.Â 4.5.4 that the parameter \(\nu^{1}\) is interpreted as the average waiting time to leave the I category, i.e., the average length of the disease. The \(\nu\Delta tI\) term is aÂ loss for the I category, but aÂ gain for the R category:
Dividing these equations by \(\Delta t\) and going to the limit \(\Delta t\rightarrow 0\), gives the ODE system
with initial values \(S(0)=S_{0}\), \(I(0)=I_{0}\), and \(R(0)=0\). By adding the equations, we realize that
where N is the total number in the population under consideration. This property can be used as aÂ partial verification during simulations.
Equations (Ch4.E27)â€“(Ch4.E29) are known as the SIR model in epidemiology. The model can easily be extended to incorporate vaccination programs, immunity loss after some time, etc. Typical diseases that can be simulated by the SIR model and its variants are measles, smallpox, flu, plague, and HIV.
4.8 PredatorPrey Models in Ecology
AÂ model for the interaction of predator and prey species can be based on reasoning from population dynamics and the SIR model. Let \(H(t)\) be the number of preys in aÂ region, and let \(L(t)\) be the number of predators. For example, H may be hares and L lynx, or rabbits and foxes.
The population of the prey evolves due to births and deaths, exactly as in aÂ population dynamics model from Sect.Â 4.2.1. During aÂ time interval \(\Delta t\) the increase in the population is therefore
where a is aÂ parameter to be measured from data. The increase is proportional to H, and the proportionality constant \(a\Delta t\) is proportional to \(\Delta t\), because doubling the interval will double the increase.
However, the prey population has an additional loss because they are eaten by predators. All the prey and predator animals can form LH pairs in total (assuming all individuals meet randomly). AÂ small fraction \(b\Delta t\) of such meetings, during aÂ time interval \(\Delta t\), ends up with the predator eating the prey. The increase in the prey population is therefore adjusted to
The predator population increases as aÂ result of eating preys. The amount of eaten preys is \(b\Delta tLH\), but only aÂ fraction \(d\Delta tLH\) of this amount contributes to increasing the predator population. In addition, predators die and this loss is set to \(c\Delta tL\). To summarize, the increase in the predator population is given by
Dividing by \(\Delta t\) in the equations for H and L and letting \(t\rightarrow 0\) results in
We can simplify the notation to the following two ODEs:
This is aÂ socalled LoktaVolterra model. It contains four parameters that must be estimated from data: a, b, c, and d. In addition, two initial conditions are needed for \(H(0)\) and \(L(0)\).
4.9 Decay of Atmospheric Pressure with Altitude
4.9.1 The General Model
Vertical equilibrium of air in the atmosphere is governed by the equation
Here, \(p(z)\) is the air pressure, \(\varrho\) is the density of air, and \(g=9.807\,\mathrm{m/s}^{2}\) is aÂ standard value of the acceleration of gravity. (Equation (Ch4.E32) follows directly from the general NavierStokes equations for fluid motion, with the assumption that the air does not move.)
The pressure is related to density and temperature through the ideal gas law
where M is the molar mass of the Earthâ€™s air (0.029â€¯kg\(/\)mol), \(R^{*}\) is the universal gas constant (8.314 Nm/(mol K)), and T is the temperature in Kelvin. All variables p, \(\varrho\), and T vary with the height z. Inserting (Ch4.E33) in (Ch4.E32) results in an ODE with aÂ variable coefficient:
4.9.2 Multiple Atmospheric Layers
The atmosphere can be approximately modeled by seven layers. In each layer, (Ch4.E34) is applied with aÂ linear temperature of the form
where \(z=h_{i}\) denotes the bottom of layer number i, having temperature \(\bar{T}_{i}\), and L_{i} is aÂ constant in layer number i. The table below lists h_{i} (m), \(\bar{T}_{i}\) (K), and L_{i} (K/m) for the layers \(i=0,\ldots,6\).
For implementation it might be convenient to write (Ch4.E34) on the form
where \(\bar{T}(z)\), \(L(z)\), and \(h(z)\) are piecewise constant functions with values given in the table. The value of the pressure at the sea level zâ€‰=â€‰0, \(p_{0}=p(0)\), is 101,325â€¯Pa.
4.9.3 Simplifications
Constant layer temperature
One common simplification is to assume that the temperature is constant within each layer. This means that Lâ€‰=â€‰0.
Onelayer model
Another commonly used approximation is to work with one layer instead of seven. This onelayer model is based on \(T(z)=T_{0}Lz\), with sea level standard temperature \(T_{0}=288\)â€¯K and temperature lapse rate Lâ€‰=â€‰0.0065â€¯K\(/\)m.
4.10 Compaction of Sediments
Sediments, originally made from materials like sand and mud, get compacted through geological time by the weight of new material that is deposited on the sea bottom. The porosity Ï• of the sediments tells how much void (fluid) space there is between the sand and mud grains. The porosity drops with depth, due to the weight of the sediments above. This makes the void space shrink, and thereby compaction increases.
AÂ typical assumption is that the change in Ï• at some depth z is negatively proportional to Ï•. This assumption leads to the differential equation problem
where the z axis points downwards, zâ€‰=â€‰0 is the surface with known porosity, and câ€‰>â€‰0 is aÂ constant.
The upper part of the Earthâ€™s crust consists of many geological layers stacked on top of each other, as indicated in Fig.Â 4.1. The model (Ch4.E36) can be applied for each layer. In layer number i, we have the unknown porosity function \(\phi_{i}(z)\) fulfilling \(\phi_{i}^{\prime}(z)=c_{i}z\), since the constant c in the model (Ch4.E36) depends on the type of sediment in the layer. Alternatively, we can use (Ch4.E36) to describe the porosity through all layers if c is taken as aÂ piecewise constant function of z, equal to c_{i} in layer i. From the figure we see that new layers of sediments are deposited on top of older ones as time progresses. The compaction, as measured by Ï•, is rapid in the beginning and then decreases (exponentially) with depth in each layer.
When we drill aÂ well at present time through the rightmost column of sediments in Fig.Â 4.1, we can measure the thickness of the sediment in (say) the bottom layer. Let L_{1} be this thickness. Assuming that the volume of sediment remains constant through time, we have that the initial volume, \(\int_{0}^{L_{1,0}}\phi_{1}dz\), must equal the volume seen today, \(\int_{\ellL_{1}}^{\ell}\phi_{1}dz\), where \(\ell\) is the depth of the bottom of the sediment in the present day configuration. After having solved for \(\phi_{1}\) as aÂ function of z, we can then find the original thickness \(L_{1,0}\) of the sediment from the equation
In hydrocarbon exploration it is important to know \(L_{1,0}\) and the compaction history of the various layers of sediments.
4.11 Vertical Motion of aÂ Body in aÂ Viscous Fluid
AÂ body moving vertically through aÂ fluid (liquid or gas) is subject to three different types of forces: the gravity force, the drag force, and the buoyancy force.
4.11.1 Overview of Forces
Taking the upward direction as positive, the gravity force is \(F_{g}=mg\), where m is the mass of the body and g is the acceleration of gravity. The uplift or buoyancy force (â€˜â€˜Archimedes forceâ€™â€™) is \(F_{b}=\varrho gV\), where \(\varrho\) is the density of the fluid and V is the volume of the body.
The drag force is of two types, depending on the Reynolds number
where d is the diameter of the body in the direction perpendicular to the flow, v is the velocity of the body, and Î¼ is the dynamic viscosity of the fluid. When \(\text{Re}<1\), the drag force is fairly well modeled by the socalled Stokesâ€™ drag, which for aÂ spherical body of diameter d reads
Quantities are taken as positive in the upwards vertical direction, so if vâ€‰>â€‰0 and the body moves upwards, the drag force acts downwards and become negative, in accordance with the minus sign in expression for \(F_{d}^{(S)}\).
For large Re, typically \(\text{Re}> 10^{3}\), the drag force is quadratic in the velocity:
where C_{D} is aÂ dimensionless drag coefficient depending on the bodyâ€™s shape, and A is the crosssectional area as produced by aÂ cut plane, perpendicular to the motion, through the thickest part of the body. The superscripts \(\,{}^{q}\) and \(\,{}^{S}\) in \(F_{d}^{(S)}\) and \(F_{d}^{(q)}\) indicate Stokesâ€™ drag and quadratic drag, respectively.
4.11.2 Equation of Motion
All the mentioned forces act in the vertical direction. Newtonâ€™s second law of motion applied to the body says that the sum of these forces must equal the mass of the body times its acceleration a in the vertical direction.
Here we have chosen to model the fluid resistance by the Stokesâ€™ drag. Inserting the expressions for the forces yields
The unknowns here are v and a, i.e., we have two unknowns but only one equation. From kinematics in physics we know that the acceleration is the time derivative of the velocity: \(a=dv/dt\). This is our second equation. We can easily eliminate a and get aÂ single differential equation for v:
AÂ small rewrite of this equation is handy: We express m as \(\varrho_{b}V\), where \(\varrho_{b}\) is the density of the body, and we divide by the mass to get
We may introduce the constants
so that the structure of the differential equation becomes obvious:
The corresponding initial condition is \(v(0)=v_{0}\) for some prescribed starting velocity v_{0}.
This derivation can be repeated with the quadratic drag force \(F_{d}^{(q)}\), leading to the result
Defining
and b as above, we can write (Ch4.E43) as
4.11.3 Terminal Velocity
An interesting aspect of (Ch4.E42) and (Ch4.E45) is whether v will approach aÂ final constant value, the socalled terminal velocity v_{T}, as \(t\rightarrow\infty\). AÂ constant v means that \(v^{\prime}(t)\rightarrow 0\) as \(t\rightarrow\infty\) and therefore the terminal velocity v_{T} solves
and
The former equation implies \(v_{T}=b/a\), while the latter has solutions \(v_{T}=\sqrt{b/a}\) for aÂ falling body (\(v_{T}<0\)) and \(v_{T}=\sqrt{b/a}\) for aÂ rising body (\(v_{T}> 0\)).
4.11.4 AÂ Crankâ€“Nicolson Scheme
Both governing equations, the Stokesâ€™ drag model (Ch4.E42) and the quadratic drag model (Ch4.E45), can be readily solved by the Forward Euler scheme. For higher accuracy one can use the Crankâ€“Nicolson method, but aÂ straightforward application of this method gives aÂ nonlinear equation in the new unknown value \(v^{n+1}\) when applied to (Ch4.E45):
The first term on the righthand side of (Ch4.E46) is the arithmetic average of \(vv\) evaluated at time levels n and \(n+1\).
Instead of approximating the term \(vv\) by an arithmetic average, we can use aÂ geometric mean:
The error is of second order in \(\Delta t\), just as for the arithmetic average and the centered finite difference approximation in (Ch4.E46). With the geometric mean, the resulting discrete equation
becomes aÂ linear equation in \(v^{n+1}\), and we can therefore easily solve for \(v^{n+1}\):
Using aÂ geometric mean instead of an arithmetic mean in the Crankâ€“Nicolson scheme is an attractive method for avoiding aÂ nonlinear algebraic equation when discretizing aÂ nonlinear ODE.
4.11.5 Physical Data
Suitable values of Î¼ are \(1.8\cdot 10^{5}\,\text{Pa}\,\text{s}\) for air and \(8.9\cdot 10^{4}\,\text{Pa}\,\text{s}\) for water. Densities can be taken as \(1.2\,\mathrm{kg/m}^{3}\) for air and as \(1.0\cdot 10^{3}\,\mathrm{kg/m}^{3}\) for water. For considerable vertical displacement in the atmosphere one should take into account that the density of air varies with the altitude, see Sect.Â 4.9. One possible density variation arises from the onelayer model in the mentioned section.
Any density variation makes b time dependent and we need \(b^{n+\frac{1}{2}}\) in (Ch4.E48). To compute the density that enters \(b^{n+\frac{1}{2}}\) we must also compute the vertical position \(z(t)\) of the body. Since \(v=dz/dt\), we can use aÂ centered difference approximation:
This \(z^{n+\frac{1}{2}}\) is used in the expression for b to compute \(\varrho(z^{n+\frac{1}{2}})\) and then \(b^{n+\frac{1}{2}}\).
The drag coefficient C_{D} depends heavily on the shape of the body. Some values are: 0.45 for aÂ sphere, 0.42 for aÂ semisphere, 1.05 for aÂ cube, 0.82 for aÂ long cylinder (when the center axis is in the vertical direction), 0.75 for aÂ rocket, 1.01.3 for aÂ man in upright position, 1.3 for aÂ flat plate perpendicular to the flow, and 0.04 for aÂ streamlined, dropletlike body.
4.11.6 Verification
To verify the program, one may assume aÂ heavy body in air such that the F_{b} force can be neglected, and further assume aÂ small velocity such that the air resistance F_{d} can also be neglected. This can be obtained by setting Î¼ and \(\varrho\) to zero. The motion then leads to the velocity \(v(t)=v_{0}gt\), which is linear in t and therefore should be reproduced to machine precision (say tolerance \(10^{15}\)) by any implementation based on the Crankâ€“Nicolson or Forward Euler schemes.
Another verification, but not as powerful as the one above, can be based on computing the terminal velocity and comparing with the exact expressions. The advantage of this verification is that we can also test the situation \(\varrho\neq 0\).
As always, the method of manufactured solutions can be applied to test the implementation of all terms in the governing equation, but then the solution has no physical relevance in general.
4.11.7 Scaling
Applying scaling, as described in Sect.Â 4.1, will for the linear case reduce the need to estimate values for seven parameters down to choosing one value of aÂ single dimensionless parameter
provided \(I\neq 0\). If the motion starts from rest, Iâ€‰=â€‰0, the scaled problem reads
and there is no need for estimating physical parameters (!). This means that there is aÂ single universal solution to the problem of aÂ falling body starting from rest: \(\bar{u}(t)=1e^{\bar{t}}\). All real physical cases correspond to stretching the \(\bar{t}\) axis and the \(\bar{u}\) axis in this dimensionless solution. More precisely, the physical velocity \(u(t)\) is related to the dimensionless velocity \(\bar{u}(\bar{t})\) through
4.12 Viscoelastic Materials
When stretching aÂ rod made of aÂ perfectly elastic material, the elongation (change in the rodâ€™s length) is proportional to the magnitude of the applied force. Mathematical models for material behavior under application of external forces use strain \(\varepsilon\) and stress Ïƒ instead of elongation and forces. Strain is relative change in elongation and stress is force per unit area. An elastic material has aÂ linear relation between stress and strain: \(\sigma=E\varepsilon\). This is aÂ good model for many materials, but frequently the velocity of the deformation (or more precisely, the strain rate \(\varepsilon^{\prime}\)) also influences the stress. This is particularly the case for materials like organic polymers, rubber, and wood. When the stress depends on both the strain and the strain rate, the material is said to be viscoelastic. AÂ common model relating forces to deformation is the Kelvinâ€“Voigt model:
Compared to aÂ perfectly elastic material, which deforms instantaneously when aÂ force is acting, aÂ Kelvinâ€“Voigt material will spend some time to elongate. For example, when an elastic rod is subject to aÂ constant force \(\boldsymbol{\sigma}\) at tâ€‰=â€‰0, the strain immediately adjusts to \(\varepsilon=\sigma/E\). AÂ Kelvinâ€“Voigt material, however, has aÂ response \(\varepsilon(t)=\frac{\sigma}{E}(1e^{Et/\eta})\). Removing the force when the strain is \(\varepsilon(t_{1})=I\) will for an elastic material immediately bring the strain back to zero, while aÂ Kelvinâ€“Voigt material will decay: \(\varepsilon=Ie^{(tt_{1})E/\eta)}\).
Introducing u for \(\varepsilon\) and treating \(\boldsymbol{\sigma}(t)\) as aÂ given function, we can write the Kelvinâ€“Voigt model in our standard form
with \(a=E/\eta\) and \(b(t)=\boldsymbol{\sigma}(t)/\eta\). An initial condition, usually \(u(0)=0\), is needed.
4.13 Decay ODEs from Solving aÂ PDE by Fourier Expansions
Suppose we have aÂ partial differential equation
with boundary conditions \(u(0,t)=u(L,t)=0\) and initial condition \(u(x,0)=I(x)\). One may express the solution as
for appropriate unknown functions A_{k}, \(k=1,\ldots,m\). We use the complex exponential \(e^{ikx\pi/L}\) for easy algebra, but the physical u is taken as the real part of any complex expression. Note that the expansion in terms of \(e^{ikx\pi/L}\) is compatible with the boundary conditions: all functions \(e^{ikx\pi/L}\) vanish for xâ€‰=â€‰0 and \(x=L\). Suppose we can express \(I(x)\) as
Such an expansion can be computed by wellknown Fourier expansion techniques, but those details are not important here. Also, suppose we can express the given \(f(x,t)\) as
Inserting the expansions for u and f in the differential equations demands that all terms corresponding to aÂ given k must be equal. The calculations result in the follow system of ODEs:
From the initial condition
so it follows that \(A_{k}(0)=I_{k}\), \(k=1,\ldots,m\). We then have m equations of the form \(A_{k}^{\prime}=aA_{k}+b\), \(A_{k}(0)=I_{k}\), for appropriate definitions of a and b. These ODE problems are independent of each other such that we can solve one problem at aÂ time. The outlined technique is aÂ quite common solution approach to partial differential equations.
Remark
Since a_{k} depends on k and the stability of the Forward Euler scheme demands \(a_{k}\Delta t\leq 1\), we get that \(\Delta t\leq\alpha^{1}L^{2}\pi^{2}k^{2}\) for this scheme. Usually, quite large k values are needed to accurately represent the given functions I and f so that \(\Delta t\) in the Forward Euler scheme needs to be very small for these large values of k. Therefore, the Crankâ€“Nicolson and Backward Euler schemes, which allow larger \(\Delta t\) without any growth in the solutions, are more popular choices when creating timestepping algorithms for partial differential equations of the type considered in this example.
4.14 Exercises
Problem 4.1 (Radioactive decay of Carbon14)
The Carbon14 isotope, whose radioactive decay is used extensively in dating organic material that is tens of thousands of years old, has aÂ halflife of 5,730Â years. Determine the age of an organic material that contains 8.4â€¯% of its initial amount of Carbon14. Use aÂ time unit of 1Â year in the computations. The uncertainty in the half time of Carbon14 is Â±40Â years. What is the corresponding uncertainty in the estimate of the age?
Hint 1
Let A be the amount of Carbon14. The ODE problem is then \(A^{\prime}(t)=aA(t)\), \(A(0)=I\). Introduced the scaled amount \(u=A/I\). The ODE problem for u is \(u^{\prime}=au\), \(u(0)=1\). Measure time in years. Simulate until the first mesh point t_{m} such that \(u(t_{m})\leq 0.084\).
Hint 2
Use simulations with \(5{,}730\pm 40\)â€¯y as input and find the corresponding uncertainty interval for the result.
Filename: carbon14.
Exercise 4.2 (Derive schemes for Newtonâ€™s law of cooling)
Show in detail how we can apply the ideas of the Forward Euler, Backward Euler, and Crankâ€“Nicolson discretizations to derive explicit computational formulas for new temperature values in Newtonâ€™s law of cooling (see Sect.Â 4.4):
Here, T is the temperature of the body, \(T_{s}(t)\) is the temperature of the surroundings, t is time, k is the heat transfer coefficient, and T_{0} is the initial temperature of the body. Summarize the discretizations in aÂ Î¸rule such that you can get the three schemes from aÂ single formula by varying the Î¸ parameter.
Filename: schemes_cooling.
Exercise 4.3 (Implement schemes for Newtonâ€™s law of cooling)
The goal of this exercise is to implement the schemes from ExerciseÂ 4.2 and investigate several approaches for verifying the implementation.

a)
Implement the Î¸rule from ExerciseÂ 4.2 in aÂ function
where T0 is the initial temperature, k is the heat transfer coefficient, T_s is aÂ function of t for the temperature of the surroundings, t_end is the end time of the simulation, dt is the time step, and theta corresponds to Î¸. The cooling function should return the temperature as an array T of values at the mesh points and the time mesh t.

b)
In the case \(\lim_{t\rightarrow\infty}T_{s}(t)=C=\text{const}\), explain why \(T(t)\rightarrow C\). Construct an example where you can illustrate this property in aÂ plot. Implement aÂ corresponding test function that checks the correctness of the asymptotic value of the solution.

c)
AÂ piecewise constant surrounding temperature,
$$T_{s}(t)=\left\{\begin{array}[]{ll}C_{0},&0\leq t\leq t^{*}\\ C_{1},&t> t^{*},\end{array}\right.$$corresponds to aÂ sudden change in the environment at \(t=t^{*}\). Choose \(C_{0}=2T_{0}\), \(C_{1}=\frac{1}{2}T_{0}\), and \(t^{*}=3/k\). Plot the solution \(T(t)\) and explain why it seems physically reasonable.

d)
We know from the ODE \(u^{\prime}=au\) that the Crankâ€“Nicolson scheme can give nonphysical oscillations for \(\Delta t> 2/a\). In the present problem, this results indicates that the Crankâ€“Nicolson scheme give undesired oscillations for \(\Delta t> 2/k\). Discuss if this aÂ potential problem in the physical case from c).

e)
Find an expression for the exact solution of \(T^{\prime}=k(TT_{s}(t))\), \(T(0)=T_{0}\). Construct aÂ test case and compare the numerical and exact solution in aÂ plot.
Find aÂ value of the time step \(\Delta t\) such that the two solution curves cannot (visually) be distinguished from each other. Many scientists will claim that such aÂ plot provides evidence for aÂ correct implementation, but point out why there still may be errors in the code. Can you introduce bugs in the cooling function and still achieve visually coinciding curves?
Hint
The exact solution can be derived by multiplying (Ch4.E8) by the integrating factor \(e^{kt}\).

f)
Implement aÂ test function for checking that the solution returned by the cooling function is identical to the exact numerical solution of the problem (to machine precision) when T_{s} is constant.
Hint
The exact solution of the discrete equations in the case T_{s} is aÂ constant can be found by introducing \(u=TT_{s}\) to get aÂ problem \(u^{\prime}=ku\), \(u(0)=T_{0}T_{s}\). The solution of the discrete equations is then of the form \(u^{n}=(T_{0}T_{s})A^{n}\) for some amplification factor A. The expression for T^{n} is then \(T^{n}=T_{s}(t_{n})+u^{n}=T_{s}+(T_{0}T_{s})A^{n}\). We find that
The test function, testing several Î¸ values for aÂ quite coarse mesh, may take the form
Running this function shows that the diff variable is 3.55E15 as maximum so aÂ tolerance of \(10^{14}\) is appropriate. This is aÂ good test that the cooling function works!
Filename: cooling.
Exercise 4.4 (Find time of murder from body temperature)
AÂ detective measures the temperature of aÂ dead body to be 26.7â€¯\({}^{\circ}\)C at 2â€¯pm. One hour later the temperature is 25.8â€¯\({}^{\circ}\)C. The question is when death occurred.
Assume that Newtonâ€™s law of cooling (Ch4.E8) is an appropriate mathematical model for the evolution of the temperature in the body. First, determine k in (Ch4.E8) by formulating aÂ Forward Euler approximation with one time steep from time 2â€¯am to time 3â€¯am, where knowing the two temperatures allows for finding k. Assume the temperature in the air to be 20â€¯\({}^{\circ}\)C. Thereafter, simulate the temperature evolution from the time of murder, taken as tâ€‰=â€‰0, when \(T=37\,^{\circ}\text{C}\), until the temperature reaches 25.8â€¯\({}^{\circ}\)C. The corresponding time allows for answering when death occurred.
Filename: detective.
Exercise 4.5 (Simulate an oscillating cooling process)
The surrounding temperature T_{s} in Newtonâ€™s law of cooling (Ch4.E8) may vary in time. Assume that the variations are periodic with period P and amplitude a around aÂ constant mean temperature T_{m}:
Simulate aÂ process with the following data: \(k=0.05\,\text{min}^{1}\), \(T(0)=5\,^{\circ}\text{C}\), \(T_{m}=25\,^{\circ}\text{C}\), \(a=2.5\,^{\circ}\text{C}\), and Pâ€‰=â€‰1â€¯h, Pâ€‰=â€‰10â€¯min, and Pâ€‰=â€‰6â€¯h. Plot the T solutions and T_{s} in the same plot.
Filename: osc_cooling.
Exercise 4.6 (Simulate stochastic radioactive decay)
The purpose of this exercise is to implement the stochastic model described in Sect.Â 4.5 and show that its mean behavior approximates the solution of the corresponding ODE model.
The simulation goes on for aÂ time interval \([0,T]\) divided into N_{t} intervals of length \(\Delta t\). We start with N_{0} atoms. In some time interval, we have N atoms that have survived. Simulate N Bernoulli trials with probability \(\lambda\Delta t\) in this interval by drawing N random numbers, each being 0 (survival) or 1 (decay), where the probability of getting 1 is \(\lambda\Delta t\). We are interested in the number of decays, d, and the number of survived atoms in the next interval is then \(Nd\). The Bernoulli trials are simulated by drawing N uniformly distributed real numbers on \([0,1]\) and saying that 1 corresponds to aÂ value less than \(\lambda\Delta t\):
Observe that uniform < lambda_*dt is aÂ boolean array whose true and false values become 1 and 0, respectively, when converted to an integer array.
Repeat the simulation over \([0,T]\) aÂ large number of times, compute the average value of N in each interval, and compare with the solution of the corresponding ODE model.
Filename: stochastic_decay.
Problem 4.7 (Radioactive decay of two substances)
Consider two radioactive substances A and B. The nuclei in substance AÂ decay to form nuclei of type B with aÂ halflife \(A_{1/2}\), while substance B decay to form type A nuclei with aÂ halflife \(B_{1/2}\). Letting u_{A} and u_{B} be the fractions of the initial amount of material in substance A and B, respectively, the following system of ODEs governs the evolution of \(u_{A}(t)\) and \(u_{B}(t)\):
with \(u_{A}(0)=u_{B}(0)=1\).

a)
Make aÂ simulation program that solves for \(u_{A}(t)\) and \(u_{B}(t)\).

b)
Verify the implementation by computing analytically the limiting values of u_{A} and u_{B} as \(t\rightarrow\infty\) (assume \(u_{A}^{\prime},u_{B}^{\prime}\rightarrow 0\)) and comparing these with those obtained numerically.

c)
Run the program for the case of \(A_{1/2}=10\) minutes and \(B_{1/2}=50\) minutes. Use aÂ time unit of 1 minute. Plot u_{A} and u_{B} versus time in the same plot.
Filename: radioactive_decay_2subst.
Exercise 4.8 (Simulate aÂ simple chemical reaction)
Consider the simple chemical reaction where aÂ substance A is turned into aÂ substance B according to
where \([A]\) and \([B]\) are the concentrations of A and B, respectively. It may be aÂ challenge to find appropriate values of k, but we can avoid this problem by working with aÂ scaled model (as explained in Sect.Â 4.1). Scale the model above, using aÂ time scale \(1/k\), and use the initial concentration of \([A]\) as scale for \([A]\) and \([B]\). Show that the scaled system reads
with initial conditions \(u(0)=1\), and \(v(0)=\alpha\), where \(\alpha=[B](0)/[A](0)\) is aÂ dimensionless number, and u and v are the scaled concentrations of \([A]\) and \([B]\), respectively. Implement aÂ numerical scheme that can be used to find the solutions \(u(t)\) and \(v(t)\). Visualize u and v in the same plot.
Filename: chemcial_kinetics_AB.
Exercise 4.9 (Simulate an nth order chemical reaction)
An norder chemical reaction, generalizing the model in ExerciseÂ 4.8, takes the form
where symbols are as defined in ExerciseÂ 4.8. Bring this model on dimensionless form, using aÂ time scale \([A](0)^{n1}/k\), and show that the dimensionless model simplifies to
with \(u(0)=1\) and \(v(0)=\alpha=[B](0)/[A](0)\). Solve numerically for \(u(t)\) and show aÂ plot with u for nâ€‰=â€‰0.5,1,2,4.
Filename: chemcial_kinetics_ABn.
Exercise 4.10 (Simulate aÂ biochemical process)
The purpose of this exercise is to simulate the ODE system (Ch4.E23)â€“(Ch4.E26) modeling aÂ simple biochemical process.

a)
Scale (Ch4.E23)â€“(Ch4.E26) such that we can work with dimensionless parameters, which are easier to prescribe. Introduce
$$\bar{Q}=\frac{[ES]}{Q_{c}},\quad\bar{P}=\frac{P}{P_{c}},\quad\bar{S}=\frac{S}{S_{0}},\quad\bar{E}=\frac{E}{E_{0}},\quad\bar{t}=\frac{t}{t_{c}},$$where appropriate scales are
$$Q_{c}=\frac{S_{0}E_{0}}{K},\quad P_{c}=Q_{c},\quad t_{c}=\frac{1}{k_{+}E_{0}},$$with \(K=(k_{v}+k_{})/k_{+}\) (Michaelis constant). Show that the scaled system becomes
$$\frac{d\bar{Q}}{d\bar{t}} =\alpha(\bar{E}\bar{S}\bar{Q}),$$(4.54)$$\frac{d\bar{P}}{d\bar{t}} =\beta\bar{Q},$$(4.55)$$\frac{d\bar{S}}{d\bar{t}} =\bar{E}\bar{S}+(1\beta\alpha^{1})\bar{Q},$$(4.56)$$\epsilon\frac{d\bar{E}}{d\bar{t}} =\bar{E}\bar{S}+\bar{Q},$$(4.57)where we have three dimensionless parameters
$$\alpha=\frac{K}{E_{0}},\quad\beta=\frac{k_{v}}{k_{+}E_{0}},\quad\epsilon=\frac{E_{0}}{S_{0}}\thinspace.$$The corresponding initial conditions are \(\bar{Q}=\bar{P}=0\) and \(\bar{S}=\bar{E}=1\).
 b)

c)
There are two conservation equations implied by (Ch4.E23)â€“(Ch4.E26):
$$[ES]+[E] =E_{0},$$(4.58)$$+[S]+[P] =S_{0}\thinspace.$$(4.59)Derive these two equations. Use these properties in the function in b) to do aÂ partial verification of the solution at each time step.

d)
Simulate aÂ case with Tâ€‰=â€‰8, \(\alpha=1.5\) and \(\beta=1\), and two Ïµ values: 0.9 and 0.1.
Filename: biochem.
Exercise 4.11 (Simulate spreading of aÂ disease)
The SIR model (Ch4.E27)â€“(Ch4.E29) can be used to simulate spreading of an epidemic disease.

a)
Estimating the parameter Î² is difficult so it can be handy to scale the equations. Use \(t_{c}=1/\nu\) as time scale, and scale S, I, and R by the population size \(N=S(0)+I(0)+R(0)\). Show that the resulting dimensionless model becomes
$$\frac{d\bar{S}}{d\bar{t}} =R_{0}\bar{S}\bar{I},$$(4.60)$$\frac{d\bar{I}}{d\bar{t}} =R_{0}\bar{S}\bar{I}\bar{I},$$(4.61)$$\frac{d\bar{R}}{d\bar{t}} =I,$$(4.62)$$\bar{S}(0) =1\alpha,$$(4.63)$$\bar{I}(0) =\alpha,$$(4.64)$$\bar{R}(0) =0,$$(4.65)where R_{0} and Î± are the only parameters in the problem:
$$R_{0}=\frac{N\beta}{\nu},\quad\alpha=\frac{I(0)}{N}\thinspace.$$AÂ quantity with aÂ bar denotes aÂ dimensionless version of that quantity, e.g, \(\bar{t}\) is dimensionless time, and \(\bar{t}=\nu t\).

b)
Show that the R_{0} parameter governs whether the disease will spread or not at tâ€‰=â€‰0.
Hint
Spreading means \(dI/dt> 0\).

a)
Implement the scaled SIR model. Check at every time step, as aÂ verification, that \(\bar{S}+\bar{I}+\bar{R}=1\).

b)
Simulate the spreading of aÂ disease where \(R_{0}=2,5\) and 2â€¯% of the population is infected at time tâ€‰=â€‰0.
Filename: SIR.
Exercise 4.12 (Simulate predatorprey interaction)
SectionÂ 4.8 describes aÂ model for the interaction of predator and prey populations, such as lynx and hares.

a)
Scale the equations (Ch4.E30)â€“(Ch4.E31). Use the initial population \(H(0)=H_{0}\) of H has scale for H and L, and let the time scale be \(1/(bH_{0})\).

b)
Implement the scaled model from a). Run illustrating cases how the two populations develop.

c)
The scaling in a) used aÂ scale for H and L based on the initial condition \(H(0)=H_{0}\). An alternative scaling is to make the ODEs as simple as possible by introducing separate scales H_{c} and L_{c} for H and L, respectively. Fit H_{c}, L_{c}, and the time scale t_{c} such that there are as few dimensionless parameters as possible in the ODEs. Scale the initial conditions. Compare the number and type of dimensionless parameters with a).

d)
Compute with the scaled model from c) and create plots to illustrate the typical solutions.
Filename: predator_prey.
Exercise 4.13 (Simulate the pressure drop in the atmosphere)
We consider the models for atmospheric pressure in Sect.Â 4.9. Make aÂ program with three functions,

one computing the pressure \(p(z)\) using aÂ sevenlayer model and varying L,

one computing \(p(z)\) using aÂ sevenlayer model, but with constant temperature in each layer, and

one computing \(p(z)\) based on the onelayer model.
How can these implementations be verified? Should ease of verification impact how you code the functions? Compare the three models in aÂ plot.
Filename: atmospheric_pressure.
Exercise 4.14 (Make aÂ program for vertical motion in aÂ fluid)
Implement the Stokesâ€™ drag model (Ch4.E40) and the quadratic drag model (Ch4.E43) from Sect.Â 4.11, using the Crankâ€“Nicolson scheme and aÂ geometric mean for \(vv\) as explained, and assume constant fluid density. At each time level, compute the Reynolds number Re and choose the Stokesâ€™ drag model if \(\text{Re}<1\) and the quadratic drag model otherwise.
The computation of the numerical solution should take place either in aÂ standalone function or in aÂ solver class that looks up aÂ problem class for physical data. Create aÂ module and equip it with pytest/nose compatible test functions for automatically verifying the code.
Verification tests can be based on

the terminal velocity (see Sect.Â 4.11),

the exact solution when the drag force is neglected (see Sect.Â 4.11),

the method of manufactured solutions (see Sect.Â 3.1.5) combined with computing convergence rates (see Sect.Â 3.1.6).
Use, e.g., aÂ quadratic polynomial for the velocity in the method of manufactured solutions. The expected error is \(\mathcal{O}(\Delta t^{2})\) from the centered finite difference approximation and the geometric mean approximation for \(vv\).
AÂ solution that is linear in t will also be an exact solution of the discrete equations in many problems. Show that this is true for linear drag (by adding aÂ source term that depends on t), but not for quadratic drag because of the geometric mean approximation. Use the method of manufactured solutions to add aÂ source term in the discrete equations for quadratic drag such that aÂ linear function of t is aÂ solution. Add aÂ test function for checking that the linear function is reproduced to machine precision in the case of both linear and quadratic drag.
Apply the software to aÂ case where aÂ ball rises in water. The buoyancy force is here the driving force, but the drag will be significant and balance the other forces after aÂ short time. AÂ soccer ball has radius 11 cm and mass 0.43â€¯kg. Start the motion from rest, set the density of water, \(\varrho\), to \(1000\,\mathrm{kg/m}^{3}\), set the dynamic viscosity, Î¼, to \(10^{3}\,\text{Pa\,s}\), and use aÂ drag coefficient for aÂ sphere: 0.45. Plot the velocity of the rising ball.
Filename: vertical_motion.
Project 4.15 (Simulate parachuting)
The aim of this project is to develop aÂ general solver for the vertical motion of aÂ body with quadratic air drag, verify the solver, apply the solver to aÂ skydiver in free fall, and finally apply the solver to aÂ complete parachute jump.
All the pieces of software implemented in this project should be realized as Python functions and/or classes and collected in one module.

a)
Set up the differential equation problem that governs the velocity of the motion. The parachute jumper is subject to the gravity force and aÂ quadratic drag force. Assume constant density. Add an extra source term to be used for program verification. Identify the input data to the problem.

b)
Make aÂ Python module for computing the velocity of the motion. Also equip the module with functionality for plotting the velocity.
Hint 1
Use the Crankâ€“Nicolson scheme with aÂ geometric mean of \(vv\) in time to linearize the equation of motion with quadratic drag.
Hint 2
You can either use functions or classes for implementation. If you choose functions, make aÂ function solver that takes all the input data in the problem as arguments and that returns the velocity (as aÂ mesh function) and the time mesh. In case of aÂ classbased implementation, introduce aÂ problem class with the physical data and aÂ solver class with the numerical data and aÂ solve method that stores the velocity and the mesh in the class.
Allow for aÂ timedependent area and drag coefficient in the formula for the drag force.

a)
Show that aÂ linear function of t does not fulfill the discrete equations because of the geometric mean approximation used for the quadratic drag term. Fit aÂ source term, as in the method of manufactured solutions, such that aÂ linear function of t is aÂ solution of the discrete equations. Make aÂ test function to check that this solution is reproduced to machine precision.

b)
The expected error in this problem goes like \(\Delta t^{2}\) because we use aÂ centered finite difference approximation with error \(\mathcal{O}(\Delta t^{2})\) and aÂ geometric mean approximation with error \(\mathcal{O}(\Delta t^{2})\). Use the method of manufactured solutions combined with computing convergence rate to verify the code. Make aÂ test function for checking that the convergence rate is correct.

c)
Compute the drag force, the gravity force, and the buoyancy force as aÂ function of time. Create aÂ plot with these three forces.
Hint
You can either make aÂ function forces(v, t, plot=None) that returns the forces (as mesh functions) and t, and shows aÂ plot on the screen and also saves the plot to aÂ file with name stored in plot if plot is not None, or you can extend the solver class with computation of forces and include plotting of forces in the visualization class.

f)
Compute the velocity of aÂ skydiver in free fall before the parachute opens.
Hint
Meade and Struthers [11] provide some data relevant to skydiving. The mass of the human body and equipment can be set to 100â€¯kg. AÂ skydiver in spreadeagle formation has aÂ crosssection of 0.5â€¯\(\text{m}^{2}\) in the horizontal plane. The density of air decreases with altitude, but can be taken as constant, 1â€¯\(\mathrm{kg/m}^{3}\), for altitudes relevant to skydiving (0â€“4000â€¯m). The drag coefficient for aÂ man in upright position can be set to 1.2. Start with aÂ zero velocity. AÂ free fall typically has aÂ terminating velocity of 45â€¯m\(/\)s. (This value can be used to tune other parameters.)

g)
The next task is to simulate aÂ parachute jumper during free fall and after the parachute opens. At time t_{p}, the parachute opens and the drag coefficient and the crosssectional area change dramatically. Use the program to simulate aÂ jump from zâ€‰=â€‰3000â€¯m to the ground zâ€‰=â€‰0. What is the maximum acceleration, measured in units of g, experienced by the jumper?
Hint
Following Meade and Struthers [11], one can set the crosssection area perpendicular to the motion to 44â€¯\(\text{m}^{2}\) when the parachute is open. Assume that it takes 8â€¯s to increase the area linearly from the original to the final value. The drag coefficient for an open parachute can be taken as 1.8, but tuned using the known value of the typical terminating velocity reached before landing: 5.3â€¯m\(/\)s. One can take the drag coefficient as aÂ piecewise constant function with an abrupt change at t_{p}. The parachute is typically released after \(t_{p}=60\) s, but larger values of t_{p} can be used to make plots more illustrative.
Filename: parachuting.
Exercise 4.16 (Formulate vertical motion in the atmosphere)
Vertical motion of aÂ body in the atmosphere needs to take into account aÂ varying air density if the range of altitudes is many kilometers. In this case, \(\varrho\) varies with the altitude z. The equation of motion for the body is given in Sect.Â 4.11. Let us assume quadratic drag force (otherwise the body has to be very, very small). AÂ differential equation problem for the air density, based on the information for the onelayer atmospheric model in Sect.Â 4.9, can be set up as
To evaluate \(p(z)\) we need the altitude z. From the principle that the velocity is the derivative of the position we have that
where v is the velocity of the body.
Explain in detail how the governing equations can be discretized by the Forward Euler and the Crankâ€“Nicolson methods. Discuss pros and cons of the two methods.
Filename: falling_in_variable_density.
Exercise 4.17 (Simulate vertical motion in the atmosphere)
Implement the Forward Euler or the Crankâ€“Nicolson scheme derived in ExerciseÂ 4.16. Demonstrate the effect of air density variation on aÂ falling human, e.g., the famous fall of Felix Baumgartner. The drag coefficient can be set to 1.2.
Filename: falling_in_variable_density.
Problem 4.18 (Compute \(y=x\) by solving an ODE)
Consider the ODE problem
which has the solution \(y(x)=x\). Using aÂ mesh \(x_{0}=1\), \(x_{1}=0\), and \(x_{2}=1\), calculate by hand y_{1} and y_{2} from the Forward Euler, Backward Euler, Crankâ€“Nicolson, and Leapfrog methods. Use all of the former three methods for computing the y_{1} value to be used in the Leapfrog calculation of y_{2}. Thereafter, visualize how these schemes perform for aÂ uniformly partitioned mesh with Nâ€‰=â€‰10 and Nâ€‰=â€‰11 points.
Filename: signum.
Problem 4.19 (Simulate fortune growth with random interest rate)
The goal of this exercise is to compute the value of aÂ fortune subject to inflation and aÂ random interest rate. Suppose that the inflation is constant at i percent per year and that the annual interest rate, p, changes randomly at each time step, starting at some value p_{0} at tâ€‰=â€‰0. The random change is from aÂ value p^{n} at \(t=t_{n}\) to \(p_{n}+\Delta p\) with probability 0.25 and \(p_{n}\Delta p\) with probability 0.25. No change occurs with probability 0.5. There is also no change if \(p^{n+1}\) exceeds 15 or becomes below 1. Use aÂ time step of one month, \(p_{0}=i\), initial fortune scaled to 1, and simulate 1000 scenarios of length 20 years. Compute the mean evolution of one unit of money and the corresponding standard deviation. Plot the mean curve along with the mean plus one standard deviation and the mean minus one standard deviation. This will illustrate the uncertainty in the mean curve.
Hint 1
The following code snippet computes \(p^{n+1}\):
Hint 2
If \(u_{i}(t)\) is the value of the fortune in experiment number i, \(i=0,\ldots,N1\), the mean evolution of the fortune is
and the standard deviation is
Suppose \(u_{i}(t)\) is stored in an array u. The mean and the standard deviation of the fortune is most efficiently computed by using two accumulation arrays, sum_u and sum_u2, and performing sum_u += u and sum_u2 += u**2 after every experiment. This technique avoids storing all the \(u_{i}(t)\) time series for computing the statistics.
Filename: random_interest.
Exercise 4.20 (Simulate aÂ population in aÂ changing environment)
We shall study aÂ population modeled by (Ch4.E3) where the environment, represented by r and f, undergoes changes with time.

a)
Assume that there is aÂ sudden drop (increase) in the birth (death) rate at time \(t=t_{r}\), because of limited nutrition or food supply:
$$r(t)=\left\{\begin{array}[]{ll}\varrho,&t<t_{r},\\ \varrhoA,&t\geq t_{r}.\end{array}\right.$$This drop in population growth is compensated by aÂ sudden net immigration at time \(t_{f}> t_{r}\):
$$f(t)=\left\{\begin{array}[]{ll}0,&t<t_{f},\\ f_{0},&t\geq t_{a}.\end{array}\right.$$Start with \(\varrho\) and make \(A> \varrho\). Experiment with these and other parameters to illustrate the interplay of growth and decay in such aÂ problem.

b)
Now we assume that the environmental conditions changes periodically with time so that we may take
$$r(t)={\varrho}+A\sin\left(\frac{2\pi}{P}t\right)\thinspace.$$That is, the combined birth and death rate oscillates around \(\varrho\) with aÂ maximum change of Â±A repeating over aÂ period of length P in time. Set fâ€‰=â€‰0 and experiment with the other parameters to illustrate typical features of the solution.
Filename: population.py.
Exercise 4.21 (Simulate logistic growth)
Solve the logistic ODE (Ch4.E4) using aÂ Crankâ€“Nicolson scheme where \((u^{n+\frac{1}{2}})^{2}\) is approximated by aÂ geometric mean:
This trick makes the discrete equation linear in \(u^{n+1}\).
Filename: logistic_CN.
Exercise 4.22 (Rederive the equation for continuous compound interest)
The ODE model (Ch4.E7) was derived under the assumption that r was constant. Perform an alternative derivation without this assumption: 1) start with (Ch4.E5); 2) introduce aÂ time step \(\Delta t\) instead of m: \(\Delta t=1/m\) if t is measured in years; 3) divide by \(\Delta t\) and take the limit \(\Delta t\rightarrow 0\). Simulate aÂ case where the inflation is at aÂ constant level I percent per year and the interest rate oscillates: \(r=I/2+r_{0}\sin(2\pi t)\). Compare solutions for \(r_{0}=I,3I/2,2I\).
Filename: interest_modeling.
Exercise 4.23 (Simulate the deformation of aÂ viscoelastic material)
Stretching aÂ rod made of polymer will cause deformations that are well described with aÂ Kelvinâ€“Voigt material model (Ch4.E49). At tâ€‰=â€‰0 we apply aÂ constant force \(\sigma=\sigma_{0}\), but at \(t=t_{1}\), we remove the force so \(\sigma=0\). Compute numerically the corresponding strain (elongation divided by the rodâ€™s length) and visualize how it responds in time.
Hint
To avoid finding proper values of the E and Î· parameters for aÂ polymer, one can scale the problem. AÂ common dimensionless time is \(\bar{t}=tE/\eta\). Note that \(\varepsilon\) is already dimensionless by definition, but it takes on small values, say up to 0.1, so we introduce aÂ scaling: \(\bar{u}=10\varepsilon\) such that \(\bar{u}\) takes on values up to about unity.
Show that the material model then takes the form \(\bar{u}^{\prime}=\bar{u}+10\sigma(t)/E\). Work with the dimensionless force \(F=10\sigma(t)/E\), and let Fâ€‰=â€‰1 for \(\bar{t}\in(0,\bar{t}_{1})\) and Fâ€‰=â€‰0 for \(\bar{t}\geq\bar{t}_{1}\). AÂ possible choice of t_{1} is the characteristic time \(\eta/E\), which means that \(\bar{t}_{1}=1\).
Filename: KelvinVoigt.
Author information
Authors and Affiliations
Corresponding author
Rights and permissions
<SimplePara><Emphasis Type="Bold">Open Access</Emphasis> This chapter is distributed under the terms of the Creative Commons AttributionNonCommercial 4.0 International License (http://creativecommons.org/licenses/bync/4.0/), which permits any noncommercial use, duplication, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, a link is provided to the Creative Commons license and any changes made are indicated.</SimplePara> <SimplePara>The images or other third party material in this chapter are included in the work's Creative Commons license, unless indicated otherwise in the credit line; if such material is not included in the work's Creative Commons license and the respective action is not permitted by statutory regulation, users will need to obtain permission from the license holder to duplicate, adapt or reproduce the material.</SimplePara>
Copyright information
Â© 2016 The Author(s)
About this chapter
Cite this chapter
Langtangen, H.P. (2016). Models. In: Finite Difference Computing with Exponential Decay Models. Lecture Notes in Computational Science and Engineering, vol 110. Springer, Cham. https://doi.org/10.1007/9783319294391_4
Download citation
DOI: https://doi.org/10.1007/9783319294391_4
Published:
Publisher Name: Springer, Cham
Print ISBN: 9783319294384
Online ISBN: 9783319294391
eBook Packages: Mathematics and StatisticsMathematics and Statistics (R0)