## Time Courses of Reactions 141 Introduction

The chemical reaction depicted in the Section 1.3.5 has an associated differential equation that describes the rate of the reaction for any given concentration of the reactant A. The time course of [A] is described by a mathematical equation that is obtained by solving this differential equation; in other words, we integrate the differential equation to obtain [A] as a function of time. The solution of Eqn [1.8] is a fundamental result in integral calculus and is

A: To plot the equation we must choose the initial condition, namely, the value of the dependent variable [A] at t = 0, and also assign a value to k. However, we must first define the function. This is done with the following Mathematica input:

There are four important features to note about this definition. The first is the use of lower case 'a' rather than 'A' to denote the concentration of the reactant. Because Mathematica commands all begin with a capital letter, it is good practice to use lower case letters when defining our own variable- and function-names. This allows Mathematica commands and functions to be easily distinguished from user-defined ones in programs. The second point is that a denotes the concentration of A at t = 0. Third, the definition involves the use of the _ (called a "blank") on the left-hand side (Ihs) of the equation. This indicates that the argument of the function can be any symbol, but the symbol must also appear on the right-hand side (rhs) in the definitional equation. This ability to define so easily our own functions is an important feature of Mathematica. The fourth point to note is the use of the symbol := to assign the lhs of the function to the rhs. The colon before the equals sign indicates that this assignment is a delayed assignment, which means that the rhs of the equation is not evaluated when the assignment is made, but instead it is evaluated each time the value of lhs is requested in the program. In contrast an equals sign without the colon invokes an immediate assignment. Thus lhs = rhs evaluates rhs at the time the assignment is made in the program. In the program below we use = to assign the initial condition to A and to assign the value to k.

Finally, we use the function Plot to draw the graph of the expression from t = 0 to t = 10.

AxesLabel -> {"Time ", "Concentration"} ] ;

Concentration Figure 1.1. Time course of the so-called exponential decay defined by Eqn [1.10].

To determine the value of a[t] at any time, say, t = 4, we simply type the following: a

1.35335

lhs = rhs rhs is evaluated when the assignment is made lhs := rhs rhs is evaluated each time the value of lhs is requested

Plot[f, {x, xmin, xmax}, plot f as a function of x from xmin to xmax. See option —> value] Mathematica help browser for a list of options

Basic Mathematica commands.

Q: Use the Mathematica function DSolve to verify that Eqn [1.10] is indeed the solution to the differential equation defined by Eqn [1.9].

A: DSolve is a powerful function that determines analytical solutions to differential equations. Before we use DSolve it is useful to unassign or clear those variables and names we have used in the previous worked example. These assignments are permanent in a Mathematica session and are kept until they are explicitly removed, or when we quit the Mathematica session. By clearing values we eliminate a common source of error that arises when programming in Mathematica. In fact, we find it good programming practice to clear all variables that we intend to use in a program in the first line of the code, just in case these variables have been used previously and still have assigned values.

By solving Eqn [1.9] with the initial condition [A]0 = AO we obtain the required result. solution = DSolve [{a' [t] & - ka[t], a & a0},a[t],t]

There are two important points to note about DSolve. First, the equations and initial conditions must be written as lhs == rhs where == is the logical operator equals sign which is different from the immediate assignment (=) and delayed assignment (:=) operators. The second is that the solution to the differential equation is given as a replacement rule rather than a simple mathematical expression. Replacement rules along with the /. (ReplaceAll) command can be used to transform any expression. This subtle and very valuable operator is illustrated next.

The replacement rule can be converted to a function by using the following input:

AxesLabel -> { " Time " , " Concentration" }] ;

Concentration

Concentration Figure 1.2. Time course of a reaction defined by Eqn [1.10] with the initial condition [A]0 = 10 mmol L-1 and rate constant k = 0.5. The ordinate denotes concentration in units of mmol L-1 and the abscissa denotes time in units of seconds.

We can also determine the value of [A] at any time, say t = 4, by using the following input:

 x = . or Clear[x] remove any value assigned to x DSolve[e^«s, f [x], x] solves a differential equation for the function f [x], with independent variable x == the logical operator equal lhs -> rhs or lhs 0 rhs lhs 0 rhs represents a rule that transforms lhs to rhs expr /. lhs —> rhs apply a transformation rule to expr f [x_] = f [x] /. rule define a function using a repacement rule

More Mathematics commands.

More Mathematics commands.