Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
\
|
= =
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.