Sei sulla pagina 1di 9

1

Department of Chemistry, BHU


CHM-401(P): Computer Applications in Chemistry (Practical)
M. Sc. (IV Semester) 2011 2012


NOTE: Submitting Practical Notebook is mandatory.

A computer is a machine which manipulates data according to a list of instructions. It has
different components. The major components are:
1. CPU:
Abbreviation of central processing unit, and pronounced as separate letters. The CPU is the
brains of the computer. Sometimes referred to simply as the processor or central processor, the
CPU is where most calculations take place. In terms of computing power, the CPU is the most
important element of a computer system.
On large machines, CPUs require one or more printed circuit boards. On personal computers and
small workstations, the CPU is housed in a single chip called a microprocessor.
Two typical components of a CPU are:
The arithmetic logic unit (ALU), which performs arithmetic and logical operations.
The control unit (CU), which extracts instructions from memory and decodes and
executes them, calling on the ALU when necessary.
Motherboard - This is where the core components of your computer reside which are listed
below. Also the support cards for video, sound, networking and more are mounted into this board.
(i) Microprocessor - This is the brain of your computer. It performs commands and
instructions and controls the operation of the computer.
(ii) Memory - The RAM (Random Access Memory) in your system is mounted on the
motherboard. This is memory that must be powered on to retain its contents.
(iii) Drive controllers - The drive controllers control the interface of your system to your
hard drives. The controllers let your hard drives work by controlling their operation. On most
systems, they are included on the motherboard; however you may add additional controllers for
faster or other types of drives.
Hard disk drive(s) - This is where your files are permanently stored on your computer. Also,
normally, your operating system is installed here.
2. Monitor: This device which operates like a TV set lets the user see how the computer is
responding to their commands.
3. Keyboard: This is where the user enters text commands into the computer.
4. Mouse: A point and click interface for entering commands which works well in graphical
environments.
2

Operating system: Operating systems provide a software platform on top of which other
programs, called application programs, can run.


The most commonly used operating system are Windows, Disk Operating System (DOS) e.g. MS-DOS
(short for Microsoft Disk Operating System), UNIX, Linux.
We shall mostly be using DOS through out this course.

How to put on a computer safely?
Please follow the following sequence: (a) put on the main power switch, (b) put on the
monitors power switch, and then (c) CPU power switch. Then wait until the computer is
booted fully.
To open command prompt in MS-DOS:
(i) Click on the start icon (at the left-bottom corner) select all programs
select Accessories select command prompt; a window will appear and
you will be in C:\ drive.
(ii) Change the drive to D:\ by typing d: and then press enter
Few commands for DOS:
To list the present directories or files: type dir and then press enter

To make a new directory: type md directory-name (your choice) and then press enter;
e.g. md MSc1 will create a directory called MSc1.

To change directory: type cd directory-name and then press enter; e.g. cd MSc1
command will let you to get in directory MSc1.

To open a new file or edit an existing file: edit fl-name and then press enter, a new
window will open where you can type or edit. Then click on file to get options to save,
exit etc. There are two options for saving a file (or modified file): save as and save. The
former will allow giving a file name that is easy to remember, but the later will over write
on the existing file name.

To rename a file: ren filename (or directory-name) and then enter; e.g. ren MSc1 MSc2
will rename the directory MSc1 to MSc2.
To copy an existing file with different name: copy fl-name new-fl-name; e.g.
copy test.for first.for will copy the content of test.for into first.for.

3

Department of Chemistry, BHU
CHM-401(P): Computer Applications in Chemistry (Practical)
M. Sc. (IV Semester) 2011 2012
Problem Set I

For numerical calculations there are different computer programming languages, like
FORTRAN, C, C++ etc. We will be using FORTRAN (stands for FORmula
TRANslating system) throughout this course as we believe till the date this the best
programming language for numerical calculations.

Using FORTRAN:

1. Compute and print the addition of 5, 10, 17.
2. Add 1 to 10 and print on the screen.
3. Evaluate (10 + 19.7 + 20.5 + 34.5 + 37 + 45.5 + 50 + 60.5 + 65 + 70.9 + 85.3).
4. Add 1.2+2.2+3.2+4.2+.up to 1000
th
term.

Mean and standard deviation:

Mean =
N
X
N
i
i
=1
; N = number of data Standard deviation =
2
1 1
2
|
|
|
|

\
|


= =
N
X
N
X
N
i
i
N
i
i

