0% found this document useful (0 votes)
11 views37 pages

CH332 28jan

The document outlines the course CH 332 on Computational Chemistry, focusing on numerical analysis and its applications in solving mathematical problems relevant to chemistry. It discusses the differences between analytical and numerical methods, classifications of numerical methods, and their practical applications such as curve fitting, integration, and optimization. Additionally, it emphasizes the importance of understanding mathematical modeling, approximations, errors, and significant digits in computational work.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views37 pages

CH332 28jan

The document outlines the course CH 332 on Computational Chemistry, focusing on numerical analysis and its applications in solving mathematical problems relevant to chemistry. It discusses the differences between analytical and numerical methods, classifications of numerical methods, and their practical applications such as curve fitting, integration, and optimization. Additionally, it emphasizes the importance of understanding mathematical modeling, approximations, errors, and significant digits in computational work.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

CH 332

Computational Chemistry

Course Instructor: Dr. Debdas Dhabal

Department of Chemistry, IIT Guwahati


28 January 2024
Outline

ØWhat is Numerical Analysis?


ØTopic-wise classification
ØAn overview of some commonly used numerical
methods
ØMathematical modeling and problem-solving
ØSolving the same problem both analytically and
numerically
ØApproximations and Errors in Computing
ØSignificant digits
Numerical analysis

“A mathematical tool designed to solve numerical problems”


or
“Techniques by which mathematical problems are formulated so that they can be
solved with arithmetic operations.” Chapra et al. (2015)

When do we need it?


o Analytical solutions do not exist
o Experimental data do not permit the direct use of existing analytical methods

Note: The numerical method not only solves a problem but also provides
computable error estimates of the procedures it uses.
Difference between analytical and numerical methods

Analytical Numerical
o Analytical methods provide the exact o Numerical methods provide
solution approximate solutions.

o We have well-defined equations to solve o We don’t have well-defined


the problem equations to solve the problem

A simple example to understand the difference


You will use the
You have a function fundamental theorem of
calculus
You want to calculate But now let’s say you
the integration have this function
Can you do this easily?
Numerical Method Classification
vBroadly, numerical methods can be classified into three categories based on the topics of
mathematics

o Numerical Linear Algebra: solutions of linear systems a=xb, eigenvalues and


eigenvectors, matrix factorization
o Calculus: Solution of nonlinear equations f(x)=0, differential differentiation and
integration, and interpolation.
o Statistical: Polynomial approximation, fitting

Let’s talk a bit more about some of these specific topics!

How can we, as a (physical) chemist, benefit from these methods?


1. Roots of equations
Solve f(x)=0 for x Let’s take a real-life example: Throw a ball in the air

Where do we use this? At what time the ball will reach the ground?
Ø y is the height of the ball from the ground.
Ø Now when the ball reaches the ground; y=0 and –x2+4x+5 = 0; finding the value of x for which y=0 will
solve the problem. That is the root of that equation

For quadratic equation: We have an analytical solution


Now let’s say a certain process follows this algebraic equation
−𝒃 ± 𝒃𝟐 − 𝟒𝒂𝒄
𝒙=
𝟐𝒂 y=3x1.5+6x We need a numerical solution!!
2. Curve fitting
Curve fitting: Both regression
and interpolation are a special case Real-life example: Arrhenius plot
Data:
of curve fitting #k(s-1) T(K)
0.022 1400 1
0.07 1460 Raw data
0.21 1520 Fitted line
0
0.686 1580
1.578 1620 −1

ln (k)
−2

−3

−4
6.0x10−4 6.4x10−4 6.8x10−4 7.2x10−4
1/T

You can find out the value of the rate


constant at any arbitrary temperature
3. Integration
𝒃
Integration: 𝑰 = ∫𝒂 𝒇 𝒙 𝒅𝒙
Use in physical chemistry: Maxwell-Boltzmann distribution

Find the area under the curve

You may want to calculate the percentage of particles


with certain range of speed
4. Derivative
𝒅𝒇(𝒙)
Derivative: 𝒇# (𝒙) =
𝒅𝒙
Use in chemistry: pH titration curves; finding the
accurate value of the equivalence point

There are many numerical methods to find the


Derivative of sin(x) is cos(x): Analytical ) +
solution value of )*
sin ,
= 0.7071
5. Optimization

