Ineed an expert who can do it right and on time

profileneedhelp
Experiment01-Mathematica11.pdf

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 1 of 60

CHEM 4331 Computer Laboratory 1: Mathematics of Physical Chemistry

“Computer! Computer?... Hello, computer.”

Lieutenant Commander Montgomery "Scotty" Scott

Star Trek IV: The Voyage Home (1986)

Contents:

page #

1. Objectives and Notes on Completing the Exercises 1

2. Introduction to Mathematica 3

3. Solutions of Algebraic Equations 17

4. Differential Calculus 28

5. Geometrical Interpretation of Derivatives 38

6. Integral Calculus 46

7. References 60

1. Objectives and Notes on Completing the Exercises

The purpose of this first computer Physical Chemistry laboratory is to briefly review [and, perhaps,

somewhat extend] mathematical techniques learned in the Pre-Calculus and Calculus courses, and

apply those to solving relatively simple problems in already familiar basic Physics and Chemistry.

In the process you will also be introduced to one of [if not the!] best computer algebra software

Mathematica [1,2,3] designed by Dr. Stephen Wolfram [4] (PhD in particle physics from Caltech)

and developed by Wolfram Research [5]. The main goal of this lab is to help you better understand

the material presented in CHEM 4330, and, perhaps, demonstrate that doing Mathematics can be

exciting and fun!

The laboratory requires you to complete in Mathematica ten (10) exercises included in this

handout. Each exercise is worth 10 points. Mathematica notebooks for all exercises must be

submitted to a D2L dropbox by the date and time indicated in your syllabus.

Each exercise contains a set of objectives listed as (a), (b), (c) etc.. A successful completion of

each objective includes obtaining

1) correct numerical value(s) and/or formula/equation(s), and

2) correct units (where applicable).

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 2 of 60

Even if one of those is incorrect or missing (for example, units!), no credit shall be given for the

objective. When in doubt, go back to the worked-out examples, and if it does not help, ask your

lab instructor.

In each Mathematica notebook, you must clearly indicate/label objectives (answers and graphs)

with symbols (a), (b), (c) … as instructed in the Exercises. For example:

�a� v�t� = 4.4  + 0.6 � �m/s� �b� x�t� = 1.4  + 4.4 + 0.2 � �m� ….

�e� a�2s� = 2.4 �m/s�� ….

Unlabeled answers will be ignored, i.e. no points shall be given for unlabeled answers.

When working on the exercises, it is permitted to consult with your classmates. In fact, we

encourage discussions that promote a creative learning environment. However, copying each

other’s code is strictly prohibited! You absolutely must write your own code following the

guidelines and style of the worked-out examples provided in the handout. As such, you will have

to come up with your own comments and names for the variables/parameters used in your

calculations. Of course, make sure that those names are meaningful (see worked-out examples

provided in this handout). This is your chance to be creative – make good use of it!

A couple of [hopefully, useful] suggestions. When working with Mathematica notebooks, save

them often as it is not uncommon for Windows OS to crash. When done for the day, do not forget

to either copy all your files from the computer to your USB flash drive, or email the files to your

own email (home, college etc.) account. Alternatively, you can store files in the “cloud” – for

more information contact the MTSU IT department (ITD). Note that computers in SCI 3095 will

reboot every night, and all user-created files located on the desktop and disk D: (where applicable)

will be permanently deleted. This, of course, applies to ALL CHEM 4331 labs (not just this one)

Good luck! … and try to have fun!

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 3 of 60

2. Introduction to Mathematica

Mathematica is a powerful computer algebra software for numerical and symbolic

calculations. It is extensively used as a research tool in many scientific, engineering, mathematical

and computing fields [3].

Mathematica is split into two parts, the kernel and the front end [3]. The kernel interprets

expressions (Mathematica code) and returns result expressions [3]. The front end provides a GUI,

which allows the creation and editing of Notebook documents containing program code with

prettyprinting, formatted text together with results including typeset mathematics, graphics, GUI

components, tables, and sounds [3]. All contents and formatting can be generated algorithmically

or interactively edited [3]. Most standard word processing capabilities are supported [3]. It

includes a spell-checker but does not spell check automatically as you type [3].

Documents can be structured using a hierarchy of cells, which allow for outlining and

sectioning of a document and support automatic numbering index creation [3]. Documents can be

presented in a slideshow environment for presentations [3]. Notebooks and their contents are

represented as Mathematica expressions that can be created, modified or analyzed by Mathematica

programs [3]. This allows conversion to other formats such as TeX or XML [3].

The front end includes development tools such as a debugger, input completion and

automatic syntax coloring [3].

To start Mathematica, click on the Mathematica icon located on your desktop

or go through the Windows “Start” menu: “Start” → “All Programs” → “Wolfram Mathematica”

→ “Wolfram Mathematica”:

Note that in this tutorial I will be using Mathematica 10.1, while you may be using Mathematica

v9 or v11. Not to worry, the interface and functionality of the two versions are almost the same!

After the program is loaded, you will see a welcoming screen

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 4 of 60

Note that because I have already worked with Mathematica, I have several projects listed under

the “Open Recent” menu. Now, left-click on the “New Document” button (or choose the

“Notebook” option in the “New Document”

Whatever the case, a new Mathematica notebook will open.

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 5 of 60

The Mathematica fully-interactive notebook interface looks almost like a text editor, and is quite

intuitive. There is a menu bar, and an empty [for now] notebook canvas. Several short tutorials

on how to start working with a notebook are available on the Mathematica website at:

https://reference.wolfram.com/language/tutorial/UsingANotebookInterface.html

https://reference.wolfram.com/language/guide/MenuItems.html

https://reference.wolfram.com/language/guide/NotebookBasics.html

https://reference.wolfram.com/language/tutorial/WorkingWithTheNotebookInterfaceOverview.html

Let’s do a couple of simple calculations. In your empty notebook, type in “2+2” (without the

double quotes, of course) and hit the key combination to perform a computation:

Note how Mathematica labels the input (In[n]) commands and the output (Out[n]), where n is a greater-than-zero integer number. Usually, for each input command, there is output. On the very

right side of the notebook, you find cell (inner) and group (outer) brackets. Each input cell can

contain one or more commands. At this time, there is only one input command in the first cell (i.e.

“2+2” in cell In[1]). If you wish to add another command, for example “2-2”, you can add it to the first input cell (In[1]) by positioning the mouse cursor inside that cell and typing the text. When done, hit to get Mathematica to do a computation:

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 6 of 60

Alternatively, you can open a new cell by positioning the cursor below the last output cell, and

type in the command (of course, do not forget the “magic” key combination!):

If at any time you wish to delete all your output cells, you can do so by using the “Delete All

Output” option under the “Cell” menu:

If you wish to delete a particular cell (input or output), simply left-click the bracket of the cell you

wish to get rid of, and hit the “Delete” button on your keyboard. Now, delete all output and the

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 7 of 60

bottom set of cells, and, using the “File” menu, save the notebook to the Windows desktop as

“Test-1.nb”. Now select all previously entered input and delete all cells to leave a blank notebook.

Mathematica obviously can do much more than a simple addition and subtraction. To

multiply the two numbers, use the “*”symbol. To divide the two numbers, use the “/”symbol.

Note the difference between the results of the two divisions. Division of 6 by 3 gives 2 which is

an exact number. Why didn’t Mathematica do the same for the 2/3 operation? This is NOT

because Mathematica does not know how to divide 2 by 3, but rather because it knows that the

result is 0.666666666….... Thus, rather than truncating the number at some arbitrary decimal, it

keeps it as a fraction. If you want a numerical value, use the N[…] operator: https://reference.wolfram.com/language/ref/N.html?q=N

By the way, to make input easier, you can use the good old copy-and-paste option. First, select

the text you wish to copy using the “left-click and drag” technique. Then, select “Copy” from the

“Edit” menu (or simply hit “Ctrl+C”), and paste using either the “Paste” option from the “Edit”

menu or the “Ctrl+V” key combination. Trust me, it makes working with Mathematica a lot easier

and much more fun!

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 8 of 60

Note how the N[2 3⁄ ] command evaluates the fraction to some default number of decimals. The N[2 3⁄ , 20] command evaluates the same to 20 decimal points. N[2 3⁄ , 80] gives the result to 80 decimals. How about that?!

When fractions are entered using the “/” symbol, the code is not very readable. The Wolfram

System's notebook interface is a very powerful typesetting system that allows you to enter formulas

as they are written in mathematical literature, using two-dimensional notation such as superscripts,

subscripts, and so on. For example, try entering the “2/3” fraction using the key

combination:

https://reference.wolfram.com/language/tutorial/EnteringInputInNotebooks.html

Looks much better, doesn’t it? Another useful option in Mathematica is its ability to store the

result of a mathematical operation (numerical or symbolic) in a named variable. For example,

WARNING!!! Do not use subscripts, superscripts, and special symbols such as but not limited to ( ) [ ] & % $ # @ etc., in the names of the Mathematica variables because it can

easily lead to program errors and wrong results!

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 9 of 60

To see what is stored in a given variable, simply type in its name, or use the Print[] command:

Note how in the last statement (Print["variable c = ", c]) we have supplemented the printout with text. This type of output can be very helpful when writing a code, and will be required when

processing exercises.

If you wish to clear the value or definition of a given variable, use the Clear[] command:

Clearing the declared values as they are no longer needed is definitely a good habit [6]. Beginning

a new Mathematica session, like starting with a clean slate, for each problem is a good practice

[6].

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 10 of 60

An alternative, almost as good as starting with a clean slate, is to execute the command

Clear["Global` ∗ "] which clears the values for all symbols in the Global` context, except those that are protected [6]. Note that symbol “ ` ” is not an apostrophe, it is the so-called “grave accent”:

https://en.wikipedia.org/wiki/Grave_accent

which can be located in your keyboard as shown below [7]:

Here is an example that shows how to use the Clear["Global` ∗ "] statement:

If you wish to execute the entire notebook automatically (one cell after another), use the “Evaluate

Notebook” option in the “Evaluation” menu. Keep in mind, that Mathematica keeps definitions

and assignments of all variables in memory as it executes notebook(s). Sometimes, you want to

start over, and erase all those assignments. In this case, use option “Quit Kernel” → “Local” in

the same “Evaluation” menu, and re-evaluate the cells of interest, or use the “Evaluate Notebook”

option to evaluate all cells in your notebook. To clear the output only, use the “Cell” → “Delete

All Output” option.

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 11 of 60

Now, let’s try some other mathematical operations that you may find useful. To raise a number or

a variable (including a symbolic variable) to a power, you can either use the “^” symbol or

. To take square root, you can use the Sqrt[] function, or .

As you can see, the readability of the notebook improves dramatically when using the Mathematica

typesetting system. Also note that a variable need not have a numerical value assigned for

Mathematica to apply a certain operation to it. This comes in very handy when doing symbolic

computations (we will get to that in just a moment).

I hope that you have noted that Mathematica always prints out variables and parameters as they

are defined. If you do not want Mathematica to do that, terminate a command with the semicolon

symbol (“;”). For example, compare the two seemingly identical sequences:

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 12 of 60

In this lab, we require your Mathematica notebooks to have user-friendly printouts of parameters

using the Print[] option. In the following, I show how to do that:

Note how the values of parameters a, b, and c are not printed out as they are defined because each line is terminated with the semicolon. Indeed, rather than printing them out one by one without

annotation, it is much better to print out their values in a separate Print[] statement with accompanying [self-explanatory] text.

It is often desirable to separate two printout statements by a blank line. While one can use the

]" Print[" option to print out a blank line, a more elegant solution is to include the newline character “\n” in the second Print[] statement.