Q1. Write a FORTRAN code to evaluate the mean and standard deviation using the
following data
i 1 2 3 4 5 6 7 8 9 10 11
X
i
5 6 4 7 3 8 5 6 4 5 6

Q2. Consider a function f(x) = 2x + 3. When x varies from 1 to 2 with an increment of
0.001, compute the mean and standard deviation of the function f(x) using FORTRAN.


Hints:
First we have to feed the data.
X and X
2
should be evaluated. For these we can define two variables, let S and S2,
respectively.

S=0.0
S2=0.0
DO I = 1,N
READ(*,*) X
S = S + X
S2 = S2 + X*X !(OR X**2)
ENDDO

4

123456789..72
C TO COMPUTE MEAN AND STANDARD DEVIATION
WRITE(*,*) ENTER THE VALUE OF N
READ(*,*) N
WRITE(*,*) ENTER THE DATA FOR X
S=0.0
S2=0.0
DO I = 1,N
READ(*,*) X
S = S + X
S2 = S2 + X*X !(OR X**2)
ENDDO
AN = FLOAT (N)
AMEAN = S/AN
AMEAN2= AMEAN*AMEAN
TERM= S2/AN AMEAN2
SD = SQRT(TERM)
WRITE(*,*) MEAN = , AMEAN
WRITE(*,*) STANDARD DEVIATION = ,SD
STOP
END

Write the code using DIMENSION statement and ARRAY, to solve the second problem.























5

Department of Chemistry, BHU
CHM-401(P): Computer Applications in Chemistry (Practical)
M. Sc. (IV Semester) 2011 2012
Problem Set II

Correlation coefficient:
Let there be two sets of observations X
1
, X
2
,.X
N
and Y
1
,Y
2
,.Y
N
. The
correlation coefficient between these two sets of observations is defined as:

Correlation coefficient =
2 / 1
2
2
2
2
/ /
/
(
(

\
|

\
|



N Y Y N X X
N Y X Y X
i i
i i
i i
i i
i
i
i
i
i
i i

Q. Develop a FORTRAN program to calculate the correlation coefficient between two
sets of data having N observation each as follows:
X: 18 16 18 12 20 17 18 20 22 20 10 8 20 12 16 16 18 20 18 21
Y: 20 22 24 10 25 19 20 21 23 20 10 12 22 14 12 20 22 24 23 17

Ans: 0.79309

t-ratio:
Often a test that is employed to determine whether there is a significant difference
between the means of two samples, or whether the difference could have occurred by
chance, is known as t-ratio. The formula of the t-test is:
2
2
2
1
2
1
2 1
N
S
N
S
M M
t
+

= ,
Where, M
1
= mean of sample 1, M
2
= mean of sample 2,
S
1
= standard deviation of sample 1, S
2
= standard deviation of sample 2
N
1
= number of observation of sample 1, N
2
= number of observation of sample 2
Mean (M) =
N
X
N
i
i
=1
; Standard deviation (S) =
2
1 1
2
|
|
|
|

\
|


= =
N
X
N
X
N
i
i
N
i
i



Q. Given two sets of data of two observations as:
Set I 26 24 18 17 18 20 18
Set II 38 26 24 24 30 22

Write a FORTRAN program to compute t-ratio for the data.

Ans: -2.864
6

Q1. Suppose you are measuring the spectral intensity of an organic sample with varying
concentration in the range 0.5 to 3.5 mol/L, using 0.05 mol/L variations. Your spectral
data fit to a Lorentzian function I(c) =
2
) 0 . 2 ( 1
1
+ c
. Your friend also did the same
experiment but his/her spectral data fit to a Gaussian function I(c) = exp{-(c-2.0)
2
}.
Write a FORTRAN program to calculate the correlation coefficient between you and
your friends observation.

Ans. 0.998903

Q2. Write a FORTRAN code to calculate the t-ratio for the two sets of data obtained in
the above experiment.

Ans. 1.76384
































7

Department of Chemistry, BHU
CHM-401(P): Computer Applications in Chemistry (Practical)
M. Sc. (IV Semester) 2011 2012
Problem Set III
Integration
In the
1
H-NMR spectra the amount of energy absorbed at each frequency is proportional
to the number of protons absorbing. Consequently, the area under each set of spectral
lines is proportional to the relative number of protons absorbing. Many machines give
this information directly by plotting an integration curve on the spectrum as follows.

Now the question is how to do the numerical integration for a curve f(x)?
We know that

b
a
dx x f ) ( is the area bounded by the curve y = f(x) and an x-axis in
between the ordinates x = a and x = b. We can assume that it is a trapezoid; the two
parallel sides are f(a) and f(b).


The area of the trapezoid is
2
) ( ) ( )( ( b f a f a b +
=

b
a
dx x f ) ( . This formula will give
meaningful result only when the interval (a,b) is very small. If we want to find the
integral over an interval (a,b), we must first divide the interval into a number of equal
subintervals: a = x
1
< x
2
< x
3
< .< x
n
= b, where x
i+1
x
i
= h

b
a
dx x f ) ( = ) (
2
....... .......... ) (
2
) (
2
1 3 2 2 1 n n
f f
h
f f
h
f f
h
+ + + + + +


= ) 2 ....... .......... ) 2 2 (
2
1 3 2 1 n n
f f f f f
h
+ + + + +


8

Q1. Develop a program to integrate the function f(x) = x(x+1), where x varies in the
range 0.0 to 4.0 when the total interval is divided into n=100 parts.

Ans: 29.23 (exact value=29.3333, the difference is due to the approximation nature
of the trapezoidal rule).

Q2. Evaluate

8 . 0
0
tan
dx e
x x
using FORTRAN programming.
Ans: 1.05973 (with 8 intervals)
Simpson's Rule: In the example above, you can see that the Trapezoidal Rule provides
a reasonable approximation to a definite integral if we take a large number of steps.
Notice that the error in the approximation originates in the fact that general graphs are
curved and we are approximating them by straight lines. We will now form an
approximation which takes into account the curvature of the graph: the result is a more
efficient approximation called Simpson's Rule.
Simpson's Rule is formed by approximating a general curve by a parabola. We start by
partitioning [a, b] into intervals all of the same width, but this time we must use an even
number of intervals, so n will be even.
Q. Why?
A. As with the trapezoid rule, we want to approximate the areas in each strip by
something more complicated than a rectangle. This time we take the strips in pairs (which
is why we need an even number of them) and draw a parabola through the three
points (x
k
-
1
, f(x
k
-
1
)), (x
k
, f(x
k
)), and (x
k+1
, f(x
k+1
)), as shown in the figure. It is then not
too difficult to find the equation of this parabola (it has the form y = Ax
2
+Bx+C), and
from that to find the area underneath by integrating. The remarkably simple answer
is: area under parabola = [ ] ) ( ) ( 4 ) (
3
1 1 +
+ +

k k k
x f x f x f
n
a b

When we add the area under the parabola over the first two strips to the area under
the parabola over the 3rd and 4th strips, and so on, we get Simpson's rule:
[ ]

+ + + + + +


b
a
n n n
x f x f x f x f x f x f x f
n
a b
dx x f ) ( ) ( 4 ) ( 2 )....... ( 4 ) ( 2 ) ( 4 ) (
3
) (
1 2 3 2 1 0

Q1. Use 6 intervals in Simpson's rule to approximate


6
0
2
dx e
x
. Ans: 0.83621
Q2. Using Simpsons approximation evaluate ( )

+
2
1
3
dx e x
x
accurate to four decimal
places? Compare the result with trapezoidal approximation.
9

Department of Chemistry, BHU
CHM-401(P): Computer Applications in Chemistry (Practical)
M. Sc. (IV Semester) 2011 2012
Problem Set IV

Matrix algebra is a very useful tool in chemistry; like group theory, spectra etc.

Q1. Consider two matrices: A=
(

2 3 7
8 5 1
and B =
(

12 27 8
9 15 13
. Write a
FORTRAN code to evaluate 2A 3B, and find the transpose of the resultant matrix.

Q2. M and N are two following matrices:
M=
(

6 5 4
3 2 1
; N=
(
(
(


9 0 9 0
4 3 2 1
8 7 6 5
. Write a FORTRAN code to obtain
T = MN. Also obtain the transpose of the matrix T.

Q3. Consider a 3x3 matrix P =
(
(
(


0 9 0
3 2 1
7 6 5
Write a FORTRAN program to obtain
Q = 3P
2
- 2P
3
. Also obtain R = Q Q
t
, where Q
t
is the transpose of Q. Use a subroutine
subprogram to write the code.

Q4. Repeat the Q3 using an identity matrix, I =
(
(
(

1 0 0
0 1 0
0 0 1
, instead of P.

Potrebbero piacerti anche