Optimization: finding the maximum or Use in physical chemistry: Protein folding pathway
minimum of a function

Determine x that gives optimum f(x)

Then, the parameters of


For some problems, it can be However, it is relatively easy to that function can be
difficult to figure out the set up a loss function that minimized to find the
best solution directly. measures how good a solution is. solution.
6. Linear algebraic equations
Linear algebraic equations: a=xb
Let’s take a simple example to understand this

Given the a’s and the c’s, solve


a11x1 + a12x2 = c1
a21x1 + a22x2 = c2
for the x’s.

Use in chemistry: Linear algebra is used to


balance chemical equations

xA + yB = zC https://youvegotthismath.com
7. Ordinary Differential equations

Ordinary differential equations: an


equation that contains only the ordinary Use in physical chemistry: Newton’s law of cooling
derivatives of one or more dependent
variables of a single independent
variable Linear first order differential equation:

𝑑𝑇
= 𝛼(𝑇 − 𝑇* )
𝑑𝑡
𝛼à constant
Tà initial temperature
Tmà temperrture after cooling

)- ∆-
Given ≈ = 𝑓 𝑡, 𝑦 , Rate of a first-order reaction:
). ∆.
solve y as a function of t
𝑦012 = 𝑦0 + 𝑓(𝑡0 , 𝑦0 )∆𝑡
Mathematical modelling and problem solving

“No matter how impressive tool you have, you will have a hard time repairing a
car if you do not understand how it works.”
Chapra et al. (2015)

The same analogy applies to solving a chemistry problem

o Same starting material, different product:


Identify the reagents

o To correctly answer these questions, you


need an understanding of the main
principles of addition reaction

Similarly, computers are practically


useless without a fundamental
understanding of how engineering
systems work.
A mathematical model

A mathematical model can be broadly defined as a formulation or equation that expresses the essential features of a
physical system or process in mathematical terms.

Dependent variable = f(independent variable, parameters, forcing functions)

A characteristic that Independent reflective of the external influences acting


usually reflects the variables are usually system’s properties upon the system
behavior or state of dimensions, such as or composition
the system time and space

𝒏𝑹𝑻
𝒑=
𝑽
Dependent variable three independent variable
Characteristics of a mathematical model

o It should describe a natural process or system in mathematical terms.


o It should represent an idealization and simplification of reality.
o It should yield reproducible results and, consequently, can be used for predictive
purposes.

A mathematical expression or a model of the second law is


𝑭 = 𝒎𝒂

𝑭 the forcing function


𝒂=
𝒎
a parameter representing
dependent variable the property of the system
Terminal velocity of a free-falling body
The falling parachutist
𝑑𝑣 𝐹
= where v is velocity and t is time
𝑑𝑡 𝑚

Two opposing forces: the downward pull of gravity FD and


𝐹 = 𝐹3 + 𝐹4 the upward force of air resistance FU

𝐹" = 𝑚𝑔 g = the gravitational constant = 9.81 m/s2

𝐹# = −𝑐𝑣 proportional to the velocity but in an opposite direction

Advanced techniques, such as calculus, must be applied to obtain an exact or


analytical solution
v(t) à the dependent variable, t à the
𝒈𝒎 5
𝒄
𝒗 𝒕 = 𝟏−𝒆 𝒎 𝒕 independent variable, c and m à parameters,
𝒄 and g à the forcing function.
Analytical solution to the falling parachutist problem

o A parachutist of mass 68.1 kg jumps out of a stationary hot air balloon. Compute the velocity
before opening the chute. The drag coefficient is equal to 12.5 kg/s.

9.81×68.1 5
29.;
𝑣 𝑡 = 1−𝑒 <=.2 .
12.5

• After a sufficiently long time, a


constant velocity, called the
terminal velocity, of 53.44 m/s is
reached

• The force of gravity will be balanced by


the air resistance.

Note: this is an analytical, or


exact, solution
Let’s solve the same problem using numerical method

The change of velocity can be approximated by

𝑑𝑣 Δ𝑣 𝑣 𝑡012 − 𝑣(𝑡0 )
≅ = because ∆t is finite
𝑑𝑡 Δ𝑡 𝑡012 − 𝑡0