http://reference.wolfram.com/language/tutorial/NewlinesAndTabsInStrings.html

For example,

By default, Mathematica prints out all numbers in some default output format. Only very large

and very small numbers are given in scientific notation:

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 13 of 60

To force Mathematica print out numbers in scientific notation, use the ScientificForm[] option:

There are many other number output formats available. For more information, refer to

http://reference.wolfram.com/language/tutorial/OutputFormatsForNumbers.html

Note how all Mathematica built-in functions (Print[], Clear[], N[], Sqrt[] etc. are spelled with the first character in upper case, while all characters that follow are in lower case. If you misspell a

name of the function, the function will not work! At the same time, the name of the

unrecognized function will be highlighted in blue:

Finally, if you do not wish to remember all the special key combinations for symbols of

mathematical operations, you can use the “Palettes” option. Left-click on the “Palettes” menu and

choose the “Basic Math Assistant” option (actually, it is not very basic at all!):

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 14 of 60

You will immediately get a new “Basic Math Assistant” palette, which has two options” “Basic”

and “Advanced”. Try switching between those to see the difference. Note that in addition to a

number of algebraic and trigonometric functions,

it has many Calculus-related options, such as derivatives, limits, sums, and integrals:

Finally, before you can start working on the exercises, let’s look at a couple of very useful

functions.

Functions Simplify[] and FullSimplify[] : http://reference.wolfram.com/language/ref/Simplify.html

http://reference.wolfram.com/language/ref/FullSimplify.html

request simplification of the specified equation(s). These functions are extremely powerful

because Mathematica knows how to handle a lot of mathematical identifies.

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 15 of 60

For example, here is a simple familiar simplification:

Perhaps, something a little more complicated involving a trigonometric function:

In the following example, we

1) define function f that depends on variables x, y, and z, which we usually write as ),,( zyxf ,

2) differentiate f(x,y,z) with respect to (w.r.t.) x., and

3) simplify the resulting expression:

Note that taking a derivative of function ),,( zyxf w.r.t. variable x is very easy in Mathematica.

Alternatively, we could have written:

However, from our point of view the first way is more efficient because one may want to do

something else with function ),,( zyxf , i.e. re-use the definition of function f. Perhaps, you know

that when a function of several variables is differentiated w.r.t. one of the variables, the result is

called a partial derivative of the function with respect to the variable. For example, when

differentiating function ),,( zyxf w.r.t. parameter x, we get partial derivative x

zyxf

∂ ),,( . Because

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 16 of 60

function ),,( zyxf depends on three parameters, there will be three partial derivatives. The

remaining two partial derivatives are y

zyxf

∂ ),,( and

z

zyxf

∂ ),,( . The total derivative (aka

differential change or total differential) of function ),,( zyxf , denoted usually as ),,(d zyxf , is

the sum of all of its partial derivatives:

z z

zyxf y

y

zyxf x

x

zyxf zyxf d

),,( d

),,( d

),,( ),,(d

∂ +

∂ +

∂ = ,

where each of xd , yd , and zd is called simply a differential.

Ok, now that you know how to do some basic [and not very basic] things in Mathematica, let’s

see how you can use it to perform familiar scientific computations.

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 17 of 60

3. Solutions of Algebraic Equations

Before diving into Calculus (which is what Physical Chemistry is all about), let’s learn how to

solve equations with Mathematica. In this section we limit ourselves to solving [relatively simple]

algebraic equations: quadratic, cubic, and quartic. For example, we wish to solve a standard

quadratic equation in the form

0 2

=++ cbxax (1)

Of course, we know that there are two solutions for x given by

a

acbb x

2

4 2

−±− = (2)

Let’s see if Mathematica can do that. In this case, we can use the Solve[] option: http://reference.wolfram.com/language/ref/Solve.html

Yes, it can! Note how I have used the “==” symbol to define the equality telling Mathematica that

the right had side of the equation (rhs) is equal to the left hand side (lhs).

Actually, according to the Mathematica documentation,

“[b]uilt into the Wolfram Language is the world's largest collection of both numerical and

symbolic equation solving capabilities—with many original algorithms, all automatically accessed

through a small number of exceptionally powerful functions. The Wolfram Language's symbolic

architecture allows both equations and their solutions to be conveniently given in symbolic form,

and immediately integrated into computations and visualizations.”

http://reference.wolfram.com/language/guide/EquationSolving.html

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 18 of 60

Example 3.1. Let’s consider the following exercise taken from your Physical Chemistry textbook

[8]. At a certain temperature, for reaction

(g)2NH (g)3H(g)N 322

→←+ (3)

the equilibrium constant K (Kp) is equal to 977. For this particular example, the equilibrium is

given by

3

HN

2

NH

p

22

3

pp

p KK == (4)

where pJ is the partial pressure of substance J divided by standard pressure of 1 bar, i.e. o

JJ / ppp ← (5)

where o

p = 1 bar. Note that the equilibrium constant K is a dimensionless (unitless) quantity. In

general, the equilibrium constant K equals the value of the reaction quotient Q at equilibrium. For

a general chemical reaction of the form [8]:

a A + b B ↔ c C + d D (6)

the equilibrium constant is given by [8]

mequilibriuBA

DC mequilibriu 

  

 ==

ba

dc

QK αα

αα (7)

where αJ is the activity of species J [8]. For perfect gases, o

JJ / pp=α , the partial pressure of J

relative to the standard pressure o

p = 1 bar [8]. For solutes in very dilute solutions, o

J /]J[ c=α ,

the molar concentration (molarity) of J relative to the standard value o

c = 1 mol/L (M) [8]. If one

wishes to discuss a gas-phase reaction in terms of molar concentrations (the amount of gas

molecules in moles divided by the volume of the container, Vn /]J[ J

= ), rather than partial

pressures, the equilibrium constant Kp is replaced with Kc [8]:

ba

dc

c K

]B[]A[

]D[]C[ = (8)

where each molar concentration is raised to a power equal to the stoichiometric coefficient of the

species in the chemical equation [8]. As usual, we have replaced [J]/ o

c by [J] itself, which

represents the numerical value of the molar concentration of the gas J [8]. For example, for the

chemical reaction shown in equation (3), [8]

3

22

2

3

]H][N[

]NH[ =

c K (9)

Now, back to our example. Suppose we mix in 1.00 bar of N2(g) with 3.00 bar of H2(g). We need

to find the equilibrium partial pressures of all three gases: (a) 2N

p , (b) 2H

p , and (c) 3NH

p , and (d)

check the final results using the equilibrium constant.

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 19 of 60

After setting up the ICE table [8],

we get:

3

2

)300.3)(00.1(

)2(

xx

x K

−− = (10)

Note that this is a quartic equation (i.e. the highest power of x is 4)! Mathematica can [relatively]

easily solve this equation:

Note how I used the N[] function to get Mathematica to output numerical values. Because this is a quartic equation, we get four solutions. Which one is correct? Well, mathematically all of them

are correct! However, according to Physical Chemistry, partial pressure (or any other physically

observable quantity) can not be a complex number (i.e. number which includes the imaginary

component with 1−=i ). Thus, solutions two and three are not physical, and should be

discarded! In fact, in Thermodynamics and Kinetics we are usually interested in real solutions

only

https://en.wikipedia.org/wiki/Real_number

If x is real, it must belong to a domain of real numbers. In the language of Mathematics, it can be

written as 6 ∈ ℝ, where the symbol “∈” means “is an element of” and the symbol “ℝ” denotes the set of ALL real numbers. How about that! Anyway, if we are interested only in real solutions of

a given equation, the Solve[] command can be modified as follows:

This leaves us with only two solutions. That is nice! But which one (or both) is (are) physically

meaningful? Recall that in our ICE table, x denotes the change in partial pressure. The equilibrium

partial pressures of N2(g) and H2(g) are (1.00-x) bar and (3.00-3x) bar. Solution x = 1.1173 bar

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 20 of 60

would give us negative equilibrium pressures of N2(g) and H2(g), and thus is not physically

meaningful. This leaves us with only one solution: x = 0.895018 bar. Now we can calculate the

final partial pressures of all three gases. Here is our Mathematica code that does that:

Let me explain what I am doing in each cell:

In[1]: Solve equation, get numerical solutions, and store all solutions in a variable (to be more precise, a list of variables) called “solutions”

In[2]: Extract the first solution (command “solutions[[1]]”), and put it in variable “x” using command “/.”. For example, command a�/. a → 2 means: evaluate “a2” while replacing “a” with 2 (symbol → can be typed in Mathematica as “->”). Naturally, the answer is 4.

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 21 of 60

To do the same with several variables is not much more difficult:

A detailed information on the “/.” command can be obtained here:

http://reference.wolfram.com/language/ref/ReplaceAll.html

In[3]: Calculate the final partial pressures of all three gases and store them in variables pN2, pH2, and pNH3. Note how the names of variables are self-explanatory. This is VERY important!

Note on using Units in Mathematica: Each scientific calculation must include units. In general,

Mathematica can use units:

https://reference.wolfram.com/language/guide/Units.html

However, the interface is not very user-friendly. Thus, for now, it is acceptable to ignore units

when doing calculations in Mathematica.

That said, in every single Mathematica notebook you absolutely must include comments that

describe your calculation steps and the units of variables used. A comment in Mathematica is any

text entered between symbols sequences “(*” and “*)”

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 22 of 60

Note how I have also added a check: the numerical value of the reaction quotient at equilibrium

must be equal to the equilibrium constant (K = 977). The difference between the equilibrium

constant that was calculated using the equilibrium partial pressures of the three gases and the given

value is below 10-12, which means that the final equilibrium partial pressures must be correct!

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 23 of 60

Now we tweak the processing of variables (to make the code more transparent and portable, and

less cluttered), and add the project number, author name, date, the Clear["Global` ∗ "] command, and user-friendly output of calculated properties. See for yourself:

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 24 of 60

Note how we suppressed the default Mathematica printout by terminating each line (except for

the Solve[] statement) with a semicolon. This eliminates unnecessary printout from the final version of the code (we suggest you do so only in the final version of the code, after you have

made sure that it produces correct results, and when you are ready to upload it to D2L).

Finally, once you are satisfied with your code, go through the following checklist before

submitting your Mathematica notebook to D2L:

1) Make sure that the header of the Mathematica notebook includes the exercise number, your

name, and the creation date. .

2) Make sure that all required answers are printed out using the Print[] statement.

3) Verify that each Print[] statement includes the appropriate label, i.e.

Print[“(a) …… “];

Print[“(b) …… “];

Print[“(c) …… “]; etc.

4) Suppress output from lines that do not contain printout of answers.

5) Remove all output cells (go to the “Cell” option of the notebook menu and select “Delete

All Output”)

6) Merge all input cells, which can be done using the following two steps:

a. go to the “Edit” option of the notebook menu and select “Select All” (or simply use

the “Ctrl+A” key combination)

b. go to the “Cell” option of the notebook menu and select “Merge Cells” (or simply

use the “Shift + Ctrl + M”

7) Save the notebook, and upload it to D2L.

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 25 of 60

Here is the final version of the Example 3.1 Mathematica notebook:

Note that your Mathematica notebook for this example should look very similar!

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 26 of 60

Perhaps now is a good time to demonstrate how to use the Mathematica Solve[] function http://reference.wolfram.com/language/ref/Solve.html

to solve two equations for two unknowns simultaneously:

where x and y are the unknowns, and a and b are constants. Note how we used the “&&” symbol

to specify the logical AND function. Suppose, we wish to save the solutions to some variables.

Here is how we save the solution for x to a variable called xs:

, and the same for y:

If numerical values for a and b are known, xs and ys can be easily evaluated. For example,

Not bad!

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 27 of 60

Now that we have shown you how to perform this kind of calculations, it is your turn to do some.

Exercise 3.1. At a certain temperature, the equilibrium constant Kp for the gas-phase reaction

H2(g) + I2(g) ↔ 2HI(g)

is 40. Suppose, a gas mixture of H2 and I2 is prepared that has initial partial pressures (before

reaction) of 1.8 bar for H2 and 3.2 bar for I2. Using the final notebook from Example 3.1 as a

template, create a Mathematica notebook to calculate the equilibrium partial pressures (in bar) of

all three gases: (a) H2, (b) I2, (c) HI, and (d) perform the check for K (Kp). Save the notebook as

“Exercise_3.1.nb”. Warning! All calculation steps must be performed in your Mathematica

notebook, and all items (a-d) must be clearly labelled in the Print[]Print[]Print[]Print[] functions, or the score for this exercise will be zero!

Answers: (a) 0.17 bar (b) 1.6 bar (c) 3.3 bar (d) …

Exercise 3.2. At a certain temperature, the equilibrium constant Kp for the gas-phase reaction

CO(g) + Br2(g) ↔ COBr2(g)

is 0.0250. Suppose a 9:4 (in terms of partial pressures) reaction mixture of CO and Br2 is heated

in a closed vessel at a total pressure of 19.5 bar. Using the final notebook from Example 3.1 as a

template, create a Mathematica notebook to calculate the equilibrium partial pressures (in bar) of

all three gases: (a) CO, (b) Br2, (c) COBr2, (d) perform the check for Kp, and (e) calculate the

percentage of Br2(g) that will be converted to COBr2(g) under these conditions. Save the notebook

as “Exercise_3.2.nb”. Warning! All calculation steps must be performed in your Mathematica

notebook, and all items (a-e) must be clearly labelled in the Print[]Print[]Print[]Print[] functions, or the score for this exercise will be zero! Hint: https://en.wikipedia.org/wiki/Partial_pressure

Answers: (a) 12.1 bar (b) 4.61 bar (c) 1.39 bar (d) … (e) …

Exercise 3.3. It is sometimes convenient to express concentrations of species in a gas phase

reaction in mol L-1. For example, consider the gas-phase reaction

4 HCl(g) + O2 (g) ↔ 2 H2O(g) + 2 Cl2(g)

that has reached equilibrium at the following concentrations of substances: [H2O(g)] = [Cl2(g)] =

0.14 mol L-1, [HCl(g)] = 0.20 mol L-1, and [O2(g)] = 0.32 mol L -1. Using the final notebook from

Example 3.1 as a template, create a Mathematica notebook to calculate (a) the equilibrium constant

