40 Finding a “solution”
As you saw in the previous chapter, each differential equation in a dynamical system relates the derivative of a function to the function itself. For instance, in
In high-school mathematics, many algebraic problems were of the form, “Solve for
Having been exposed to this style in high school, you may have come to think of “finding a solution” as the only task to perform in working on a problem.
In working with dynamical systems, “finding a solution” is one of the several tasks, among others, that you might need to perform to serve the purpose of your modeling effort. But not every modeling purpose requires “finding a solution,” that is, finding the function
Given what you learned in studying Block 3 of this book, you likely will be tempted to approach the task of “finding a solution” by applying symbolic anti-differentiation techniques to the problem. After all, each differential equation in a dynamical system involves a function
Admittedly, in mathematics it is common to refer to integrating a differential equation, but this should be broadly understood as accumulating the increments
In this chapter we will introduce three different techniques to accumulating a solution to a differential equation or a pair of such equations. First, we will look again at the graphical method of “following the flow” in a plot of the flow field. This technique is mainly of use for developing intuition about the dynamics.
Second, we will develop a simple Euler method for accumulating a solution. Third, we will explore how to take a guess about the solution and, when the guess is good enough, refine that into an actual solution. This is called the method of ansätze.
Third, and briefly, we will look at some of the situations where symbolic anti-differentiation can be used. This includes a very brief introduction to substitution methods.
A differential equation like
In many texts and research papers, differential equations are written using Leibniz’s notation, like this:
An even more concise notation, originated by Isaac Newton, is to replace the
This dot notation is even more expressive when working with second-order differential equations involving second derivative. In the dot notation,
40.1 The flow field
With a pair of differential equations, as with the pendulum or the rabbit-fox model, each equation gives one component of the change in state. To draw the flow at single point in state space, evaluate the dynamical functions at that point. Each dynamical function contributes, as its output, one of the components of the state velocity vector. If the parameters in the model have been assigned numerical values, the result of evaluating the right-hand sides will be two numbers.
A case in point is the rabbit-fox system. The axes in the rabbit-fox state space are denominated in units of rabbit density
To to find the state velocity at, say,
Once you know the numerical vector value of the state velocity, you need to convert it to a form suitable for plotting in the state space. The conversion is needed because the state space is denominated in rabbit density and fox density, not in rabbit density per month or fox density per month. The conversion is accomplished by multiplying the state velocity vector by a small
The conversion produces a vector whose components are denominated in the same way as the state space and thus can be plotted meaningfully in the state space.
To illustrate, let’s draw a flow vector for the state space coordinate
To draw the entire flow field, repeat this process at many other points in the state space as in Figure 40.2.
Some people prefer a visualization of short segments of actual trajectories, as in the right panel in Figure 40.2, rather than the state velocity vector. This is a matter of personal preference.
With the flow field depicted in sufficient detail, you can now trace out trajectory.
To trace out a trajectory, select a initial condition for the system. Then follow the flow, taking only a small step in state space. The next step should be in the direction of the flow arrow at the end of the previous step.
The trajectory you draw will be only a sketch, but it can be effective for developing intuition. Figure 40.3 shows a semi-automated version of the go-with-the-flow method. The computer has been used to draw the arrows. When you click in the plot, the computer also undertakes calculation of the trajectory.
Regrettably, from such a sketch of the trajectory, you cannot easily construct
The next section will show you how the computer constructed the trajectory and how we can get information on the speed of the flow.
40.2 Euler method
Recall from Block 2 the limit definition of the derivative:
The differential equations specify the values of
Our starting point for solving each differential equation is to re-write it as a finite difference. To illustrate, we will solve the equation
Applying the finite difference definition, we get
To use this, we start at the initial condition, say
Next, pick a value for
To fill in the next row, as in Table 40.2, we apply the Euler formula. Sine
The next step is shown in Table 40.3 and will bring us to time
Add as many rows to the table as you like; the process will be the same for each step, the new row being calculated from the values in the previous row.
Recognize that this is an iterative process.
As is so often the case, it is wise to think about carrying fundamental tasks as they can be accomplished by calculus operations—evaluate, differentiate, anti-differentiate, solve, find argmax, iterate. The obvious choice for integrating differential equations is “anti-differentiate,” but as described previously, the techniques we covered in Block 3 are not sufficient for the task. Instead, we use iteration to solve differential equations.
This example uses the software you have already seen, Iterate()
, to carry out the task. In practice, however, you will use a special form of Iterate()
called integrateODE()
that makes use of interpolation techniques to give a more precise answer.
To implement the iteration to solve
Notice that we wrote next_step()
with an input slot for
Use Iterate()
to carry out the iteration of next_step()
. Note that we use the fargs
argument to Iterate()
to pass our selected value for dt
to the function next_step()
. We will run the iteration for 100 steps. With
Or, in graphical form ….
The previous example used Iterate()
to solve a differential equation. The output of the iteration was a data frame containing values for the solution at discrete times: 0, 0.1, 0.2, and so on. A data table is a perfectly good way to represent a function, but it is handier to have a function in a form that operations like slice_plot()
and D()
can be applied to. Another way to look at things is that, mathematically, the solution to a differential equation should be a continuous-time function. Fortunately, we have at hand the interpolation techniques covered in Chapter 48 to carry out the construction of a continuous-time function from a tabular representation. The R/mosaic function integrateODE()
connects together the iteration and interpolation to provide a solution that is in the form of continuous-time function(s).
Use the R/mosaic function integrateODE()
to solve differential equations numerically. It is a specialized function that handles sets of first-order differential equations, but any high-order differential equation can be separated into a set of first-order equations.
To illustrate, this command will solve the differential equation Iterate()
.
The first argument is a tilde expression, but in a form that is different from from that used in functions such as D()
or contour_plot()
, etc. To the left of the tilde is a single name composed of the state variable—x
here—prefixed by a d
. The d
is just a reminder that we are describing not x
itself, but
The next argument is the initial condition. We are starting the integration at bounds()
sets the time interval for the integration and dt
sets the time step..
The output of integrateODE()
is an R structure of a type called a “list” that is new to us. The list contains the function(s) created by integrateODE()
which you refer to by name (x
) using a special form of R punctuation $
suited to lists.. In other words, Soln2$x
will be a function, which you can plot like any other function, for instance:
This use of the R symbol $
is new to us. We won’t emphasize it here. Instead, we’ll use the traj_plot()
graphics function (introduced in Chapter 48) which already knows how to access the functions created by integrateODE()
.
An important feature of integrateODE()
is its ability to handle sets of first-order differential equations. For instance, the rabbit/fox system
You can plot the time series using slice_plot()
To plot the trajectory, simply change the tilde expression used in traj_plot()
. which creates a time series plot, traj_plot()
shows the trajectory.
40.3 Symbolic solutions
Occasionally it is possible to integrate a differential equation using symbolic techniques. This is particularly true for differential equations that are linear. The example we will handle here is the first-order linear differential equation
A method we will use repeatedly in this block is called the “method of ansätze.” An ansatz (singular of the German “ansätze”) is, in this context, a guess for the solution. Since differential equations have been a central part of science for more than 200 years, you can imagine that a large library of equations and their solutions has been assembled. For the equations that are most frequently used and that can be solved symbolically, the solutions are already known. Thus, the “guess” for the solution can be a very well informed guess.
Let’s see how this works for
Plugging in the ansatz, translates the differential equation to a new form:
A slightly more complex differential equation is
For nonlinear dynamical function, there is no perfectly general way to find symbolic solutions. But for some dynamical functions, it can be done. we will demonstrate by integrating
The idea of separating the differential equation is to algebraically move all the
The integral on the right side,
The integral on the left side may not be as familiar, but the person solving this problem for the second time will remember that
Now we have
= makeFun(A*exp(t)/(1 + A*exp(t)) ~ t)
Symb_soln slice_plot(Symb_soln(t, A=0.2) ~ t, bounds(t=-5:10))
Not all differential equations can be separated in this way, and even for those that can, the integrals may not be tractable. So this route to a solution is not a general-purpose one, unlike the Euler method. Still, the Euler method gives only an approximate solution, so with Euler we need to take care that the approximation is close enough for the purpose at hand. In this case, we have both an Euler solution (with