a finite divided difference approximation of the derivative at time ti.

𝑑𝑣 Δ𝑣
Note: = lim
𝑑𝑡 ∆.→? Δ𝑡

𝑣 𝑡012 − 𝑣(𝑡0 ) 𝑐 The differential equation has been transformed into


= 𝑔 − 𝑣(𝑡0 )
𝑡012 − 𝑡0 𝑚 an equation that can be used to determine the
velocity algebraically at ti+1 using the slope and
𝒄 previous values of v and t
𝒗 𝒕𝒊3𝟏 = 𝒗 𝒕𝒊 + 𝒈 − 𝒗(𝒕𝒊 ) 𝒕𝒊3𝟏 − 𝒕𝒊
𝒎 This approach is formally called Euler’s method
Numerical solution to the falling parachutist problem

o Perform the same computation as before but numerically to compute the velocity.
Employ a step size of 2 s for the calculation.

when ti=0, v(ti)=0 Let’s say 𝑡012 − 𝑡0 = 2 𝑠

12.5
velocity at ti+1 𝑣 = 0 + 9.81 − (0) ×2 = 19.62 𝑚/𝑠
68.1

We repeat the same for the next interval (from 2 to 4 s)

12.5
𝑣 = 19.62 + 9.81 − (19.62) ×2 = 32.04 𝑚/𝑠
68.1

….and so on
Numerical method captures the essential features of the exact
solution

o Some discrepancy between the two results: We used


straight-line segments to approximate a continuously
curving function

How to minimize this error?

o Use a smaller step size (eg. 1 s): as the straight-line


segments track closer to the true solution

o The pen-paper calculation seems impractical if you


want to use a very small step size

Computers can save us!!


With the aid of the computer, such calculations can be
performed easily.
A FORTRAN code for the analytical solution

Output:
FORTRAN code for the numerical solution
The numerical approach gives the same result as Analytical when we
use a very small timestep

If we use smaller and smaller steps


Numerical solution with dt = 2 s
60
60
50
50
40
40

t (m/s)
t (m/s)

30
30
Analytical
20
20 Numerical (dt = 2s)
Analytical 10 Numerical (dt = 1s)
10 Numerical (dt = 2s) Numerical (dt = 0.1s)
0
0 0 4 8 12 16 20
0 4 8 12 16 20
t (s)
t (s)
We cannot ignore the existence of errors in numerical
methods
“Approximations and errors are an integral part of human life” Numerical methods,
Balagurusami (2013)

To do science, we must
do experiments and
analysis (either in the Collect data Error
lab or on the
computer)
Some errors
Human errors
are avoidable

Some errors are data conversion and


unavoidable round-off errors

Let’s review basic concepts of approximate representation of numbers


Significant Digits
vSignificant digits (or significant figures) are the number of digits in a given value that carry a
contribution to a measurement and are necessary to indicate the accuracy and precision of
numerical value.
𝝅 =3.1415926535897932384626

3.14 3.14159 3.14159265


round-off error
o This is a transcendental number: can never be represented accurately

3.14 3 significant figures


3.14159 6 significant figures
3.14000 6 significant figures
0003.14 3 significant figures
Rules for the the notion of Significant Digits

Non-zeros are
significant

Trailing zeros
Leading zeros
following a
are not 0.0003100400 decimal point
significant
are significant
zeros between
non-zero digits
are significant
Detailed explanation
o All non-zero digits are significant. o All zeros in between non-zero digits are significant.

3.1415 -----> 5 23.0041 -----> 6


3141.5 -----> 5 4005 -----> 4

o Trailing zeros following a decimal point o Zeros on the right of a decimal point and before the
are significant first non-zero digit are not significant. They only
represent the position of the decimal point.
3.1400 -----> 5
0.00031415 -----> 5
65.000 -----> 5
0.0031415 -----> 5
0.23000 -----> 5
0.031415 -----> 5
o When the decimal point is not written,
trailing zeros are not considered to be 31415 × 10 -8 -----> 5
significant 31415 × 10 -7 -----> 5
31415 × 10 -6 -----> 5
4500 = 45 × 102 -----> 2
A decimal rounded from 6 significant digits to 1 significant
digit
Errors associated with measurements can be characterized by their
accuracy and precision
o Accuracy refers to how closely a
computed or measured value agrees with
the true value.
o Precision refers to how closely individual
computed or measured values agree with
each other.
Let’s say you are estimating the root of an
equation, and you know the true value is 1.0