Kc of the reaction. Considering that the initial reaction mixture did not contain any of the products,

calculate the initial (before reaction) concentrations of (b) O2(g) (mol L -1) and (c) HCl(g)

(mol L<=�. Save the notebook as “Exercise_3.3.nb”. Warning! All calculation steps must be performed in your Mathematica notebook, and all items (a-c) must be clearly labelled in the

Print[]Print[]Print[]Print[] functions, or the score for this exercise will be zero! Answers: (a) 0.75 (b) 0.39 mol L-1 (c) 0.48 mol L-1

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 28 of 60

4. Differential Calculus

In this part of the lab, we are going to review some of the most fundamental physical concepts,

and at the same time refresh your knowledge of Differential Calculus.

Displacement [9]. Pretty much everything around [and inside] us is in motion. Motion involves

the displacement of an object from one place in space and time to another. Describing motion

requires some convenient coordinate system and a specified origin. A frame of reference is a

choice of coordinate axes that defines the starting point for measuring any quantity, an essential

first step in solving virtually any problem in mechanics. The displacement ∆x of an object is

defined as its change in position and is given by

if xxx −=∆ (11)

where xi is the coordinate of the initial position of the object and xf is the coordinate of the objects’

final position (here, indices i and f stand for initial and final, respectively). The SI unit of

displacement is a meter (m).

Because displacement has both a magnitude (size) and a direction, it’s a vector quantity.

In general, a vector quantity is characterized by having both a magnitude and a direction. By

contrast, a scalar quantity has magnitude, but no direction. Scalar quantities such as mass and

temperature are completely specified by a numeric value with appropriate units; no direction is

involved.

Velocity and speed [9]. In everyday usage the terms speed and velocity are interchangeable. In

physics, however, there’s a clear distinction between them: speed is a scalar quantity, having only

magnitude, whereas velocity is a vector quantity, having both magnitude and direction. However,

the two quantities share the same SI unit: meter per second (m/s).

The average speed of an object over a given time interval is the length of the path it travels

divided by the total elapsed time:

timeelapsed

lengthpath speed Average = (12)

Unlike average speed, average velocity is a vector quantity, having both a magnitude and a

direction. The average velocity v during a time interval t∆ is the displacement, x∆ , divided by

the elapsed time, t∆ :

if

if

tt

xx

t

x v

− =

∆ = (13)

While the average speed is always non-negative, the average velocity of an object in one dimension

can be either zero, or positive or negative, depending on the sign of the displacement. (The time

interval t∆ is always positive.)

The instantaneous velocity v is the limit of the average velocity as the time interval t∆

becomes infinitesimally small:

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 29 of 60

t

x v

t ∆

∆ =

→∆ 0 lim (14)

The notation 0

lim →∆t

means that the ratio tx ∆∆ / is repeatedly evaluated for smaller and smaller time

intervals t∆ . Notice that the displacement x∆ approaches zero as t∆ approaches zero, so the ratio

looks like 0/0 [10]. While this ratio may appear to be difficult to evaluate, it does have a specific

value. As x∆ and t∆ become smaller and smaller, the ratio tx ∆∆ / approaches a value equal to

the slope of the line tangent to the x-versus-t curve, which is defined as the instantaneous velocity

[Fig. 1].

Figure 1. The instantaneous x-velocity v at any given point equals the slope of the tangent to the

x-t curve at that point [11].

In the Calculus notation, this limit is called the derivative of x with respect to (w.r.t.) t, written as

dtdx / [10]

dt

dx

t

x v

t =

∆ =

→∆ 0 lim (15)

The instantaneous speed of an object, which is a scalar quantity, is defined as the magnitude of

the instantaneous velocity. Like average speed, instantaneous speed (which we will usually call,

simply, “speed”) has no direction associated with it and hence carries no algebraic sign.

Acceleration, a [9]. The changing of an object’s velocity with time is called acceleration. The

average acceleration a during the time interval t∆ is the change in velocity v∆ divided by t∆ :

if

if

tt

vv

t

v a

− =

∆ = (16)

Acceleration is a vector quantity having dimensions of length divided by the time squared. In the

SI system of units, acceleration has dimensions of meters per second per second ( (m/s)/s, which

is usually written as m s-2 ). Acceleration is a vector quantity. For the case of motion in a straight

line, the direction of the velocity of an object and the direction of its acceleration are related as

follows: When the object’s velocity and acceleration are in the same direction, the speed of the

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 30 of 60

object increases with time. When the object’s velocity and acceleration are in opposite directions,

the speed of the object decreases with time (this type of acceleration is often called deceleration).

a) b)

Figure 2. (a) A car, modeled as a particle, moving along the x axis from A to B, has velocity vi at t = ti and velocity vf at t = tf . (b) Velocity–time graph (red-brown) for the particle moving in a

straight line. [10]

The value of the average acceleration often differs in different time intervals, so it is useful to

define the instantaneous acceleration, which is analogous to the instantaneous velocity discussed

above. The instantaneous acceleration a is the limit of the average acceleration as the time interval

t∆ goes to zero:

t

v a

t ∆

∆ =

→∆ 0 lim (17)

Here again, the notation 0

lim →∆t

means that the ratio tv ∆∆ / is evaluated for smaller and smaller

values of t∆ . The closer t∆ gets to zero, the closer the ratio gets to a fixed number, which is the

instantaneous acceleration.

In the language of Calculus, instantaneous acceleration equals the derivative of the velocity

with respect to time:

dt

dv

t

v a

t =

∆ =

→∆ 0 lim (18)

which, by definition, is the slope of the velocity–time graph [10]. The slope of the green line in

Figure 2b is equal to the instantaneous acceleration at point B. Notice that Figure 2b is a velocity–

time graph, not a position–time graph like Figure 1. Therefore, we see that just as the velocity of

a moving particle is the slope at a point on the particle’s x–t graph, the acceleration of a particle is

the slope at a point on the particle’s v–t graph. One can interpret the derivative of the velocity

with respect to time as the time rate of change of velocity. If a is positive, the acceleration is in

the positive x direction; if a is negative, the acceleration is in the negative x direction (often called

deceleration) [10].

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 31 of 60

Because v = dx/dt, the acceleration can also be written as

( ) 2

2

dt

xd

dt

dx

dt

d v

dt

d

dt

dv a =

  

 === (19)

That is, in one-dimensional motion, the acceleration also equals the second derivative of x with

respect to time [10].

Figure 3 [10] illustrates how an

acceleration–time graph is related to a velocity–

time graph. The acceleration at any time is the

slope of the velocity–time graph at that time.

Positive values of acceleration correspond to those

points in Figure 3 where the velocity is increasing

in the positive x direction. The acceleration

reaches a maximum at time tA, when the slope of

the velocity–time graph is a maximum. The

acceleration then goes to zero at time tB, when the

velocity is a maximum (that is, when the slope of

the v–t graph is zero). The acceleration is negative

when the velocity is decreasing in the positive x

direction, and it reaches its most negative value at

time tC [10].

Figure 3 [10]. (a) The velocity–time

graph for a particle moving along the x

axis. (b) The instantaneous acceleration

can be obtained from the velocity–time

graph.

Example 4.1. Consider a particle moving along the x axis according to the equation 2

00.100.300.2)( tttx −+= (20)

where x is in meters (m) and t is in seconds (s). Using Mathematica, derive general expressions

for (a) v(t) and (b) a(t). At t = 3.00 s, find (c) the position of the particle, (d) its velocity, and (e)

its acceleration. Plot (f) x vs t, (g) v vs t , and (h) a vs t for t = 0…5 seconds.

Open a new Mathematica notebook, and call it, say, “Example_4.1.nb”. After typing in the project

number, define function x(t) given above:

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 32 of 60

First, we derive a general expression for velocity at any t, i.e. find v(t). Recall that dt

tdx tv

)( )( = ,

so we need to differentiate x(t) with respect to (w.r.t.) t. In Mathematica, differentiation can be

done using the command D[] https://reference.wolfram.com/language/ref/D.html?q=D

or using the button in the section of the “Basic Math Assistant” palette:

Here is my code that demonstrates how to use both options (of course, you should use only one,

which makes more sense!):

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 33 of 60

As expected, the two differentiation commands give the same result. Thus, v(t) = 3 – 2t. Note how

I used the Print[] statement to print out answer for (a).

How about the acceleration? Well, according to equation (18), we get a(t) by differentiating v(t)

w.r.t. t once, or differentiate x(t) w.r.t t twice: 2

2 )()(

)( dt

txd

dt

tdv ta == . Both methods can be easily

implemented Mathematica (of course, you should use only one, whichever makes more sense!):

Again, as expected, a is the same regardless of the method used. Note that because a does not

depend on t, we are dealing with a case of the constant acceleration. Thus, a = -2 m/s2 (units come

directly from the question) at any time t. To summarize,

secondsin is where,00.100.300.2 m)(in )( 2

ttttx −+=

secondsin is where,00.200.3 m/s)(in )( tttv −=

ta any at 00.2 )m/s(in 2

−=

Finding x, v, and, especially, a (duh!) at t = 3 s is very easy:

Again, note how I use the Print[] statement to create a user-friendly output. Also note that acceleration, a, is of course constant at -2 m/s2.

Now the fun part. We can easily plot x(t), v(t), and a(t) in Mathematica using the Plot[] function. In the following, I show how to do it for t = 0…5 s:

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 34 of 60

While this is nice plot, it is missing labels of the x- and y- axes, and the plot label (legend). Those

can be added to any Mathematica plot as shown below:

Much better! Note that I have used Mathematica’s function SetOptions[Plot, BaseStyle → {FontSize → 14}] to increase the font size in the plots. Now, let’s plot v(t) and a(t):

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 35 of 60

I hope that it is obvious that because velocity changes uniformly with time (i.e. a v-t plot is a

straight line), acceleration is constant, and vice versa.

Finally, it may be worthwhile to show how easy it is to plot two or more equations on the same

graph in Mathematica. Consider the following three functions 2

321 5 ,310 ,21 xyxyxy +−=−=+=

that we wish to plot on the same graph for 50 ≤≤ x . First, we define the functions:

Then, we define the minimum and maximum values for x, and the font size for the plot:

Because we terminated each command here with a semicolon, there is no output. Finally, we plot

all three functions on the same plot using the same command Plot[] which was used to plot a single function:

Note how we included a list of functions that we want to plot in the curly brackets [thus forming

as so-called “list” in Mathematica]. Also note that in addition to already familiar options

AxesLabel and PlotLabel, we added the PlotLegends option that, as you can guess from its name, adds a legend to the graph.

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 36 of 60

Sometimes Mathematica does not plot the entire range for x and/or y variable(s). For example,

To fix that, simply add the PlotRange→Full option to the Plot[] command:

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 37 of 60

Ok, now it is your turn to perform a couple of calculations in Mathematica.

Exercise 4.1. An object moves along the x axis according to the equation

6� � = G + ℬ + I � + J � where x is in cm, t is in seconds, and G, ℬ, I, and J are some constants. Using the notebook from Example 4.1 as a template, write a Mathematica code to derive expressions for (a) velocity and

(b) acceleration as a function of time t and general coefficients G, ℬ, I, and J . If G = 0.1 cm, ℬ = 0.04 cm s<=, I = −0.3 cm s<� and J = 0.05 cm s<�, calculate (c) the distance, (d) velocity, and (e) acceleration at t = 4.0 s. Plot (f) x vs t, (g) v vs t, and (h) a vs t for t = 0… 7 s. Save the

notebook as “Exercise_4.1.nb”. Warning! All calculation steps must be performed in your

Mathematica notebook, and all items (a-h) must be clearly labelled in the Print[]Print[]Print[]Print[] functions, or the score for this exercise will be zero!

Answers: (a) ℬ + 2I + 3J � (b) 2I + 6J

(c) -1.3 cm (d) 0.04 cm s-1 (e) 0.6 cm s-2

(f,g,h) …

Exercise 4.2. An object moves along the 6 axis according to the equation 6� � = M�2 � − N� − O sin P2Q3 R

where x is in meters, t is in seconds, and M, N and O are some constants. Using the notebook from Example 4.1 as a template, write a Mathematica code to derive expressions for (a) velocity and

(b) acceleration as a function of time t and general coefficients M, N and O. If M = 0.3 m s<�, N = 0.1 s� and O = 0.8 m, calculate (c) the distance, (d) velocity, and (e) acceleration at t = 2.0 s. Plot (f) x vs t, (g) v vs t, and (h) a vs t for t = 0… 3 s. Save the notebook as “Exercise_4.2.nb”.

Warning! All calculation steps must be performed in your Mathematica notebook, and all

items (a-h) must be clearly labelled in the Print[]Print[]Print[]Print[] functions, or the score for this exercise will be zero!

Answers: (a) 6M � − �� QO cos S �TU

� V (b) 12M + WX Q�O sin S

�T � V

(c) 5.5 m (d) 8.0 m s-1 (e) 4.2 m s-2

(f,g,h) …

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 38 of 60

5. Geometrical interpretation of derivatives [12]

In the previous section we introduced the idea that in the limiting case the derivative represents an

instantaneous rate of change of two variables [12]. Hence, if, for example, y = f(x) is plotted on a

two-dimensional Cartesian coordinate system, then dxdy / is the slope of the curve at any point

),( yx on the curve. With exception of the function )( xy = constant, functions either increase or

decrease as the value of x increases. By looking at the derivative (or slope) evaluated at the point

),( yx , we can determine whether the function )( xf is increasing or decreasing as x increases

without having to graph the function. If dxdy / is positive, then )( xf increases as x increases. If

dxdy / is negative, then )( xf decreases as x increases [12].

Certain functions, such as parabolas (Fig. 4a), or functions of higher order, such as cubic

functions (Fig. 4b), have either a maximum or a minimum value, or both [12]. Differential calculus

can be used to help us determine the point or points along the curve where maxima or minima

occur. Since the slope of the curve must be zero at these points, the first derivative also must be

zero [12].

a) 232

2 +−= xxy

b) 262

3 +−= xxy

Figure 4 [12]. Sample graphs of (a) quadratic and (b) cubic functions.

For example, the parabola shown in Fig. 4a is described by the equation [12]

232 2

+−= xxy (21)

Taking the first derivative gives [12]

34 −= x dx

dy (22)

Setting the first derivative equal to zero and solving for x, we have [12]

034 =−x or 4

3 =x (23)

Substituting 4

3 =x into the equation y(x), yields y = 0.875, which gives the minimum point on the

curve [12]. In Mathematica, the same calculation can be performed as follows:

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 39 of 60

In order to determine whether the curve is a maximum or a minimum at a point without actually

plotting the curve, we can substitute values for x that are greater than the value at the point where

the derivative is zero and the values for x that are smaller than the value at the point where the

derivative is zero (a.k.a. stationary point). Then we note the behavior of y. A simpler way to test

whether the function is a maximum or a minimum is to look at the second derivative of the function

[12].

If 0 2

2

< dx

yd , then the function is a maximum.

If 0 2

2

> dx

yd , then the function is a minimum.

If 0 2

2

= dx

yd ,

then the function is at a point of inflection – a point on the curve where the curve

changes from one that exhibits a maximum at some point (i.e., is “concave

downward”) to one that exhibits a minimum at some point (i.e., is “concave

downward”), or vice versa; note that inflections points may be stationary points

(as shown in Fig. 5), but are not local maxima or local minima.

Figure 5 [13]. Example of an inflection point.

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 40 of 60

Thus, in the parabola example, the second derivative at x = ¾ (and, incidentally, everywhere else)

is

This makes sense because any parabola is “concave downward” everywhere...

Now, consider the cubic function shown in Fig. 4b [12]:

262 3

+−= xxy (24)

Taking the first derivative and setting it equal to zero yields [12]

066 2

=−= x dx

dy ; 01

2 =−x ; 1±=x (25)

which indicates that there is maximum or a minimum at x = +1 and x = -1 [12]. Taking the second

derivative of this cubic equation gives

x dx

yd 12

2

2

= (26)

For x = +1, 12/ 22

=dxyd , which indicates that the curve is a minimum at this point. For x = -1,

12/ 22

−=dxyd , which indicates that the curve is a maximum at this point.

In Mathematica, these calculations can be done as follows:

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 41 of 60

Now you may wonder at which point the sign of the curvature changes from negative (maximum)

to positive (minimum). Well, clearly it should be at a point where the second derivative vanishes,

i.e.

012 2

2

== x dx

yd (27)

It follows that x = 0 is an inflection point of this function. Mathematica can find this point easily:

Example 5.1. The mathematical expression that tells us the probability, P, that the molecules in

a sample of gas have a speed that lies in a particular range at any instant is called the distribution

of molecular speeds [14]. The precise form of the distribution was worked out by James Clerk

Maxwell (1831-1879) towards the end of the nineteenth century, and his expression is known as

the Maxwell distribution of speeds [14]. A sample Maxwell distribution of molecular speeds for

the argon gas at 500 K is shown in Fig 6 [15].

Figure 6 [15]. The Maxwell distribution of molecular speeds for the argon gas at 500 K.