1.001 1.173 2.814 0.312


1.000 1.284 2.837 6.398
0.998 0.881 2.822 2.141
1.002 0.917 2.819 0.805
accurate accurate inaccurate inaccurate
and but but and
precise imprecise precise imprecise
Taxonomy of Errors
Inherent Errors
an automobile speedometer
Data error (empirical error):
o When data for a problem are obtained from
experiments
o Limited accuracy and precision
o There may be limitations to experimentation and
reading

Conversions error (representations error):


o When there is a limitation of the computer to store the data exactly
Let’s say a computer uses 8 binary digits: A computer uses 16 binary digits:

0.110 = 0.00011001 0.110 = 0001100110011001


0.410 = 0.01100110 0.410 = 0110011001100110
sum = 0.01111111 = 0.49609375 sum = 0.0111111111111111 = 0.4999847412109375
error = 0.00390625 error = 0.00001525878906
Numerical Errors
o Numerical errors (or procedural errors) appear during the implementation of a numerical
method.
Roundoff errors:
o It occurs when a fixed number of digits is used to represent an exact number.
o Even though an individual roundoff error could be very small, the cumulative effect of a series of computations
can be very significant.
o There are two ways Chopping: Symmetric roundoff:
o 42.7893 ------> 42.78 o 42.7893 ------> 42.79

Truncation errors:
o Arise from an approximation in place of an exact mathematical procedure.
o Appears a lot in numerical analysis because many of them are iterative procedures and the computing is
infinite
We terminate
The sum of ' ( the process
$ ≈ 6 𝑎 𝑥$
Sine of an 𝑥 ) 𝑥 * 𝑥 +
after a certain
an infinite 𝑆 = 6 𝑎$ 𝑥 $ sin 𝑥 = 𝑥 − + − + …
angle with a 3! 5! 7! term is
series $%& $%&
series calculated
Modelling errors
o Mathematical models are the first step (basic input) in designing numerical solutions
o We try to develop a model as accurate as possible. However, in many situations, it is
impractical/impossible to include all real problems. So, we take some assumptions

Let’s go back to the free-falling parachutist problem

Total force:
𝐹 = 𝐹3 + 𝐹4 𝐹3 = 𝑚𝑔 𝐹4 = −𝑐𝑣

Assumption:
We may not be able 1. Force due to air
to estimate the air resistance is linearly
resistance properly proportional to the
velocity of the falling
o We can reduce errors by refining or enlarging body
the models by incorporating more features ---- 2. there is no wind force
> But this makes the model more difficult to acting on the body
solve
Blunders
o Errors due to human imperfections
o Such errors may cause serious disaster in the result.
Some common types of errors are:
o Lack of understanding of the problem
o Wrong assumptions
o Overlooking some basic assumptions required for formulating the model
o Selecting the wrong numerical method for solving the mathematical model
o Wrong guessing of initial values
o Making mistakes in the computer program

These errors could be avoided


Absolute and Relative errors
True value xt = Approximate value xa + Error
Error = xt - xa
In error analysis, the magnitude is important
Absolute error: 𝑒D = 𝑥E − 𝑥D
An absolute error may not reflect its influence correctly as compared to the
magnitude of the value under study
absolute error
Normalization is required 𝑒@ =
true value

𝑥. − 𝑥A
𝑒@ =
𝑥.

𝑥. − 𝑥A
Percent relative error: 𝑒@ = ×100
𝑥.
Minimizing the Errors

o Let’s assume that the mathematical model is properly formulated, and the input
data are accurate
1. Increasing the significant figures of the
Truncation error can be reduced by
computer
decreasing step size: But it can increase the
o 0.110 = 0.00011001 (8 binary digits) vs 0.110 = roundoff error
0001100110011001
o Use double precision for floating point
calculation
2. Minimizing the number of arithmetic
operations
o ax+bx could be written as (a+b)x
3. Avoiding subtractive cancellations
! ! "# !
o could be written as 𝑥 + 𝑦
!"#
4. Choosing the proper initial parameters
Process and Job-control

THANK YOU!

You might also like