According to Maxwell’s equation, the probability ),( vvvP ∆+ that the molecules have a speed in

a narrow range between v and v+∆v (for example, between 300 m/s and 301 m/s, corresponding to

v = 300 m/s and ∆v = 1 m/s) is [14]

RT

Mv

ev RT

M vvvvvvP 2

2

2/3 2

2 4)(with)(),(

 

  

 =∆=∆+

π πρρ (28)

where M is the molar mass of the gas, R is the gas constant, and T is temperature. We wish to

derive an expression for the most probable speed (identified as vmost prob in Fig. 6). Note that the

most probable speed is the speed at which the probability is a maximum. Thus, we must maximize

the function

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 42 of 60

RT

Mv

ev RT

M v 2

2

2/3 2

2 4)(

 

  

 =

π πρ (29)

with respect to v, set the derivative to zero, and solve for v. This is a simple task for Mathematica.

We always start with the project title (and so should you!). Then, we define function )(vρ :

A couple of notes. Instructions on how to enter Greek letters in Mathematica can be found at

http://reference.wolfram.com/language/tutorial/EnteringGreekLetters.html

Of course, constants, such as π, i, and e can also be entered using the “Basic Math Assistant”

palette. Alternatively, you can use the “Special Characters” palette under the “Palettes” menu.

Second, an exponential can be taken using the Exp[] function, or using the button in the “Basic Math Assistant” palette

Naturally, the result is the same:

Now, we calculate the derivative of )(vρ w.r.t. v, dv

vd )(ρ , and store the result in variable dvdρ :

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 43 of 60

We can also ask Mathematica to try to simplify the result [to make it more “visually appealing”]

using command Simplify[] or, even better, FullSimplify[]:

We set the derivative (stored in variable dvdρ ) to zero, and use the Solve[] function to solve the equation for v:

There are three solutions. While all of them are mathematically correct, the first two solutions are

not physically meaningful (I hope you see why…). Thus, the only acceptable solution is number

three, which we then copy to variable vmostprob, and print it out:

Now, compare the expression derived in Mathematica to that given in [almost] every single

Physical Chemistry textbook [13,15]: 2/1

probmost

2  

  

 =

M

RT v (30)

Not bad, eh?!

Well, it is time for you to differentiate a couple of simple functions in Mathematica.

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 44 of 60

Exercise 5.1. An object is oscillating along the 6-axis according to the following equation 6� � = 0.1 sin STZ +

T WV (31)

where is time. Using the final notebook from Example 5.1 as a template, create a Mathematica notebook that determines the maximum and minimum 6-coordinate of the object. Save the notebook as “Exercise_5.1.nb”. Your Mathematica notebook must include the following items

in the printout, all clearly labelled using the Print[]Print[]Print[]Print[] function: (a) define function 6� �, (b) derive formula for the first derivative of 6� � with respect to (w.r.t.) , [6/[ (recall that

the first derivative of position w.r.t. time is a velocity!)

(c) locate the stationary points of 6� � by determining values of at which [6/[ = 0; you should get two points: = = −6 and � = 2; note that since this function is periodic, it is sufficient to consider −10 ≤ ≤ 6; depending on the version of Mathematica that you use, you may have to explicitly define

the region for in the Solve[] command: Solve[…&& ≥ −10&& ≤ 6], where symbol “&&” is the Mathematica logical AND function:

http://reference.wolfram.com/language/ref/And.html

(d) derive formula for the second derivative of 6� � w.r.t. , [�6/[ � (recall that the second derivative of position w.r.t. time is an acceleration!),

(e-f) for each point found at step (c), calculate numerical value of the second derivative,

[�6/[ �, and decide whether 6� � at this point is a minimum, maximum, or an inflection point ( = – minimum, � – maximum),

(g) plot 6� � vs for −12 ≤ ≤ 8 to confirm your conclusions for (e-f). Warning! All calculation steps must be performed in your Mathematica notebook, or the

score for this exercise will be zero!

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 45 of 60

Exercise 5.2. Using the final notebook from Example 5.1 as a template, create a Mathematica

notebook that determines the maximum velocity in the positive and negative 6-directions for the object whose position is given by the function 6� � defined in Exercise 5.1:

6� � = 0.1 sin STZ + T WV (32)

Save the notebook as “Exercise_5.2.nb”. Your Mathematica notebook must include the

following items in the printout, all clearly labelled in the Print[]Print[]Print[]Print[] functions: (a) define function 6� �, (b) differentiate 6� � w.r.t. to calculate ^� �, (c) derive formula for the first derivative of ^� � with respect to (w.r.t.) , [^/[ (recall that

the first derivative of velocity is an acceleration!)

(d) locate the stationary points of ^� � by determining values of at which [^/[ = 0 (i.e. when the acceleration is zero!);

note that since this function is periodic, it is sufficient to consider −10 ≤ ≤ 6; depending on the version of Mathematica that you use, you may have to explicitly define

the region for in the Solve[] command: Solve[…&& ≥ −10&& ≤ 6], where symbol “&&” is the Mathematica logical AND function:

http://reference.wolfram.com/language/ref/And.html

you should get three points: = = −10, � = −2 and � = 6; (e) derive formula for the second derivative of ^� � w.r.t. , [�^/[ � (this would be the first

derivative of acceleration!),

(f,g,h) for each point found at step (d), calculate numerical value of the second derivative,

[�^/[ �, and decide whether ^� � at this point is a minimum, maximum, or an inflection point ( = and � – minima, � – maximum),

(i) plot ^� � vs for −12 ≤ ≤ 8 to confirm your conclusions for (f-g). Warning! All calculation steps must be performed in your Mathematica notebook, or the

score for this exercise will be zero!

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 46 of 60

6. Integral Calculus

In Section 4 we discussed that the velocity of a particle moving in a straight line can be obtained

if its position as a function of time is known [10]. Mathematically, the velocity equals the

derivative of the position with respect to time [10], i.e.

dt

tdx tv

)( )( =

It is also possible to find the position of a particle if its velocity is known as a function of time

[10]. In calculus, the procedure used to perform this task is referred to either as integration or as

finding the antiderivative. Graphically, it is equivalent to finding the area under a curve [10].

Figure 8 [10]. Velocity versus time for a particle moving along the x axis. The total area under

the curve is the total displacement of the particle [10].

Suppose the tv − graph for a particle moving along the x axis is as shown in Figure 8 [10].

Let us divide the time interval if tt − into many small intervals, each of duration ∆tn. From the

definition of average velocity, we see that the displacement of the particle during any small

interval, such as the one shaded in Figure 8, is given by ∆xn = vn,avg - ∆tn, where vn,avg is the average

velocity in that interval [10]. Therefore, the displacement during this small interval is simply the

area of the shaded rectangle in Figure 8 [10]. The total displacement for the interval if tt − is the

sum of the areas of all the rectangles from ti to tf [10]:

 ∆=∆ n

nxn tvx

avg, (33)

Now, as the intervals are made smaller and smaller, the number of terms in the sum increases and

the sum approaches a value equal to the area under the curve in the velocity–time graph [10].

Therefore, in the limit ∞→n , or 0→∆t , the displacement is [10]

 ∆=∆ →∆

n

nn t

tvx n

avg, 0

lim (34)

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 47 of 60

If we know the tv − graph for motion along a straight line, we can obtain the displacement during

any time interval by measuring the area under the curve corresponding to that time interval [10].

The limit of the sum shown in equation (34) is called a definite integral and is written [10]

 =∆→∆ f

in

t

t n

nn t

dttvtv )(lim avg,

0 (35)

where )(tv denotes the velocity at any time t [10]. If the explicit functional form of )(tv is known

and the limits are given, the integral can be evaluated [10].

Sometimes the tv − graph for a moving particle has a shape much simpler than that shown

in Figure 8 [10]. For example, suppose an object is described with the particle under a constant

velocity model [10]. In this case, the tv − graph is a horizontal line as in Figure 9 and the

displacement of the particle during the time interval t∆ is simply the area of the shaded rectangle

[10]:

tvx i

∆=∆ avg, (when )constant== ivv (36)

Figure 9 [10]. The velocity–time curve for a particle moving with constant velocity vi. The displacement of the particle during the time interval tf - ti is equal to the area of the shaded

rectangle.

Recall, that the acceleration is defined as

dt

dv a =

First, we rewrite this equation as

adtdv = (37)

We now integrate the two sides between the initial (i) and final (f) values:

 = f

i

f

i

t

t

v

v adtdv (38)

The left hand side (lhs) is trivial, it evaluates to

vvvdv if

v

v

f

i

∆=−= (39)

In Mathematica, integration is easy. You can either type in the command Integrate[] http://reference.wolfram.com/language/ref/Integrate.html

or use the integral buttons in the section of the “Basic Math Assistant” palette:

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 48 of 60

Here is my Mathematica code that demonstrates how to use both options:

As expected the result is the same, and, of course, agrees with that given in equation (39). Now

we deal with the right hand side (rhs) of equation (38). Note that we integrate between the initial

time (ti) and final time (tf). By convention, the initial time is set to zero, i.e. ti = 0: recall that when

you time an event, you usually start at zero, i.e. t = 0! On the contrary, the initial velocity is not

necessarily zero (the object can be moving when we start the timer), so vi = v0 (which may or may

not be zero). Then, we can drop the index (f) on the final time, t = tf, and velocity (vf = v) and

write:

=−=∆ t

adtvvv 0

0 (40)

This shows that the change in the x-velocity is the time integral of the x-acceleration. In general,

acceleration may change with time, a = a(t), which gives:

+= t

dttavv 0

0 )( (41)

Using the same arguments, we can rewrite the equation for the displacement as

+= t

dttvxx 0

0 )( (42)

Here x and v are the position and x-velocity at time t. If we know the x-acceleration as a function

of time and we know the initial velocity we can use equation (41) to find the x-velocity at any time,

i.e. as a function of time. Once we know this function, and given the initial position we can use

equation (42) to find the position x at any time.

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 49 of 60

Equations (41) and (42) are called the kinematic equations. Unfortunately, the right-hand

side of each equation is impossible to evaluate without the explicit knowledge of a time-

dependence of velocity or acceleration, i.e. )(tv and )(ta .

In your basic Physics course, you considered the special case in which the acceleration is

constant, a = constant. Recall that a constant can be moved out of an integral. As such, the integral

in equation (41) can be evaluated as

Which gives a very simple formula for the time-dependence of velocity v(t):

atvtavdtavadtvv tt

+=−+=+=+=  000000 )0( (43) This powerful expression enables us to determine an object’s velocity at any time t if we know the

object’s initial velocity v0 and its (constant) acceleration a [10]. A velocity–time graph for this

constant-acceleration motion is shown in Figure 10a [10]. The graph is a straight line, the slope

of which is the acceleration a; the (constant) slope is consistent with dtdva /= being a constant

[10]. Notice that the slope is positive, which indicates a positive acceleration [10]. If the

acceleration were negative, the slope of the line in Figure 10a would be negative [10]. When the

acceleration is constant, the graph of acceleration versus time (Fig. 10b) is a straight line having a

slope of zero [10].

a)

b)

Figure 10 [10]. A particle under constant acceleration a moving along the x axis: (a) the velocity–time graph, and (b) the acceleration–time graph [10].

Because we know how velocity depends on time, atvv += 0 , we can use this expression to

evaluate the integral on the right-hand side of equation (42):

 ++= t

dtatvxx 0

00 )( (44)

First we recall that the integral of a sum is a sum of integrals, i.e.

 ++= tt

dtatdtvxx 00

00 )( (45)

The first integral is easy because the initial velocity (v0) is a constant (naturally, it does not change

with time), so we get:

tvtvdtvdtv tt

00 0

0 0

0 )0( =−==  (46)

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 50 of 60

The second integral is not much more complicated. Because acceleration is constant, we get:

2 22

00 2

1

2

0

2 at

t atdtaatdt

tt

= 

  

 −==  (47)

Combining the results for the two integrals, we get:

2

00 2

1 attvxx ++= (48)

This equation provides the final position of the particle at time t in terms of the initial position, the

initial velocity, and the constant acceleration. Of course in Mathematica, equation (48) can be

obtained from equation (44) in one simple step:

Example 6.1. Suppose, a car is moving along a straight highway. At exactly 4 hours (h) after

beginning its journey, it is 200 km from the starting point (x0), and the speed is 120 km/h (v0). At

this point the driver begins to decrease the speed exponentially (with a constant acceleration) such

that at t = 5 h the car’s speed is 16.240 km/h. (a) Calculate the numerical value of acceleration

Find expressions for (b) x-velocity v and (c) position x as functions of time after t = 4 hours.

Compute the (d) velocity and (e) distance of the car from its starting point at t = 6 hours. Plot (f) x

vs t, and (g) v vs t for t = 4…7 hours

In the first cell, specify the project number:

In the next couple of statements define x0 and v0 as given in the text:

Note that because we do not wish to print those out, we terminate each statement with the “;”

symbol. Now there is a more difficult part. The question says that speed decreases exponentially

with time but acceleration is constant, i.e. at

e −

, where t is time (in h) a is the acceleration (in

km/h2). Note that in this equation t is being counted from 4 hours (because that is when

deceleration started). To bring t to the absolute time scale (i.e. counting t from the beginning of

the journey), I modify t in at

e −

to t-4, i.e. )4( −− ta

e . Note that this equation shows the change in

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 51 of 60

speed, but the initial speed was v0, so I include it in )4( −− ta

e which completes the expression for

v(t):

hours 4for )( )4(

0 ≥=

−− tevtv

ta (49)

where v is speed (in km/h) after t = 4 hours, t is time (in h), and a is the acceleration (in km/h2).

Of course, this equation is valid only for t ≥ 4 hours, because we have no knowledge of how the

car was moving between t = 0 and t = 3.99999… hours. Now I enter this expression into

Mathematica and include a bunch of comments (so I do not forget what I am doing):

Note that in this expression acceleration, a, is not known. But we can certainly determine it

because we know that at t = 5 h the speed (v) was 16.240 km/h. All we need to do is insert these

values of t and v into the formula for v(t) (equation 49) and solve it for a :

Once a is known, we can complete the expression for v(t)

If v(t) is known, we can calculate x(t) using equation (42).

Note that x0 is given in the text. You can easily verify that our expressions for x(t) and v(t) are

correct, by using t = 4 h and t = 5 h and comparing the calculated values of x and v with those

given in the text:

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 52 of 60

They agree!!! Now we can calculate x and v at t = 6 hours:

Finally, plotting x(t) is straightforward:

Note that we, again, used Mathematica’s function SetOptions[Plot, BaseStyle → {FontSize → 14}] to increase the font size in the plots.

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 53 of 60

Let’s see how the v(t) plot looks like:

Now, that wasn’t too bad, was it?!

Integral Calculus is, in general, not easy, so we shall consider another example. This time it is

your favorite subject – Chemistry!

Example 6.2. Consider the following chemical reaction [8,13,14]

PA → k

(50)

where A is a reactant, P is a product, and k is the rate constant [10,6]. Suppose the reaction follows

the first order mechanism, which means that the rate of consumption of A is proportional to the

first power of the concentration of A, [A]:

[A] [A]

k dt

d =− (51)

We need to (a) derive the expression for [A] = f(t) (called the integrated rate law), and (b)

determine the expression for the parameter half-life, t1/2 at which the concentration [A] falls to half

of its original concentration [A]0.

Before we get to Mathematica, we need to rearrange equation (51) in such a way as to

collect terms related to the concentration of A (i.e. [A] and d[A]) on one side of the equation

(suppose, left hand side, lhs) and terms related to time (t) on the other side (suppose, right hand

side, rhs). It does not matter where you put constants such as k and (-1) because they always factor

out of integrals. To this purpose, I rearrange equation (51) as

kdtd −=[A] [A]

1 (52)

In the next step, we need to integrate both sides. Suppose, the left hand side is integrated between

the initial concentration [A]0 and concentration [A] at time t. Then, the right hand side is integrated

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 54 of 60

between the initial time (which we always consider as zero), and time t at which the concentration

of A falls to [A]. The following equation demonstrates that:

 −= t

kdtd 0

[A]

[A]0

[A] [A]

1 (53)

Now, it is time to go to Mathematica. As always, the first cell contains the project number:

Then, we add a comment summarizing the preliminary steps:

We integrate the left hand side:

Note that because Mathematica always thinks that a given symbolic parameter may be complex, I

had to give it additional information about the integrand and the limits of the integration. Indeed,

the initial concentration [A]0 must always be positive, while [A] is always less than [A]0. Note

that while in general, [A] = [A]0 at t = 0, in this particular case it is safer to use the relationship

shown above. As you can see, we make use of the Mathematica command Assumptions: http://reference.wolfram.com/language/ref/Assumptions.html

As expected, the integral on rhs evaluates to   

   

0 [A]

[A] ln . Note that in Mathematica the natural

logarithm is entered as Log[ ], http://reference.wolfram.com/language/ref/Log.html

while the base-10 logarithm is written as Log10[]: http://reference.wolfram.com/language/ref/Log10.html

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 55 of 60

Ok, now we need to evaluate the right hand side of equation (53). This, of course, is very easy:

Now we combine the two sides, and solve for [A]:

Note how I told Mathematica that we are interested in Real solutions only (concentrations can not

be complex!). In the next step, I copy the solution to variable “A” and print it out:

This is exactly the same result as given in your Physical Chemistry textbook [8,13,14].

kt e

− =

0 [A][A] (54)

Now, all we need to do is solve this equation for half-life (t1/2). From the definition of half-life, it

is time (t) at which [A] falls to [A]0/2. We can certainly do that in Mathematica:

Compare our formula with that given in the textbook [8,13,14],

k t

)2ln( 2/1 = (55)

Success!

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 56 of 60

Exercise 6.1. An object is oscillating along the x-axis with acceleration ` (cm s-2) given by the equation

`� � = −Q� sin ST� V (56) where t is in seconds. Suppose, the object initial velocity was 2Q (cm s-1) and the initial position was 1 cm. Using your Mathematica notebook for Example 6.1 as a template, derive the

expressions for (a) ^� � and (b) 6� �. (c) On the same graph (set FontSize to 14, set ImageSize to 600, and include the plot legend as shown in section 4 of this tutorial), plot x, ^, and ` vs for t = 0…6 s. Save the notebook as “Exercise_6.1.nb”. Warning! All calculation steps must be

performed in your Mathematica notebook, and all items (a-c) must be clearly labelled in the

Print[]Print[]Print[]Print[] functions, or the score for this exercise will be zero! Answers: (a) 2Q cos ST� V (cm s-1) (b) 1 + 4 sin S

T � V (cm)

(c) …

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 57 of 60

Exercise 6.2. An object is moving along the x-axis with acceleration ` (m s-2) given by the equation

`� � = Na<bU (57) where M and N are some constants (M is in s-1, and N is in m s-2), and t is in seconds. Suppose the object initial position (at t = 0 s) was 6c and its initial velocity was ^c. Using your Mathematica notebook for Example 6.1 as a template, determine equations for the object (a) x-velocity and (b)

x-position as a function of time and general constants 6c, ^c, M and N. Suppose, at = 2 s the object was moving with velocity

= d −

de fgh b (m s

-1), and at = 4 s the object was located at M + Wd + de fih

bg (m). Determine and simplify the values of (c) ^c and (d) 6c in terms of coefficients M and N. Derive and simplify the expressions for (e) ^� � and (f) 6� � in terms of time and coefficients M and N. Save the notebook as “Exercise_6.2.nb”. Warning! All calculation steps must be performed in your Mathematica notebook, and all items (a-f) must be clearly labelled in the

Print[]Print[]Print[]Print[] functions, or the score for this exercise will be zero! Answers: (a) … (b) …

(c) = d −

d b (m s

-1) (d) M + dbg (m)

(e) … (f) M + Ud + de fjh

bg (m)

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 58 of 60

Exercise 6.3. In this final exercise you will follow a 1911 determination of Avogadro’s number

(the currently established IUPAC value is NA = 6.02214179×10 23 mol-1 [16]) based on the rate of

emission of M-particles by radium (Ra, Z = 88), and the rate of production of helium by radium. In case you have forgotten, an M-particle is just a bare nucleus of the helium-4 isotope ( He�W ) that carries a positive charge of +2. Radium undergoes M-decay to yield radon (Rn, Z = 86) [17]:

HeZZ��k → HeZk��� + He�W The rate of emission of M-particles by radium was determined by Rutherford and Geiger [18] to be 3.4×1010 M-particles per second per 1 g of radium.

Then, Boltwood and Rutherford [19] separated some radium salt from its decomposition

products and measured the volume of helium produced after known times. They found that from

192 mg of radium 6.58 mm3 at STP of helium was produced in 83 days, and 10.38 mm3 at STP in

132 days. The half-life of radon ( =/�) is 3.83 days (d). STP stands for “standard temperature and pressure”. Until 1982, STP was defined as a temperature of 273.15 K and pressure of exactly 1

atm; since 1982, STP is defined as a temperature of 273.15 K and pressure of exactly 1 bar = 105

Pa [20].

Boltwood and Rutherford also derived the following formula for the total quantity of

helium produced �l�: l = 6m + 36 n o1 − a<pU q[ rc (58)

where 6 is the rate of production of helium by the radium itself, m - period of accumulation of helium, and s is the decay constant of radon. From 6 we can obtain the number of moles of helium produced by 1 g of radium per second. Comparing this with the actual number of M-particles emitted by 1 g of radium per second we obtain Avogadro’s number. Warning! All calculation

steps (a-j) must be performed in your Mathematica notebook, and all result (a-j) must be

clearly labelled in the Print[]Print[]Print[]Print[] functions, or the score for this exercise will be zero! The following sequence of steps is required:

(a) evaluate the right hand side (r.h.s) of equation (58), t�m, 6, s� (b) rearrange equation l = t�m, 6, s� to 6 = t�l, m, s�, (c) calculate the decay constant of radon, s = uv �Uw/g (d

-1),

(d) determine the value of 6= S xx y z{ |}~

� V - the rate of production of helium by 192 mg of radium for m= = 83 d and l= = 6.58 mm3 at STP,

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 59 of 60

(e) determine the value of 6� S xx y z{ |}~

� V - the rate of production of helium by 192 mg of radium for m� = 132 d and l� = 10.38 mm3 at STP,

(f) using the Mathematica function Mean[] calculate the average value of 6 S xxy z{ |}~� V,

(g) convert the average value of 6 from S xxy z{ |}~� V to S x�u

� V; recall that … • 1 mol of gas at STP occupies 22.4 L, • 1 L = 10 cm × 10 cm × 10 cm, • 1 cm = 10 mm, • 1 d �day� = 24 hours, 1 hour = 60 min, 1 min = 60 s,

(h) calculate the rate of production of helium S x�u� V by 1 g of radium (note that the value of 6 calculated at the previous step is the rate of production of helium by 192 mg of radium),

(i) since the rate of emission of M-particles by 1 g of radium is 3.4×1010 s-1, our (technically,

Rutherford’s) experimental Avogadro’s number, ��,��� = �.W×=cw�S w�V

� S ���� V ,

(j) calculate the percent error for ��,��� relative to the currently established value; how well do you think they did in 1911 ?

Answers: (a) … (b) e ���p

��e ���<��Wrp� (c) …

(d) … (e) … (f) 2.06×10-2 xxy z{ |}~

(g) … (h) 5.54 × 10<=W x�u� (i) … (j) …

Whew, wasn’t it fun?! � Believe it or not, but this concludes our brief Mathematica tutorial. We hope that we have been able to convince you that this amazing software can provide a significant

help in learning subjects like Mathematics, Physics, and Chemistry (recall that Physical Chemistry

= Mathematics + Physics + Chemistry).

Computer Laboratory 1: Mathematics of Physical Chemistry revision 8/21/18

page 60 of 60

7. References

1. Wolfram Research, Inc. Mathematica 9.0. Champaign, Illinois, USA, 2012.

2. http://www.wolfram.com/mathematica

3. https://en.wikipedia.org/wiki/Mathematica

4. https://en.wikipedia.org/wiki/Stephen_Wolfram

5. https://en.wikipedia.org/wiki/Wolfram_Research

6. Tam, P. T. A Physicist's Guide to Mathematica, 2nd edition, Academic Press, 2008.

7. https://www.duolingo.com/comment/15264140/How-To-Type-Accented-Characters-On-An-

English-Keyboard-Windows-10-Tutorial

8. Atkins, P; de Paula, J. Elements of Physical Chemistry, 5th edition, W. H. Freeman, New York, 2009.

9. Serway, R. A., Vuille, C. College Physics, 9th edition. Cengage Learning, 2011.

10. Serway, R. A., Jewett, J. W. Physics for Scientists and Engineers with Modern Physics, 9th

edition. Brooks Cole, 2013.

11. Young, H. D., Freedman, R. A., Ford, A. L. Sears and Zemansky’s University Physics with

Modern Physics, 13th edition. Pearson Education, Inc., 2012.

12. Barrante, J. R. Applied Mathematics for Physical Chemistry, 3rd edition. Prentice Hall; 2003.

13. Atkins, P; de Paula, J. Physical Chemistry, 8th edition, W. H. Freeman and Company, New

York, 2006.

14. Atkins, P; de Paula, J. Elements of Physical Chemistry, 6th edition, W. H. Freeman, New York, 2012.

15. Ball, D. W. Physical Chemistry, 1st edition. Cengage Learning; 2002.

16. http://goldbook.iupac.org/html/A/A00543.html

17. Silberberg, M. Principles of General Chemistry, 1st edition. McGraw-Hill, 2007.

18. Rutherford, E. & Geiger, H. Proc. Roy. Soc. A, 81, 141, 1908.

19. Boltwood, B. B. & Rutherford, E. Phi. Mag., 22, 586, 1911.

20. http://en.wikipedia.org/wiki/Standard_conditions_for_temperature_and_pressure